Class: Strling::Core::Compiler
- Inherits:
-
Object
- Object
- Strling::Core::Compiler
- Defined in:
- lib/strling/core/compiler.rb
Overview
Compiler class for transforming AST to IR
Class Method Summary collapse
-
.compile(node) ⇒ IROp
Compile an AST node tree to IR.
Instance Method Summary collapse
-
#compile_node(node) ⇒ IROp
Compile a single AST node to its IR equivalent.
Class Method Details
.compile(node) ⇒ IROp
Compile an AST node tree to IR
26 27 28 |
# File 'lib/strling/core/compiler.rb', line 26 def self.compile(node) new.compile_node(node) end |
Instance Method Details
#compile_node(node) ⇒ IROp
Compile a single AST node to its IR equivalent
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/strling/core/compiler.rb', line 34 def compile_node(node) case node when Alt IRAlt.new(node.branches.map { |b| compile_node(b) }) when Seq IRSeq.new(node.parts.map { |p| compile_node(p) }) when Lit IRLit.new(node.value) when Dot IRDot.new when Anchor IRAnchor.new(node.at) when CharClass IRCharClass.new( node.negated, node.items.map { |item| compile_class_item(item) } ) when Quant IRQuant.new( compile_node(node.child), node.min, node.max, node.mode ) when Group IRGroup.new( node.capturing, compile_node(node.body), name: node.name, atomic: node.atomic ) when Backref IRBackref.new(by_index: node.by_index, by_name: node.by_name) when Look IRLook.new(node.dir, node.neg, compile_node(node.body)) else raise "Unknown AST node type: #{node.class}" end end |