Trouble writing grammar for nandeck script.

I am new to Lezer and parser grammar in general. The only tool I found to rapidly iterate is lezer-playground which seems a bit outdated.

I am trying parse nanDeck script files which is heavily directive based.

I wrote a fairly hacked together grammar by following some examples from php and js grammars but the problem i have is commonly ambiguity and the differentiation of directives and variable assignments which are the same syntax structure.

; this is a comment
[foo] = "bar" ; a variable, 
Directive = arguments, [... arguments]
<frame> = x, y, w, h ; a special type of variable that makes a segment on the canvas

[copyHeight] = 1cm ; a length value 
<copy> = <frame, TS, [copyHeight]> ; a reference to a frame with using the last height in <frame>s children as the Y of copy

[r]=1.18
[cx]=4.83
[cy]=7.38
LAYER=100 ; like svg G making the opacity 100%
  ELLIPSE=[all],[cx],[cy],[r],[r],#000000 ; variables passed into a directive and a color value
ENDLAYER

What I saw with PHP grammar is that it was written with specialization on identifiers for functions like for and if.

link to grammar https://gist.github.com/cmargroff/2a252aa7e3c3a38583a600e3ff0f965e
I make no claims that I 100% know what I was writing.

The grammar seems to compile, and variable assignments and directives seem easily disambiguated by whether they start with an identifier or a variable name. Is there a specific problem you’re dealing with?

I don’t think the @precedence notation works how you think it works. It defines named precedences, but you have to insert them into rules with !name syntax. Putting rule names in a @precedence block but not using them as a marker does nothing.

ok GTK

The common problem I had was “overlapping” when capturing Identifier and specific tokens like layer or for that it would complain about the first character being overlapping. Is that where specilization comes in?

Is there a better tool to use than lezer-playground to use for development?
I have gotten it to lockup a lot where it tried to compile grammar and it was just an infinite loop. It’s seems fine but only for some quick simple development.

The overlapping tokens you should solve with @specialize (I don’t think you need to define an external specializer for keywords like this).

When I develop a grammar I just run lezer-generator locally, I don’t use a playground.