get_action: Retrieve an action to the rule specified by rule.id

Description Usage Arguments Value Examples

View source: R/get_action.R

Description

Retrieve an action to the rule specified by rule.id

Usage

1
get_action(pegR, rule.id)

Arguments

parser,

a peg parser produced by new.parser

rule.id,

a character string naming the rule

Value

action attached to the specified rule. The action may be may take two forms:

  1. the name of a function

  2. 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.

Examples

 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")

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