Description Usage Arguments Details Value Using Named Vector Using Unnamed Vectors Inline Action Short Cuts Examples
Used to modify the rule definition and/or description and/or action of of an exiting rule
1 2 |
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. |
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.
peg parser
For named vectors the valid names are:
rule: The name rule is used to specify a field containing a rule definition (a.k.a. source). (like "A<-'a'") to be associated with the named rule.
des: The name des is used to specify a field containing a description or comment to be associated with the named rule
act: The name act is used to specify a field containing an action to be associated with the rule. The action can either be NULL, or text which representing the body of function taking a single parameter v that is a list and returns a list. When NULL, any existing action is deleted.
For unnamed vectors, each vector consists of a single string of the form:
"...<-..."
: Specifies a rule definition
(a.k.a. source). (like "A<-'a'")
"#..."
Specifies description or comment to be associated
with the rule (like "# my clever rule")
"{...} "
Specifies an inline action to be
associated with the rule. (like
"list(toupper(unlist(v)))" )
"{}=NULL"
Specifies to delete any existing to be associated with
the rule.
As a convenience the following short cuts are provided:
"{}"
: Specifies the action
"{list()}"
, which essentially says drop (ignore)
the values produce by this rule.
"{-}"
Specifies the action "list(paste(v,collapse=''))"
,
which says paste all the values together.
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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.