Skip to content

Commit 59982ce

Browse files
committed
pymcnp/inp: parser debugging
1 parent b2d20b5 commit 59982ce

492 files changed

Lines changed: 714 additions & 573 deletions

File tree

Some content is hidden

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

scripts/inp_code.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ def _REGEX(element):
4343

4444
if 'Tuple' in attribute.type:
4545
if 'Option_' in attribute.type:
46-
o += (
47-
f'(( ({{{SNAKE(element.name)}.{CAMEL(element.name)}Option_._REGEX.pattern}}))+)'
48-
)
46+
o += f'((?: (?:{{{SNAKE(element.name)}.{CAMEL(element.name)}Option_._REGEX.pattern}}))+?)'
4947
else:
50-
o += f'(( {{{attribute.type[12:-1]}._REGEX.pattern}})+)'
48+
o += f'((?: {{{attribute.type[12:-1]}._REGEX.pattern}})+?)'
5149
else:
5250
if 'Option_' in attribute.type:
53-
o += f'( ({{{SNAKE(element.name)}.{CAMEL(element.name)}Option_._REGEX.pattern}}))'
51+
o += f'( (?:{{{SNAKE(element.name)}.{CAMEL(element.name)}Option_._REGEX.pattern}}))'
52+
elif attribute.type == 'types.Boolean':
53+
o += f'( {attribute.restriction})'
5454
else:
5555
o += f'( {{{attribute.type}._REGEX.pattern}})'
5656

@@ -207,7 +207,7 @@ class {CAMEL(element.name)}({f"{CAMEL(parent_name)}Option_, keyword='{element.mn
207207
208208
_ATTRS = {{{ATTRS_DICT(element)}}}
209209
210-
_REGEX = re.compile(rf"{element.mnemonic}{r"(\d+)" if has_suffix(element) else ""}{r":(\S+)" if has_designator(element) else ""}{ATTRS_REGEX(element)}")
210+
_REGEX = re.compile(rf"\\A{element.mnemonic}{r"(\d+)" if has_suffix(element) else ""}{r":(\S+)" if has_designator(element) else ""}{ATTRS_REGEX(element)}\\Z")
211211
212212
def __init__(self, {ATTRS_PARAM(element)}):
213213
"""

scripts/inp_data.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2528,8 +2528,8 @@ def draw(self):
25282528
AttributeScheme(
25292529
name='no',
25302530
type='types.String',
2531-
description='Calculation on/off',
2532-
restriction='no == "no"',
2531+
description='Volume calculation on/off',
2532+
restriction='no in {"no"}',
25332533
optional=True,
25342534
),
25352535
AttributeScheme(
@@ -5841,6 +5841,7 @@ def from_formula(number: int, formulas: dict[str, float], atomic_or_weight: bool
58415841
type='types.String',
58425842
description='Probability kind setting',
58435843
restriction='option in {"d", "c", "v", "w"}',
5844+
optional=True,
58445845
),
58455846
AttributeScheme(
58465847
name='probabilities',
@@ -5888,6 +5889,7 @@ def from_formula(number: int, formulas: dict[str, float], atomic_or_weight: bool
58885889
type='types.String',
58895890
description='Bias kind setting',
58905891
restriction='option in {"d", "c", "v", "w"}',
5892+
optional=True,
58915893
),
58925894
AttributeScheme(
58935895
name='biases',
@@ -5934,6 +5936,7 @@ def from_formula(number: int, formulas: dict[str, float], atomic_or_weight: bool
59345936
type='types.String',
59355937
description='Dependent variable setting',
59365938
restriction='option in {"h", "l", "s"}',
5939+
optional=True,
59375940
),
59385941
AttributeScheme(
59395942
name='js',
@@ -5952,12 +5955,7 @@ def from_formula(number: int, formulas: dict[str, float], atomic_or_weight: bool
59525955
description='Data card option suffix',
59535956
restriction='1 <= suffix <= 999',
59545957
),
5955-
AttributeScheme(
5956-
name='t',
5957-
type='types.String',
5958-
description='Dependent source T option',
5959-
restriction='t in {"t"}',
5960-
),
5958+
# t
59615959
AttributeScheme(
59625960
name='ijs',
59635961
type='types.Tuple[types.IndependentDependent]',
@@ -5975,12 +5973,7 @@ def from_formula(number: int, formulas: dict[str, float], atomic_or_weight: bool
59755973
description='Data card option suffix',
59765974
restriction='1 <= suffix <= 999',
59775975
),
5978-
AttributeScheme(
5979-
name='q',
5980-
type='types.String',
5981-
description='Dependent source Q option',
5982-
restriction='q in {"q"}',
5983-
),
5976+
# q
59845977
AttributeScheme(
59855978
name='vss',
59865979
type='types.Tuple[types.IndependentDependent]',
@@ -7138,6 +7131,7 @@ def from_formula(number: int, formulas: dict[str, float], atomic_or_weight: bool
71387131
type='types.String',
71397132
description='Interpolation method for energy table',
71407133
restriction='method in {"log", "lin"}',
7134+
optional=True,
71417135
),
71427136
AttributeScheme(
71437137
name='values',
@@ -7161,6 +7155,7 @@ def from_formula(number: int, formulas: dict[str, float], atomic_or_weight: bool
71617155
type='types.String',
71627156
description='Interpolation method for dose function table',
71637157
restriction='method in {"log", "lin"}',
7158+
optional=True,
71647159
),
71657160
AttributeScheme(
71667161
name='values',
@@ -9549,10 +9544,10 @@ def from_formula(number: int, formulas: dict[str, float], atomic_or_weight: bool
95499544
mnemonic='event',
95509545
attributes=[
95519546
AttributeScheme(
9552-
name='setting',
9553-
type='types.String',
9547+
name='settings',
9548+
type='types.Tuple[types.String]',
95549549
description='Specifies the type of events written to the PTRAC file',
9555-
restriction='setting in {"src", "bnk", "sur", "col", "ter", "cap"}',
9550+
restriction='all(map(lambda setting: setting in {"src", "bnk", "sur", "col", "ter", "cap"}, settings))',
95569551
),
95579552
],
95589553
),

src/pymcnp/inp/cell/Bflcl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Bflcl(CellOption_, keyword='bflcl'):
1919
'number': types.Integer,
2020
}
2121

22-
_REGEX = re.compile(rf'bflcl( {types.Integer._REGEX.pattern})')
22+
_REGEX = re.compile(rf'\Abflcl( {types.Integer._REGEX.pattern})\Z')
2323

2424
def __init__(self, number: types.Integer):
2525
"""

src/pymcnp/inp/cell/Cosy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Cosy(CellOption_, keyword='cosy'):
1919
'number': types.Integer,
2020
}
2121

22-
_REGEX = re.compile(rf'cosy( {types.Integer._REGEX.pattern})')
22+
_REGEX = re.compile(rf'\Acosy( {types.Integer._REGEX.pattern})\Z')
2323

2424
def __init__(self, number: types.Integer):
2525
"""

src/pymcnp/inp/cell/Dxc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Dxc(CellOption_, keyword='dxc'):
2121
'probability': types.Real,
2222
}
2323

24-
_REGEX = re.compile(rf'dxc(\d+):(\S+)( {types.Real._REGEX.pattern})')
24+
_REGEX = re.compile(rf'\Adxc(\d+):(\S+)( {types.Real._REGEX.pattern})\Z')
2525

2626
def __init__(
2727
self, suffix: types.Integer, designator: types.Designator, probability: types.Real

src/pymcnp/inp/cell/Elpt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Elpt(CellOption_, keyword='elpt'):
2020
'cutoff': types.Real,
2121
}
2222

23-
_REGEX = re.compile(rf'elpt:(\S+)( {types.Real._REGEX.pattern})')
23+
_REGEX = re.compile(rf'\Aelpt:(\S+)( {types.Real._REGEX.pattern})\Z')
2424

2525
def __init__(self, designator: types.Designator, cutoff: types.Real):
2626
"""

src/pymcnp/inp/cell/Ext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Ext(CellOption_, keyword='ext'):
2020
'stretch': types.String,
2121
}
2222

23-
_REGEX = re.compile(rf'ext:(\S+)( {types.String._REGEX.pattern})')
23+
_REGEX = re.compile(rf'\Aext:(\S+)( {types.String._REGEX.pattern})\Z')
2424

2525
def __init__(self, designator: types.Designator, stretch: types.String):
2626
"""

src/pymcnp/inp/cell/Fcl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Fcl(CellOption_, keyword='fcl'):
2020
'control': types.Real,
2121
}
2222

23-
_REGEX = re.compile(rf'fcl:(\S+)( {types.Real._REGEX.pattern})')
23+
_REGEX = re.compile(rf'\Afcl:(\S+)( {types.Real._REGEX.pattern})\Z')
2424

2525
def __init__(self, designator: types.Designator, control: types.Real):
2626
"""

src/pymcnp/inp/cell/Fill_0.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ class Fill_0(CellOption_, keyword='fill'):
2020
'transformation': types.Integer,
2121
}
2222

23-
_REGEX = re.compile(rf'fill( {types.Integer._REGEX.pattern})( {types.Integer._REGEX.pattern})?')
23+
_REGEX = re.compile(
24+
rf'\Afill( {types.Integer._REGEX.pattern})( {types.Integer._REGEX.pattern})?\Z'
25+
)
2426

2527
def __init__(self, universe: types.Integer, transformation: types.Integer = None):
2628
"""

src/pymcnp/inp/cell/Fill_1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Fill_1(CellOption_, keyword='fill'):
2121
}
2222

2323
_REGEX = re.compile(
24-
rf'fill( {types.Integer._REGEX.pattern})( {types.Transformation._REGEX.pattern})?'
24+
rf'\Afill( {types.Integer._REGEX.pattern})( {types.Transformation._REGEX.pattern})?\Z'
2525
)
2626

2727
def __init__(self, universe: types.Integer, transformation: types.Transformation = None):

0 commit comments

Comments
 (0)