Class: Take::Unit::Compiler
- Inherits:
-
Object
- Object
- Take::Unit::Compiler
- Includes:
- PredictMatch
- Defined in:
- lib/take/unit/compiler.rb
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #compile ⇒ Object
- #compile_after ⇒ Object
- #compile_before ⇒ Object
- #compile_group ⇒ Object
- #compile_macro ⇒ Object
- #compile_part ⇒ Object
- #compile_prefix ⇒ Object
- #compile_test ⇒ Object
-
#initialize(file, tokens) ⇒ Compiler
constructor
A new instance of Compiler.
Methods included from PredictMatch
Constructor Details
#initialize(file, tokens) ⇒ Compiler
Returns a new instance of Compiler.
9 10 11 12 13 14 |
# File 'lib/take/unit/compiler.rb', line 9 def initialize(file, tokens) @file = file @tokens = tokens @enum = tokens.each @parent = nil end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
7 8 9 |
# File 'lib/take/unit/compiler.rb', line 7 def parent @parent end |
Instance Method Details
#compile ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/take/unit/compiler.rb', line 16 def compile @parent ||= begin @parent = AST::Parent.new(name: File.basename(@file). gsub(/\..*\z/, "")) while peek do part = predict(:group => :group, :prefix => :prefix) @parent.children << part if part end add_parent_prefix @parent.source = sourcify([0, 0]) @parent end end |
#compile_after ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/take/unit/compiler.rb', line 77 def compile_after after = match(:after) body = match(:block) AST::After.new(name: after[1], children: [AST::Block.new({ body: body[1], source: sourcify(body) })], source: sourcify(after)) end |
#compile_before ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/take/unit/compiler.rb', line 65 def compile_before before = match(:before) body = match(:block) AST::Before.new(name: before[1], children: [AST::Block.new({ body: body[1], source: sourcify(body) })], source: sourcify(before)) end |
#compile_group ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/take/unit/compiler.rb', line 32 def compile_group group = match(:group) node = AST::Group.new(name: group[1], source: sourcify(group)) until peek == :group_end part = compile_part node.children << part if part end match(:group_end) node end |
#compile_macro ⇒ Object
104 105 106 |
# File 'lib/take/unit/compiler.rb', line 104 def compile_macro end |
#compile_part ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/take/unit/compiler.rb', line 46 def compile_part predict :group => :group, :test => :test, :before => :before, :after => :after, :macro => :macro end |
#compile_prefix ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/take/unit/compiler.rb', line 89 def compile_prefix prefix = match(:prefix) body = match(:block) @parent.children << AST::Prefix.new( name: prefix[1], children: [AST::Block.new({ body: body[1], source: sourcify(body) })], source: sourcify(prefix)) nil end |