@@ -9,8 +9,8 @@ module TOML
99
1010using Base: IdSet
1111
12- # In case we do not have the Dates stdlib available
1312# we parse DateTime into these internal structs,
13+ # unless a different DateTime library is passed to the Parser constructor
1414# note that these do not do any argument checking
1515struct Date
1616 year:: Int
@@ -85,12 +85,10 @@ mutable struct Parser
8585 # Filled in in case we are parsing a file to improve error messages
8686 filepath:: Union{String, Nothing}
8787
88- # Gets populated with the Dates stdlib if it exists
88+ # Optionally populate with the Dates stdlib to change the type of Date types returned
8989 Dates:: Union{Module, Nothing}
9090end
9191
92- const DATES_PKGID = Base. PkgId (Base. UUID (" ade2ca70-3891-5945-98fb-dc099432e06a" ), " Dates" )
93-
9492function Parser (str:: String ; filepath= nothing )
9593 root = TOMLDict ()
9694 l = Parser (
@@ -109,7 +107,7 @@ function Parser(str::String; filepath=nothing)
109107 IdSet {TOMLDict} (), # defined_tables
110108 root,
111109 filepath,
112- isdefined (Base, :maybe_root_module ) ? Base . maybe_root_module (DATES_PKGID) : nothing ,
110+ nothing
113111 )
114112 startup (l)
115113 return l
151149# Errors #
152150# #########
153151
154- throw_internal_error (msg) = error (" internal TOML parser error: $msg " )
155-
156152# Many functions return a ParserError. We want this to bubble up
157153# all the way and have this error be returned to the user
158154# if the parse is called with `raise=false`. This macro
900896function parse_float (l:: Parser , contains_underscore):: Err{Float64}
901897 s = take_string_or_substring (l, contains_underscore)
902898 v = Base. tryparse (Float64, s)
903- v === nothing && return ( ParserError (ErrGenericValueError) )
899+ v === nothing && return ParserError (ErrGenericValueError)
904900 return v
905901end
906902
@@ -909,8 +905,8 @@ function parse_int(l::Parser, contains_underscore, base=nothing)::Err{Int64}
909905 v = try
910906 Base. parse (Int64, s; base= base)
911907 catch e
912- e isa Base. OverflowError && return ( ParserError (ErrOverflowError) )
913- error ( " internal parser error: did not correctly discredit $( repr (s)) as an int " )
908+ e isa Base. OverflowError && return ParserError (ErrOverflowError)
909+ rethrow ( )
914910 end
915911 return v
916912end
@@ -932,8 +928,8 @@ for (name, T1, T2, n1, n2) in (("integer", Int64, Int128, 17, 33),
932928 Base. parse (BigInt, s; base)
933929 end
934930 catch e
935- e isa Base. OverflowError && return ( ParserError (ErrOverflowError) )
936- error ( " internal parser error: did not correctly discredit $( repr (s)) as an int " )
931+ e isa Base. OverflowError && return ParserError (ErrOverflowError)
932+ rethrow ( )
937933 end
938934 return v
939935 end
@@ -1030,8 +1026,9 @@ function try_return_datetime(p, year, month, day, h, m, s, ms)
10301026 if Dates != = nothing
10311027 try
10321028 return Dates. DateTime (year, month, day, h, m, s, ms)
1033- catch
1034- return ParserError (ErrParsingDateTime)
1029+ catch ex
1030+ ex isa ArgumentError && return ParserError (ErrParsingDateTime)
1031+ rethrow ()
10351032 end
10361033 else
10371034 return DateTime (year, month, day, h, m, s, ms)
@@ -1043,8 +1040,9 @@ function try_return_date(p, year, month, day)
10431040 if Dates != = nothing
10441041 try
10451042 return Dates. Date (year, month, day)
1046- catch
1047- return ParserError (ErrParsingDateTime)
1043+ catch ex
1044+ ex isa ArgumentError && return ParserError (ErrParsingDateTime)
1045+ rethrow ()
10481046 end
10491047 else
10501048 return Date (year, month, day)
@@ -1065,8 +1063,9 @@ function try_return_time(p, h, m, s, ms)
10651063 if Dates != = nothing
10661064 try
10671065 return Dates. Time (h, m, s, ms)
1068- catch
1069- return ParserError (ErrParsingDateTime)
1066+ catch ex
1067+ ex isa ArgumentError && return ParserError (ErrParsingDateTime)
1068+ rethrow ()
10701069 end
10711070 else
10721071 return Time (h, m, s, ms)
0 commit comments