Description Usage Arguments Value Examples
Retrieve an action to the rule specified by rule.id
1 | get_action(pegR, rule.id)
|
parser, |
a peg parser produced by new.parser |
rule.id, |
a character string naming the rule |
action attached to the specified rule. The action may be may take two forms:
the name of a function
a string of text interpreted as a function body with an input parameter consisting of a list named v, and return value which is also a list.
1 2 3 4 5 6 7 8 9 10 11 12 13 | # Delete all vowels
peg<-new.parser()
peg<-add_rule(peg, "V<-'a' / 'e' / 'i' / 'o' / 'u' ")
peg<-add_rule(peg, "R<-(V / .)+")
peg<-set_action(peg, "V", "list()" )
g<-function(v){ list(paste(v,collapse='')) }
peg<-set_action(peg, "R", g )
#see the result
value(apply_rule(peg, "R", "cat in the hat", exe=T))
# inspect the action for rule "V"
get_action(peg, "V")
# inspect the action for rule "R"
get_action(peg, "R")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.