All Projects → charliec443 → Ramble

charliec443 / Ramble

Licence: MIT license
A R parser based on combinatory parsers.

Programming Languages

r
7636 projects
TeX
3793 projects

Projects that are alternatives of or similar to Ramble

Lug
Parsing expression grammar (PEG) embedded domain specific language and parsing machine for C++17
Stars: ✭ 44 (+131.58%)
Mutual labels:  parsing, parser-combinators
Pegtl
Parsing Expression Grammar Template Library
Stars: ✭ 1,295 (+6715.79%)
Mutual labels:  parsing, parser-combinators
Pyparsing
Python library for creating PEG parsers
Stars: ✭ 1,052 (+5436.84%)
Mutual labels:  parsing, parser-combinators
Pidgin
C#'s fastest parser combinator library
Stars: ✭ 469 (+2368.42%)
Mutual labels:  parsing, parser-combinators
ParsecSharp
The faster monadic parser combinator library for C#
Stars: ✭ 23 (+21.05%)
Mutual labels:  parsing, parser-combinators
Scala Parser Combinators
simple combinator-based parsing for Scala. formerly part of the Scala standard library, now a separate community-maintained module
Stars: ✭ 523 (+2652.63%)
Mutual labels:  parsing, parser-combinators
Parsing With Haskell Parser Combinators
🔍 A step-by-step guide to parsing using Haskell parser combinators.
Stars: ✭ 72 (+278.95%)
Mutual labels:  parsing, parser-combinators
loquat
Monadic parser combinators for JavaScript / TypeScript
Stars: ✭ 47 (+147.37%)
Mutual labels:  parsing, parser-combinators
metal
A Java library for parsing binary data formats, using declarative descriptions.
Stars: ✭ 13 (-31.58%)
Mutual labels:  parsing, parser-combinators
Combine
A parser combinator library for Elixir projects
Stars: ✭ 174 (+815.79%)
Mutual labels:  parsing, parser-combinators
Angstrom
Parser combinators built for speed and memory efficiency
Stars: ✭ 434 (+2184.21%)
Mutual labels:  parsing, parser-combinators
autumn
A Java parser combinator library written with an unmatched feature set.
Stars: ✭ 112 (+489.47%)
Mutual labels:  parsing, parser-combinators
Pom
PEG parser combinators using operator overloading without macros.
Stars: ✭ 310 (+1531.58%)
Mutual labels:  parsing, parser-combinators
Comby
A tool for structural code search and replace that supports ~every language.
Stars: ✭ 912 (+4700%)
Mutual labels:  parsing, parser-combinators
parser-combinators
Lightweight package providing commonly useful parser combinators
Stars: ✭ 41 (+115.79%)
Mutual labels:  parsing, parser-combinators
Parser Combinators From Scratch
Code that accompanies the series
Stars: ✭ 56 (+194.74%)
Mutual labels:  parsing, parser-combinators
parser-lang
A parser combinator library with declarative superpowers
Stars: ✭ 25 (+31.58%)
Mutual labels:  parsing, parser-combinators
Parjs
JavaScript parser-combinator library
Stars: ✭ 145 (+663.16%)
Mutual labels:  parsing, parser-combinators
Funcparserlib
Recursive descent parsing library for Python based on functional combinators
Stars: ✭ 250 (+1215.79%)
Mutual labels:  parsing, parser-combinators
Syntax
Write value-driven parsers quickly in Swift with an intuitive SwiftUI-like DSL
Stars: ✭ 134 (+605.26%)
Mutual labels:  parsing, parser-combinators

Ramble

status CRAN_Status_Badge Travis-CI Build Status Coverage Status

This project is just an example to examine the functional components of R.

Installation

Ramble is now on CRAN:

install.packages("Ramble")

The development version can be installed from github:

# install.packages("devtools")
devtools::install_github("chappers/Ramble")

Goals

Create a parser combinator written in pure R. This is mostly a proof of concept, but could be useful or helpful to someone.

This is inspired by Programming in Haskell by Graham Hutton, and also the JavaScript port, and Python's recursive descent parsing library.

References:

Contributing

You can contribute by opening issues on Github or implementing things yourself and making a pull request.

Please ensure that package passes all checks with --as-cran flag (i.e. via devtools::check(args = c('--as-cran'))) before submitting a pull request.

How it Works

To understand the differences between Ramble and other combinatory parsers please read Ramble: A Parser Combinator in R.

Example

You may view examples for:

  • Parsing xml file
  • Creating a simple calculator
  • Reading a number given in words, and converting it to the appropriate numeric value

Within the examples/* folder. Below is the calculator example.

#' expr :: = term + term | term - term | term
#' term :: = factor * factor | factor / factor | factor
#' factor :: = (expr) | digit+

expr <- ((term %then% 
            symbol("+") %then%
            expr %using% function(x) {
              print(unlist(c(x)))
              return(sum(as.numeric(unlist(c(x))[c(1,3)])))
            }) %alt% 
           (term %then% 
              symbol("-") %then%
              expr %using% function(x) {
                print(unlist(c(x)))
                return(Reduce("-", as.numeric(unlist(c(x))[c(1,3)])))
              }) %alt% term)


term <- ((factor %then% 
             symbol("*") %then%
             term %using% function(x) {
               print(unlist(c(x)))
               return(prod(as.numeric(unlist(c(x))[c(1,3)])))
             }) %alt% 
           (factor %then% 
              symbol("/") %then%
              term %using% function(x) {
                print(unlist(c(x)))
                return(Reduce("/", as.numeric(unlist(c(x))[c(1,3)])))
              }) %alt% factor)

factor <- ((
    symbol("(") %then%
      expr %then%
      symbol(")") %using% 
      function(x){
        print(unlist(c(x)))
        return(as.numeric(unlist(c(x))[2]))
        })
    %alt% natural())

Output:

> expr("(1+1)*2")
[1] "1" "+" "1"
[1] "(" "2" ")"
[1] "2" "*" "2"
[1] "1" "+" "1"
[1] "(" "2" ")"
[1] "2" "*" "2"
[1] "1" "+" "1"
[1] "(" "2" ")"
[1] "2" "*" "2"
$result
[1] 4

$leftover
[1] ""

> expr("(1+2)*3")
[1] "1" "+" "2"
[1] "(" "3" ")"
[1] "3" "*" "3"
[1] "1" "+" "2"
[1] "(" "3" ")"
[1] "3" "*" "3"
[1] "1" "+" "2"
[1] "(" "3" ")"
[1] "3" "*" "3"
$result
[1] 9

$leftover
[1] ""

> expr("1*(2+3)*4*5")
[1] "2" "+" "3"
[1] "(" "5" ")"
[1] "4" "*" "5"
[1] "5"  "*"  "20"
[1] "1"   "*"   "100"
[1] "2" "+" "3"
[1] "(" "5" ")"
[1] "4" "*" "5"
[1] "5"  "*"  "20"
[1] "1"   "*"   "100"
[1] "2" "+" "3"
[1] "(" "5" ")"
[1] "4" "*" "5"
[1] "5"  "*"  "20"
[1] "1"   "*"   "100"
$result
[1] 100

$leftover
[1] ""

> expr("(4-2)+3")
[1] "4" "-" "2"
[1] "(" "2" ")"
[1] "4" "-" "2"
[1] "(" "2" ")"
[1] "4" "-" "2"
[1] "(" "2" ")"
[1] "2" "+" "3"
$result
[1] 5

$leftover
[1] ""
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].