Class: TDParser::ConditionParser

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, #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(&condition) ⇒ ConditionParser

Returns a new instance of ConditionParser.



746
747
748
# File 'lib/tdp.rb', line 746

def initialize(&condition)
  @condition = condition
end

Instance Attribute Details

#conditionObject (readonly)

Returns the value of attribute condition.



744
745
746
# File 'lib/tdp.rb', line 744

def condition
  @condition
end

Instance Method Details

#==(r) ⇒ Object



762
763
764
765
# File 'lib/tdp.rb', line 762

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

#call(tokens, buff) ⇒ Object



750
751
752
753
754
755
756
# File 'lib/tdp.rb', line 750

def call(tokens, buff)
  if (res = @condition.call(buff.map))
    Sequence[res]
  else
    nil
  end
end

#same?(r) ⇒ Boolean

Returns:

  • (Boolean)


767
768
769
# File 'lib/tdp.rb', line 767

def same?(r)
  false
end

#to_sObject



758
759
760
# File 'lib/tdp.rb', line 758

def to_s()
  "<condition:#{@condition}>"
end