@@ -38,7 +38,7 @@ const TOMLDict = Dict{String, Any}
3838# Parser #
3939# #########
4040
41- mutable struct Parser
41+ mutable struct Parser{Dates}
4242 str:: String
4343 # 1 character look ahead
4444 current_char:: Char
@@ -86,12 +86,12 @@ mutable struct Parser
8686 filepath:: Union{String, Nothing}
8787
8888 # Optionally populate with the Dates stdlib to change the type of Date types returned
89- Dates:: Union{Module, Nothing}
89+ Dates:: Union{Module, Nothing} # TODO : remove once Pkg is updated
9090end
9191
92- function Parser (str:: String ; filepath= nothing )
92+ function Parser {Dates} (str:: String ; filepath= nothing ) where {Dates}
9393 root = TOMLDict ()
94- l = Parser (
94+ l = Parser {Dates} (
9595 str, # str
9696 EOF_CHAR, # current_char
9797 firstindex (str), # pos
@@ -112,6 +112,7 @@ function Parser(str::String; filepath=nothing)
112112 startup (l)
113113 return l
114114end
115+
115116function startup (l:: Parser )
116117 # Populate our one character look-ahead
117118 c = eat_char (l)
@@ -122,8 +123,10 @@ function startup(l::Parser)
122123 end
123124end
124125
125- Parser () = Parser (" " )
126- Parser (io:: IO ) = Parser (read (io, String))
126+ Parser {Dates} () where {Dates} = Parser {Dates} (" " )
127+ Parser {Dates} (io:: IO ) where {Dates} = Parser {Dates} (read (io, String))
128+
129+ # Parser(...) will be defined by TOML stdlib
127130
128131function reinit! (p:: Parser , str:: String ; filepath:: Union{Nothing, String} = nothing )
129132 p. str = str
@@ -1021,11 +1024,11 @@ function parse_datetime(l)
10211024 return try_return_datetime (l, year, month, day, h, m, s, ms)
10221025end
10231026
1024- function try_return_datetime (p, year, month, day, h, m, s, ms)
1025- Dates = p. Dates
1026- if Dates != = nothing
1027+ function try_return_datetime (p:: Parser{Dates} , year, month, day, h, m, s, ms) where Dates
1028+ if Dates != = nothing || p. Dates != = nothing
1029+ mod = Dates != = nothing ? Dates : p . Dates
10271030 try
1028- return Dates . DateTime (year, month, day, h, m, s, ms)
1031+ return mod . DateTime (year, month, day, h, m, s, ms)
10291032 catch ex
10301033 ex isa ArgumentError && return ParserError (ErrParsingDateTime)
10311034 rethrow ()
@@ -1035,11 +1038,11 @@ function try_return_datetime(p, year, month, day, h, m, s, ms)
10351038 end
10361039end
10371040
1038- function try_return_date (p, year, month, day)
1039- Dates = p. Dates
1040- if Dates != = nothing
1041+ function try_return_date (p:: Parser{Dates} , year, month, day) where Dates
1042+ if Dates != = nothing || p. Dates != = nothing
1043+ mod = Dates != = nothing ? Dates : p . Dates
10411044 try
1042- return Dates . Date (year, month, day)
1045+ return mod . Date (year, month, day)
10431046 catch ex
10441047 ex isa ArgumentError && return ParserError (ErrParsingDateTime)
10451048 rethrow ()
@@ -1058,11 +1061,11 @@ function parse_local_time(l::Parser)
10581061 return try_return_time (l, h, m, s, ms)
10591062end
10601063
1061- function try_return_time (p, h, m, s, ms)
1062- Dates = p. Dates
1063- if Dates != = nothing
1064+ function try_return_time (p:: Parser{Dates} , h, m, s, ms) where Dates
1065+ if Dates != = nothing || p. Dates != = nothing
1066+ mod = Dates != = nothing ? Dates : p . Dates
10641067 try
1065- return Dates . Time (h, m, s, ms)
1068+ return mod . Time (h, m, s, ms)
10661069 catch ex
10671070 ex isa ArgumentError && return ParserError (ErrParsingDateTime)
10681071 rethrow ()
0 commit comments