mixinafPegger::Rules

afPegger::Rules

@Js

(Advanced) A collection of utility methods that return PEG rules.

Use when programmatically creating PEG grammar.

alpha

Source

static Rule alpha()

Matches any character in the current locale. See sys::Locale for details.

Example PEG notation:

\aplha
alphaChar

Source

static Rule alphaChar(Bool not := false)

Matches any alphabetical ASCII character.

PEG notation:

[a-zA-Z]
alphaNumChar

Source

static Rule alphaNumChar(Bool not := false)

Matches any alphabetical ASCII or numerical character.

PEG notation:

[a-zA-Z0-9]
anyChar

Source

static Rule anyChar()

Matches any character.

PEG notation:

.
atLeast

Source

static Rule atLeast(Int n, Rule rule)

Processes the given rule repeatedly until it fails. Returns success if it succeeded at least n times.

Example PEG notation:

rule{3,}
atMost

Source

static Rule atMost(Int n, Rule rule)

Processes the given rule repeatedly, but at most n times. Returns success always.

Example PEG notation:

rule{,5}
between

Source

static Rule between(Int? min, Int? max, Rule rule)

Processes the given rule between the given values (inclusive). If min is null it is taken to be 0. If max is null it is taken to be infinity.

Example PEG notation:

rule{2,6}

char

Source

static Rule char(Int char, Bool not := false)

Matches the given character.

Example PEG notation:

[C]
charIn

Source

static Rule charIn(Range charRange, Bool not := false)

Matches any character in the given range.

Example PEG notation:

[C-N]
charNot

Source

static Rule charNot(Int ch)

Matches any character except the given one.

Example PEG notation:

[^C]
charNotOf

Source

static Rule charNotOf(Int[] chars)

Matches any character not in the given list.

Example PEG notation:

[^ChukNoris]
charOf

Source

static Rule charOf(Int[] chars, Bool not := false)

Matches any character in the given list.

Example PEG notation:

[ChukNoris]
charRule

Source

static Rule charRule(Str charClass)

Multi-purpose char class rule.

Example PEG notation:

[a-z_]i
eol

Source

static Rule eol()

Matches if at the End-Of-Line (EOL) (or at the end of stream).

Example PEG notation:

\eol
eos

Source

static Rule eos()

Matches if at the End-Of-Stream (EOS). (Does not consume an characters.)

Example PEG notation:

\eos
err

Source

static Rule err(Str msg := "FAIL")

This rule throws an error if processed.

Example PEG notation:

\fail(FAIL)
fail

Source

static Rule fail()

A rule that will always fail. Does not consume any characters.

Example PEG notation:

\fail
firstOf

Source

static Rule firstOf(Rule[] rules := Rule[,])

Processes the given rules in order until one succeeds. Returns success any succeeded.

firstOf([rule1, rule2, rule3])

Example PEG notation:

rule1 / rule2 / rule3 / ... / rule4

When defining a firstOf() rule you may also use it-block syntax:

firstOf { rule1, rule2, rule3, }
hexChar

Source

static Rule hexChar(Bool not := false)

Matches any hexadecimal character.

PEG notation:

[a-fA-F0-9]
lower

Source

static Rule lower()

Matches a lowercase character in the current locale. See sys::Locale for details.

Example PEG notation:

\lower
nTimes

Source

static Rule nTimes(Int times, Rule rule)

Processes the given rule n times. Returns success if the it always succeeded.

Example PEG notation:

rule{5,5}
newLineChar

Source

static Rule newLineChar(Bool not := false)

Matches the new line character. This assumes all new lines have been normalised to \n.

PEG notation:

[\n]
numChar

Source

static Rule numChar(Bool not := false)

Matches any numerical character.

PEG notation:

[0-9]
oneOrMore

Source

static Rule oneOrMore(Rule rule)

Processes the given rule repeatedly until it fails. Returns success if it succeeded at least once.

Example PEG notation:

(rule)+
onlyIf

Source

static Rule onlyIf(Rule rule)

Processes the given rule and return success if it succeeded. The rule is always rolled back so the characters may be subsequently re-read.

Example PEG notation:

&(rule)
onlyIfNot

Source

static Rule onlyIfNot(Rule rule)

Processes the given rule and return success if it failed. The rule is always rolled back so the characters may be subsequently re-read.

Example PEG notation:

!(rule)
optional

Source

static Rule optional(Rule rule)

Processes the given rule and returns success whether it passes or not.

Example PEG notation:

(rule)?
pass

Source

static Rule pass()

A rule that will always pass. Does not consume any characters.

Example PEG notation:

\pass
sequence

Source

static Rule sequence(Rule[] rules := Rule[,])

Processes the given rules in order until. Returns success if they all succeeded.

sequence([rule1, rule2, rule3])

Example PEG notation:

rule1 rule2 rule3 ... rule4

When defining a sequence() rule you may also use it-block syntax:

sequence { rule1, rule2, rule3, }
sol

Source

static Rule sol()

Matches if at the Start-Of-Line (SOL) (or at the start of stream).

Example PEG notation:

\sos
sos

Source

static Rule sos()

Matches if at the Start-Of-Stream (SOS). (Does not consume an characters.)

Example PEG notation:

\sos
spaceChar

Source

static Rule spaceChar(Bool not := false)

Matches any space character (excluding new line chars).

PEG notation:

[ \t]
str

Source

static Rule str(Str string, Bool ignoreCase := false)

Matches the given string.

Example PEG notation:

"ChuckNorris"
strNot

Source

static Rule strNot(Str string, Bool ignoreCase := false)

Matches one or more characters up to (but not including) the given string.

Example PEG notation:

(!"ChuckNorris" .)+
upper

Source

static Rule upper()

Matches an uppercase character in the current locale. See sys::Locale for details.

Example PEG notation:

\upper
whitespaceChar

Source

static Rule whitespaceChar(Bool not := false)

Matches any whitespace character, including new lines.

PEG notation:

[ \t\n]
wordChar

Source

static Rule wordChar(Bool not := false)

Matches any word character, used as a Fantom identifier.

PEG notation:

[a-zA-Z0-9_]
zeroOrMore

Source

static Rule zeroOrMore(Rule rule)

Processes the given rule repeatedly until it fails.

Example PEG notation:

(rule)*