tomlrb-1.3.0/0000755000004100000410000000000013641341630013043 5ustar www-datawww-datatomlrb-1.3.0/lib/0000755000004100000410000000000013641341630013611 5ustar www-datawww-datatomlrb-1.3.0/lib/tomlrb/0000755000004100000410000000000013641341630015110 5ustar www-datawww-datatomlrb-1.3.0/lib/tomlrb/version.rb0000644000004100000410000000005513641341630017122 0ustar www-datawww-datamodule Tomlrb VERSION = '1.3.0'.freeze end tomlrb-1.3.0/lib/tomlrb/string_utils.rb0000644000004100000410000000132513641341630020164 0ustar www-datawww-datamodule Tomlrb class StringUtils SPECIAL_CHARS = { '\\t' => "\t", '\\b' => "\b", '\\f' => "\f", '\\n' => "\n", '\\r' => "\r", '\\"' => '"', '\\\\' => '\\' }.freeze def self.multiline_replacements(str) strip_spaces(str).gsub(/\\\n\s+/, '') end def self.replace_escaped_chars(str) str.gsub(/\\(u[\da-fA-F]{4}|U[\da-fA-F]{8}|.)/) do |m| if m.size == 2 SPECIAL_CHARS[m] || (raise Tomlrb::ParseError.new "Escape sequence #{m} is reserved") else m[2..-1].to_i(16).chr(Encoding::UTF_8) end end end def self.strip_spaces(str) str[0] = '' if str[0] == "\n" str end end end tomlrb-1.3.0/lib/tomlrb/generated_parser.rb0000644000004100000410000003346513641341630020762 0ustar www-datawww-data# # DO NOT MODIFY!!!! # This file is automatically generated by Racc 1.4.16.pre.1 # from Racc grammer file "". # require 'racc/parser.rb' module Tomlrb class GeneratedParser < Racc::Parser ##### State transition tables begin ### racc_action_table = [ 2, 17, 11, 31, 12, 31, 13, 79, 14, 40, 41, 80, 15, 16, 8, 71, 72, 10, 27, 29, 32, 29, 59, 60, 61, 62, 58, 55, 52, 53, 54, 56, 57, 46, 33, 34, 10, 59, 60, 61, 62, 58, 55, 52, 53, 54, 56, 57, 46, 35, 36, 10, 59, 60, 61, 62, 58, 55, 52, 53, 54, 56, 57, 46, 37, 38, 10, 59, 60, 61, 62, 58, 55, 52, 53, 54, 56, 57, 46, 43, 68, 10, 59, 60, 61, 62, 58, 55, 52, 53, 54, 56, 57, 46, nil, nil, 10, 59, 60, 61, 62, 58, 55, 52, 53, 54, 56, 57, 46, nil, nil, 10, 59, 60, 61, 62, 58, 55, 52, 53, 54, 56, 57, 46, nil, nil, 10, 59, 60, 61, 62, 58, 55, 52, 53, 54, 56, 57, 46, 75, nil, 10, 59, 60, 61, 62, 58, 55, 52, 53, 54, 56, 57, 46, 75, 21, 10, 22, nil, 23, nil, 24, nil, nil, nil, 25, 26, 21, 19, 22, nil, 23, nil, 24, nil, nil, nil, 25, 26, nil, 19 ] racc_action_check = [ 1, 2, 1, 9, 1, 72, 1, 76, 1, 20, 20, 76, 1, 1, 1, 42, 42, 1, 8, 9, 11, 72, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 12, 13, 32, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 14, 15, 33, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 16, 19, 34, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 30, 40, 35, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, nil, nil, 36, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, nil, nil, 37, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, nil, nil, 43, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, nil, 45, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 7, 80, 7, nil, 7, nil, 7, nil, nil, nil, 7, 7, 41, 7, 41, nil, 41, nil, 41, nil, nil, nil, 41, 41, nil, 41 ] racc_action_pointer = [ nil, 0, 1, nil, nil, nil, nil, 153, 4, 1, nil, 0, 14, 15, 29, 30, 44, nil, nil, 50, -6, nil, nil, nil, nil, nil, nil, nil, nil, nil, 59, nil, 19, 34, 49, 64, 79, 94, nil, nil, 65, 165, -3, 109, nil, 124, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 3, nil, nil, nil, -8, nil, nil, nil, 139, nil ] racc_action_default = [ -1, -58, -58, -2, -3, -4, -5, -58, -8, -58, -22, -58, -58, -58, -58, -58, -58, 82, -6, -10, -58, -15, -16, -17, -18, -19, -20, -7, -21, -23, -58, -27, -46, -46, -46, -46, -46, -46, -9, -11, -13, -58, -58, -46, -29, -46, -40, -41, -42, -43, -44, -45, -47, -48, -49, -50, -51, -52, -53, -54, -55, -56, -57, -30, -31, -32, -33, -34, -12, -14, -24, -25, -58, -28, -35, -36, -58, -26, -37, -38, -46, -39 ] racc_goto_table = [ 28, 74, 1, 18, 44, 63, 64, 65, 66, 67, 3, 4, 5, 6, 7, 73, 39, 42, 70, 78, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 81, 69, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 77 ] racc_goto_check = [ 11, 18, 1, 7, 15, 15, 15, 15, 15, 15, 2, 3, 4, 5, 6, 15, 9, 13, 14, 19, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 18, 7, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 11 ] racc_goto_pointer = [ nil, 2, 9, 10, 11, 12, 13, -4, nil, -4, nil, -9, nil, -13, -24, -28, nil, nil, -44, -57, nil, nil, nil ] racc_goto_default = [ nil, nil, nil, nil, nil, 49, nil, nil, 20, nil, 9, nil, 30, nil, nil, 76, 48, 45, nil, nil, 47, 50, 51 ] racc_reduce_table = [ 0, 0, :racc_error, 0, 22, :_reduce_none, 2, 22, :_reduce_none, 1, 23, :_reduce_none, 1, 23, :_reduce_none, 1, 23, :_reduce_none, 2, 24, :_reduce_none, 2, 27, :_reduce_7, 1, 27, :_reduce_8, 2, 28, :_reduce_9, 1, 28, :_reduce_10, 2, 28, :_reduce_none, 2, 30, :_reduce_12, 1, 30, :_reduce_13, 2, 30, :_reduce_none, 1, 29, :_reduce_15, 1, 29, :_reduce_16, 1, 29, :_reduce_17, 1, 29, :_reduce_18, 1, 29, :_reduce_19, 1, 29, :_reduce_20, 2, 26, :_reduce_none, 1, 31, :_reduce_22, 1, 32, :_reduce_23, 3, 32, :_reduce_none, 1, 35, :_reduce_25, 2, 35, :_reduce_none, 1, 33, :_reduce_27, 2, 34, :_reduce_none, 3, 25, :_reduce_29, 3, 25, :_reduce_30, 3, 25, :_reduce_31, 3, 25, :_reduce_32, 3, 25, :_reduce_33, 3, 25, :_reduce_34, 2, 37, :_reduce_none, 1, 39, :_reduce_36, 2, 39, :_reduce_none, 1, 40, :_reduce_38, 2, 40, :_reduce_none, 1, 38, :_reduce_40, 1, 36, :_reduce_41, 1, 36, :_reduce_none, 1, 36, :_reduce_none, 1, 41, :_reduce_none, 1, 41, :_reduce_none, 0, 43, :_reduce_none, 1, 43, :_reduce_47, 1, 43, :_reduce_48, 1, 43, :_reduce_49, 1, 43, :_reduce_50, 1, 43, :_reduce_51, 1, 43, :_reduce_52, 1, 43, :_reduce_53, 1, 42, :_reduce_54, 1, 42, :_reduce_55, 1, 42, :_reduce_56, 1, 42, :_reduce_57 ] racc_reduce_n = 58 racc_shift_n = 82 racc_token_table = { false => 0, :error => 1, :IDENTIFIER => 2, :STRING_MULTI => 3, :STRING_BASIC => 4, :STRING_LITERAL_MULTI => 5, :STRING_LITERAL => 6, :DATETIME => 7, :INTEGER => 8, :FLOAT => 9, :FLOAT_INF => 10, :FLOAT_NAN => 11, :TRUE => 12, :FALSE => 13, "[" => 14, "]" => 15, "." => 16, "{" => 17, "}" => 18, "," => 19, "=" => 20 } racc_nt_base = 21 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", "IDENTIFIER", "STRING_MULTI", "STRING_BASIC", "STRING_LITERAL_MULTI", "STRING_LITERAL", "DATETIME", "INTEGER", "FLOAT", "FLOAT_INF", "FLOAT_NAN", "TRUE", "FALSE", "\"[\"", "\"]\"", "\".\"", "\"{\"", "\"}\"", "\",\"", "\"=\"", "$start", "expressions", "expression", "table", "assignment", "inline_table", "table_start", "table_continued", "table_identifier", "table_next", "inline_table_start", "inline_continued", "inline_assignment_key", "inline_assignment_value", "inline_next", "value", "array", "start_array", "array_continued", "array_next", "scalar", "string", "literal" ] Racc_debug_parser = false ##### State transition tables end ##### # reduce 0 omitted # reduce 1 omitted # reduce 2 omitted # reduce 3 omitted # reduce 4 omitted # reduce 5 omitted # reduce 6 omitted module_eval(<<'.,.,', 'parser.y', 15) def _reduce_7(val, _values, result) @handler.start_(:array_of_tables) result end .,., module_eval(<<'.,.,', 'parser.y', 16) def _reduce_8(val, _values, result) @handler.start_(:table) result end .,., module_eval(<<'.,.,', 'parser.y', 19) def _reduce_9(val, _values, result) array = @handler.end_(:array_of_tables); @handler.set_context(array, is_array_of_tables: true) result end .,., module_eval(<<'.,.,', 'parser.y', 20) def _reduce_10(val, _values, result) array = @handler.end_(:table); @handler.set_context(array) result end .,., # reduce 11 omitted module_eval(<<'.,.,', 'parser.y', 24) def _reduce_12(val, _values, result) array = @handler.end_(:array_of_tables); @handler.set_context(array, is_array_of_tables: true) result end .,., module_eval(<<'.,.,', 'parser.y', 25) def _reduce_13(val, _values, result) array = @handler.end_(:table); @handler.set_context(array) result end .,., # reduce 14 omitted module_eval(<<'.,.,', 'parser.y', 29) def _reduce_15(val, _values, result) @handler.push(val[0]) result end .,., module_eval(<<'.,.,', 'parser.y', 30) def _reduce_16(val, _values, result) @handler.push(val[0]) result end .,., module_eval(<<'.,.,', 'parser.y', 31) def _reduce_17(val, _values, result) @handler.push(val[0]) result end .,., module_eval(<<'.,.,', 'parser.y', 32) def _reduce_18(val, _values, result) @handler.push(val[0]) result end .,., module_eval(<<'.,.,', 'parser.y', 33) def _reduce_19(val, _values, result) @handler.push(val[0]) result end .,., module_eval(<<'.,.,', 'parser.y', 34) def _reduce_20(val, _values, result) @handler.push(val[0]) result end .,., # reduce 21 omitted module_eval(<<'.,.,', 'parser.y', 40) def _reduce_22(val, _values, result) @handler.start_(:inline) result end .,., module_eval(<<'.,.,', 'parser.y', 43) def _reduce_23(val, _values, result) array = @handler.end_(:inline); @handler.push(Hash[*array]) result end .,., # reduce 24 omitted module_eval(<<'.,.,', 'parser.y', 48) def _reduce_25(val, _values, result) array = @handler.end_(:inline) array.map!.with_index{ |n,i| i.even? ? n.to_sym : n } if @handler.symbolize_keys @handler.push(Hash[*array]) result end .,., # reduce 26 omitted module_eval(<<'.,.,', 'parser.y', 55) def _reduce_27(val, _values, result) @handler.push(val[0]) result end .,., # reduce 28 omitted module_eval(<<'.,.,', 'parser.y', 61) def _reduce_29(val, _values, result) @handler.assign(val[0]) result end .,., module_eval(<<'.,.,', 'parser.y', 62) def _reduce_30(val, _values, result) @handler.assign(val[0]) result end .,., module_eval(<<'.,.,', 'parser.y', 63) def _reduce_31(val, _values, result) @handler.assign(val[0]) result end .,., module_eval(<<'.,.,', 'parser.y', 64) def _reduce_32(val, _values, result) @handler.assign(val[0]) result end .,., module_eval(<<'.,.,', 'parser.y', 65) def _reduce_33(val, _values, result) @handler.assign(val[0]) result end .,., module_eval(<<'.,.,', 'parser.y', 66) def _reduce_34(val, _values, result) @handler.assign(val[0]) result end .,., # reduce 35 omitted module_eval(<<'.,.,', 'parser.y', 72) def _reduce_36(val, _values, result) array = @handler.end_(:array); @handler.push(array) result end .,., # reduce 37 omitted module_eval(<<'.,.,', 'parser.y', 76) def _reduce_38(val, _values, result) array = @handler.end_(:array); @handler.push(array) result end .,., # reduce 39 omitted module_eval(<<'.,.,', 'parser.y', 80) def _reduce_40(val, _values, result) @handler.start_(:array) result end .,., module_eval(<<'.,.,', 'parser.y', 83) def _reduce_41(val, _values, result) @handler.push(val[0]) result end .,., # reduce 42 omitted # reduce 43 omitted # reduce 44 omitted # reduce 45 omitted # reduce 46 omitted module_eval(<<'.,.,', 'parser.y', 92) def _reduce_47(val, _values, result) result = val[0].to_f result end .,., module_eval(<<'.,.,', 'parser.y', 93) def _reduce_48(val, _values, result) result = (val[0][0] == '-' ? -1 : 1) * Float::INFINITY result end .,., module_eval(<<'.,.,', 'parser.y', 94) def _reduce_49(val, _values, result) result = Float::NAN result end .,., module_eval(<<'.,.,', 'parser.y', 95) def _reduce_50(val, _values, result) result = val[0].to_i result end .,., module_eval(<<'.,.,', 'parser.y', 96) def _reduce_51(val, _values, result) result = true result end .,., module_eval(<<'.,.,', 'parser.y', 97) def _reduce_52(val, _values, result) result = false result end .,., module_eval(<<'.,.,', 'parser.y', 98) def _reduce_53(val, _values, result) result = Time.new(*val[0]) result end .,., module_eval(<<'.,.,', 'parser.y', 101) def _reduce_54(val, _values, result) result = StringUtils.replace_escaped_chars(StringUtils.multiline_replacements(val[0])) result end .,., module_eval(<<'.,.,', 'parser.y', 102) def _reduce_55(val, _values, result) result = StringUtils.replace_escaped_chars(val[0]) result end .,., module_eval(<<'.,.,', 'parser.y', 103) def _reduce_56(val, _values, result) result = StringUtils.strip_spaces(val[0]) result end .,., module_eval(<<'.,.,', 'parser.y', 104) def _reduce_57(val, _values, result) result = val[0] result end .,., def _reduce_none(val, _values, result) val[0] end end # class GeneratedParser end # module Tomlrb tomlrb-1.3.0/lib/tomlrb/scanner.rb0000644000004100000410000000365113641341630017073 0ustar www-datawww-datarequire 'strscan' module Tomlrb class Scanner COMMENT = /#.*/ IDENTIFIER = /[A-Za-z0-9_-]+/ SPACE = /[ \t\r\n]/ STRING_BASIC = /(["])(?:\\?.)*?\1/ STRING_MULTI = /"{3}([\s\S]*?"{3,4})/m STRING_LITERAL = /(['])(?:\\?.)*?\1/ STRING_LITERAL_MULTI = /'{3}([\s\S]*?'{3})/m DATETIME = /(-?\d{4})-(\d{2})-(\d{2})(?:(?:t|\s)(\d{2}):(\d{2}):(\d{2}(?:\.\d+)?))?(z|[-+]\d{2}:\d{2})?/i FLOAT = /[+-]?(?:[0-9_]+\.[0-9_]*|\d+(?=[eE]))(?:[eE][+-]?[0-9_]+)?/ FLOAT_INF = /[+-]?inf/ FLOAT_NAN = /[+-]?nan/ INTEGER = /[+-]?([1-9](_?\d)*|0)(?![A-Za-z0-9_-]+)/ TRUE = /true/ FALSE = /false/ def initialize(io) @ss = StringScanner.new(io.read) end def next_token return if @ss.eos? case when @ss.scan(SPACE) then next_token when @ss.scan(COMMENT) then next_token when @ss.scan(DATETIME) then process_datetime when text = @ss.scan(STRING_MULTI) then [:STRING_MULTI, text[3..-4]] when text = @ss.scan(STRING_BASIC) then [:STRING_BASIC, text[1..-2]] when text = @ss.scan(STRING_LITERAL_MULTI) then [:STRING_LITERAL_MULTI, text[3..-4]] when text = @ss.scan(STRING_LITERAL) then [:STRING_LITERAL, text[1..-2]] when text = @ss.scan(FLOAT) then [:FLOAT, text] when text = @ss.scan(FLOAT_INF) then [:FLOAT_INF, text] when text = @ss.scan(FLOAT_NAN) then [:FLOAT_NAN, text] when text = @ss.scan(INTEGER) then [:INTEGER, text] when text = @ss.scan(TRUE) then [:TRUE, text] when text = @ss.scan(FALSE) then [:FALSE, text] when text = @ss.scan(IDENTIFIER) then [:IDENTIFIER, text] else x = @ss.getch [x, x] end end def process_datetime if @ss[7].nil? offset = '+00:00' else offset = @ss[7].gsub('Z', '+00:00') end args = [@ss[1], @ss[2], @ss[3], @ss[4] || 0, @ss[5] || 0, @ss[6].to_f, offset] [:DATETIME, args] end end end tomlrb-1.3.0/lib/tomlrb/handler.rb0000644000004100000410000000351513641341630017056 0ustar www-datawww-datamodule Tomlrb class Handler attr_reader :output, :symbolize_keys def initialize(**options) @output = {} @current = @output @stack = [] @array_names = [] @symbolize_keys = options[:symbolize_keys] end def set_context(identifiers, is_array_of_tables: false) @current = @output deal_with_array_of_tables(identifiers, is_array_of_tables) do |identifierz| identifierz.each do |k| k = k.to_sym if @symbolize_keys if @current[k].is_a?(Array) @current[k] << {} if @current[k].empty? @current = @current[k].last else @current[k] ||= {} @current = @current[k] end end end end def deal_with_array_of_tables(identifiers, is_array_of_tables) identifiers.map!{|n| n.gsub("\"", '')} stringified_identifier = identifiers.join('.') if is_array_of_tables @array_names << stringified_identifier last_identifier = identifiers.pop elsif @array_names.include?(stringified_identifier) raise ParseError, 'Cannot define a normal table with the same name as an already established array' end yield(identifiers) if is_array_of_tables last_identifier = last_identifier.to_sym if @symbolize_keys @current[last_identifier] ||= [] @current[last_identifier] << {} @current = @current[last_identifier].last end end def assign(k) k = k.to_sym if @symbolize_keys @current[k] = @stack.pop end def push(o) @stack << o end def start_(type) push([type]) end def end_(type) array = [] while (value = @stack.pop) != [type] raise ParseError, 'Unclosed table' if value.nil? array.unshift(value) end array end end end tomlrb-1.3.0/lib/tomlrb/parser.rb0000644000004100000410000000047213641341630016734 0ustar www-datawww-datarequire "tomlrb/generated_parser" class Tomlrb::Parser < Tomlrb::GeneratedParser def initialize(tokenizer, **options) @tokenizer = tokenizer @handler = Tomlrb::Handler.new(**options) super() end def next_token @tokenizer.next_token end def parse do_parse @handler end end tomlrb-1.3.0/lib/tomlrb/parser.y0000644000004100000410000000626513641341630016607 0ustar www-datawww-dataclass Tomlrb::GeneratedParser token IDENTIFIER STRING_MULTI STRING_BASIC STRING_LITERAL_MULTI STRING_LITERAL DATETIME INTEGER FLOAT FLOAT_INF FLOAT_NAN TRUE FALSE rule expressions | expressions expression ; expression : table | assignment | inline_table ; table : table_start table_continued ; table_start : '[' '[' { @handler.start_(:array_of_tables) } | '[' { @handler.start_(:table) } ; table_continued : ']' ']' { array = @handler.end_(:array_of_tables); @handler.set_context(array, is_array_of_tables: true) } | ']' { array = @handler.end_(:table); @handler.set_context(array) } | table_identifier table_next ; table_next : ']' ']' { array = @handler.end_(:array_of_tables); @handler.set_context(array, is_array_of_tables: true) } | ']' { array = @handler.end_(:table); @handler.set_context(array) } | '.' table_continued ; table_identifier : IDENTIFIER { @handler.push(val[0]) } | STRING_BASIC { @handler.push(val[0]) } | STRING_LITERAL { @handler.push(val[0]) } | INTEGER { @handler.push(val[0]) } | TRUE { @handler.push(val[0]) } | FALSE { @handler.push(val[0]) } ; inline_table : inline_table_start inline_continued ; inline_table_start : '{' { @handler.start_(:inline) } ; inline_continued : '}' { array = @handler.end_(:inline); @handler.push(Hash[*array]) } | inline_assignment_key inline_assignment_value inline_next ; inline_next : '}' { array = @handler.end_(:inline) array.map!.with_index{ |n,i| i.even? ? n.to_sym : n } if @handler.symbolize_keys @handler.push(Hash[*array]) } | ',' inline_continued ; inline_assignment_key : IDENTIFIER { @handler.push(val[0]) } ; inline_assignment_value : '=' value ; assignment : IDENTIFIER '=' value { @handler.assign(val[0]) } | STRING_BASIC '=' value { @handler.assign(val[0]) } | STRING_LITERAL '=' value { @handler.assign(val[0]) } | INTEGER '=' value { @handler.assign(val[0]) } | TRUE '=' value { @handler.assign(val[0]) } | FALSE '=' value { @handler.assign(val[0]) } ; array : start_array array_continued ; array_continued : ']' { array = @handler.end_(:array); @handler.push(array) } | value array_next ; array_next : ']' { array = @handler.end_(:array); @handler.push(array) } | ',' array_continued ; start_array : '[' { @handler.start_(:array) } ; value : scalar { @handler.push(val[0]) } | array | inline_table ; scalar : string | literal ; literal | FLOAT { result = val[0].to_f } | FLOAT_INF { result = (val[0][0] == '-' ? -1 : 1) * Float::INFINITY } | FLOAT_NAN { result = Float::NAN } | INTEGER { result = val[0].to_i } | TRUE { result = true } | FALSE { result = false } | DATETIME { result = Time.new(*val[0])} ; string : STRING_MULTI { result = StringUtils.replace_escaped_chars(StringUtils.multiline_replacements(val[0])) } | STRING_BASIC { result = StringUtils.replace_escaped_chars(val[0]) } | STRING_LITERAL_MULTI { result = StringUtils.strip_spaces(val[0]) } | STRING_LITERAL { result = val[0] } ; tomlrb-1.3.0/lib/tomlrb.rb0000644000004100000410000000301113641341630015430 0ustar www-datawww-datarequire 'time' require 'stringio' require "tomlrb/version" require 'tomlrb/string_utils' require "tomlrb/scanner" require "tomlrb/parser" require "tomlrb/handler" module Tomlrb class ParseError < StandardError; end # Parses a valid TOML string into its Ruby data structure # # @param string_or_io [String, StringIO] the content # @param options [Hash] the options hash # @option options [Boolean] :symbolize_keys (false) whether to return the keys as symbols or strings # @return [Hash] the Ruby data structure represented by the input def self.parse(string_or_io, **options) io = string_or_io.is_a?(String) ? StringIO.new(string_or_io) : string_or_io scanner = Scanner.new(io) parser = Parser.new(scanner, **options) begin handler = parser.parse rescue Racc::ParseError => e raise ParseError, e.message end handler.output end # Reads a file content and parses it into its Ruby data structure # # @param path [String] the path to the file # @param options [Hash] the options hash # @option options [Boolean] :symbolize_keys (false) whether to return the keys as symbols or strings # @return [Hash] the Ruby data structure represented by the input def self.load_file(path, **options) # By default Ruby sets the external encoding of an IO object to the # default external encoding. The default external encoding is set by # locale encoding or the interpreter -E option. tmp = File.read(path, :encoding=>'utf-8') Tomlrb.parse(tmp, **options) end end tomlrb-1.3.0/LICENSE.txt0000644000004100000410000000207313641341630014670 0ustar www-datawww-dataThe MIT License (MIT) Copyright (c) 2015 Francois Bernier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. tomlrb-1.3.0/tomlrb.gemspec0000644000004100000410000000221413641341630015706 0ustar www-datawww-data######################################################### # This file has been automatically generated by gem2tgz # ######################################################### # -*- encoding: utf-8 -*- # stub: tomlrb 1.3.0 ruby lib Gem::Specification.new do |s| s.name = "tomlrb".freeze s.version = "1.3.0" s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= s.require_paths = ["lib".freeze] s.authors = ["Francois Bernier".freeze] s.date = "2020-03-19" s.description = "A racc based toml parser".freeze s.email = ["frankbernier@gmail.com".freeze] s.files = ["LICENSE.txt".freeze, "lib/tomlrb.rb".freeze, "lib/tomlrb/generated_parser.rb".freeze, "lib/tomlrb/handler.rb".freeze, "lib/tomlrb/parser.rb".freeze, "lib/tomlrb/parser.y".freeze, "lib/tomlrb/scanner.rb".freeze, "lib/tomlrb/string_utils.rb".freeze, "lib/tomlrb/version.rb".freeze] s.homepage = "https://github.com/fbernier/tomlrb".freeze s.licenses = ["MIT".freeze] s.required_ruby_version = Gem::Requirement.new(">= 2.0".freeze) s.rubygems_version = "2.5.2.1".freeze s.summary = "A racc based toml parser".freeze end