@@ -83,7 +83,7 @@ julia> measurement("-1234e-1")
83
83
"""
84
84
measurement (str:: AbstractString ) = parse (Measurement{Float64}, str)
85
85
86
- function Base. parse (:: Type{Measurement{T}} , str:: S ) where {T<: AbstractFloat , S<: AbstractString }
86
+ function Base. tryparse (:: Type{Measurement{T}} , str:: S ) where {T<: AbstractFloat , S<: AbstractString }
87
87
m = match (rxp_error_with_parentheses, str)
88
88
if m != = nothing # "123(45)e6"
89
89
val_str:: S , val_dec, err_str:: S , err_dec_str, expn = m. captures
@@ -105,7 +105,7 @@ function Base.parse(::Type{Measurement{T}}, str::S) where {T<:AbstractFloat, S<:
105
105
val_str, err_str, val_dec, expn =
106
106
m. captures[1 ], " 0" , nothing , nothing
107
107
else
108
- throw ( ArgumentError ( " cannot parse $( repr (str)) as Measurement{ $T } " ))
108
+ return nothing
109
109
end
110
110
end
111
111
end
@@ -127,3 +127,9 @@ function Base.parse(::Type{Measurement{T}}, str::S) where {T<:AbstractFloat, S<:
127
127
end
128
128
return measurement (val, err)
129
129
end
130
+
131
+ function Base. parse (:: Type{Measurement{T}} , str:: S ) where {T<: AbstractFloat , S<: AbstractString }
132
+ out = tryparse (Measurement{T}, str)
133
+ out === nothing && throw (ArgumentError (" cannot parse $(repr (str)) as Measurement{$T }" ))
134
+ return out
135
+ end
0 commit comments