Note: This integration is not finished, and therefore still has many inconsistencies with Ripper
. If you’d like to help out, pull requests would be greatly appreciated!
This class is meant to provide a compatibility layer between prism and Ripper
. It functions by parsing the entire tree first and then walking it and executing each of the Ripper
callbacks as it goes.
This class is going to necessarily be slower than the native Ripper
API. It is meant as a stopgap until developers migrate to using prism. It is also meant as a test harness for the prism parser.
To use this class, you treat ‘Prism::RipperCompat` effectively as you would treat the `Ripper` class.
- E
- N
- P
- S
- V
Attributes
[R] | column | The current column number of the parser. |
[R] | lineno | The current line number of the parser. |
[R] | source | The source that is being parsed. |
Class Public methods
new(source) Link
Create a new RipperCompat
object with the given source.
sexp(source) Link
This is a convenience method that runs the SexpBuilderPP
subclass parser.
sexp_raw(source) Link
This is a convenience method that runs the SexpBuilder
subclass parser.
Instance Public methods
error?() Link
True if the parser encountered an error during parsing.
parse() Link
Parse the source and return the result.
# File ruby/lib/prism/ripper_compat.rb, line 91 def parse result.magic_comments.each do |magic_comment| on_magic_comment(magic_comment.key, magic_comment.value) end if error? result.errors.each do |error| on_parse_error(error.message) end else result.value.accept(self) end end
visit_call_node(node) Link
Visit a CallNode node.
# File ruby/lib/prism/ripper_compat.rb, line 110 def visit_call_node(node) if !node.message.match?(/^[[:alpha:]_]/) && node.opening_loc.nil? && node.arguments&.arguments&.length == 1 left = visit(node.receiver) right = visit(node.arguments.arguments.first) bounds(node.location) on_binary(left, node.name, right) else raise NotImplementedError end end
visit_imaginary_node(node) Link
Visit a ImaginaryNode
node.
visit_integer_node(node) Link
Visit an IntegerNode
node.
visit_program_node(node) Link
Visit a ProgramNode node.
visit_rational_node(node) Link
Visit a RationalNode
node.