abstract classafPegger::Rule

sys::Obj
  afPegger::Rule

@Js

(Advanced) Models a PEG Rule.

Rules are commonly created by using methods from the Rules mixin, but may be parsed from string patterns.

Rule may sub-classed to create your own custom rules.

debug

Source

virtual Bool debug := true

Disable debugging of this rule if it gets too noisy.

debugOff

Source

This debugOff()

A helpful builder method for turning debug off.

In PEG grammar, rules are excluded from debug by add a hyphen suffix to the declaration.

noDebugRule-  = foobar foobar
definition

Source

Str definition()

Returns the PEG definition for this rule. Example:

alphaNum <- [a-zA-Z0-9]
excludeFromResults

Source

This excludeFromResults()

A helpful builder method for removing this rule from tree results.

In PEG grammar, rules are excluded from results by add a hyphen prefix to the declaration.

-excludedRule  = foobar foobar
expression

Source

Str expression()

Returns the PEG expression for this rule (with any label definition). Example:

label:[a-zA-Z0-9]
label

Source

virtual Str? label

A label for this rule.

someRule <- label:foobar foobar

Note the same rule definition may have multiple / different labels when used in different parts of PEG grammar.

Only rules with labels (or names) appear in debug output and the output tree, unless explicitly disabled.

Should be a legal Fantom identifier (think variable names!).

match

Source

Match? match(Str str)

Matches this rule against the given string.

See Peg.match

name

Source

virtual Str? name { internal set }

The name of this rule, as defined by grammar.

name <- foobar foobar

Only rules with names (or labels) appear in debug output and the output tree, unless explicitly disabled.

Should be a legal Fantom identifier (think variable names!).

parseRule

Source

static new parseRule(Str pattern)

Creates a rule by parsing the given pattern:

Rule.fromPattern("[abc] / [xyz]")

See Peg.parseRule

useInResult

Source

virtual Bool useInResult := true

Not all rules are useful in the parsed AST.

withLabel

Source

This withLabel(Str? label)

A helpful builder method for setting the label.

someRule <- label:foobar foobar

Note the same rule definition may have multiple / different labels when used in different parts of PEG grammar.

Only rules with labels (or names) appear in debug output and the output tree.

Should be a legal Fantom identifier (think variable names!).