DanilaFe / pegasus

A parser generator for C and Crystal.
MIT License
62 stars 3 forks source link

issue with period "." character and regex #3

Closed sam0x17 closed 5 years ago

sam0x17 commented 5 years ago

This has been giving me trouble as well:

S = FLOAT;
FLOAT = "[0-9]*.[0-9]+";
nojs$ echo '22.2' | pegasus-sim -i test.json
ParentTree(S)
  ParentTree(FLOAT)
    Token(1, 22.2)
(correct)
nojs$ echo '22.' | pegasus-sim -i test.json
ParentTree(S)
  ParentTree(FLOAT)
    Token(1, 22)
(shouldn't work because no ".")
nojs$ echo '.2' | pegasus-sim -i test.json
ParentTree(S)
  ParentTree(FLOAT)
    Token(1, .2)
(correct)

It's allowing a plain "2" to be a float, even though there is no ".". I'm pretty sure it's not my regex but something else going on with how the regex is parsed.

DanilaFe commented 5 years ago

. is actually a reserved character in regular expressions that represents any character. It needs to be escaped to be used as a period character, and I just fixed the fact that it wasn't allowed to be escaped (similar to #2 )

sam0x17 commented 5 years ago

ah ok perfect that is why thanks!