add_rule: Adds a rule to the parser

Description Usage Arguments Value See Also Examples

View source: R/add_rule.R

Description

Adds a rule to the parser, if the rule exists, it is overwritten, getting a new definition, a new (possibly empty) description, and a new (possibly empty) action.

Usage

1
add_rule(parser, rule, des = NULL, act = NULL)

Arguments

parser,

a peg parser produced by new.parser

rule,

the rule description, a quoted string that defines a rule according to the PEG Grammer

des,

(optional: NULL by default) sets a rule description for this rule

act,

(optional: NULL by default) sets an action, to be executed by this rule. This NULL by default.

Value

Status and the rule processed

See Also

For a description of actions see set_action and appy_rule )

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
peg<-new.parser()
peg<-add_rule(peg, "X<-x", des="A bad rule (I forgot quotes)")

# Next we inspect the rule
inspect_rule(peg, "X")
# Inspect rule returns the following
# Rule: X
# Def: X<-x
# Com: A bad rule (needs quotes)
# Act:

# Now we replace the rule by overwriting
peg<-add_rule(peg, "X<-'x'", act="list('X')")
# When again inspect, we see
# the definition was fixed (x now is quoted), the description was removed, an action was added.
inspect_rule(peg,"X")

mslegrand/pegr documentation built on May 23, 2019, 7:53 a.m.