I have the following treetop grammar:
grammar TestGrammar
rule body
text / expression
end
rule text
not_delimiter*
end
rule expression
delimiter text delimiter
end
rule delimiter
'$'
end
rule not_delimiter
!delimiter
end
end
When I try to parse an expression, eg 'hello world $test$', the script goes in an infinite loop.
The problem seems to come from the not_delimiter rule, as when I remove it the expression get parsed.
What is the problem with this grammar?
Thanks in advance.
The problem seems to be where you are attempting to match:
Since the
*
will also match nothing you have the possibility of matching[^$]*
, which I think is what is causing the infinite loop.Also, you need to match multiple
bodies
at the starting rule, otherwise it will returnnil
, since you will only ever match either atext
rule or anexpression
rule but not both.This will parse: