This an R package for generating a peg parser. Peg is short for parsing expression grammer. The specification for the Peg grammar can be found at http://bford.info/pub/lang/peg. This software generates parsers based on that specification. By staying as close as possible to the original specification, we hope to provide a parsing solution which is language agnostic. That is, our hope is for a tool allowing one to concentrate on rule building, and not the nuances of any particular programming language.
One of the biggest issues in using a peg generator to create a parser is getting the rules "right"." In particular: Ensuring the rules have a valid PEG syntax. Ensuring the rules don't hang on a given input. (infinite recursion) Ensuring the rules accept the correct input. Ensuring the rules perform the right actions.
This tool is built with one principle in mind: Let the user concentrate on the getting rules right with as few of distractions as possible. This means we want debug rules , not code. Rules are entered as text- NOT CODE; debugging steps through the rules- NOT CODE; breakpoints are for rules- NOT CODE, stacks are stacks of rules -not code. To sum it up: IT'S THE RULES that rule!
Usage is described in the vignette and in the tutorial under inst/documents/tutorial.pdf. Various examples contained in help the online help (rd docs). For additional insight, there is a growing number of demos located inside the demos directory.
The steps for usage are:
Step 1: Construct a new peg parser:
peg<-new.parser()
Note: An data.frame argument may be supplied, which will load a set of rules stored as a data.frame
Step 2: Add rules to the parser (The "{...}" are optional actions.)
peg<-peg + c("A<- 'a' .", "{-}") + c("X<-.", "{}") + "R<- A / X"
Step 3: Apply a rule to an input string
example: peg[['R']]('abacda')
We currently supply 2 approaches to usage:
From Git using R CMD build
install.packages("devtools")
library(devtools)
install_github("mslegrand/pegr")
To delete
remove.packages("pegr")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.