Skip to content

Star rule problem for empty input #199

Answered by d-frey
icze asked this question in Q&A
Discussion options

You must be logged in to vote

The library works as expected.

Let's analyze what is happening in your case: The input is OBJ end OBJ; (if I replace newline with space, which is equivalent in this case).

Now the rules are trying to match content = star<entry> with entry = seq< IDENT, composition, "end", IDENT, ";" >. (I hope the pseudo-syntax is OK for you)

The first OBJ is IDENT. Next we try to match composition = seq< entry_list, star< "public" > >. Looking at entry_list = star< name, component_list, ";" >. And here, it matches the end OBJ;-part of the input. name matches end and OBJ matches component_list = seq< IDENT, star<...> >.

Now the problem is that PEGs (unlike CFGs) are truly greedy. composition does eat the e…

Replies: 6 comments

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
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
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 #199 on December 09, 2020 08:21.