Sha256: bf60109bb0f5af3e133bca5636f9e7bd8e43e0c6d58f4805de34a093bd28bec3
Contents?: true
Size: 867 Bytes
Versions: 4
Compression:
Stored size: 867 Bytes
Contents
# Ripper translation Prism provides the ability to mirror the `Ripper` standard library. You can do this by: ```ruby require "prism/translation/ripper/shim" ``` This provides the APIs like: ```ruby Ripper.lex Ripper.parse Ripper.sexp_raw Ripper.sexp Ripper::SexpBuilder Ripper::SexpBuilderPP ``` Briefly, `Ripper` is a streaming parser that allows you to construct your own syntax tree. As an example: ```ruby class ArithmeticRipper < Prism::Translation::Ripper 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] ``` The exact names of the `on_*` methods are listed in the `Ripper` source.
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
prism-0.28.0 | docs/ripper_translation.md |
prism-0.27.0 | docs/ripper_translation.md |
prism-0.26.0 | docs/ripper_translation.md |
prism-0.25.0 | docs/ripper_translation.md |