Sha256: db7b1d622e4823fef741cb54678a1e948e26004379244183ceefaec28ffa503f

Contents?: true

Size: 1.32 KB

Versions: 23

Compression:

Stored size: 1.32 KB

Contents

# Ripper

To test the parser, we compare against the output from `Ripper`, both for testing the lexer and testing the parser. The lexer test suite is much more feature complete at the moment.

To lex source code using `prism`, you typically would run `Prism.lex(source)`. If you want to instead get output that `Ripper` would normally produce, you can run `Prism.lex_compat(source)`. This will produce tokens that should be equivalent to `Ripper`.

To parse source code using `prism`, you typically would run `Prism.parse(source)`. If you want to instead using the `Ripper` streaming interface, you can inherit from `Prism::RipperCompat` and override the `on_*` methods. This will produce a syntax tree that should be equivalent to `Ripper`. That would look like:

```ruby
class ArithmeticRipper < Prism::RipperCompat
  def on_binary(left, operator, right)
    left.public_send(operator, right)
  end

  def on_int(value)
    value.to_i
  end

  def on_program(stmts)
    stmts
  end

  def on_stmts_new
    []
  end

  def on_stmts_add(stmts, stmt)
    stmts << stmt
    stmts
  end
end

ArithmeticRipper.new("1 + 2 - 3").parse # => [0]
```

There are also APIs for building trees similar to the s-expression builders in `Ripper`. The method names are the same. These include `Prism::RipperCompat.sexp_raw(source)` and `Prism::RipperCompat.sexp(source)`.

Version data entries

23 entries across 23 versions & 4 rubygems

Version Path
jruby-prism-parser-0.24.0-java docs/ripper.md
jruby-prism-parser-0.23.0.pre.SNAPSHOT-java docs/ripper.md
prism-0.24.0 docs/ripper.md
prism-0.23.0 docs/ripper.md
prism-0.22.0 docs/ripper.md
prism-0.21.0 docs/ripper.md
prism-0.20.0 docs/ripper.md
prism-0.19.0 docs/ripper.md
study_line-0.1.6 vendor/bundle/ruby/3.2.0/gems/prism-0.15.1/docs/ripper.md
study_line-0.1.5 vendor/bundle/ruby/3.2.0/gems/prism-0.15.1/docs/ripper.md
study_line-0.1.4 vendor/bundle/ruby/3.2.0/gems/prism-0.15.1/docs/ripper.md
study_line-0.1.3 vendor/bundle/ruby/3.2.0/gems/prism-0.15.1/docs/ripper.md
study_line-0.1.2 vendor/bundle/ruby/3.2.0/gems/prism-0.15.1/docs/ripper.md
study_line-0.1.1 vendor/bundle/ruby/3.2.0/gems/prism-0.15.1/docs/ripper.md
prism-0.18.0 docs/ripper.md
prism-0.17.1 docs/ripper.md
prism-0.17.0 docs/ripper.md
prism-0.16.0 docs/ripper.md
prism-0.15.1 docs/ripper.md
prism-0.15.0 docs/ripper.md