# # DO NOT MODIFY!!!! # This file is automatically generated by Racc 1.4.6 # from Racc grammer file "". # require 'racc/parser.rb' require 'strscan' module NagiosParser module Object class Parser < Racc::Parser module_eval(<<'...end parser.y/module_eval...', 'parser.y', 34) private def last_is_key?(list) list.last[0] == :KEY end public def create_token(string) result = [] inside = false scanner = StringScanner.new(string) until scanner.empty? case when scanner.scan(/\s+/) # ignore whitespace when scanner.scan(/#[^\n]*/) # ignore comments when scanner.scan(/define/) result << [:DEFINE, nil] when (!inside and match = scanner.scan(/\w+/)) result << [:TYPE, match] when match = scanner.scan(/\{/) inside = true result << [:OPEN, nil] when match = scanner.scan(/\}/) inside = false result << [:CLOSE, nil] when (!last_is_key?(result) and match = scanner.scan(/\w+/)) result << [:KEY, match.chomp.gsub(/\s+$/, '')] when (inside and match = scanner.scan(/\d+$/)) result << [:VALUE, match.to_i] when (inside and match = scanner.scan(/[^\n\}]+/)) # Make sure to ignore inline comments starting with ';'. result << [:VALUE, match.split(';').first.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 = {} @token = create_token(string) do_parse @result end def next_token @token.shift end ...end parser.y/module_eval... ##### State transition tables begin ### racc_action_table = [ 5, 8, 1, 13, 11, 7, 1, 11, 4, 14 ] racc_action_check = [ 2, 5, 2, 9, 9, 4, 0, 7, 1, 11 ] racc_action_pointer = [ 4, 5, 0, nil, 1, 1, nil, 1, nil, -2, nil, 2, nil, nil, nil ] racc_action_default = [ -7, -7, -7, -1, -7, -7, -2, -7, 15, -7, -4, -7, -5, -3, -6 ] racc_goto_table = [ 10, 3, 12, 6, 9, 2 ] racc_goto_check = [ 4, 2, 4, 2, 3, 1 ] racc_goto_pointer = [ nil, 5, 1, -3, -7 ] racc_goto_default = [ nil, nil, nil, nil, nil ] racc_reduce_table = [ 0, 0, :racc_error, 1, 9, :_reduce_none, 2, 9, :_reduce_none, 5, 10, :_reduce_3, 1, 11, :_reduce_none, 2, 11, :_reduce_5, 2, 12, :_reduce_6 ] racc_reduce_n = 7 racc_shift_n = 15 racc_token_table = { false => 0, :error => 1, :DEFINE => 2, :TYPE => 3, :OPEN => 4, :CLOSE => 5, :KEY => 6, :VALUE => 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", "DEFINE", "TYPE", "OPEN", "CLOSE", "KEY", "VALUE", "$start", "defines", "define", "assignments", "assignment" ] Racc_debug_parser = false ##### State transition tables end ##### # reduce 0 omitted # reduce 1 omitted # reduce 2 omitted module_eval(<<'.,.,', 'parser.y', 11) def _reduce_3(val, _values, result) @result[val[1]] ||= [] @result[val[1]] << val[3] result end .,., # reduce 4 omitted module_eval(<<'.,.,', 'parser.y', 18) def _reduce_5(val, _values, result) val[1].each do |key, value| val[0][key] = value end result = val[0] result end .,., module_eval(<<'.,.,', 'parser.y', 25) def _reduce_6(val, _values, result) result = {val[0] => val[1]} result end .,., def _reduce_none(val, _values, result) val[0] end end # class Parser end # module Object end # module NagiosParser