Class: TDParser::TerminalParser

Inherits:
Parser
  • Object
show all
Defined in:
lib/tdp.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Parser

#%, #*, #+, #-, #/, #>, #>>, #do, #optimize, #parse, #peek, #same?, #to_proc, #|, #~@

Methods included from TDParser

#any_rule, #backref, #chainl, #chainr, #condition_rule, define, #empty_rule, #fail_rule, #leftrec, #none_rule, #rightrec, #rule, #stackref, #state, #token

Methods included from BufferUtils

#prepare, #recover

Constructor Details

#initialize(obj, eqsym) ⇒ TerminalParser

Returns a new instance of TerminalParser.



240
241
242
243
# File 'lib/tdp.rb', line 240

def initialize(obj, eqsym)
  @symbol   = obj
  @equality = eqsym
end

Instance Attribute Details

#equalityObject (readonly)

Returns the value of attribute equality.



238
239
240
# File 'lib/tdp.rb', line 238

def equality
  @equality
end

#symbolObject (readonly)

Returns the value of attribute symbol.



238
239
240
# File 'lib/tdp.rb', line 238

def symbol
  @symbol
end

Instance Method Details

#==(r) ⇒ Object



255
256
257
258
259
# File 'lib/tdp.rb', line 255

def ==(r)
  (self.class == r.class) &&
  (@symbol == r.symbol) &&
  (@equality == r.equality)
end

#call(tokens, buff) ⇒ Object



245
246
247
248
249
250
251
252
253
# File 'lib/tdp.rb', line 245

def call(tokens, buff)
  t = tokens.shift
  buff.unshift(t)
  if( @symbol.__send__(@equality,t) || t.__send__(@equality,@symbol) )
    Sequence[t]
  else
    nil
  end
end

#to_sObject



261
262
263
# File 'lib/tdp.rb', line 261

def to_s()
  "#{@symbol}"
end