-2

I'm trying to make a "very simple" syntax highlight for "cottle" (which is a script language used in a text-to-speech app dedicated to Elite:Dangerous). All i want (at least at the beginning) is to have three different colours: Comments, "non-strings", and strings.

I started trying with the ST3 wiki, youtube tutorials, questions here.... but i can't sort out how to do it, 'cause the way the language work. I'll try to show you an example

{ everything_between_a_pair_of_brackets_is_code }
everything outside all pairs of bracket is a string {_ and this is a comment. It begins with "_" and ends at the closing bracket }
{ This_is_code("but this is a string")
  This_is_still_code("this is also a string {but_this_is_code(\"and a string\")} and this the end of the string")
}

My problem is how to define this kind of "nidification" in my cottle.sublime-syntax file. I managed to get the comment, but only the first one.


- EDIT -


This is a real script:

{event.item} 
{if event.repairedfully:
    fully repaired
|else:
    partially repaired 
    {Occasionally(2,
        cat(
            OneOf("to ", "at "),
            Humanise(event.health * 100),
            " percent functionality"
        )
    )}
}

{Occasionally(2, 
    cat(OneOf(", ", "and is"), " ready for re-activation")
)}.

The output of this script could be "Engine module fully repaired." or "Engine module partially repaired, and is ready for re-activation."

Please note the last dot of the phrase, which in the code is after the last bracket.

This is another sample, with strings passed to functions inside other strings:

{OneOf("{ShipName()} has", "")} 
{OneOf("left supercruise", "{OneOf(\"entered\", \"returned to\", \"dropped to\")} normal space")}

My question is: how sublime-syntax files handle this kind of nidification?

Parduz
  • 662
  • 5
  • 22
  • Questions seeking debugging help (**"why isn't this code working?"**) should include the desired behavior, *a specific problem or error* and *the shortest code necessary* to reproduce it *as formatted text* (not images) **in the question itself**. Questions without **a clear problem statement** are not useful to other readers. See: [mre]. In particular, along with your pseudocode, please post some actual code *and the contents of your `.sublime-syntax` file.* – MattDMo Apr 09 '21 at 20:36
  • Is there more than one comment section? Also, on line 4, why is `\"and a string\"` escaped? It's in the middle of a `{ }`-delimited code block. – MattDMo Apr 09 '21 at 20:40
  • MaddDMo: Comments: how many you want. But no "block comments". Escaped quotes: 'cause it is inside the first double quotes (after "This_is_still_code" call). – Parduz Apr 09 '21 at 21:06
  • @MattDMo: about my syntax file: it's just 10 lines of ... garbage? i copied some code from the sample in the wiki (about C syntax) trying to sort out something. I'll post real Cottle code ASAP. – Parduz Apr 09 '21 at 21:10

1 Answers1

3

Looking at the overview of the templating language over at https://cottle.readthedocs.io/en/stable/page/01-overview.html, it seems to be an easy syntax for which to write a .sublime-syntax for, but given the utter lack of resources for knowing how syntax files works in ST, I can understand it can be sometimes difficult to start or even understand.

So, I took the liberty of creating a starter syntax definition (the result of an hour & a half of boredom on a Saturday evening), which you can take and work upon. Note that I have not used the language and as such made it by just reading the docs and looking over code snippets.

You can find a gist for it here (https://gist.github.com/Ultra-Instinct-05/96fa99e1aaeb32b12d1e62109d61fcc2)

Here is a screenshot showing it in the color scheme I use (which follows the official scope naming guidelines).

enter image description here

It still lacks support for user defined functions (as I came to know from the docs) (and probably a few other things), but maybe that's something you can add to it !

Note that to use it, save the file as Cottle.sublime-syntax in your User package. Right now files having a .cottle extension are highlighted (because I don't know how you create a cottle file).

The syntax definition doesn't use any new feature added in ST4, so it should work the same in both ST3 & ST4.

Ashwin Shenoy
  • 661
  • 5
  • 8
  • Thanks a lot! It took me the whole saturday ( :D ) to come to something similar (while less accurate). Your sample syntax solves a lot of the problem my has, but the main difficulties are still there: - the "stray text" (like *X is negative* in your screenshot) aren't treated as strings (which leads to breaking the whole highlighting if you have something like *it's a string*) - the "recursion" (nesting? what's the right word?) of the syntax: if in the middle of a string you open a **{** you're starting a whole new *cottle_code_block*, with quoted strings inside it being escaped. – Parduz Apr 11 '21 at 09:02
  • 1
    Like I said, I have never used cottle before (& probably don't intend to use it in the near future as well), so I am not aware about the quirks of this templating language. The syntax itself was a quick "put together" like thing and I haven't dwelled upon it much. If you could post sample code snippets about where the syntax fails *in the github gist comments*, I could probably give some pointers. – Ashwin Shenoy Apr 11 '21 at 09:17
  • Done. I was trying to edit my comment while you posted your. – Parduz Apr 11 '21 at 09:48