Class: SyntaxTree::YARV::Compiler::RubyVisitor
- Inherits:
-
BasicVisitor
- Object
- BasicVisitor
- SyntaxTree::YARV::Compiler::RubyVisitor
- Defined in:
- lib/syntax_tree/yarv/compiler.rb
Overview
This visitor is responsible for converting Syntax Tree nodes into their corresponding Ruby structures. This is used to convert the operands of some instructions like putobject that push a Ruby object directly onto the stack. It is only used when the entire structure can be represented at compile-time, as opposed to constructed at run-time.
Direct Known Subclasses
Defined Under Namespace
Classes: CompilationError
Class Method Summary collapse
-
.compile(node) ⇒ Object
This will attempt to compile the given node.
Instance Method Summary collapse
-
#visit_regexp_literal_flags(node) ⇒ Object
This isn’t actually a visit method, though maybe it should be.
- #visit_unsupported(_node) ⇒ Object
Methods inherited from BasicVisitor
valid_visit_methods, #visit, #visit_all, #visit_child_nodes, visit_method, visit_methods
Class Method Details
.compile(node) ⇒ Object
This will attempt to compile the given node. If it’s possible, then it will return the compiled object. Otherwise it will return nil.
122 123 124 125 |
# File 'lib/syntax_tree/yarv/compiler.rb', line 122 def self.compile(node) node.accept(new) rescue CompilationError end |
Instance Method Details
#visit_regexp_literal_flags(node) ⇒ Object
This isn’t actually a visit method, though maybe it should be. It is responsible for converting the set of string options on a regular expression into its equivalent integer.
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/syntax_tree/yarv/compiler.rb', line 249 def visit_regexp_literal_flags(node) node . .chars .inject(0) do |accum, option| accum | case option when "i" Regexp::IGNORECASE when "x" Regexp::EXTENDED when "m" Regexp::MULTILINE else raise "Unknown regexp option: #{option}" end end end |
#visit_unsupported(_node) ⇒ Object
268 269 270 |
# File 'lib/syntax_tree/yarv/compiler.rb', line 268 def visit_unsupported(_node) raise CompilationError end |