MyNixOS website logo
Description

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.

Parsing Expression Grammars in Rcpp

Travis-CI Build Status CRAN_Status_Badge 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")
Metadata

Version

1.0.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows