Class Methods
::
lib/racc/grammar.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammar.rb, line 203
def initialize
@grammar = Grammar.new
@seqs = Hash.new(0)
@delayed = []
end
No documentation available
Instance Methods
lib/racc/grammar.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/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
No documentation available
lib/racc/grammar.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammar.rb, line 257
def _added?(sym)
@grammar.added?(sym) or @delayed.detect {|r| r.target == sym }
end
No documentation available
lib/racc/grammar.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammar.rb, line 329
def _defmetasyntax(type, id, action, &block)
if action
idbase = "#{type}@#{id}-#{@seqs[type] += 1}"
target = _wrap(idbase, "#{idbase}-core", action)
_regist("#{idbase}-core", &block)
else
target = _regist("#{type}@#{id}", &block)
end
@grammar.intern(target)
end
No documentation available
lib/racc/grammar.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammar.rb, line 253
def _delayed_add(rule)
@delayed.push rule
end
No documentation available
lib/racc/grammar.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammar.rb, line 316
def _intern(x)
case x
when Symbol, String
@grammar.intern(x)
when Racc::Sym
x
else
raise TypeError, "wrong type #{x.class} (expected Symbol/String/Racc::Sym)"
end
end
No documentation available
lib/racc/grammar.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammar.rb, line 340
def _regist(target_name)
target = target_name.intern
unless _added?(@grammar.intern(target))
yield(target).each_rule do |rule|
rule.target = @grammar.intern(target)
_delayed_add rule
end
end
target
end
No documentation available
lib/racc/grammar.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/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
No documentation available
lib/racc/grammar.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/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
No documentation available
lib/racc/grammar.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammar.rb, line 261
def flush_delayed
return if @delayed.empty?
@delayed.each do |rule|
@grammar.add rule
end
@delayed.clear
end
No documentation available
#
lib/racc/grammar.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/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
No documentation available
lib/racc/grammar.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammar.rb, line 291
def many(sym, &block)
_defmetasyntax("many", _intern(sym), block) {|target|
seq() { [] }\
| seq(target, sym) {|list, x| list.push x; list }
}
end
No documentation available
lib/racc/grammar.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammar.rb, line 298
def many1(sym, &block)
_defmetasyntax("many1", _intern(sym), block) {|target|
seq(sym) {|x| [x] }\
| seq(target, sym) {|list, x| list.push x; list }
}
end
No documentation available
lib/racc/grammar.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/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
No documentation available
lib/racc/grammar.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammar.rb, line 273
def null(&block)
seq(&block)
end
No documentation available
lib/racc/grammar.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammar.rb, line 285
def option(sym, default = nil, &block)
_defmetasyntax("option", _intern(sym), block) {|target|
seq() { default } | seq(sym)
}
end
No documentation available
lib/racc/grammar.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/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
No documentation available
lib/racc/grammar.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammar.rb, line 305
def separated_by(sep, sym, &block)
option(separated_by1(sep, sym), [], &block)
end
No documentation available
lib/racc/grammar.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammar.rb, line 309
def separated_by1(sep, sym, &block)
_defmetasyntax("separated_by1", _intern(sym), block) {|target|
seq(sym) {|x| [x] }\
| seq(target, sep, sym) {|list, _, x| list.push x; list }
}
end
No documentation available
lib/racc/grammar.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammar.rb, line 269
def seq(*list, &block)
Rule.new(nil, list.map {|x| _intern(x) }, UserAction.proc(block))
end
No documentation available