@@ -10,7 +10,12 @@ function parse(::Type{DecoratedInterval{T}}, s::AbstractString) where T
10
10
m = match (r" (\[ .*\] )(\_ .*)?" , s)
11
11
12
12
if m == nothing # matched
13
- throw (ArgumentError (" Unable to process string $x as decorated interval" ))
13
+
14
+ m = match (r" (.*\? [a-z0-9]*)(\_ .*)?" , s)
15
+
16
+ if m == nothing
17
+ throw (ArgumentError (" Unable to process string $x as decorated interval" ))
18
+ end
14
19
15
20
end
16
21
@@ -49,32 +54,196 @@ function parse(::Type{Interval{T}}, s::AbstractString) where T
49
54
b = parse (T, strip (m. captures[2 ]))
50
55
51
56
return a ± b
52
- end
53
57
54
58
a = parse (T, s, RoundDown)
55
59
b = parse (T, s, RoundUp)
56
60
57
61
return Interval (a, b)
58
62
63
+ end
64
+
65
+ if m == nothing
66
+
67
+ m = match (r" (\- ?\d *\. ?\d *)\?\? ([ud]?)" , s) # match with string of form "34??"
68
+
69
+ if m!= nothing
70
+ if m. captures[2 ] == " " # strings of the form "10??"
71
+ return entireinterval (T)
72
+ end
73
+ if m. captures[2 ] == " u" # strings of the form "10??u"
74
+ lo = parse (Float64, m. captures[1 ])
75
+ hi = Inf
76
+ interval = eval (make_interval (T, lo, [hi]))
77
+ return interval
78
+ end
79
+ if m. captures[2 ] == " d" # strings of the form "10??d"
80
+ lo = - Inf
81
+ hi = parse (Float64, m. captures[1 ])
82
+ interval = eval (make_interval (T, lo, [hi]))
83
+ return interval
84
+ end
85
+ end
86
+
87
+ m = match (r" (\- ?\d *)\. ?(\d *)\? (\d *)([ud]?)(e-?\d *)?" , s) # match with strings like "3.56?1u" or "3.56?1e2"
88
+
89
+ if m != nothing # matched
90
+ if m. captures[3 ] != " " && m. captures[4 ] == " " && m. captures[5 ] == nothing # string of form "3.4?1" or "10?2"
91
+ d = length (m. captures[2 ])
92
+ x = parse (Float64, m. captures[3 ] * " e-$d " )
93
+ n = parse (Float64, m. captures[1 ]* " ." * m. captures[2 ])
94
+ lo = n - x
95
+ hi = n + x
96
+ interval = eval (make_interval (T, lo, [hi]))
97
+ return interval
98
+ end
99
+
100
+ if m. captures[3 ] == " " && m. captures[4 ] == " " && m. captures[5 ] == nothing # strings of the form "3.46?"
101
+ d = length (m. captures[2 ])
102
+ x = parse (Float64, " 0.5" * " e-$d " )
103
+ n = parse (Float64, m. captures[1 ]* " ." * m. captures[2 ])
104
+ lo = n - x
105
+ hi = n + x
106
+ interval = eval (make_interval (T, lo, [hi]))
107
+ return interval
108
+ end
109
+
110
+ if m. captures[3 ] == " " && m. captures[4 ] == " " && m. captures[5 ] != nothing # strings of the form "3.46?e2"
111
+ d = length (m. captures[2 ])
112
+ x = parse (Float64, " 0.5" * " e-$d " )
113
+ n = parse (Float64, m. captures[1 ]* " ." * m. captures[2 ])
114
+ lo = parse (Float64, string (n- x) * m. captures[5 ])
115
+ hi = parse (Float64, string (n+ x) * m. captures[5 ])
116
+ interval = eval (make_interval (T, lo, [hi]))
117
+ return interval
118
+ end
119
+
120
+ if m. captures[3 ] == " " && m. captures[4 ] == " u" && m. captures[5 ] == nothing # strings of the form "3.4?u"
121
+ d = length (m. captures[2 ])
122
+ x = parse (Float64, " 0.5" * " e-$d " )
123
+ n = parse (Float64, m. captures[1 ]* " ." * m. captures[2 ])
124
+ lo = n
125
+ hi = n+ x
126
+ interval = eval (make_interval (T, lo, [hi]))
127
+ return interval
128
+ end
129
+
130
+ if m. captures[3 ] == " " && m. captures[4 ] == " d" && m. captures[5 ] == nothing # strings of the form "3.4?d"
131
+ d = length (m. captures[2 ])
132
+ x = parse (Float64, " 0.5" * " e-$d " )
133
+ n = parse (Float64, m. captures[1 ]* " ." * m. captures[2 ])
134
+ lo = n - x
135
+ hi = n
136
+ interval = eval (make_interval (T, lo, [hi]))
137
+ return interval
138
+ end
139
+
140
+ if m. captures[3 ] != " "
141
+ if m. captures[4 ] == " u" && m. captures[5 ] != nothing # strings of the form "3.46?1u"
142
+ d = length (m. captures[2 ])
143
+ x = parse (Float64, m. captures[3 ] * " e-$d " )
144
+ n = parse (Float64, m. captures[1 ]* " ." * m. captures[2 ])
145
+ lo = parse (Float64, string (n) * m. captures[5 ])
146
+ hi = parse (Float64, string (n+ x) * m. captures[5 ])
147
+ interval = eval (make_interval (T, lo, [hi]))
148
+ return interval
149
+ end
150
+
151
+ if m. captures[4 ] == " u" && m. captures[5 ] == nothing # strings of the form "3.46?1u"
152
+ d = length (m. captures[2 ])
153
+ x = parse (Float64, m. captures[3 ] * " e-$d " )
154
+ n = parse (Float64, m. captures[1 ]* " ." * m. captures[2 ])
155
+ lo = n
156
+ hi = n+ x
157
+ interval = eval (make_interval (T, lo, [hi]))
158
+ return interval
159
+ end
160
+
161
+ if m. captures[4 ] == " d" && m. captures[5 ] != nothing # strings of the form "3.46?1d"
162
+ d = length (m. captures[2 ])
163
+ x = parse (Float64, m. captures[3 ] * " e-$d " )
164
+ n = parse (Float64, m. captures[1 ]* " ." * m. captures[2 ])
165
+ lo = parse (Float64, string (n- x) * m. captures[5 ])
166
+ hi = parse (Float64, string (n) * m. captures[5 ])
167
+ interval = eval (make_interval (T, lo, [hi]))
168
+ return interval
169
+ end
170
+
171
+ if m. captures[4 ] == " d" && m. captures[5 ] == nothing # strings of the form "3.46?1d"
172
+ d = length (m. captures[2 ])
173
+ x = parse (Float64, m. captures[3 ] * " e-$d " )
174
+ n = parse (Float64, m. captures[1 ]* " ." * m. captures[2 ])
175
+ lo = n- x
176
+ hi = n
177
+ interval = eval (make_interval (T, lo, [hi]))
178
+ return interval
179
+ end
180
+
181
+ if m. captures[4 ] == " " && m. captures[5 ] != nothing # strings of the form "3.56?1e2"
182
+ d = length (m. captures[2 ])
183
+ x = parse (Float64, m. captures[3 ] * " e-$d " )
184
+ n = parse (Float64, m. captures[1 ]* " ." * m. captures[2 ])
185
+ lo = parse (Float64, string (n- x)* m. captures[5 ])
186
+ hi = parse (Float64, string (n+ x)* m. captures[5 ])
187
+ interval = eval (make_interval (T, lo, [hi]))
188
+ return interval
189
+ end
190
+ end
191
+ end
192
+
193
+ m = match (r" (-?\d *\. ?\d *)" , s) # match strings of form "1" and "2.4"
194
+
195
+ if m != nothing
196
+ lo = parse (Float64, m. captures[1 ])
197
+ hi = lo
198
+ end
199
+
200
+ if m == nothing
201
+ throw (ArgumentError (" Unable to process string $s as interval" ))
202
+ end
203
+
204
+ interval = eval (make_interval (T, lo, [hi]))
205
+ return interval
206
+ end
59
207
end
60
208
61
209
# match string of form [a, b]_dec:
62
210
m = match (r" \[ (.*),(.*)\] " , s)
63
211
64
212
if m != nothing # matched
213
+
214
+ m. captures[1 ] = strip (m. captures[1 ], [' ' ])
215
+ m. captures[2 ] = strip (m. captures[2 ], [' ' ])
65
216
lo, hi = m. captures
66
217
67
- else
218
+ if m. captures[2 ] == " +infinity" || m. captures[2 ] == " "
219
+ hi = " Inf"
220
+ end
221
+
222
+ if m. captures[1 ] == " -infinity" || m. captures[1 ] == " "
223
+ lo = " -Inf"
224
+ end
225
+
226
+ end
227
+
228
+ if m == nothing
68
229
69
230
m = match (r" \[ (.*)\] " , s) # string like "[1]"
70
231
71
232
if m == nothing
72
233
throw (ArgumentError (" Unable to process string $s as interval" ))
73
234
end
74
235
75
- if m. captures[1 ] == " Empty"
236
+ m. captures[1 ] = strip (m. captures[1 ], [' ' ])
237
+
238
+ if m. captures[1 ] == " Empty" || m. captures[1 ] == " "
76
239
return emptyinterval (T)
77
240
end
241
+ if m. captures[1 ] == " entire"
242
+ return entireinterval (T)
243
+ end
244
+ if m. captures[1 ] == " nai" || m. captures[1 ] == " Nai"
245
+ return nai (T)
246
+ end
78
247
79
248
lo = m. captures[1 ]
80
249
hi = lo
@@ -83,6 +252,12 @@ function parse(::Type{Interval{T}}, s::AbstractString) where T
83
252
84
253
expr1 = Meta. parse (lo)
85
254
expr2 = Meta. parse (hi)
255
+ if lo == " -Inf"
256
+ expr1 = parse (Float64, lo)
257
+ end
258
+ if hi == " Inf"
259
+ expr2 = parse (Float64, hi)
260
+ end
86
261
87
262
interval = eval (make_interval (T, expr1, [expr2]))
88
263
0 commit comments