sub-subset-.pegR: Reset an existing rule: definition, description, action

Description Usage Arguments Details Value Using Named Vector Using Unnamed Vectors Inline Action Short Cuts Examples

Description

Used to modify the rule definition and/or description and/or action of of an exiting rule

Usage

1
2
## S3 replacement method for class 'pegR'
parser[[rule.id]] <- value

Arguments

parser,

the peg parser containing the rule to be modified

rule.id,

the identifier of the rule to be modified

value,

the modifications to be applied. Can be either a named vector or a named list (see below), a unnamed character vector(see below), or NULL, which case the rule is deleted.

Details

This is a very flexiable way of resetting the action, description and even the definition of an existing rule. This encompasses the functionality of set_definition, set_description and set_action This rule accepts either named vectors/lists or unnamed vectors. In both cases, the vectors are character vectors and the list components are either strings or a function representing an action.

Value

peg parser

Using Named Vector

For named vectors the valid names are:

Using Unnamed Vectors

For unnamed vectors, each vector consists of a single string of the form:

Inline Action Short Cuts

As a convenience the following short cuts are provided:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Modfiying a rule (adding a comment and  action):
peg<-new.parser()
peg + "A<-'a'"
peg
peg[["A"]]<-"A<-'ab'"
peg
peg[["A"]]<-c("A<-'xx'", des="replace xx by a", act="list('a')")

# Another way of doing the same thing (adding a comment and  action):
peg<-new.parser()
peg + "A<-'a'"
peg
peg[["A"]]<-"A<-'ab'"
peg
peg[["A"]]<-c("A<-'xx'", "#replace xx by a", "{list('a')}")

# The following are equivalent:
peg[['A']]<-list(act="list()")
peg[['A']]<-"{}" # A shortcut

# Deleteing a rule
peg<-new.parser()
peg + "A<-'a'" + "B<-'b'"
peg[["A"]]<-NULL
peg

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