Class: TDParser::StackParser

Inherits:
CompositeParser show all
Defined in:
lib/tdp.rb

Instance Attribute Summary collapse

Attributes inherited from CompositeParser

#parsers

Instance Method Summary collapse

Methods inherited from CompositeParser

#optimize

Methods inherited from Parser

#%, #*, #+, #-, #/, #>, #>>, #do, #optimize, #parse, #peek, #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(parser, stack) ⇒ StackParser

Returns a new instance of StackParser.



348
349
350
351
# File 'lib/tdp.rb', line 348

def initialize(parser, stack)
  @stack = stack
  super(parser)
end

Instance Attribute Details

#stackObject (readonly)

Returns the value of attribute stack.



347
348
349
# File 'lib/tdp.rb', line 347

def stack
  @stack
end

Instance Method Details

#==(r) ⇒ Object



359
360
361
362
# File 'lib/tdp.rb', line 359

def ==(r)
  super(r) &&
  (@stack == r.stack)
end

#call(tokens, buff) ⇒ Object



353
354
355
356
357
# File 'lib/tdp.rb', line 353

def call(tokens, buff)
  x = @parsers[0].call(tokens, buff)
  @stack.push(x)
  x
end

#same?(r) ⇒ Boolean

Returns:

  • (Boolean)


364
365
366
# File 'lib/tdp.rb', line 364

def same?(r)
  false
end

#to_sObject



368
369
370
# File 'lib/tdp.rb', line 368

def to_s()
  "<stack:#{@stack.object_id}>"
end