Sublime Forum

Help with writing a syntax definition

#1

Hi all, I’d like to write a simple syntax definition to parse what is essentially an extended version of LaTeX. It looks for example as follows:

#lang mylang

?title{Cookies and Milk}

?theorem{
If you give a mouse a cookie, it's going to ask for a glass of milk.
}

?proof{
Let $M$ be a mouse and give it a cookie.
It is well-known that a mouse will eat any cookie it's given \cite{OfMiceAndMen}.
Similarly it is a standard fact that cookies are not eaten without milk.
The claim now follows by a standard argument that is well-known to the experts.
\todo{Give some thought to the case where $M$ already has a glass of milk.}
}

(I’ve replaced at-signs by ?s above so that the forum software doesn’t think I’m trying to mention users.)
For the purposes of syntax highlighting, I’d like to think of this as LaTeX, but with extra syntax like #lang and ?theorem added (the content inside ?title, ?theorem and ?proof is to be interpreted as LaTeX). I tried to model this on the HTML+Jinja example here:

contexts:
  main:
    - match: ""
      push: Packages/LaTeX/LaTeX.sublime-syntax
      with_prototype:
        - match: "((#)lang)\b"
          captures:
            1: keyword.declaration.sbl
            2: punctuation.definition.keyword.sbl
          push:
            - meta_scope: meta.string.sbl
            - match: '\n'
              pop: true

This is only the #lang syntax, but even this keeps giving me a recursion error:

Apparent recursion within a with_prototype action: 25000 context sanity limit hit

In fact in the dozens of variants I’ve tried I keep getting the same issue, so I clearly don’t understand with_prototype.

For ?theorem and ?proof it should be similar: I’d just want to parse those keywords and let the rest be parsed as if it were LaTeX. That seems like it should be trivial, but I’m running into the same with_prototype issue as above. Any help would be greatly appreciated.

0 Likes