How can I return from parsing ahead of time? #342
-
Hi, I'm parsing big files, but somethings I don't need to parse them all. Is there any mechanism to return from parsing ahead of time? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Sure, your grammar doesn't have to include the |
Beta Was this translation helpful? Give feedback.
-
Alternatively you could use the |
Beta Was this translation helpful? Give feedback.
Alternatively you could use the
tao::pegtl::until
rule, increment a counter in the action for each item, and check whether the counters match in a separate action attached to thetao::pegtl::success
rule that you use as termination condition for theuntil
. This works if you use a slightly less often used feature, namely that actions can returnbool
instead ofvoid
; if an action returnsfalse
then the rule that it is attached to will be considered as not matched, "as if" the rule had returnedfalse
itself (though in that case the action wouldn't have been called).