Sections
Use sections for lines identified by keywords. Arms match in whatever order
the lines appear, and an arm’s body runs as soon as it matches. This suits
headers whose order varies, as in TSPLIB.
Read headers and a body
Section titled “Read headers and a body”This coordinate reader requires a dimension, an edge-weight type and a coordinate section. Only the name is optional.
comment "COMMENT"sections until "EOF" { "NAME : {name:rest}" optional "DIMENSION : {n:2..46340}" "EDGE_WEIGHT_TYPE : {edge_weight_type:word}" "NODE_COORD_SECTION" { repeat n { node: int x: float y: float } }}check edge_weight_type == "EUC_2D" "this reader requires EUC_2D coordinates"check x >= -1e9 && x <= 1e9 && y >= -1e9 && y <= 1e9 "coordinates must be between -1e9 and 1e9"NAME : triangleEDGE_WEIGHT_TYPE : EUC_2DDIMENSION:3NODE_COORD_SECTION1 0 02 3 03 3 4EOFiris read site/examples/tutorial/tsplib-coordinates.iris site/examples/tutorial/tsplib-coordinates.txt --dznname = "triangle";
edge_weight_type = "EUC_2D";
n = 3;
node = [1, 2, 3];
x = [0.0, 3.0, 3.0];
y = [0.0, 0.0, 4.0];
The coordinate body uses n, so DIMENSION must occur before
NODE_COORD_SECTION. Other header arms may occur in either order. Names are
defined when their arms run; sections do not rearrange input or defer bodies.
Required, optional and last arms
Section titled “Required, optional and last arms”An ordinary arm must match exactly once. optional changes that to zero or
one, so guard an optional capture with defined before using it. last ends
sections after the selected arm’s body runs. It still checks for missing
required arms. The job shop tutorial
uses a last arm to leave the next instance header for the next pass.
A terminator is tested before arms. Actual end of input also ends sections,
even with until "EOF". On completion, a missing required arm reports
E-LINE-MATCH.
Repeated and unknown lines
Section titled “Repeated and unknown lines”A repeated dimension is an error even when its value is unchanged:
NAME : triangleDIMENSION : 3DIMENSION : 3EDGE_WEIGHT_TYPE : EUC_2DNODE_COORD_SECTION1 0 02 3 03 3 4EOFiris read site/examples/tutorial/tsplib-coordinates.iris site/examples/guides/sections-repeated.txt --dznsite/examples/guides/sections-repeated.txt:3:1: a second line matching "DIMENSION : {n:2..46340}" (the first is on line 2)
3 | DIMENSION : 3
| ^
spec: site/examples/tutorial/tsplib-coordinates.iris:2
This is E-SECTIONS-REPEATED. Optional arms also reject a second match. Use a repeat for repeated records; a sections arm does not collect repeated headers into an array.
Unknown lines report
E-SECTIONS-UNEXPECTED.
skip other discards unmatched lines when the format permits irrelevant text.
Keep sections strict when an unknown keyword is likely to be a spelling error.
If two patterns could match, the first complete match wins.
The Specification defines the full sections execution order. The TSPLIB tutorial grows this example into the library reader.