Skip to content

Commit 07d5255

Browse files
authored
oc parser/transformer working (#249)
rough but it works. involved a few fixes upstream in devtools, record subfield order was getting scrambled and some v1 schema things were not getting converted to v2. and a few fixes here, mostly to allow the typed transformer to handle composites i.e. (lists of) records and unions. I think this should generalize pretty well but it needs cleanup/refactoring. still need an inbound converter. right now we only support array conversion and haven't tried plugging it into the output of the loader.
1 parent 3182e11 commit 07d5255

File tree

152 files changed

+904
-368
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+904
-368
lines changed

flopy4/mf6/codec/reader/grammar/filters.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,21 @@ def field_type(field: FieldV2) -> str:
1818

1919

2020
def record_child_type(field: FieldV2) -> str:
21-
"""Get the grammar type for a field within a record context."""
21+
"""
22+
Get the grammar type for a field within a record context.
23+
24+
In records, string fields should use 'word' instead of 'string'
25+
to avoid consuming the rest of the line (since string matches token+ NEWLINE).
26+
"""
2227
match field.type:
23-
case t if t in ["string", "double", "integer"]:
28+
case "string":
29+
return "word" # Use word for strings in records to match single tokens
30+
case t if t in ["double", "integer"]:
2431
return t
2532
case "keyword":
2633
return ""
2734
case "union":
28-
return "" # keystrings generate their own union rules
35+
return "" # unions generate their own union rules
2936
case _:
3037
return field.type
3138

flopy4/mf6/codec/reader/grammar/generated/chf-cdb.lark

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
%import typed.double -> double
55
%import typed.number -> number
66
%import typed.string -> string
7+
%import typed.word -> word
78
%import typed.array -> array
89
%import typed.record -> record
910
%import typed.NEWLINE -> NEWLINE
@@ -27,6 +28,6 @@ boundnames: "boundnames"i
2728
print_input: "print_input"i
2829
print_flows: "print_flows"i
2930
save_flows: "save_flows"i
30-
obs_filerecord: "filein"i "obs6"i string
31+
obs_filerecord: "obs6"i "filein"i word
3132
maxbound: "maxbound"i integer
3233
stress_period_data: record+

flopy4/mf6/codec/reader/grammar/generated/chf-chd.lark

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
%import typed.double -> double
55
%import typed.number -> number
66
%import typed.string -> string
7+
%import typed.word -> word
78
%import typed.array -> array
89
%import typed.record -> record
910
%import typed.NEWLINE -> NEWLINE
@@ -28,7 +29,7 @@ boundnames: "boundnames"i
2829
print_input: "print_input"i
2930
print_flows: "print_flows"i
3031
save_flows: "save_flows"i
31-
ts_filerecord: "ts6"i "filein"i string
32-
obs_filerecord: "filein"i "obs6"i string
32+
ts_filerecord: "ts6"i "filein"i word
33+
obs_filerecord: "obs6"i "filein"i word
3334
maxbound: "maxbound"i integer
3435
stress_period_data: record+

flopy4/mf6/codec/reader/grammar/generated/chf-cxs.lark

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
%import typed.double -> double
55
%import typed.number -> number
66
%import typed.string -> string
7+
%import typed.word -> word
78
%import typed.array -> array
89
%import typed.record -> record
910
%import typed.NEWLINE -> NEWLINE
@@ -26,5 +27,5 @@ crosssectiondata_fields: (crosssectiondata)*
2627
print_input: "print_input"i
2728
nsections: "nsections"i integer
2829
npoints: "npoints"i integer
29-
packagedata: "packagedata"i recarray
30-
crosssectiondata: "crosssectiondata"i recarray
30+
packagedata: "packagedata"i list
31+
crosssectiondata: "crosssectiondata"i list

flopy4/mf6/codec/reader/grammar/generated/chf-dfw.lark

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
%import typed.double -> double
55
%import typed.number -> number
66
%import typed.string -> string
7+
%import typed.word -> word
78
%import typed.array -> array
89
%import typed.record -> record
910
%import typed.NEWLINE -> NEWLINE
@@ -25,7 +26,7 @@ time_conversion: "time_conversion"i double
2526
save_flows: "save_flows"i
2627
print_flows: "print_flows"i
2728
save_velocity: "save_velocity"i
28-
obs_filerecord: "obs6"i "filein"i string
29+
obs_filerecord: "obs6"i "filein"i word
2930
export_array_ascii: "export_array_ascii"i
3031
dev_swr_conductance: "dev_swr_conductance"i
3132
manningsn: "manningsn"i array

flopy4/mf6/codec/reader/grammar/generated/chf-disv1d.lark

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
%import typed.double -> double
55
%import typed.number -> number
66
%import typed.string -> string
7+
%import typed.word -> word
78
%import typed.array -> array
89
%import typed.record -> record
910
%import typed.NEWLINE -> NEWLINE
@@ -27,7 +28,7 @@ vertices_fields: (vertices)*
2728
cell1d_fields: (cell1d)*
2829
length_units: "length_units"i string
2930
nogrb: "nogrb"i
30-
grb_filerecord: "grb6"i "fileout"i string
31+
grb_filerecord: "grb6"i "fileout"i word
3132
xorigin: "xorigin"i double
3233
yorigin: "yorigin"i double
3334
angrot: "angrot"i double
@@ -38,5 +39,5 @@ nvert: "nvert"i integer
3839
width: "width"i array
3940
bottom: "bottom"i array
4041
idomain: "idomain"i array
41-
vertices: "vertices"i recarray
42-
cell1d: "cell1d"i recarray
42+
vertices: "vertices"i list
43+
cell1d: "cell1d"i list

flopy4/mf6/codec/reader/grammar/generated/chf-evp.lark

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
%import typed.double -> double
55
%import typed.number -> number
66
%import typed.string -> string
7+
%import typed.word -> word
78
%import typed.array -> array
89
%import typed.record -> record
910
%import typed.NEWLINE -> NEWLINE
@@ -28,7 +29,7 @@ boundnames: "boundnames"i
2829
print_input: "print_input"i
2930
print_flows: "print_flows"i
3031
save_flows: "save_flows"i
31-
ts_filerecord: "ts6"i "filein"i string
32-
obs_filerecord: "filein"i "obs6"i string
32+
ts_filerecord: "ts6"i "filein"i word
33+
obs_filerecord: "obs6"i "filein"i word
3334
maxbound: "maxbound"i integer
3435
stress_period_data: record+

flopy4/mf6/codec/reader/grammar/generated/chf-flw.lark

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
%import typed.double -> double
55
%import typed.number -> number
66
%import typed.string -> string
7+
%import typed.word -> word
78
%import typed.array -> array
89
%import typed.record -> record
910
%import typed.NEWLINE -> NEWLINE
@@ -28,7 +29,7 @@ boundnames: "boundnames"i
2829
print_input: "print_input"i
2930
print_flows: "print_flows"i
3031
save_flows: "save_flows"i
31-
ts_filerecord: "ts6"i "filein"i string
32-
obs_filerecord: "filein"i "obs6"i string
32+
ts_filerecord: "ts6"i "filein"i word
33+
obs_filerecord: "obs6"i "filein"i word
3334
maxbound: "maxbound"i integer
3435
stress_period_data: record+

flopy4/mf6/codec/reader/grammar/generated/chf-ic.lark

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
%import typed.double -> double
55
%import typed.number -> number
66
%import typed.string -> string
7+
%import typed.word -> word
78
%import typed.array -> array
89
%import typed.record -> record
910
%import typed.NEWLINE -> NEWLINE

flopy4/mf6/codec/reader/grammar/generated/chf-nam.lark

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
%import typed.double -> double
55
%import typed.number -> number
66
%import typed.string -> string
7+
%import typed.word -> word
78
%import typed.array -> array
89
%import typed.record -> record
910
%import typed.NEWLINE -> NEWLINE
@@ -24,4 +25,4 @@ print_input: "print_input"i
2425
print_flows: "print_flows"i
2526
save_flows: "save_flows"i
2627
newtonoptions: "newton"i "under_relaxation"i
27-
packages: "packages"i recarray
28+
packages: "packages"i list

0 commit comments

Comments
 (0)