Skip to content

Failure handling when Matching optionals #608

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

You must be logged in to vote

The EOI rule requires the End of Input, so { "a" ~ B* ~ EOI } works here as specifically what you asked for.

More generally, you need to use & or ! lookahead; you could use !"#" to require that the following is not #, or &"b" to require that a b follows.

As an example:

WHITESPACE = _{ WHITE_SPACE }

list = { (a | error)* }

error = @{ (!WHITESPACE ~ ANY)+ }

a = @{ "a" ~ (b+ | &(WHITESPACE | EOI)) }
b = @{ "b" }
a abbbb a##bb a
- list
  - a: "a"
  - a: "abbbb"
  - error: "a##bb"
  - a: "a"

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@chichid
Comment options

Answer selected by chichid
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