Skip to content

Commit a4767e3

Browse files
Merge pull request #8 from ACCESS-NRI/lark_refactor
Refactor configuration parsers to use Lark
2 parents ad05884 + 83d02b0 commit a4767e3

14 files changed

+1577
-631
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ classifiers = [
1414
"Topic :: Utilities",
1515
]
1616
dependencies = [
17-
"f90nml",
17+
"lark",
1818
"ruamel.yaml",
1919
]
2020

src/access/parsers/config.lark

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2025 ACCESS-NRI and contributors. See the top-level COPYRIGHT file for details.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// Common terminals and rules for use in all ACCESS configuration parsers
5+
6+
// Dictionary keys
7+
key : CNAME
8+
9+
// Fortran logicals
10+
logical: FTRUE | FFALSE
11+
FTRUE: ".true."i
12+
FFALSE: ".false."i
13+
14+
// Booleans
15+
bool: TRUE | FALSE
16+
TRUE: "True"
17+
FALSE: "False"
18+
19+
// Integers
20+
integer: SIGNED_INT
21+
22+
// Floats
23+
float: SIGNED_FLOAT
24+
25+
// Fortran double values
26+
double: SIGNED_DOUBLE
27+
_DOUBLE_EXP : ("d"|"D") SIGNED_INT
28+
DOUBLE : INT _DOUBLE_EXP | DECIMAL _DOUBLE_EXP?
29+
SIGNED_DOUBLE : ["+"|"-"] DOUBLE
30+
31+
// Fortran complex floats
32+
complex: CMPLX
33+
CMPLX: "(" WS_INLINE* SIGNED_FLOAT WS_INLINE* "," WS_INLINE* SIGNED_FLOAT WS_INLINE* ")"
34+
35+
// Fortran complex doubles
36+
double_complex: DCMPLX
37+
DCMPLX: "(" WS_INLINE* SIGNED_DOUBLE WS_INLINE* "," WS_INLINE* SIGNED_DOUBLE WS_INLINE* ")"
38+
39+
// Identifiers
40+
identifier: CNAME
41+
42+
// Quoted strings
43+
string: STRING
44+
STRING: /(".*?(?<!\\)(\\\\)*?"|'(?!'').*?(?<!\\)(\\\\)*?')/
45+
46+
// Unix-like filesystem paths
47+
path: PATH
48+
PATH_COMPONENT : /[a-zA-Z0-9._-]+/
49+
PATH : ("/" | "./" | "../")? PATH_COMPONENT ("/" PATH_COMPONENT)* ("/")?
50+
51+
// Space, newlines and comments
52+
ws: WS_INLINE
53+
NEWLINE: CR? LF
54+
comment: /[ \t]*#[^\n]*/
55+
fortran_comment: /[ \t]*![^\n]*/
56+
57+
%import common.CNAME
58+
%import common.SIGNED_INT
59+
%import common.SIGNED_FLOAT
60+
%import common.INT
61+
%import common.DECIMAL
62+
%import common.CR
63+
%import common.LF
64+
%import common.WS_INLINE

0 commit comments

Comments
 (0)