consumed: Returns The portion ot the input text consumed during a...

Description Usage Arguments Details Value Examples

View source: R/consumed.R

Description

Returns The portion ot the input text consumed during a parsing

Usage

1
consumed(res)

Arguments

res,

a result obtained from parsing

Details

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.

Value

The portion ot the input text consumed during the parse

#'

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

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