Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
58 lines (42 sloc) 1.3 KB
#!/usr/local/bin/ruby -w
$VERSION = true
require_relative 'lib/sugarparser'
class MyConfig
Entry = Struct.new :name, :param, :comment
Parser = SugarParser.define self do |instance|
separator = /^-+\n/
trim(/\AHello, my too specific foolish config!\n/)
must(/^Foolish Syntax Version (\d+\.\d+)\n/){|s, version|
instance.version = version.to_f
}
trim separator
trim(/^Index. Name Param Comment\n/)
trim separator
while (
try(/^(\d+)\.\s+(\S+)\s+(\S+)\s+(\S+)\n/) do |s, idx, name, param, comment|
instance.entries[idx.to_i] = Entry.new(name, param, comment)
end
); end
trim separator
trim(/^Bye!!/)
end
def self.parse(str)
Parser.parse str
end
attr_accessor :version, :entries
def initialize
@version = nil
@entries = []
end
end
p MyConfig.parse(DATA.read)
__END__
Hello, my too specific foolish config!
Foolish Syntax Version 2.1
-------------------------------------------------------------------------------
Index. Name Param Comment
-------------------------------------------------------------------------------
1. AAA abc1234 afda
2. BBB ggggg umm
-------------------------------------------------------------------------------
Bye!!
Something went wrong with that request. Please try again.