Class: Neg::Parser::NonTerminalParser
- Defined in:
- lib/neg/parser.rb
Instance Method Summary collapse
- #==(pa) ⇒ Object
-
#do_parse(i) ⇒ Object
def reduce(children_results).
-
#initialize(name, child = nil) ⇒ NonTerminalParser
constructor
A new instance of NonTerminalParser.
- #parse(input_or_string) ⇒ Object
- #to_s(parent = nil) ⇒ Object
Methods inherited from SubParser
Constructor Details
#initialize(name, child = nil) ⇒ NonTerminalParser
Returns a new instance of NonTerminalParser.
115 116 117 118 119 |
# File 'lib/neg/parser.rb', line 115 def initialize(name, child=nil) @name = name @child = child end |
Instance Method Details
#==(pa) ⇒ Object
121 122 123 124 |
# File 'lib/neg/parser.rb', line 121 def ==(pa) @child = pa end |
#do_parse(i) ⇒ Object
def reduce(children_results)
children_results.collect { |cr|
if cr[0] && cr[0] != :digit
false
elsif cr[2]
cr[3] ? cr[3] : reduce(cr[4])
else
nil
end
}.flatten.compact
end
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/neg/parser.rb', line 139 def do_parse(i) raise ParseError.new("\"#{@name}\" is missing") if @child.nil? r = @child.do_parse(i) return r # return r if r[0] == false # # report = reduce(r[2]) # # return r if report.include?(false) # # [ true, report.join, [] ] end |
#parse(input_or_string) ⇒ Object
156 157 158 159 160 161 162 |
# File 'lib/neg/parser.rb', line 156 def parse(input_or_string) r = super(input_or_string) r[0] = @name r end |
#to_s(parent = nil) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/neg/parser.rb', line 164 def to_s(parent=nil) child = @child ? @child.to_s(self) : '<missing>' if @name.is_a?(String) "#{child}[#{@name.inspect}]" elsif parent @name.to_s else #if @name.is_a?(Symbol) "#{@name} == #{child}" end end |