# # DO NOT MODIFY!!!! # This file is automatically generated by Racc 1.4.6 # from Racc grammer file "". # require 'racc/parser.rb' require 'strscan' module BibTeX class NameParser < Racc::Parser module_eval(<<'...end names.y/module_eval...', 'names.y', 80) def initialize(options = {}) self.options.merge!(options) end def options @options ||= { :debug => ENV['DEBUG'] == true } end def parse(input) @yydebug = options[:debug] scan(input) do_parse end def next_token @stack.shift end def on_error(tid, val, vstack) BibTeX.log.error("Failed to parse BibTeX Name on value %s (%s) %s" % [val.inspect, token_to_str(tid) || '?', vstack.inspect]) end def scan(input) @src = StringScanner.new(input) @brace_level = 0 @stack = [] @word = [:PWORD,''] do_scan end private def do_scan until @src.eos? case when @src.scan(/,?\s+and\s+/io) push_word @stack.push([:AND,@src.matched]) when @src.scan(/[\t\r\n\s]+/o) push_word when @src.scan(/,/o) push_word @stack.push([:COMMA,@src.matched]) when @src.scan(/[[:lower:]][^\t\r\n\s\{\}\d\\,]*/o) is_lowercase @word[1] << @src.matched when @src.scan(/[[:upper:]][^\t\r\n\s\{\}\d\\,]*/o) is_uppercase @word[1] << @src.matched when @src.scan(/(\d|\\.)+/o) @word[1] << @src.matched when @src.scan(/\{/o) @word[1] << @src.matched scan_literal when @src.scan(/\}/o) error_unbalanced when @src.scan(/./o) @word[1] << @src.matched end end push_word @stack end def push_word unless @word[1].empty? @stack.push(@word) @word = [:PWORD,''] end end def is_lowercase @word[0] = :LWORD if @word[0] == :PWORD end def is_uppercase @word[0] = :UWORD if @word[0] == :PWORD end def scan_literal @brace_level = 1 while @brace_level > 0 @word[1] << @src.scan_until(/[\{\}]/o).to_s case @src.matched when '{' @brace_level += 1 when '}' @brace_level -= 1 else @brace_level = 0 error_unbalanced end end end def error_unexpected @stack.push [:ERROR,@src.matched] BibTeX.log.warn("NameParser: unexpected token `#{@src.matched}' at position #{@src.pos}; brace level #{@brace_level}.") end def error_unbalanced @stack.push [:ERROR,'}'] BibTeX.log.warn("NameParser: unbalanced braces at position #{@src.pos}; brace level #{@brace_level}.") end # -*- racc -*- ...end names.y/module_eval... ##### State transition tables begin ### racc_action_table = [ -13, -28, -10, -13, -30, 24, -13, -28, -29, -13, -30, -28, 19, -9, -29, 36, 14, -28, -11, 22, 35, 23, 22, 20, 23, 11, 18, 12, 33, 32, 34, 22, 35, 23, 22, 26, 23, 33, 32, 34, 33, 32, 34, 11, 7, 12, 11, 7, 12, 13 ] racc_action_check = [ 20, 18, 20, 26, 12, 13, 20, 18, 11, 26, 12, 7, 6, 7, 11, 29, 2, 7, 21, 21, 21, 21, 8, 8, 8, 5, 5, 5, 31, 31, 31, 27, 27, 27, 16, 16, 16, 36, 36, 36, 19, 19, 19, 0, 0, 0, 14, 14, 14, 1 ] racc_action_pointer = [ 40, 49, 10, nil, nil, 22, 10, 11, 19, nil, nil, 8, 4, 5, 43, nil, 31, nil, 1, 37, 0, 16, nil, nil, nil, nil, 3, 28, nil, 13, nil, 25, nil, nil, nil, nil, 34, nil, nil ] racc_action_default = [ -1, -31, -2, -3, -5, -8, -31, -21, -31, -12, -17, -19, -20, -31, -31, -6, -31, -18, -21, -26, -23, -14, -19, -20, 39, -4, -23, -14, -7, -15, -24, -27, -28, -29, -30, -22, -26, -25, -16 ] racc_goto_table = [ 17, 29, 30, 3, 21, 28, 16, 15, 2, 1, nil, nil, 27, nil, 37, nil, 17, 25, 38, 30, nil, nil, 17 ] racc_goto_check = [ 11, 10, 9, 3, 5, 7, 8, 4, 2, 1, nil, nil, 5, nil, 9, nil, 11, 3, 10, 9, nil, nil, 11 ] racc_goto_pointer = [ nil, 9, 8, 3, 2, -4, nil, -14, 1, -17, -18, -5, nil ] racc_goto_default = [ nil, nil, nil, nil, 4, 5, 6, nil, 8, 9, nil, 10, 31 ] racc_reduce_table = [ 0, 0, :racc_error, 0, 9, :_reduce_1, 1, 9, :_reduce_2, 1, 10, :_reduce_3, 3, 10, :_reduce_4, 1, 11, :_reduce_5, 2, 11, :_reduce_6, 3, 11, :_reduce_7, 1, 14, :_reduce_8, 1, 14, :_reduce_9, 2, 14, :_reduce_10, 2, 14, :_reduce_11, 1, 12, :_reduce_12, 2, 12, :_reduce_13, 2, 12, :_reduce_14, 1, 15, :_reduce_15, 3, 15, :_reduce_16, 1, 13, :_reduce_17, 2, 13, :_reduce_18, 1, 19, :_reduce_19, 1, 19, :_reduce_20, 1, 16, :_reduce_21, 3, 16, :_reduce_22, 2, 16, :_reduce_23, 1, 20, :_reduce_24, 2, 20, :_reduce_25, 0, 18, :_reduce_26, 1, 18, :_reduce_27, 1, 17, :_reduce_28, 1, 17, :_reduce_29, 1, 17, :_reduce_30 ] racc_reduce_n = 31 racc_shift_n = 39 racc_token_table = { false => 0, :error => 1, :COMMA => 2, :UWORD => 3, :LWORD => 4, :PWORD => 5, :AND => 6, :ERROR => 7 } racc_nt_base = 8 racc_use_result_var = true Racc_arg = [ racc_action_table, racc_action_check, racc_action_default, racc_action_pointer, racc_goto_table, racc_goto_check, racc_goto_default, racc_goto_pointer, racc_nt_base, racc_reduce_table, racc_token_table, racc_shift_n, racc_reduce_n, racc_use_result_var ] Racc_token_to_s_table = [ "$end", "error", "COMMA", "UWORD", "LWORD", "PWORD", "AND", "ERROR", "$start", "result", "names", "name", "last", "u_words", "sort", "first", "von", "word", "opt_words", "u_word", "words" ] Racc_debug_parser = false ##### State transition tables end ##### # reduce 0 omitted module_eval(<<'.,.,', 'names.y', 31) def _reduce_1(val, _values, result) result = [] result end .,., module_eval(<<'.,.,', 'names.y', 32) def _reduce_2(val, _values, result) result = val[0] result end .,., module_eval(<<'.,.,', 'names.y', 34) def _reduce_3(val, _values, result) result = [val[0]] result end .,., module_eval(<<'.,.,', 'names.y', 35) def _reduce_4(val, _values, result) result << val[2] result end .,., module_eval(<<'.,.,', 'names.y', 37) def _reduce_5(val, _values, result) result = Name.new(:von => val[0][0], :last => val[0][1]) result end .,., module_eval(<<'.,.,', 'names.y', 38) def _reduce_6(val, _values, result) result = Name.new(:first => val[0], :von => val[1][0], :last => val[1][1]) result end .,., module_eval(<<'.,.,', 'names.y', 39) def _reduce_7(val, _values, result) result = Name.new(:von => val[0][0], :last => val[0][1], :jr => val[2][0], :first => val[2][1]) result end .,., module_eval(<<'.,.,', 'names.y', 41) def _reduce_8(val, _values, result) result = [nil,val[0]] result end .,., module_eval(<<'.,.,', 'names.y', 42) def _reduce_9(val, _values, result) result = [nil,val[0]] result end .,., module_eval(<<'.,.,', 'names.y', 43) def _reduce_10(val, _values, result) result = [val[0],val[1]] result end .,., module_eval(<<'.,.,', 'names.y', 44) def _reduce_11(val, _values, result) result = [val[0],val[1]] result end .,., module_eval(<<'.,.,', 'names.y', 46) def _reduce_12(val, _values, result) result = [nil,val[0]] result end .,., module_eval(<<'.,.,', 'names.y', 47) def _reduce_13(val, _values, result) result = [val[0],val[1]] result end .,., module_eval(<<'.,.,', 'names.y', 48) def _reduce_14(val, _values, result) result = [val[0],val[1]] result end .,., module_eval(<<'.,.,', 'names.y', 50) def _reduce_15(val, _values, result) result = [nil,val[0]] result end .,., module_eval(<<'.,.,', 'names.y', 51) def _reduce_16(val, _values, result) result = [val[0],val[2]] result end .,., module_eval(<<'.,.,', 'names.y', 53) def _reduce_17(val, _values, result) result = val[0] result end .,., module_eval(<<'.,.,', 'names.y', 54) def _reduce_18(val, _values, result) result = val[0,2].join(' ') result end .,., module_eval(<<'.,.,', 'names.y', 56) def _reduce_19(val, _values, result) result = val[0] result end .,., module_eval(<<'.,.,', 'names.y', 57) def _reduce_20(val, _values, result) result = val[0] result end .,., module_eval(<<'.,.,', 'names.y', 59) def _reduce_21(val, _values, result) result = val[0] result end .,., module_eval(<<'.,.,', 'names.y', 60) def _reduce_22(val, _values, result) result = val[0,3].join(' ') result end .,., module_eval(<<'.,.,', 'names.y', 61) def _reduce_23(val, _values, result) result = val[0,2].join(' ') result end .,., module_eval(<<'.,.,', 'names.y', 63) def _reduce_24(val, _values, result) result = val[0] result end .,., module_eval(<<'.,.,', 'names.y', 64) def _reduce_25(val, _values, result) result = val[0,2].join(' ') result end .,., module_eval(<<'.,.,', 'names.y', 66) def _reduce_26(val, _values, result) result = nil result end .,., module_eval(<<'.,.,', 'names.y', 67) def _reduce_27(val, _values, result) result = val[0] result end .,., module_eval(<<'.,.,', 'names.y', 69) def _reduce_28(val, _values, result) result = val[0] result end .,., module_eval(<<'.,.,', 'names.y', 70) def _reduce_29(val, _values, result) result = val[0] result end .,., module_eval(<<'.,.,', 'names.y', 71) def _reduce_30(val, _values, result) result = val[0] result end .,., def _reduce_none(val, _values, result) val[0] end end # class NameParser end # module BibTeX