instaparse

If you're not trampolining your parser, why bother getting up in the morning?
2017-11-23T16:55:17.000090Z

Hey guys, I am playing with instaparse and I have a problem contructucting a grammar.

2017-11-23T16:55:38.000016Z

Here is what I am going for

(insta/defparser ex7
  "
  doc = (text | tag)*
  text = #'[^@]*'
  tag = '@' #'[a-z]*' inner-text*
  inner-text = '{' #'[^}]*' '}'
  ")

(ex7 "some text @toto{inner text}")

2017-11-23T16:58:34.000190Z

The problem is the parser when parsing a tag rule won’t consider the inner-text rule giving me the parse

[:doc [:text "some text "] [:tag "@" "toto"] [:text "{inner text}"]]

2017-11-23T16:59:15.000407Z

instead of the desired

[:doc [:text "some text "] [:tag "@" "toto" [:inner-text "{" "inner text" "}"]]]

2017-11-23T17:01:52.000152Z

Any Idea how I can modify the grammar to consider the inner-text rule before going back to the text one ?

aengelberg 2017-11-23T22:07:17.000040Z

@jeremys Maybe change inner-text* to inner-text* !inner-text, to ensure that it parses as many inner-texts as it can.

2017-11-23T23:19:13.000098Z

@aengelberg Thx Alex I’ll try to use the lookahead, I haven’t played with that yet.