Parsing Expression Grammars in Rcpp

A wrapper around the 'Parsing Expression Grammar Template Library', a C++11 library for generating Parsing Expression Grammars, that makes it accessible within Rcpp. With this, developers can implement their own grammars and easily expose them in R packages.


Travis-CI Build Status downloads

Parsing Expression Grammars (PEGs) are a way of defining formal grammars for formatted data that allow you to identify matched structures and then take actions on them. They're already used in R in the readr package, which is what makes readr so dang fast at type identification and parsing tabular data, but there's not historically been a standard way of defining and using them.

piton changes this, provides platform-independent PEG support in Rcpp. It wraps the PEGTL library by Colin Hirsch and Daniel Frey, which is header-only and so can be imported into other packages.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Use

An example of PEGs is included in the package, and takes a comma-separated set of numbers and sums them together:

library(piton)

peg_sum("1,2,  5, 91, 34")
[1] 133

piton itself is not designed for straight-up useR use - instead, it's a developer package. If you're interested in implementing a PEG using it, you need to:

  1. Link piton into your package as a dependency, using //[[Rcpp::depends()]] (see this post for an example of how it works);
  2. #include <pegtl.hpp>
  3. Write and expose your grammar
  4. Done!

The PEGTL docs contain quite a bit of documentation on how the underlying library works, and various examples of PEGs are included within the package itself. Integration with Rcpp is pretty clean, although developers may benefit from not explicitly using the Rcpp namespace due to a couple of collisions with the PEGTL namespace.

Installation

On CRAN:

install.packages("piton")

And for the development version:

devtools::install_github("ironholds/piton")

News

Version 0.1.1

  • Various CRAN fixes.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("piton")

0.1.1 by Oliver Keyes, 2 years ago


https://www.github.com/Ironholds/piton


Report a bug at https://www.github.com/Ironholds/piton/issues


Browse source code at https://github.com/cran/piton


Authors: Oliver Keyes [aut, cre] , Colin Hirsch [cph] , Daniel Frey [cph]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports Rcpp

Suggests testthat

Linking to Rcpp

System requirements: C++11


Linked to by tidyxl.


See at CRAN