Sha256: 58e9008e68a19819651f1dd17d50e4c05f788b1673592716b83097fc73626f68
Contents?: true
Size: 1.02 KB
Versions: 3
Compression:
Stored size: 1.02 KB
Contents
class NagiosParser::Config::Parser token KEY VALUE rule assignments : assignment | assignments assignment ; assignment : KEY VALUE { @result[val[0]] = val[1] } ; end ---- header require 'strscan' ---- inner 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 = {} @token = create_token(string) do_parse @result end def next_token @token.shift end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
nagios_parser-1.2.2 | lib/nagios_parser/config/parser.y |
nagios_parser-1.2.1 | lib/nagios_parser/config/parser.y |
nagios_parser-1.2.0 | lib/nagios_parser/config/parser.y |