Skip to content

Commit 33513f7

Browse files
committed
FZN: support several annotations when parsing.
1 parent ea9b5dd commit 33513f7

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

Diff for: src/ConstraintProgrammingExtensions.jl

-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,4 @@ include("Test/Test.jl")
2828
include("FlatZinc/FlatZinc.jl")
2929
include("XCSP/XCSP.jl")
3030

31-
# Compatibility layer.
32-
@deprecate Reified Reification false
33-
3431
end

Diff for: src/FlatZinc/import.jl

+7-2
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,7 @@ function split_variable(item::AbstractString)
16841684
# Typical input: "var int: x1;" -> scalar
16851685
# Complex input: "array [1..5] of var int: x1;" -> array
16861686
# Complex input: "var int: x1 :: some_annotation = some_value;" -> scalar
1687+
# Complex input: "var int: x1 :: some_annotation :: some_other_annotation;" -> scalar
16871688

16881689
@assert length(item) > 5
16891690

@@ -1713,7 +1714,8 @@ function split_variable_scalar(item::AbstractString)
17131714
item = lstrip(item)
17141715

17151716
# Potentially split on the double colon (::) to detect annotations, then
1716-
# on the equal (=) to detect literal values.
1717+
# on the equal (=) to detect literal values. There may be several
1718+
# annotations.
17171719
if occursin("::", item)
17181720
var_name, item = split(item, "::", limit=2)
17191721
var_name = strip(var_name)
@@ -1727,8 +1729,11 @@ function split_variable_scalar(item::AbstractString)
17271729
var_annotations = strip(item)
17281730
var_value = ""
17291731
end
1732+
1733+
var_annotations = split(var_annotations, "::")
1734+
var_annotations = map(strip, var_annotations)
17301735
else
1731-
var_annotations = ""
1736+
var_annotations = [""]
17321737

17331738
if occursin('=', item)
17341739
var_name, var_value = split(item, '=', limit=2)

Diff for: test/FlatZinc/import.jl

+21-10
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@
284284
@test var_array == ""
285285
@test var_type == "int"
286286
@test var_name == "x1"
287-
@test var_annotations == ""
287+
@test var_annotations == [""]
288288
@test var_value == ""
289289

290290
# With another type (still a string) and an *invalid* variable name.
@@ -293,7 +293,7 @@
293293
@test var_array == ""
294294
@test var_type == "bool"
295295
@test var_name == "5454"
296-
@test var_annotations == ""
296+
@test var_annotations == [""]
297297
@test var_value == ""
298298

299299
# With another type (range of integers).
@@ -302,7 +302,7 @@
302302
@test var_array == ""
303303
@test var_type == "4..8"
304304
@test var_name == "x1"
305-
@test var_annotations == ""
305+
@test var_annotations == [""]
306306
@test var_value == ""
307307

308308
# With another type (range of floats).
@@ -311,7 +311,7 @@
311311
@test var_array == ""
312312
@test var_type == "4.5..8.4"
313313
@test var_name == "x1"
314-
@test var_annotations == ""
314+
@test var_annotations == [""]
315315
@test var_value == ""
316316

317317
# With another type (set of floats, intension).
@@ -320,7 +320,7 @@
320320
@test var_array == ""
321321
@test var_type == "set of 4.5..8.4"
322322
@test var_name == "x1"
323-
@test var_annotations == ""
323+
@test var_annotations == [""]
324324
@test var_value == ""
325325

326326
# With another type (set of floats, extension).
@@ -329,7 +329,7 @@
329329
@test var_array == ""
330330
@test var_type == "set of {4.5, 8.4}"
331331
@test var_name == "x1"
332-
@test var_annotations == ""
332+
@test var_annotations == [""]
333333
@test var_value == ""
334334

335335
# With annotations.
@@ -340,7 +340,18 @@
340340
@test var_array == ""
341341
@test var_type == "int"
342342
@test var_name == "x1"
343-
@test var_annotations == "some_annotation"
343+
@test var_annotations == ["some_annotation"]
344+
@test var_value == ""
345+
346+
# With several annotations.
347+
var_array, var_type, var_name, var_annotations, var_value =
348+
CP.FlatZinc.split_variable(
349+
"var int: x1 :: some_annotation :: some_other_annotation;",
350+
)
351+
@test var_array == ""
352+
@test var_type == "int"
353+
@test var_name == "x1"
354+
@test var_annotations == ["some_annotation", "some_other_annotation"]
344355
@test var_value == ""
345356

346357
# With value.
@@ -349,7 +360,7 @@
349360
@test var_array == ""
350361
@test var_type == "int"
351362
@test var_name == "x1"
352-
@test var_annotations == ""
363+
@test var_annotations == [""]
353364
@test var_value == "some_value"
354365

355366
# With annotations and value.
@@ -360,7 +371,7 @@
360371
@test var_array == ""
361372
@test var_type == "int"
362373
@test var_name == "x1"
363-
@test var_annotations == "some_annotation"
374+
@test var_annotations == ["some_annotation"]
364375
@test var_value == "some_value"
365376

366377
# Array declaration.
@@ -369,7 +380,7 @@
369380
@test var_array == "[1..5]"
370381
@test var_type == "int"
371382
@test var_name == "x1"
372-
@test var_annotations == ""
383+
@test var_annotations == [""]
373384
@test var_value == ""
374385
end
375386

0 commit comments

Comments
 (0)