Class: Join
- Inherits:
-
Combinator
- Object
- Combinator
- Join
- Defined in:
- lib/hivemind/combinators.rb
Instance Attribute Summary collapse
-
#as ⇒ Object
Returns the value of attribute as.
-
#parser ⇒ Object
Returns the value of attribute parser.
Instance Method Summary collapse
-
#initialize(parser, separator, as: nil) ⇒ Join
constructor
A new instance of Join.
- #parse(input, refs) ⇒ Object
Methods inherited from Combinator
Constructor Details
#initialize(parser, separator, as: nil) ⇒ Join
Returns a new instance of Join.
107 108 109 110 111 112 113 |
# File 'lib/hivemind/combinators.rb', line 107 def initialize(parser, separator, as: nil) @parser = parser @separator = separator @as = as.to_sym @separator_parser = Lit.new(@separator) & Mat.new(/ */) #workaround hivemind @@depth ||= 0 end |
Instance Attribute Details
#as ⇒ Object
Returns the value of attribute as.
105 106 107 |
# File 'lib/hivemind/combinators.rb', line 105 def as @as end |
#parser ⇒ Object
Returns the value of attribute parser.
105 106 107 |
# File 'lib/hivemind/combinators.rb', line 105 def parser @parser end |
Instance Method Details
#parse(input, refs) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/hivemind/combinators.rb', line 115 def parse(input, refs) success = true remaining = input results = [] while success # puts "#{' ' * @@depth}BEFORE " + @parser.label.to_s # p [" " * @@depth, remaining] # @@depth += 1 success, result, remaining = @parser.parse(remaining, refs) # @@depth -= 1 # puts "#{' ' * @@depth}AFTER " + @parser.label.to_s # p [" " * @@depth, success, remaining, results.length] # puts results.push(result) if success if success if remaining.start_with? ' (' # fix later remaining = "\n#{remaining}" end success, result, remaining = @separator_parser.parse(remaining, refs) end end [true, results, remaining] end |