Class: Neg::Parser::NonTerminalParser

Inherits:
SubParser
  • Object
show all
Defined in:
lib/neg/parser.rb

Instance Method Summary collapse

Methods inherited from SubParser

#*, #+, #[], #|

Constructor Details

#initialize(name, child = nil) ⇒ NonTerminalParser

Returns a new instance of NonTerminalParser.



134
135
136
137
138
# File 'lib/neg/parser.rb', line 134

def initialize(name, child=nil)

  @name = name
  @child = child
end

Instance Method Details

#==(pa) ⇒ Object



140
141
142
143
# File 'lib/neg/parser.rb', line 140

def ==(pa)

  @child = pa
end

#do_parse(i) ⇒ Object



145
146
147
148
# File 'lib/neg/parser.rb', line 145

def do_parse(i)

  @child.do_parse(i)
end

#parse(input_or_string) ⇒ Object



150
151
152
153
154
155
156
# File 'lib/neg/parser.rb', line 150

def parse(input_or_string)

  r = super(input_or_string)
  r[0] = @name

  r
end

#to_s(parent = nil) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/neg/parser.rb', line 158

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