Module: TDParser

Includes:
BufferUtils
Included in:
Grammar, Parser
Defined in:
lib/tdp.rb

Defined Under Namespace

Modules: BufferUtils Classes: ActionParser, AnyParser, BackrefParser, ChoiceParser, CompositeParser, ConcatParser, ConditionParser, EmptyParser, FailParser, Grammar, IterationParser, LabelParser, NegativeParser, NonTerminalParser, NoneParser, ParallelParser, Parser, ParserException, ReferenceParser, Sequence, StackParser, StackrefParser, StateParser, TerminalParser, TokenBuffer, TokenGenerator

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BufferUtils

#prepare, #recover

Class Method Details

.define(*args, &block) ⇒ Object



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

def TDParser.define(*args, &block)
  klass = Class.new(Grammar)
  g = klass.new()
  begin
    if defined?(g.instance_exec)
      g.instance_exec(g, &block)
    else
      g.instance_eval(&block)
    end
  ensure
    g.instance_eval{
      undef method_missing
    }
  end
  g
end

Instance Method Details

#any_ruleObject Also known as: any



826
827
828
# File 'lib/tdp.rb', line 826

def any_rule()
  AnyParser.new()
end

#backref(x, eqsym = :===) ⇒ Object



809
810
811
# File 'lib/tdp.rb', line 809

def backref(x, eqsym=:===)
  BackrefParser.new(x, eqsym)
end

#chainl(base, *infixes, &act) ⇒ Object



868
869
870
871
872
# File 'lib/tdp.rb', line 868

def chainl(base, *infixes, &act)
  infixes.inject(base){|acc,r|
    leftrec(acc, r - acc, &act)
  }
end

#chainr(base, *infixes, &act) ⇒ Object



874
875
876
877
878
# File 'lib/tdp.rb', line 874

def chainr(base, *infixes, &act)
  infixes.inject(base){|acc,r|
    rightrec(acc - r, acc, &act)
  }
end

#condition_rule(&b) ⇒ Object Also known as: condition



841
842
843
# File 'lib/tdp.rb', line 841

def condition_rule(&b)
  ConditionParser.new(&b)
end

#empty_rule(&b) ⇒ Object Also known as: empty



821
822
823
# File 'lib/tdp.rb', line 821

def empty_rule(&b)
  EmptyParser.new(&b)
end

#fail_ruleObject Also known as: fail



836
837
838
# File 'lib/tdp.rb', line 836

def fail_rule()
  FailParser.new()
end

#leftrec(*rules, &act) ⇒ Object



846
847
848
849
850
851
852
853
854
# File 'lib/tdp.rb', line 846

def leftrec(*rules, &act)
  f = Proc.new{|x|
    x[1].inject(x[0]){|acc,y|
      act.call(Sequence[acc,*y])
    }
  }
  base = rules.shift()
  rules.collect{|r| base - r*0 >> f}.inject(fail()){|acc,r| r | acc}
end

#none_ruleObject Also known as: none



831
832
833
# File 'lib/tdp.rb', line 831

def none_rule()
  NoneParser.new()
end

#rightrec(*rules, &act) ⇒ Object



856
857
858
859
860
861
862
863
864
865
866
# File 'lib/tdp.rb', line 856

def rightrec(*rules, &act)
  f = Proc.new{|x|
    x[0].reverse.inject(x[1]){|acc,y|
      ys = y.dup()
      ys.push(acc)
      act.call(Sequence[*ys])
    }
  }
  base = rules.pop()
  rules.collect{|r| r*0 - base >> f}.inject(fail()){|acc,r| r | acc}
end

#rule(sym, *opts) ⇒ Object



801
802
803
# File 'lib/tdp.rb', line 801

def rule(sym, *opts)
  NonTerminalParser.new(self, sym, *opts)
end

#stackref(stack, eqsym = :===) ⇒ Object



813
814
815
# File 'lib/tdp.rb', line 813

def stackref(stack, eqsym=:===)
  StackrefParser.new(stack, eqsym)
end

#state(s) ⇒ Object



817
818
819
# File 'lib/tdp.rb', line 817

def state(s)
  StateParser.new(s)
end

#token(x, eqsym = :===) ⇒ Object



805
806
807
# File 'lib/tdp.rb', line 805

def token(x, eqsym=:===)
  TerminalParser.new(x, eqsym)
end