Class: Racc::Grammar::DefinitionEnv
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/racc/grammar.rb |
Class Method Summary
- .new ⇒ DefinitionEnv constructor
Instance Method Summary
-
#_(&block)
Alias for #action.
- #_add(target, x)
- #_added?(sym) ⇒ Boolean
- #_delayed_add(rule)
- #_intern(x)
- #action(&block) (also: #_)
- #flush_delayed
- #grammar
- #many(sym, &block)
- #many1(sym, &block)
- #method_missing(mid, *args, &block)
- #null(&block)
- #option(sym, default = nil, &block)
- #precedence_table(&block)
- #separated_by(sep, sym, &block)
- #separated_by1(sep, sym, &block)
- #seq(*list, &block)
- #_defmetasyntax(type, id, action, &block) private
- #_regist(target_name) private
- #_wrap(target_name, sym, block) private
Constructor Details
.new ⇒ DefinitionEnv
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(mid, *args, &block)
[ GitHub ]# File 'lib/racc/grammar.rb', line 226
def method_missing(mid, *args, &block) unless mid.to_s[-1,1] == '=' super # raises NoMethodError end target = @grammar.intern(mid.to_s.chop.intern) unless args.size == 1 raise ArgumentError, "too many arguments for #{mid} (#{args.size} for 1)" end _add target, args.first end
Instance Method Details
#_(&block)
Alias for #action.
# File 'lib/racc/grammar.rb', line 283
alias _ action
#_add(target, x)
[ GitHub ]# File 'lib/racc/grammar.rb', line 237
def _add(target, x) case x when Sym @delayed.each do |rule| rule.replace x, target if rule.target == x end @grammar.symboltable.delete x else x.each_rule do |r| r.target = target @grammar.add r end end flush_delayed end
#_added?(sym) ⇒ Boolean
# File 'lib/racc/grammar.rb', line 257
def _added?(sym) @grammar.added?(sym) or @delayed.detect {|r| r.target == sym } end
#_defmetasyntax(type, id, action, &block) (private)
[ GitHub ]#_delayed_add(rule)
[ GitHub ]# File 'lib/racc/grammar.rb', line 253
def _delayed_add(rule) @delayed.push rule end
#_intern(x)
[ GitHub ]#_regist(target_name) (private)
[ GitHub ]#_wrap(target_name, sym, block) (private)
[ GitHub ]# File 'lib/racc/grammar.rb', line 351
def _wrap(target_name, sym, block) target = target_name.intern _delayed_add Rule.new(@grammar.intern(target), [@grammar.intern(sym.intern)], UserAction.proc(block)) target end
#action(&block) Also known as: #_
[ GitHub ]# File 'lib/racc/grammar.rb', line 277
def action(&block) id = "@#{@seqs["action"] += 1}".intern _delayed_add Rule.new(@grammar.intern(id), [], UserAction.proc(block)) id end
#flush_delayed
[ GitHub ]#grammar
[ GitHub ]# File 'lib/racc/grammar.rb', line 209
def grammar flush_delayed @grammar.each do |rule| if rule.specified_prec rule.specified_prec = @grammar.intern(rule.specified_prec) end end @grammar.init @grammar end
#many(sym, &block)
[ GitHub ]#many1(sym, &block)
[ GitHub ]#null(&block)
[ GitHub ]# File 'lib/racc/grammar.rb', line 273
def null(&block) seq(&block) end
#option(sym, default = nil, &block)
[ GitHub ]#precedence_table(&block)
[ GitHub ]# File 'lib/racc/grammar.rb', line 220
def precedence_table(&block) env = PrecedenceDefinitionEnv.new(@grammar) env.instance_eval(&block) @grammar.end_precedence_declaration env.reverse end
#separated_by(sep, sym, &block)
[ GitHub ]# File 'lib/racc/grammar.rb', line 305
def separated_by(sep, sym, &block) option(separated_by1(sep, sym), [], &block) end
#separated_by1(sep, sym, &block)
[ GitHub ]#seq(*list, &block)
[ GitHub ]# File 'lib/racc/grammar.rb', line 269
def seq(*list, &block) Rule.new(nil, list.map {|x| _intern(x) }, UserAction.proc(block)) end