/language-ruby

Primary LanguageHaskellBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

language-ruby

Haskell parser for the Ruby 2.6 Language. Project structure is loosely based https://github.com/erikd/language-javascript, lexer is based on https://github.com/bjpop/language-python and parser is based on https://github.com/whitequark/parser.

Building

$ stack build

Running tests

$ stack test --file-watch --fast

Debugging Grammar

$ happy src/Parser.y -dai

Nodes naming

AST Nodes naming is the same as whitequark/parser's, with the following notable exceptions and changes:

  • CamelCase is used instead of snake_case. E.g.:
    • (Str "foo") instead of s(:str, "foo")
    • (BackRef "$&") instead of s(:back_ref, :$&)
  • Special __ variables have being completly renamed and are not being processed:
    • File instead of __FILE__
    • Encoding instead of __ENCODING__
    • Line instead of __LINE__
  • Varargs are replaced by lists:
    • (Begin [RInt 4, RInt 5]) instead of s(:begin, s(:int, 4), s(:int, 5))
  • Ruby datatypes are prefixed with an in order to avoid collisions. E.g.:
    • RInt instead of int
    • RFloat instead of float

Caveats

  1. Parser acts as if run with Parser::Builders::Default.emit_procarg0 = false and thus makes no distinction between f {|a|} and f{|a,|} since making such a distinction for only blocks with a single parameter seems odd.

Pending tasks

This project is just an on-going progress:

  • ✔️ Grammar is mostly finished
  • ❎ Lexer is incompletle
  • ❎ Tree builder and AST is mostly unimplemented
  • ❎ Happy build times are slow which is cumbersome for development, I should check bjpop/language-python#41. On the meanwhile, just comment grammar rules that are not being developed.