Class: TDParser::Grammar

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

Instance Method Summary collapse

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missingObject



916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
# File 'lib/tdp.rb', line 916

def g_method_missing(sym, *args)
  arg0 = args[0]
  sym = sym.to_s()
  if (sym[-1,1] == "=")
    case arg0
    when Parser
      self.class.instance_eval{
        define_method(sym[0..-2]){ arg0 }
      }
    else
      t = token(arg0)
      self.class.instance_eval{
        define_method(sym[0..-2]){ t }
      }
    end
  elsif (args.size == 0)
    rule(sym)
  else
    raise(NoMethodError, "undefined method `#{sym}' for #{self.inspect}")
  end
end

Instance Method Details

#define(&block) ⇒ Object



883
884
885
886
887
888
889
890
891
892
# File 'lib/tdp.rb', line 883

def define(&block)
  instance_eval{
    begin
      alias method_missing g_method_missing
      block.call(self)
    ensure
      undef method_missing
    end
  }
end

#g_method_missing(sym, *args) ⇒ Object Also known as: method_missing



894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
# File 'lib/tdp.rb', line 894

def g_method_missing(sym, *args)
  arg0 = args[0]
  sym = sym.to_s()
  if (sym[-1,1] == "=")
    case arg0
    when Parser
      self.class.instance_eval{
        define_method(sym[0..-2]){ arg0 }
      }
    else
      t = token(arg0)
      self.class.instance_eval{
        define_method(sym[0..-2]){ t }
      }
    end
  elsif (args.size == 0)
    rule(sym)
  else
    raise(NoMethodError, "undefined method `#{sym}' for #{self.inspect}")
  end
end