qp: A simple tool to examine a parsing expression in isolation

Description Usage Arguments Value Examples

View source: R/qp.R

Description

This can be quite useful in getting to know the PEG syntax

Usage

1
qp(p.expression, record = TRUE)

Arguments

expression,

a parsing expression (the right hand side of a rule definiton)

text.input,

text string to apply expression to.

record=TRUE,

By default TRUE, so one can immediately graph (plot) or print (tree)

Value

PEGResult, an object giving the result

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# A simple choice operator
qp("'a' / 'b'")( "ab")
# A simple sequence operator
qp("'a' 'b'")( "ab")
# A combination of choice and sequence
qp("('a'/'c') ('b' / 'd')")( "ab")
qp("('a'/'c') ('b' / 'd')")( "cd")
# A lookahead not operator
qp("'a' !'b'")( "ab" )
qp("'a' !'b'")( "ac" )
# An lookahead and operator
qp("'a' & 'b'")( "ab")
qp("'a' & 'b'")( "ac")
# An optional operator
qp("'a' 'b'?")( "ab")
qp("'a' 'b'?")( "ac")
qp("'a'? 'b'")( "ab")
qp("'a'? 'b'")( "ba")

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