Hey guys, I am playing with instaparse and I have a problem contructucting a grammar.
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}")
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}"]]
instead of the desired
[:doc [:text "some text "] [:tag "@" "toto" [:inner-text "{" "inner text" "}"]]]
Any Idea how I can modify the grammar to consider the inner-text rule
before going back to the text
one ?
@jeremys Maybe change inner-text*
to inner-text* !inner-text
, to ensure that it parses as many inner-texts as it can.
@aengelberg Thx Alex I’ll try to use the lookahead, I haven’t played with that yet.