Replies: 1 comment
-
That is not really possible. Instead, I'd recommend using the operator parser to parse expressions. See here for an example of how that looks: https://github.com/foonathan/clauf/blob/main/src/compiler.cpp#L1847-L1867 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I'm working on a parser, which accepts C++ type-names. Therefore, I'm currently working my way through the relevant productions given by the C++ standard. As those are more complex than necessary for my usecase, they still provide a good starting point for making that work and simplify them later.
At least that's my strategy for now, so I would like to transport them as closely to lexy as possible.
That out of the way, let me quickly demonstrate my issue.
Consider the two input strings
char(*)[42]
andchar*()
where the prior denotes "a pointer to an array of chars" and the latter "a function returning a pointer to char".In fact, this case merely boils down to the decision between:
noptr_abstract_declarator -> ( ptr_abstract_declarator )
andnoptr_abstract_declarator -> parameters_and_qualifiers
with:
parameters_and_qualifiers -> ( parameter_declaration_clause )
(This is very much simplified!)parameter_declaration_clause -> parameter_declaration_list?
As you can see, both productions share the
(
as prefix. In the current setup I can successfully recognizechar(*)[42]
but fail withchar*()
. However, when I change my decision fromdsl::parenthesized(dsl::recurse_branch<ptr_abstract_declarator>) | dsl::recurse_branch<parameters_and_qualifiers>
(1) todsl::recurse_branch<parameters_and_qualifiers> | dsl::parenthesized(dsl::recurse_branch<ptr_abstract_declarator>)
(2) the outcomes will be negated.This the relevant part of tracing the
char*()
string with the setup (1):This correctly consumes the
*
and then consumes the(
(due to branch (1)) and eventually runs into a dead-end.This is more or less the expected behaviour, but I expected it to just backtrack right before the
(
literal and test branch (2).So, my question is: Is it possible to somehow "unconsume" the
(
when the branch (1) fails and let lexy try for branch (2)?Beta Was this translation helpful? Give feedback.
All reactions