Quick reference
Every word and sign of the notation on one page, each with the chapter that tells it. The specification is
syntax.md; every message the generator reports is in diagnostics.md.
Signs
| Sign | Means | Chapter |
|---|---|---|
'x', "text" |
a character, a string | elements |
'x'i, "text"i |
the same without regard to case | elements |
\', \", \\, \0, \a, \b, \f, \n, \r, \t, \v, \uXXXX |
escapes in a literal | elements |
[ … ], [^ … ], .., \p{Lu} |
an element set, its complement, a range, a Unicode category | elements |
& |
sequence | composition |
\| |
ordered choice; set union inside [ … ] |
composition |
~ |
sequence with no trivia between | trivia |
( … ) |
a group; a rule's parameters; a call's arguments; a rebinding list | composition |
{ … } |
an atomic group; a namespace block; a switch body |
composition |
?, *, + |
zero or one, zero or more, one or more | composition |
{n}, {n,m}, {n,} |
a count | composition |
?=X, ?!X |
positive and negative lookahead | composition |
name: X |
a capture | values |
$q: X, $q |
bind the text X read; match it again |
bindings |
#q |
the length of the bound text, inside count braces | bindings |
= |
a rule's body; one side of a rebinding | rules |
: |
a type in a rule's head, a parameter or a directive; a capture; a switch label |
rules |
T[] |
a sequence of T |
values |
Name? |
a rule that gives back over tokens | reading over tokens |
=> |
a construction; a recovery's factory | values |
<< n, >> n |
a binding power: left- or right-associative at level n |
rules |
@Name, @A.B, @M(…), @T<U>, @(…) |
C#: a name, a call, a generic name, an expression | the grammar and its host, C# seam |
[@M] |
a C# predicate in an element set | C# seam |
. |
a qualified name, Ns.Rule, Std.Integer |
namespaces |
, |
between parameters, arguments, rebindings and count bounds | |
; |
ends a using; optional after a switch body |
the grammar and its host |
- |
a negative switch label |
guards |
//, /* … */ |
comments in a grammar | the grammar and its host |
Words
All are words only where the notation reads them; elsewhere they are ordinary names.
| Word | Where | Chapter |
|---|---|---|
using, @using |
an import of a grammar namespace, of a C# namespace | the grammar and its host |
namespace |
a namespace block | namespaces |
with (…) |
a rebinding: of a namespace, an expression, a publication | namespaces |
with state @(…) |
a state mark | context and state |
parse, find |
publication | publication |
public, internal, private, positional |
before parse or find |
publication |
as, stream, bytes, yield |
after a directive's operand | publication |
context, state |
context : @T, state : @T |
context and state |
on fail |
on fail "…" in a rule's head, or after a guard's C# |
values, guards |
when |
a guard or a condition | guards |
is, not, and, or |
in a condition after when |
guards |
switch, case, default |
computed choice | guards |
recover |
a recovering repetition | recovery |
Built-in rules
| Rule | Matches | Chapter |
|---|---|---|
any |
one input item | elements |
none |
nothing | elements |
eol |
a line ending | elements |
eof |
the end of input | elements |
eos |
the end of a segment | elements |
trivia |
what may stand between operands | trivia |
wordboundary |
what a word is made of | words |
word |
one whole word | words |
The standard library, Std, is in its own chapter; the names the parser supplies to C# are listed
in the grammar and its host.
All of it at once
@using System;
using Std;
trivia = { (Spacing | LineComment("//"))* }
wordboundary = [\p{L} | \p{Nd} | '_']
Value : int = left: Value & '+' & right: Value << 1 => @(left + right)
| left: Value & '*' & right: Value << 2 => @(left * right)
| '(' & inner: Value & ')' => inner
| n: Integer => n
Let : @string = "let"i & name: Identifier & '=' & v: Value & ';' => @($"{name}={v}")
Script : @string[] = Let* recover ';'
parse Script
ParseScript("let a = 1 + 2 * 3; LET b = (1 + 2) * 3; // done") → ["a=7", "b=9"]
ParseScript("let a = 1; let = 2; let c = 3;") → ["a=1", "c=3"]