Skip to content

Question: Access/Match Last Consumed Character(s) of Input #144

Answered by ColinH
sanssecours asked this question in Q&A
Discussion options

You must be logged in to vote

Scanning backwards is not properly supported because the usual (?) way with PEGs is to make use of the infinite look-ahead and disambiguate in advance. Or you rework the grammar in other ways, by deferring decisions to as late as possible.

Now you would presumable prefer to use the YAML grammar as is, without major refactoring.

The memory_input now also remembers where it started parsing, so you could actually check whether there are bytes between begin() and current(), and implement a kind of backward-scanning UTF-8 decoding function.

So it's a hassle, but it's possible, and I couldn't say whether there is a more elegant solution without thinking about it some more.

Replies: 6 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by d-frey
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #144 on December 09, 2020 09:45.