Skip to content

Commit

Permalink
Parser: Updated dimensioned values
Browse files Browse the repository at this point in the history
- Accept macro values for dimension values
- Accept dimensions with no key
  • Loading branch information
sayerhs committed Jul 13, 2024
1 parent 1864711 commit 808d74a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions caelus/io/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,19 @@ def p_dim_value(self, p):
| identifier dimension vector
| identifier dimension symm_tensor
| identifier dimension tensor
| identifier dimension MACRO_VAR
"""
p[0] = dtypes.DimValue(p[1], p[2], p[3])

def p_dim_value_nokey(self, p):
""" dim_value : dimension number
| dimension vector
| dimension symm_tensor
| dimension tensor
| dimension MACRO_VAR
"""
p[0] = dtypes.DimValue("", p[1], p[2])

def p_dimension(self, p):
""" dimension : LBRACKET INT_CONST INT_CONST INT_CONST INT_CONST INT_CONST INT_CONST INT_CONST RBRACKET
| LBRACKET INT_CONST INT_CONST INT_CONST INT_CONST INT_CONST RBRACKET
Expand Down
10 changes: 10 additions & 0 deletions tests/io/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,16 @@ def test_dimension_str(cparse):
out = cparse.parse(text)
assert(isinstance(out.kappa.dims, dtypes.DimStr))

def test_dimension_nokey(cparse):
"""Test dimension entry without an identifier key"""
text = """
rho [1 -3 0 0 0] $rho_input;
"""
out = cparse.parse(text)
assert isinstance(out.rho, dtypes.DimValue)
assert out.rho.name == ""
assert out.rho.value.startswith("$")

def test_arrays(cparse):
text = """
vertices
Expand Down

0 comments on commit 808d74a

Please sign in to comment.