2

I am using Grako EBNF/PEG parser.

I know that EBNF syntax allows to grab expressions that satisfy one of given options:

(a | b | c)

Is there a similar part of syntax or a workaround that allows to grab expessions that are any combinations of a, b and c without repetitions so that valid expressions would be like:

a b c
b a c
a b
b c
b
none

but not like:

b b c
a a

?

Sashko Lykhenko
  • 1,554
  • 4
  • 20
  • 36

1 Answers1

2

One way is to spell out the combinations in the rule.

Another way is to use a semantic action that checks for repetitions and raises grako.exceptions.FailedSemantics if it finds them. The parser's behaviour will be just as if the input hadn’t parsed.

Apalala
  • 9,017
  • 3
  • 30
  • 48