mixinafPegger::Rules

afPegger::Rules

@Js

A collection of PEG rules, ready for use!

anyAlphaChar

Source

const static Rule anyAlphaChar()

Matches any alphabetical character.

PEG notation:

[a-zA-Z]
anyAlphaNumChar

Source

const static Rule anyAlphaNumChar()

Matches any alphabetical or numerical character.

PEG notation:

[a-zA-Z0-9]
anyChar

Source

const static Rule anyChar()

Matches any character.

PEG notation:

"."
anyCharInRange

Source

const static Rule anyCharInRange(Range charRange)

Matches any character in the given range.

Example PEG notation:

[C-N]
anyCharNot

Source

const static Rule anyCharNot(Int char)

Matches any character except the given one.

Example PEG notation:

!"C" .
anyCharNotInRange

Source

const static Rule anyCharNotInRange(Range charRange)

Matches any character not in the given range.

Example PEG notation:

![C-N] .
anyCharNotOf

Source

const static Rule anyCharNotOf(Int[] chars)

Matches any character not in the given list.

Example PEG notation:

![ChukNoris] .
anyCharOf

Source

const static Rule anyCharOf(Int[] chars)

Matches any character in the given list.

Example PEG notation:

[ChukNoris]
anyHexChar

Source

const static Rule anyHexChar()

Matches any hexadecimal character.

PEG notation:

[a-fA-F0-9]
anyNonSpaceChar

Source

const static Rule anyNonSpaceChar()

Matches any non whitespace character.

PEG notation:

![ \t\n\r\f]
anyNumChar

Source

const static Rule anyNumChar()

Matches any numerical character.

PEG notation:

[0-9]
anySpaceChar

Source

const static Rule anySpaceChar()

Matches any whitespace character.

PEG notation:

[ \t\n\r\f]
anySpaceChars

Source

const static Rule anySpaceChars()

Matches multiple whitespace characters.

PEG notation:

[ \t\n\r\f]+
atLeast

Source

const 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:

???
atMost

Source

const static Rule atMost(Int n, Rule rule)

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

Example PEG notation:

???
between

Source

const static Rule between(Range times, Rule rule)

Processes the given rule at most n times. Returns success if it succeeded at least n times.

Example PEG notation:

???
char

Source

const static Rule char(Int char)

Matches the given character.

Example PEG notation:

"C"
doAction

Source

const static Rule doAction(|Str,Obj?? action)

Essentially a no-op rule as it always returns true - but processes the given action func when successful. Useful for inserting arbitrary actions in sequences:

sequence { rule1, doAction { echo("Hello!") }, rule2, }

Example PEG notation:

???
eos

Source

const static Rule eos()

Matches if the of the stream (EOS) is reached.

firstOf

Source

const 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, }
nTimes

Source

const static Rule nTimes(Int times, Rule rule)

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

Example PEG notation:

rule rule rule ... rule
oneOf

Source

const static Rule oneOf(Rule rule)

Processes the given rule and returns success if it succeeded. Convenience for nTimes(1, rule)

Example PEG notation:

???
oneOrMore

Source

const 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

const 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

const 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

const static Rule optional(Rule rule)

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

Example PEG notation:

(rule)?
sequence

Source

const 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, }
str

Source

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

Matches the given string.

Example PEG notation:

"ChuckNorris"
strNot

Source

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

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

Example PEG notation:

(!"ChuckNorris" .)+
todo

Source

const static Rule todo(Bool pass := false)

A placeholder. The rule will always succeed if pass is true, and always fail if pass is false.

zeroOrMore

Source

const static Rule zeroOrMore(Rule rule)

Processes the given rule repeatedly until it fails.

Example PEG notation:

(rule)*