# # DO NOT MODIFY!!!! # This file is automatically generated by Racc 1.4.7 # from Racc grammer file "". # require 'racc/parser.rb' require 'strscan' require 'nagios_parser/result' module NagiosParser module Config class Parser < Racc::Parser module_eval(<<'...end parser.y/module_eval...', 'parser.y', 20) def create_token(string) result = [] scanner = StringScanner.new(string) until scanner.empty? case when scanner.scan(/\s+/) # ignore whitespace when scanner.scan(/#[^\n]*/) # ignore comments when match = scanner.scan(/\w+\=/) result << [:KEY, match.chop.gsub(/\s+$/, '')] when match = scanner.scan(/\-?\d+$/) result << [:VALUE, match.to_i] when match = scanner.scan(/[^\n]+$/) result << [:VALUE, match.gsub(/\s+$/, '')] else raise "Can't tokenize <#{scanner.peek(10)}>" end end result << [false, false] end attr_accessor :token def self.parse(string) new.parse(string) end def parse(string) @result = NagiosParser::Result.new(:multi_value => %w{cfg_file cfg_dir}) @token = create_token(string) do_parse @result.to_hash end def next_token @token.shift end ...end parser.y/module_eval... ##### State transition tables begin ### racc_action_table = [ 4, 6, 3, 3, 7 ] racc_action_check = [ 1, 3, 1, 0, 4 ] racc_action_pointer = [ 1, 0, nil, -2, 4, nil, nil, nil ] racc_action_default = [ -4, -4, -1, -4, -4, -2, -3, 8 ] racc_goto_table = [ 2, 5, 1 ] racc_goto_check = [ 2, 2, 1 ] racc_goto_pointer = [ nil, 2, 0 ] racc_goto_default = [ nil, nil, nil ] racc_reduce_table = [ 0, 0, :racc_error, 1, 5, :_reduce_none, 2, 5, :_reduce_none, 2, 6, :_reduce_3 ] racc_reduce_n = 4 racc_shift_n = 8 racc_token_table = { false => 0, :error => 1, :KEY => 2, :VALUE => 3 } racc_nt_base = 4 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", "KEY", "VALUE", "$start", "assignments", "assignment" ] Racc_debug_parser = false ##### State transition tables end ##### # reduce 0 omitted # reduce 1 omitted # reduce 2 omitted module_eval(<<'.,.,', 'parser.y', 10) def _reduce_3(val, _values, result) @result[val[0]] = val[1] result end .,., def _reduce_none(val, _values, result) val[0] end end # class Parser end # module Config end # module NagiosParser