I am struggling with the following: In my application, I have to perform many parses on the same string. It really drags performance down if I recreate the recognizer on a new string every time.
To solve this problem, I attempt to use the same recognizer and string to perform these parses in a single parse series. I set up the grammar so that an event is triggered when I recognized enough so that it constitutes a "parse". At this point I handle what I got and then resume the parsing at an appropriate point.
The parsing process works fine using this scheme. Instead of performing a new parse on the same string, I perform these parse sections on the same string in the same series.
But here is the rub: I need to get at the syntax tree that is recognized at the intermediate stages. But after I call "value" in the recognizer the first time, I run into trouble: While the parser still is set up and can continue perfectly fine, any subsequent calls to "value" return undef.
This is frustrating, because I can see in the lexeme tracing that the parser continues doing the expected thing, recognizing the fragments I throw at it. But I can no longer obtain the value constructed.
I realize that this does not quite follow the rules, since the document on "Phases" states that the evaluation phase has to come after the reading phase (it says even strong that if I call "resume" in the evaluation phase the behavior is undefined, which is what I am doing here). However, Marpa is clearly set up to not require this, because the parser can continue after the evaluation phase back in the reading phase. But somehow, I cannot enter any further evaluation phases.
I was thinking that maybe starting another parse series might work. So I do a "series_restart" before I call "resume", but now the evaluation phase gets confused about the packages it is in. It is not clear to me whether this is supposed to be supported because the documentation is confusing. It states that "The
series_restart()
method must be called before
value()
when
ambiguous()
detects an ambiguous parse and the application needs to get the parse values." As I am not dealing with an ambiguous parse, this may not apply but maybe it is meant to be broader.
Does anybody know if this situation is meant to be supported?
Thanks, Th.
P.S. Marpa provides these amazing possibilities, so maybe I am getting greedy with what I am trying to accomplish. But parsing has never been more fun as when I learned about Marpa.