Description Usage Arguments Details Value Examples
Returns The portion ot the input text consumed during a parsing
1 | consumed(res)
|
res, |
a result obtained from parsing |
Applying a rule to an input string will consume only the portion for which there is a match. If no match, is consumed is "", then the status is FALSE, but even if there is a partial match, the status will be TRUE. In debugging it may be useful to see how far the parser succeeded. If a complete is required then end the rule with !., meaning no more charactes.
The portion ot the input text consumed during the parse
#'
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 26 27 28 29 30 | peg<-new.parser()
peg<-add_rule(pe)
#A returns TRUEfor "aab" but consumes on the first 2 charactes
peg<-new.parser()
peg<-add_rule(peg, "A <- ('a' A) / 'a' ")
apply_rule(peg, "A", "aab")->res
status(res
consumed(res)
#All returns FALSE on "aab"
peg<-add_rule(peg, "All <- A !. ")
apply_rule(peg, "All", "aab")->res
status(res)
consumed(res)
#All return TRUE on "aaa"
apply_rule(peg, "All", "aaa")->res
status(res)
consumed(res)
#Another approach: change A to
#This now returns FALSE on "aab
peg<-add_rule(peg, "A<- ('a' A ) / ('a' !.)")
apply_rule(peg, "A", "aab")->res
status(res)
consumed(res)
#But returns true on: "aaa"
apply_rule(peg, "A", "aaa")->res
status(res)
consumed(res)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.