Skip to content

kenaniah/ruby-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Background

The goal of this project is to create a complete parser for the Ruby language using parser combinators.

Differences from MRI

  • Control characters can be recursively escaped:
    "\C-\C-\\n" # => "\n"

Implementation Notes

Expressions / Statements / Groups

  • There is no semantic difference between an expression and a statement in this implementation
  • Node::Block contains a list of statements (each item is considered to be a statement)
  • Node::Expression contains a list of tokens that make up an individual statement
  • Block and expression tokens may be nested via the use of parenthesis:
    (2 + (puts "hi"; 4 - 8;;)) * 5
    #hi
    #=> -10

Lexing partial inputs

The Input type can be extended to track a boolean field that denotes whether the parser's input is complete or partial (such as within IRB's REPL). Combinators that may be partially completed (such as open strings, arrays, etc.) can additionally return a Node::IncompleteInput on the end of their token stream in partial mode to signal that the token has not been completed by the end of the user's input.

I'm not yet sure if start / end tokens should be used for complex objects, but they may be helpful when dealing with partial inputs.

To Do

About

An experimental lexer for Ruby using the nom library

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published