Class: TDParser::NonTerminalParser

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

Overview

end of Parser

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(context, sym, *options) ⇒ NonTerminalParser

Returns a new instance of NonTerminalParser.



208
209
210
211
212
# File 'lib/tdp.rb', line 208

def initialize(context, sym, *options)
  @context = context
  @symbol = sym
  @options = options
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



207
208
209
# File 'lib/tdp.rb', line 207

def context
  @context
end

#optionsObject (readonly)

Returns the value of attribute options.



207
208
209
# File 'lib/tdp.rb', line 207

def options
  @options
end

#symbolObject (readonly)

Returns the value of attribute symbol.



207
208
209
# File 'lib/tdp.rb', line 207

def symbol
  @symbol
end

Instance Method Details

#==(r) ⇒ Object



225
226
227
228
229
230
# File 'lib/tdp.rb', line 225

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

#call(tokens, buff) ⇒ Object



214
215
216
217
218
219
220
221
222
223
# File 'lib/tdp.rb', line 214

def call(tokens, buff)
  res = nil
  case @symbol
  when Symbol, String
    res = @context.__send__(@symbol,*@options).call(tokens, buff)
  when Parser
    res = @symbol.call(tokens, buff)
  end
  res
end

#to_sObject



232
233
234
# File 'lib/tdp.rb', line 232

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