Sublime Forum

What class of grammars can the `.sublime-syntax` parser capture?

#1

And are there any general guidelines for how to approach writing a language definition? For example I use a lot of code like this:

match: (?=some_lookahead)
push:
    - meta_scope: meta.some_statement
    - match: some_lookahead
      scope: keyword
    - match: next_word
      scope: variable.other
    - include: expression
    - match: \(\)
      scope: parens

which is intended to match lines like some_lookahead next_word (2+1)*3 (). However I don’t know if this is the right way to do this, it is just based on examples I have seen and I don’t know the theory behind its use or when to apply this trick. For example, the MagicPython package seems to be very well structured but I’m not sure what the reasoning behind it was.

1 Like

#2

LL(1)


This would be more appropriate (same functionality but with one pattern less):

match: some_lookahead
scope: keyword
push:
    - meta_scope: meta.some_statement
    - match: next_word
      scope: variable.other
    - include: expression
    - match: \(\)
      scope: parens

If the order of next_word, expression and the parentheses matters, you would push (or rather set) a new context after every match.

You can see examples of this in the Python.sublime-syntax definition’s with and import statements.

1 Like