# # DO NOT MODIFY!!!! # This file is automatically generated by Racc 1.6.0 # from Racc grammar file "". # require 'racc/parser.rb' require 'strscan' module Riemann module Tools class UptimeParser < Racc::Parser module_eval(<<'...end uptime_parser.y/module_eval...', 'uptime_parser.y', 43) def parse(text) s = StringScanner.new(text) @tokens = [] until s.eos? do case when s.scan(/\n/) then # ignore when s.scan(/\s+/) then # ignore when s.scan(/:/) then @tokens << [':', s.matched] when s.scan(/,/) then @tokens << [',', s.matched] when s.scan(/\d+[,.]\d+/) then @tokens << [:FLOAT, s.matched.sub(',', '.').to_f] when s.scan(/\d+/) then @tokens << [:INTEGER, s.matched.to_i] when s.scan(/AM/) then @tokens << [:AM, s.matched] when s.scan(/PM/) then @tokens << [:PM, s.matched] when s.scan(/up/) then @tokens << [:UP, s.matched] when s.scan(/days?/) then @tokens << [:DAYS, s.matched] when s.scan(/hrs?/) then @tokens << [:HRS, s.matched] when s.scan(/mins?/) then @tokens << [:MINS, s.matched] when s.scan(/secs?/) then @tokens << [:SECS, s.matched] when s.scan(/users?/) then @tokens << [:USERS, s.matched] when s.scan(/load averages?:/) then @tokens << [:LOAD_AVERAGES, s.matched] else raise s.rest end end do_parse end def next_token @tokens.shift end ...end uptime_parser.y/module_eval... ##### State transition tables begin ### racc_action_table = [ 29, 30, 24, 26, 27, 28, 26, 27, 28, 40, 41, 25, 31, 3, 25, 4, 6, 7, 8, 9, 15, 16, 18, 23, 32, 33, 34, 35, 36, 38, 39, 42, 43, 44, 45 ] racc_action_check = [ 16, 16, 15, 15, 15, 15, 23, 23, 23, 39, 39, 15, 16, 0, 23, 1, 2, 3, 4, 5, 6, 7, 9, 10, 17, 18, 24, 25, 31, 32, 38, 40, 41, 43, 44 ] racc_action_pointer = [ 2, 15, 12, 3, 18, 6, 9, 10, nil, 11, 12, nil, nil, nil, nil, -3, -2, 11, 16, nil, nil, nil, nil, 0, 13, 16, nil, nil, nil, nil, nil, 17, 19, nil, nil, nil, nil, nil, 18, -3, 19, 20, nil, 20, 22, nil ] racc_action_default = [ -22, -22, -22, -22, -22, -22, -22, -22, 46, -22, -22, -10, -11, -12, -13, -22, -2, -22, -22, -6, -7, -8, -9, -22, -22, -22, -16, -17, -18, -3, -4, -22, -22, -19, -14, -15, -5, -1, -22, -22, -22, -22, -20, -22, -22, -21 ] racc_goto_table = [ 11, 12, 13, 14, 19, 20, 21, 22, 1, 2, 5, 17, 37, 10 ] racc_goto_check = [ 7, 8, 9, 10, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6 ] racc_goto_pointer = [ nil, 8, 9, 8, 2, -20, 7, -6, -5, -4, -3 ] racc_goto_default = [ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil ] racc_reduce_table = [ 0, 0, :racc_error, 6, 16, :_reduce_1, 3, 17, :_reduce_none, 4, 17, :_reduce_none, 4, 17, :_reduce_none, 5, 17, :_reduce_none, 3, 18, :_reduce_6, 3, 18, :_reduce_7, 3, 18, :_reduce_8, 3, 18, :_reduce_9, 2, 18, :_reduce_10, 2, 18, :_reduce_11, 2, 18, :_reduce_12, 2, 18, :_reduce_13, 3, 21, :_reduce_14, 3, 22, :_reduce_15, 2, 23, :_reduce_16, 2, 24, :_reduce_17, 2, 25, :_reduce_18, 2, 19, :_reduce_none, 4, 20, :_reduce_20, 6, 20, :_reduce_21 ] racc_reduce_n = 22 racc_shift_n = 46 racc_token_table = { false => 0, :error => 1, :AM => 2, :PM => 3, :UP => 4, :DAYS => 5, :HRS => 6, :MINS => 7, :SECS => 8, :USERS => 9, :LOAD_AVERAGES => 10, :INTEGER => 11, :FLOAT => 12, "," => 13, ":" => 14 } racc_nt_base = 15 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", "AM", "PM", "UP", "DAYS", "HRS", "MINS", "SECS", "USERS", "LOAD_AVERAGES", "INTEGER", "FLOAT", "\",\"", "\":\"", "$start", "target", "time", "uptime", "users", "load_averages", "uptime_days", "uptime_hr_min", "uptime_hr", "uptime_min", "uptime_sec" ] Racc_debug_parser = false ##### State transition tables end ##### # reduce 0 omitted module_eval(<<'.,.,', 'uptime_parser.y', 4) def _reduce_1(val, _values, result) result = { uptime: val[1], users: val[3], load_averages: val[5] } result end .,., # reduce 2 omitted # reduce 3 omitted # reduce 4 omitted # reduce 5 omitted module_eval(<<'.,.,', 'uptime_parser.y', 11) def _reduce_6(val, _values, result) result = val[1] + val[2] result end .,., module_eval(<<'.,.,', 'uptime_parser.y', 12) def _reduce_7(val, _values, result) result = val[1] + val[2] result end .,., module_eval(<<'.,.,', 'uptime_parser.y', 13) def _reduce_8(val, _values, result) result = val[1] + val[2] result end .,., module_eval(<<'.,.,', 'uptime_parser.y', 14) def _reduce_9(val, _values, result) result = val[1] + val[2] result end .,., module_eval(<<'.,.,', 'uptime_parser.y', 15) def _reduce_10(val, _values, result) result = val[1] result end .,., module_eval(<<'.,.,', 'uptime_parser.y', 16) def _reduce_11(val, _values, result) result = val[1] result end .,., module_eval(<<'.,.,', 'uptime_parser.y', 17) def _reduce_12(val, _values, result) result = val[1] result end .,., module_eval(<<'.,.,', 'uptime_parser.y', 18) def _reduce_13(val, _values, result) result = val[1] result end .,., module_eval(<<'.,.,', 'uptime_parser.y', 20) def _reduce_14(val, _values, result) result = val[0] * 86400 result end .,., module_eval(<<'.,.,', 'uptime_parser.y', 22) def _reduce_15(val, _values, result) result = val[0] * 3600 + val[2] * 60 result end .,., module_eval(<<'.,.,', 'uptime_parser.y', 24) def _reduce_16(val, _values, result) result = val[0] * 3600 result end .,., module_eval(<<'.,.,', 'uptime_parser.y', 26) def _reduce_17(val, _values, result) result = val[0] * 60 result end .,., module_eval(<<'.,.,', 'uptime_parser.y', 28) def _reduce_18(val, _values, result) result = val[0] result end .,., # reduce 19 omitted module_eval(<<'.,.,', 'uptime_parser.y', 32) def _reduce_20(val, _values, result) result = { 1 => val[1], 5 => val[2], 15 => val[3] } result end .,., module_eval(<<'.,.,', 'uptime_parser.y', 33) def _reduce_21(val, _values, result) result = { 1 => val[1], 5 => val[3], 15 => val[5] } result end .,., def _reduce_none(val, _values, result) val[0] end end # class UptimeParser end # module Tools end # module Riemann