instaparse

roklenarcic 2023-09-06T16:07:28.836679Z

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….

2023-09-06T16:12:34.990399Z

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

roklenarcic 2023-09-06T16:35:18.481299Z

Hm I’ll just rewrite it all I think

roklenarcic 2023-09-06T16:36:15.852789Z

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?