Skip to content
Stefan Koch edited this page Feb 23, 2015 · 7 revisions

A FancyPars grammar, consists of a so called Group.

A Group can contain in turn either Groups or so called PatternElements.

Group {
  OtherGroup {
    "has_to_match_this_string"
  }
  AnotherGroup {
    "has to match that string"
  }
}

PatternElements describe the lexical and grammatical pattern of a production. PatternElements have to be seperated by commas of there are multiple if them in a group. The easiest of them is the StringElement.

A StringElement is just a string that has to be matched. The String will be a dedicated token, and the lexer will be able to recognize it.

"match me"

A NamedElement is probably the most common element. It is akin to Named-Captures in regex. It consists of a Group name, an optional "[]" to denote multiple following captures, and a capture name to access it. In Order to avoid Superfluous productions, NamedElements which have a production can have a separating StringElement, which you write behind a colon.

This called_oneof

That[] called_multipleof

That_[] called_multipleof_seperated_by_comma : ","

An probably quite uncommon concept in grammars is the FlagElement.

The FlagElement is a boolean flag based on the occurrence of a token.

? "_" : bool had_leading_underscore

This value can be queried with a so called QueryElement

? bool had_leading_underscore : Some_element_to_be_parsed_if_the_condition_was_true

Clone this wiki locally