Parent

Racc::Grammar::DefinitionEnv

Public Class Methods

new() click to toggle source
     # File lib/racc/grammar.rb, line 205
205:       def initialize
206:         @grammar = Grammar.new
207:         @seqs = Hash.new(0)
208:         @delayed = []
209:       end

Public Instance Methods

_(&block) click to toggle source
Alias for: action
_add(target, x) click to toggle source
     # File lib/racc/grammar.rb, line 239
239:       def _add(target, x)
240:         case x
241:         when Sym
242:           @delayed.each do |rule|
243:             rule.replace x, target if rule.target == x
244:           end
245:           @grammar.symboltable.delete x
246:         else
247:           x.each_rule do |r|
248:             r.target = target
249:             @grammar.add r
250:           end
251:         end
252:         flush_delayed
253:       end
_added?(sym) click to toggle source
     # File lib/racc/grammar.rb, line 259
259:       def _added?(sym)
260:         @grammar.added?(sym) or @delayed.detect {|r| r.target == sym }
261:       end
_delayed_add(rule) click to toggle source
     # File lib/racc/grammar.rb, line 255
255:       def _delayed_add(rule)
256:         @delayed.push rule
257:       end
_intern(x) click to toggle source
     # File lib/racc/grammar.rb, line 318
318:       def _intern(x)
319:         case x
320:         when Symbol, String
321:           @grammar.intern(x)
322:         when Racc::Sym
323:           x
324:         else
325:           raise TypeError, "wrong type #{x.class} (expected Symbol/String/Racc::Sym)"
326:         end
327:       end
action(&block) click to toggle source
     # File lib/racc/grammar.rb, line 279
279:       def action(&block)
280:         id = "@#{@seqs["action"] += 1}".intern
281:         _delayed_add Rule.new(@grammar.intern(id), [], UserAction.proc(block))
282:         id
283:       end
Also aliased as: _
flush_delayed() click to toggle source
     # File lib/racc/grammar.rb, line 263
263:       def flush_delayed
264:         return if @delayed.empty?
265:         @delayed.each do |rule|
266:           @grammar.add rule
267:         end
268:         @delayed.clear
269:       end
grammar() click to toggle source
     # File lib/racc/grammar.rb, line 211
211:       def grammar
212:         flush_delayed
213:         @grammar.each do |rule|
214:           if rule.specified_prec
215:             rule.specified_prec = @grammar.intern(rule.specified_prec)
216:           end
217:         end
218:         @grammar.init
219:         @grammar
220:       end
many(sym, &block) click to toggle source
     # File lib/racc/grammar.rb, line 293
293:       def many(sym, &block)
294:         _defmetasyntax("many", _intern(sym), block) {|target|
295:             seq() { [] }           | seq(target, sym) {|list, x| list.push x; list }
296:         }
297:       end
many1(sym, &block) click to toggle source
     # File lib/racc/grammar.rb, line 300
300:       def many1(sym, &block)
301:         _defmetasyntax("many1", _intern(sym), block) {|target|
302:             seq(sym) {|x| [x] }           | seq(target, sym) {|list, x| list.push x; list }
303:         }
304:       end
method_missing(mid, *args, &block) click to toggle source
     # File lib/racc/grammar.rb, line 228
228:       def method_missing(mid, *args, &block)
229:         unless mid.to_s[1,1] == '='
230:           super   # raises NoMethodError
231:         end
232:         target = @grammar.intern(mid.to_s.chop.intern)
233:         unless args.size == 1
234:           raise ArgumentError, "too many arguments for #{mid} (#{args.size} for 1)"
235:         end
236:         _add target, args.first
237:       end
null(&block) click to toggle source
     # File lib/racc/grammar.rb, line 275
275:       def null(&block)
276:         seq(&block)
277:       end
option(sym, default = nil, &block) click to toggle source
     # File lib/racc/grammar.rb, line 287
287:       def option(sym, default = nil, &block)
288:         _defmetasyntax("option", _intern(sym), block) {|target|
289:           seq() { default } | seq(sym)
290:         }
291:       end
precedence_table(&block) click to toggle source
     # File lib/racc/grammar.rb, line 222
222:       def precedence_table(&block)
223:         env = PrecedenceDefinitionEnv.new(@grammar)
224:         env.instance_eval(&block)
225:         @grammar.end_precedence_declaration env.reverse
226:       end
separated_by(sep, sym, &block) click to toggle source
     # File lib/racc/grammar.rb, line 307
307:       def separated_by(sep, sym, &block)
308:         option(separated_by1(sep, sym), [], &block)
309:       end
separated_by1(sep, sym, &block) click to toggle source
     # File lib/racc/grammar.rb, line 311
311:       def separated_by1(sep, sym, &block)
312:         _defmetasyntax("separated_by1", _intern(sym), block) {|target|
313:             seq(sym) {|x| [x] }           | seq(target, sep, sym) {|list, _, x| list.push x; list }
314:         }
315:       end
seq(*list, &block) click to toggle source
     # File lib/racc/grammar.rb, line 271
271:       def seq(*list, &block)
272:         Rule.new(nil, list.map {|x| _intern(x) }, UserAction.proc(block))
273:       end

Private Instance Methods

_defmetasyntax(type, id, action, &block) click to toggle source
     # File lib/racc/grammar.rb, line 331
331:       def _defmetasyntax(type, id, action, &block)
332:         if action
333:           idbase = "#{type}@#{id}-#{@seqs[type] += 1}"
334:           target = _wrap(idbase, "#{idbase}-core", action)
335:           _regist("#{idbase}-core", &block)
336:         else
337:           target = _regist("#{type}@#{id}", &block)
338:         end
339:         @grammar.intern(target)
340:       end
_regist(target_name) click to toggle source
     # File lib/racc/grammar.rb, line 342
342:       def _regist(target_name)
343:         target = target_name.intern
344:         unless _added?(@grammar.intern(target))
345:           yield(target).each_rule do |rule|
346:             rule.target = @grammar.intern(target)
347:             _delayed_add rule
348:           end
349:         end
350:         target
351:       end
_wrap(target_name, sym, block) click to toggle source
     # File lib/racc/grammar.rb, line 353
353:       def _wrap(target_name, sym, block)
354:         target = target_name.intern
355:         _delayed_add Rule.new(@grammar.intern(target),
356:                               [@grammar.intern(sym.intern)],
357:                               UserAction.proc(block))
358:         target
359:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.