Fork me on GitHub
#instaparse
<
2023-09-06
>
roklenarcic16:09:28

Hi. I am trying to create a very simple parser but I don’t undestand why it fails. If I have the following parser: S = E; E = 'N' | 'W' | 'S' | 'E' Then

(parser "N")
=> [:S [:E "N"]]
but if I add a rule to expand to multiple it stops parsing:
S = E; E = 'N' | 'W' | 'S' | 'E'; E = E E;
(parser "N")
=> Parse error at line 1, column 1:
N
^
Seems odd that adding more production rules would make it parse less….

hiredman16:09:34

am not sure, but I would try adding the second E production as an alternative to the first E production

roklenarcic16:09:18

Hm I’ll just rewrite it all I think

roklenarcic16:09:15

Another puzzle:

S = DIR+; DIR = ('N' | 'W' | 'S' | 'E')+;
This produces:
(parser2 "WWWW")
=> [:S [:DIR "W"] [:DIR "W"] [:DIR "W"] [:DIR "W"]]
I would prefers that DIR was greedy in that it would only parse as a single element if there are multiple letters in a row… how would I do that?