Skip to content

Commit 87b21b6

Browse files
committed
pymcnp/inp: updated DF parser
1 parent a51ea06 commit 87b21b6

7 files changed

Lines changed: 129 additions & 79 deletions

File tree

src/pymcnp/inp/data/df_1/Ic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self, function: types.IntegerOrJump):
3333
InpError: SEMANTICS_OPTION.
3434
"""
3535

36-
if function is None or function not in {10, 20, 31, 32, 33, 34, 35, 40, 99}:
36+
if function is None or function.value not in {10, 20, 31, 32, 33, 34, 35, 40, 99}:
3737
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, function)
3838

3939
self.value: typing.Final[types.Tuple] = types.Tuple(

src/pymcnp/inp/data/df_1/Int.py

Lines changed: 0 additions & 74 deletions
This file was deleted.

src/pymcnp/inp/data/df_1/Iu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self, units: types.IntegerOrJump):
3333
InpError: SEMANTICS_OPTION.
3434
"""
3535

36-
if units is None or units not in {1, 2}:
36+
if units is None or units.value not in {1, 2}:
3737
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, units)
3838

3939
self.value: typing.Final[types.Tuple] = types.Tuple(

src/pymcnp/inp/data/df_1/Lin.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import re
2+
import typing
3+
import dataclasses
4+
5+
from ._option import Df_1Option
6+
from ....utils import types
7+
from ....utils import errors
8+
9+
10+
class Lin(Df_1Option, keyword='log'):
11+
"""
12+
Represents INP log elements.
13+
14+
Attributes:
15+
16+
"""
17+
18+
_ATTRS = {}
19+
20+
_REGEX = re.compile(r'\Alog\Z')
21+
22+
def __init__(
23+
self,
24+
):
25+
"""
26+
Initializes ``Lin``.
27+
28+
Parameters:
29+
30+
31+
Raises:
32+
InpError: SEMANTICS_OPTION.
33+
"""
34+
35+
self.value: typing.Final[types.Tuple] = types.Tuple([])
36+
37+
38+
@dataclasses.dataclass
39+
class LinBuilder:
40+
"""
41+
Builds ``Lin``.
42+
43+
Attributes:
44+
45+
"""
46+
47+
def build(self):
48+
"""
49+
Builds ``LinBuilder`` into ``Lin``.
50+
51+
Returns:
52+
``Lin`` for ``LinBuilder``.
53+
"""
54+
55+
return Lin()
56+
57+

src/pymcnp/inp/data/df_1/Log.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import re
2+
import typing
3+
import dataclasses
4+
5+
from ._option import Df_1Option
6+
from ....utils import types
7+
from ....utils import errors
8+
9+
10+
class Log(Df_1Option, keyword='log'):
11+
"""
12+
Represents INP log elements.
13+
14+
Attributes:
15+
16+
"""
17+
18+
_ATTRS = {}
19+
20+
_REGEX = re.compile(r'\Alog\Z')
21+
22+
def __init__(
23+
self,
24+
):
25+
"""
26+
Initializes ``Log``.
27+
28+
Parameters:
29+
30+
31+
Raises:
32+
InpError: SEMANTICS_OPTION.
33+
"""
34+
35+
self.value: typing.Final[types.Tuple] = types.Tuple([])
36+
37+
38+
@dataclasses.dataclass
39+
class LogBuilder:
40+
"""
41+
Builds ``Log``.
42+
43+
Attributes:
44+
45+
"""
46+
47+
def build(self):
48+
"""
49+
Builds ``LogBuilder`` into ``Log``.
50+
51+
Returns:
52+
``Log`` for ``LogBuilder``.
53+
"""
54+
55+
return Log()
56+
57+

src/pymcnp/inp/data/df_1/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,26 @@
33
from .Iu import Iu
44
from .Fac import Fac
55
from .Ic import Ic
6-
from .Int import Int
6+
from .Log import Log
7+
from .Lin import Lin
78
from .Iu import IuBuilder
89
from .Fac import FacBuilder
910
from .Ic import IcBuilder
10-
from .Int import IntBuilder
11+
from .Log import LogBuilder
12+
from .Lin import LinBuilder
1113

1214
__all__ = [
1315
'Df_1Option',
1416
'Iu',
1517
'Fac',
1618
'Ic',
1719
'Int',
20+
'Log',
21+
'Lin',
1822
'IuBuilder',
1923
'FacBuilder',
2024
'IcBuilder',
2125
'IntBuilder',
26+
'LogBuilder',
27+
'LinBuilder',
2228
]

src/pymcnp/inp/data/df_1/_option.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ class Df_1Option(Option):
1414
_KEYWORD = ''
1515
_SUBCLASSES = {}
1616
_REGEX = re.compile(
17-
rf'fac( {types.IntegerOrJump._REGEX.pattern})|int( {types.String._REGEX.pattern})|iu( {types.IntegerOrJump._REGEX.pattern})|ic( {types.IntegerOrJump._REGEX.pattern})'
17+
rf'fac( {types.IntegerOrJump._REGEX.pattern})'
18+
rf'|iu( {types.IntegerOrJump._REGEX.pattern})'
19+
rf'|ic( {types.IntegerOrJump._REGEX.pattern})'
20+
rf'|log'
21+
rf'|lin'
1822
)
1923

2024
def __init_subclass__(cls, keyword: str):

0 commit comments

Comments
 (0)