Hello again!
I’m working on Hedy (you can see an example here), a language dedicated to teach kids programming. This language has lots of ambiguity, and I’m not sure how can I handle them using Lezer. I’m aware that I can mark the places where Lezer needs to use GLR, but it’s not clear to me how that would work with this particular language.
I’m having trouble with this particular construct: on Hedy there are no strings delimiters until later on in the lessons, so an assigment looks like this:
Name IsToken Text
like: age is 12
Or also like this, for asking input to the user:
Name IsToken AskToken Text
like: age is ask What is your name?
My problem lies in how this tokens are defined:
@tokens {
@precedence {
AskToken,
IsToken,
Name,
Text,
TextWithoutSpaces
}
Comment { "#" ![\n]* }
AskToken { " "* "ask" " "* }
IsToken { " "* "is" " "* }
eol { "\n" }
TextWithoutSpaces { ![\n #]+ }
Text { (![\n#ـ\r])(![\n#\r]*) }
Name { letterOrUnderscore letterOrNumeral*}
letterOrUnderscore { (@asciiLetter | $[_\u{a1}-\u{10ffff}])+ }
letterOrNumeral { letterOrUnderscore | (@digit | letterOrUnderscore)* }
}
So when I try to parse var is several lines of text
This is the tree I get:
Program(
Command(
Assign(
Var(Name),
IsToken,
⚠(Name),
Text
)
)
)
Notice how first I get a (Name) Node before it parses text. How can I do that it parses everything after
is
as text.
This is my full grammar:
@top Program { eol* (Command eol+)* Command? }
Command {
Assign | Ask | ErrorInvalid
}
Assign { Var IsToken Text }
Ask { Var IsToken AskToken Text }
ErrorInvalid { TextWithoutSpaces Text? }
Var { Name }
@tokens {
@precedence {
AskToken,
IsToken,
Name,
Text,
TextWithoutSpaces
}
Comment { "#" ![\n]* }
AskToken { " "* "ask" " "* }
IsToken { " "* "is" " "* }
eol { "\n" }
TextWithoutSpaces { ![\n #]+ }
Text { (![\n#ـ\r])(![\n#\r]*) }
Name { letterOrUnderscore letterOrNumeral*}
letterOrUnderscore { (@asciiLetter | $[_\u{a1}-\u{10ffff}])+ }
letterOrNumeral { letterOrUnderscore | (@digit | letterOrUnderscore)* }
}
@skip { Comment }