I’m continuing my halting progress on a YAML grammar and running into an issue with the YAML key definition.
For example these are all valid YAML keys/value pairs:
# ":foo" -> "value"
:foo: value
# "/foo/bar:/foo" -> "value"
/foo/bar:/foo: value
So :
is both part of the content of a key and it’s final delimeter. I’d like to demarcate the final :
as not part of the key (for syntax highlighting purposes).
The approach that I tried to take was use a @local tokens
expression:
// https://lezer.codemirror.net/docs/guide/#writing-a-grammar
@top Program { Property+ }
Property {
keyExp spaces* Value (newline | eof)
}
@local tokens {
KeyEnd { ": " }
@else Key
}
@skip {} {
keyExp {
Key+ KeyEnd
}
}
Value {
Plain | Boolean
}
@tokens {
Boolean { "true" | "false" | "nor" }
spaces { $[ \t]+ }
newline { "\n" }
eof { @eof }
Comment { "#" ![\n]+ }
Plain { (@asciiLetter|@digit) ![\n#]* }
@precedence { Boolean, Plain}
}
@skip { Comment }
@detectDelim
}
But that results in
Tokens from a local token group used together with other tokens (Key with Comment)
If I remove Comment
I get the same message but it’s (Key with Boolean). Is there a way to accomplish what I want with
@localor do I need to reach for an external tokenizer that can detect the final
": "` that termintes a key?