Using pest parser I am trying to build a grammar that can recognize variable names, but I can't get the variables to end at the next space/non-alpha character. I tried using...
var_name = {!reserved ~ ASCII_ALPHA+}
which works perfectly for single-letter variables
var_name = {!reserved ~ ASCII_ALPHA+}
but this includes a space when I do x := 1, my parser sees var_name as "x ". And even if I was okay with that, it doesn't work for parsing larger expressions while true do { if a < b then b := b - a else a := a - b }
=> parse error
var_name = {!reserved ~ ASCII_ALPHA | ASCII_ALPHA+}
reacts similar to the single character option.
I also tried using 'a'..'z', alphanumeric, and other options as well, but no change. I may be missing something from the book, but I can't seem to find anything that works.
Additional information:
- At the bottom of the pest website, there is a testing area for grammars https://pest.rs/.
- reserved is a list of reserved names, such as for, while, and int
- To reiterate the goal is for my parser to recognize variable names, 'a'..'z' and 'A'..'Z'
Thanks, any help is appreciated