-
Notifications
You must be signed in to change notification settings - Fork 30
Fluent API
Curtis Wensley edited this page May 23, 2021
·
2 revisions
The Fluent API allows you to write shorthand rules and definitions.
Some Notes:
By default sequence and alternative parsers are reused. For example, the following:
Parser first = "hello" & Terminals.WhiteSpace;
Parser second = "there";
Parser top = first & second | first;
first will be reused as there's no way to know that it is defined as a secondary parameter, so first == second
which defines a grammar that isn't what you might expect.
So, when using parsers multiple times you need to use Named()
or Separate()
to specify that it is a distinct part of your grammar. For example, this is the correct way to write this:
Parser first = ("hello" & Terminals.WhiteSpace).Named("first");
Parser second = "second";
Parser top = first & second | first;