Sha256: c797e32e6d3c5b9fc1424e9f3647b66fd383f6d359a773e9d000331fe59a7be1
Contents?: true
Size: 970 Bytes
Versions: 4
Compression:
Stored size: 970 Bytes
Contents
class NagiosParser::Resource::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+\$\s*\=/) result << [:KEY, match.chop.gsub(/\s+$/, '')] 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
4 entries across 4 versions & 1 rubygems