marpa

GitHub release

Marpa is a parsing algorithm.
From the official Marpa website:

Marpa is fast. It parses in linear time:

(emphasis added)

Installation

Add this to your application's shard.yml:

dependencies:
  marpa:
    github: omarroth/marpa

Usage

require "marpa"

parser = Marpa::Parser.new

grammar = <<-'END_BNF'
# Grammar from https://metacpan.org/pod/distribution/Marpa-R2/pod/Semantics.pod
:start ::= Expression
Expression ::= Number
  | '(' Expression ')'
 || Expression '**' Expression
 || Expression '*' Expression
  | Expression '/' Expression
 || Expression '+' Expression
  | Expression '-' Expression

Number ~ [\d]+

:discard ~ whitespace
whitespace ~ [\s]+
END_BNF

input = "3 + 5 * 10"

pp parser.parse(input, grammar) # => [["3"], "+", [["5"], "*", ["10"]]]

See examples/ for a more thorough demonstration of this interface's capabilities, including a JSON parser.

Features

Limitations

Contributing

  1. Fork it ( https://github.com/omarroth/marpa/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors