class Riddle::Configuration::Parser::InnerParser
Constants
- EndOfFileError
- SETTING_PATTERN
Public Class Methods
new(input)
click to toggle source
# File lib/riddle/configuration/parser.rb, line 138 def initialize(input) @stream = StringIO.new(input.gsub("\\\n", '')) @sections = {} end
Public Instance Methods
parse!()
click to toggle source
# File lib/riddle/configuration/parser.rb, line 143 def parse! while label = next_line do @sections[label] = next_settings end @sections rescue EndOfFileError @sections end
Private Instance Methods
next_line()
click to toggle source
# File lib/riddle/configuration/parser.rb, line 155 def next_line line = @stream.gets raise EndOfFileError if line.nil? line = line.strip (line.empty? || line[/^#/]) ? next_line : line end
next_settings()
click to toggle source
# File lib/riddle/configuration/parser.rb, line 163 def next_settings settings = Hash.new { |hash, key| hash[key] = [] } line = '' while line.empty? || line == '{' do line = next_line end while line != '}' do begin match = SETTING_PATTERN.match(line) unless match.nil? key, value = *match.captures settings[key] << value while value[/\\$/] do value = next_line settings[key].last << "\n" << value end end rescue => error raise error, "Error handling line '#{line}': #{error.message}", error.backtrace end line = next_line end settings end