Giter Club home page Giter Club logo

bullock's Introduction

Bullock

A simple Ruby PEG implementation - no strings attached!

Why Would I Need Another Ruby PEG?

Probably you don't, but I definitely do and I would like to explain you why.

I have been tackling some interesting tasks recently, such as rewriting a TemplateHandler for Rails that speaks Handlebars.

At first, I started my investigation to understand what is the best PEG for me and my team. We were in need of a PEG that was both less intrusive and with a smooth learning curve. Also, we needed the parser and lexer code to be easily maintainable in the future.

We ended up choosing RLTK, that in my opinion is a good example of clear API in terms of lexing and parsing specification - so we decided to adopt it. Although we found it compelling an clean at first, we ended up in merging in our runtime other gems that are an unnecessary risk for us. This happened simply because this implementation, like many other out there, they do more than we actually needed.

This gem aims to give to the Ruby world a simple PEG implementation, with a smooth learning curve, simple API, excellent test coverage, examples of usage with great explanation and, last but not least, no runtime dependencies at all.

These are the actual gems that are needed in develoment mode:

Using columnize 0.9.0
Using debugger-linecache 1.2.0
Using slop 3.6.0
Using byebug 4.0.3
Using diff-lcs 1.2.5
Using rspec-support 3.2.1
Using rspec-core 3.2.0
Using rspec-expectations 3.2.0
Using rspec-mocks 3.2.0
Using rspec 3.2.0
Using bundler 1.8.2

11 gems needed in development mode, and 0 gems needed at runtime!

Why This Logo?

Well... There was a Yacc, then a Bison followed and now... a Bullock :^)

How to Bullock

Lexing

lexer = Bullock.lexer do
  rule(/regex/, :state) { |match| ... }
  rule(/another_regex/) { ... }
end

tokens = lexer.lex(string)

Match First Lexer

Match Longest Lexer

Parsing

parser = Bullock.parser(start: :a) do
  symbol(:a) do
    produces('a b .c') { |c| ... }
    produces('x y z') { |x, y, z| ... }
  end

  production(:b, 'x .Y z') { |y| ... }
end

outcome = parser.parse(tokens)

Error Handling

Lexer Errors

Parse Errors

How to Contribute

Principles

Practices

Examples

Calculator

External DSL

References

bullock's People

Contributors

codella avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.