Class
Constants
No documentation available
Class Methods
lib/racc/grammarfileparser.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammarfileparser.rb, line 172
def initialize(debug_flags = DebugFlags.new)
@yydebug = debug_flags.parse
end
No documentation available
lib/racc/grammarfileparser.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammarfileparser.rb, line 168
def GrammarFileParser.parse(src, filename = '-', lineno = 1)
new().parse(src, filename, lineno)
end
No documentation available
lib/racc/grammarfileparser.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammarfileparser.rb, line 164
def GrammarFileParser.parse_file(filename)
parse(File.read(filename), filename, 1)
end
No documentation available
Instance Methods
lib/racc/grammarfileparser.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammarfileparser.rb, line 235
def add_rule(target, list, sprec)
if list.last.kind_of?(UserAction)
act = list.pop
else
act = UserAction.empty
end
list.map! {|s| s.kind_of?(UserAction) ? embedded_action(s) : s }
rule = Rule.new(target, list, act)
rule.specified_prec = sprec
@grammar.add rule
end
No documentation available
lib/racc/grammarfileparser.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammarfileparser.rb, line 211
def add_rule_block(list)
sprec = nil
target = list.shift
case target
when OrMark, UserAction, Prec
raise CompileError, "#{target.lineno}: unexpected symbol #{target.name}"
end
curr = []
list.each do |i|
case i
when OrMark
add_rule target, curr, sprec
curr = []
sprec = nil
when Prec
raise CompileError, "'=<prec>' used twice in one rule" if sprec
sprec = i.symbol
else
curr.push i
end
end
add_rule target, curr, sprec
end
No documentation available
lib/racc/grammarfileparser.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammarfileparser.rb, line 288
def add_user_code(label, src)
@result.params.send(USER_CODE_LABELS[label]).push src
end
No documentation available
lib/racc/grammarfileparser.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammarfileparser.rb, line 280
def canonical_label(src)
label = src.to_s.strip.downcase.slice(/\w+/)
unless USER_CODE_LABELS.key?(label)
raise CompileError, "unknown user code type: #{label.inspect}"
end
label
end
No documentation available
lib/racc/grammarfileparser.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammarfileparser.rb, line 247
def embedded_action(act)
sym = @grammar.intern("@#{@embedded_action_seq += 1}".intern, true)
@grammar.add Rule.new(sym, [], act)
sym
end
No documentation available
#
lib/racc/grammarfileparser.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammarfileparser.rb, line 207
def location
"#{@filename}:#{@lineno - 1 + @scanner.lineno}"
end
No documentation available
lib/racc/grammarfileparser.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammarfileparser.rb, line 192
def next_token
@scanner.scan
end
No documentation available
lib/racc/grammarfileparser.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammarfileparser.rb, line 196
def on_error(tok, val, _values)
if val.respond_to?(:id2name)
v = val.id2name
elsif val.kind_of?(String)
v = val
else
v = val.inspect
end
raise CompileError, "#{location()}: unexpected token '#{v}'"
end
No documentation available
lib/racc/grammarfileparser.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammarfileparser.rb, line 176
def parse(src, filename = '-', lineno = 1)
@filename = filename
@lineno = lineno
@scanner = GrammarFileScanner.new(src, @filename)
@scanner.debug = @yydebug
@grammar = Grammar.new
@result = Result.new(@grammar)
@embedded_action_seq = 0
yyparse @scanner, :yylex
parse_user_code
@result.grammar.init
@result
end
No documentation available
lib/racc/grammarfileparser.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/racc/grammarfileparser.rb, line 257
def parse_user_code
line = @scanner.lineno
_, *blocks = *@scanner.epilogue.split(/^----/)
blocks.each do |block|
header, *body = block.lines.to_a
label0, pathes = *header.sub(/\A-+/, '').split('=', 2)
label = canonical_label(label0)
(pathes ? pathes.strip.split(' ') : []).each do |path|
add_user_code label, SourceText.new(File.read(path), path, 1)
end
add_user_code label, SourceText.new(body.join(''), @filename, line + 1)
line += (1 + body.size)
end
end
User Code Block