Skip to content

expression cannot fail #548

Answered by CAD97
xiayulu asked this question in Q&A
Discussion options

You must be logged in to vote

PEG is greedy. Your top-level grammar is inline = { chars | em }.

To parse this, we first try chars = { char* }.

chars will always succeed -- it can match the empty string. Thus the em side of the alternation will never be tried; chars succeeded already.

The simple solution which probably does what you want is to instead use chars = { char+ }, such that chars must match at least one char, and if char fails to match, then inline will continue on to try the next alternation, em.

Replies: 1 comment

Comment options

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

This discussion was converted from issue #540 on October 10, 2021 19:40.