Skip to content

Commit

Permalink
Remove Racc as it's now replaced by the parser gem
Browse files Browse the repository at this point in the history
  • Loading branch information
elia committed Sep 2, 2018
1 parent cddf58a commit c5cceee
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 689 deletions.
4 changes: 0 additions & 4 deletions Gemfile
Expand Up @@ -9,10 +9,6 @@ tilt_version = ENV['TILT_VERSION']
rack_version = ENV['RACK_VERSION']
sprockets_version = ENV['SPROCKETS_VERSION']

# Stick with older racc until
# https://github.com/tenderlove/racc/issues/22
# is solved.
gem 'racc', '< 1.4.10', platform: :jruby
gem 'json', '< 1.8.1', platform: :ruby if ruby_version < v['2.2']
gem 'rack-test', '< 0.8' if ruby_version <= v['2.0']
gem 'rubysl', platform: :rbx
Expand Down
1 change: 0 additions & 1 deletion Guardfile
Expand Up @@ -49,7 +49,6 @@ class ::Guard::Opal < Plugin
path = m[0]
puts color("Searching specs for #{m[0]}...", :yellow)
case path
when %r{grammar\.y$} then system 'rake racc'
when %r{^spec/lib} then rspec path
when %r{^spec/ruby} then mspec path
when %r{^opal/corelib}
Expand Down
36 changes: 1 addition & 35 deletions HACKING.md
Expand Up @@ -195,38 +195,4 @@ Array#permutation_generates_from_a_defensive_copy,_ignoring_mutations

## Parser

## Enabling debug output from Racc

To enable debug output in the Racc grammar set the `RACC_DEBUG` env var and recompile the grammar. While the env variable is set the parser will output the debug info for the parsing process.

```bash
$ export RACC_DEBUG=true
$ bundle exec rake racc # recompile the grammar
$ bundle exec exe/opal --sexp -e "42" # ask Opal for the SExp of some code

read :tINTEGER(tINTEGER) [42, [1, 0]]

shift tINTEGER
[ (tINTEGER [42, [1, 0]]) ]

…cut…

shift $end
[ (program (:int, 42)) ($end [false, [1, 2]]) ($end [false, [1, 2]]) ]

goto 403
[ 0 1 97 403 ]

accept

(:int, 42)
```
When done unset the env variable and recompile the grammar.
```bash
$ unset RACC_DEBUG
$ bundle exec rake racc # recompile the grammar
$ bundle exec exe/opal --sexp -e "42" # ask Opal for the SExp of some code
(:int, 42)
```
Opal relies on the `parser` gem, see debug/development documentation there to know more about its internals: https://whitequark.github.io/parser/.
23 changes: 3 additions & 20 deletions docs/compiler.md
Expand Up @@ -9,27 +9,12 @@ other runtime helpers.

The compiler can be broken down into 3 separate stages:

* lexing
* parsing
* lexing/parsing
* code generation

### Lexer
### Lexer/Parser

The [opal lexer][lexer] is implemented in pure ruby using
the `StringScanner` class from the opal stdlib. The source code is scanned
and tokens are then provided to the parser. This process simply converts
the ruby code given as a string, into a list of tokens representing the
parts of the ruby code.

### Parser

The [opal parser][parser] is implemented using a standard
bison like syntax, but relies on `racc`, a ruby implementation of yacc/bison
which is again available in the standard library. The parser takes these tokens
generated by the lexer and builds a syntax tree representing the ruby code.
This syntax tree is represented by [sexps][sexps]. As
ruby is such a complex and dynamic language, there is a lot of interaction
between the parser and the lexer, namely through a preserved `lex_state`.
The [opal parser][parser] relies on the `parser` gem, see debug/development documentation there to know more about its internals: https://whitequark.github.io/parser/.

### Code generation

Expand All @@ -42,8 +27,6 @@ code as well as a reference back to the original sexp which is useful for
generating source maps afterwards.


[lexer]: https://github.com/opal/opal/tree/master/lib/opal/parser/lexer.rb
[parser]: https://github.com/opal/opal/tree/master/lib/opal/parser/grammar.y
[sexps]: https://github.com/opal/opal/tree/master/lib/opal/parser/sexp.rb
[compiler]: https://github.com/opal/opal/tree/master/lib/opal/compiler.rb
[fragments]: https://github.com/opal/opal/tree/master/lib/opal/fragment.rb
Expand Down
1 change: 0 additions & 1 deletion opal.gemspec
Expand Up @@ -41,7 +41,6 @@ Gem::Specification.new do |spec|

spec.add_development_dependency 'sourcemap', '~> 0.1.0'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'racc'
spec.add_development_dependency 'rspec', '~> 3.6.0'
spec.add_development_dependency 'octokit', '~> 2.4.0'
spec.add_development_dependency 'bundler', '~> 1.5'
Expand Down

0 comments on commit c5cceee

Please sign in to comment.