Changed the constant file with os.environ

Also doing some more testing and mucking around with the parser
master
Ruben Dahl 2023-04-08 23:56:30 +02:00
parent a2452e72a6
commit 465bbe9c15
No known key found for this signature in database
GPG Key ID: D9B193810A18673E
4 changed files with 15 additions and 11 deletions

View File

@ -1 +0,0 @@
DEBUG = True

View File

@ -25,5 +25,5 @@ VAR_MATCH = {
r"\".+\"": Datatype.STRING, r"\".+\"": Datatype.STRING,
r"\d+\.\d{0,}": Datatype.FLOAT, r"\d+\.\d{0,}": Datatype.FLOAT,
r"\d+": Datatype.INTEGER, r"\d+": Datatype.INTEGER,
r".+": Datatype.NONE, # r".+": Datatype.NONE,
} }

View File

@ -1,10 +1,10 @@
from constants import DEBUG import os
def todo(msg: str = "Not implemented"): def todo(msg: str = "Not implemented"):
def inner(func): def inner(func):
def inner2(*args, **kwargs): def inner2(*args, **kwargs):
if DEBUG: if "PYNE_DEBUG" in os.environ:
print(f"[{func.__name__}] TODO: {msg}") print(f"[{func.__name__}] TODO: {msg}")
return func(*args, **kwargs) return func(*args, **kwargs)
@ -15,7 +15,7 @@ def todo(msg: str = "Not implemented"):
def wip(func): def wip(func):
def inner(*args, **kwargs): def inner(*args, **kwargs):
if DEBUG: if "PYNE_DEBUG" in os.environ:
print( print(
f"Called work in progress function {func.__name__}. Functionality may change in the future." f"Called work in progress function {func.__name__}. Functionality may change in the future."
) )
@ -27,7 +27,7 @@ def wip(func):
def deprecated(func): def deprecated(func):
@functools.wraps(func) @functools.wraps(func)
def inner(*args, **kwargs): def inner(*args, **kwargs):
if DEBUG: if "PYNE_DEBUG" in os.environ:
print( print(
f"\x1b[31mWarning:\x1b[0m The function {inner.__name__} is deprecated." f"\x1b[31mWarning:\x1b[0m The function {inner.__name__} is deprecated."
) )

View File

@ -24,7 +24,7 @@ class Pyne:
def parse(self) -> list[PyneObject]: def parse(self) -> list[PyneObject]:
objects: list[PyneObject] = [] objects: list[PyneObject] = []
with open(self.path) as f: with open(self.path) as f:
for line in f.readlines(): for row, line in enumerate(f.readlines(), 1):
for var in datatypes.VAR_MATCH: for var in datatypes.VAR_MATCH:
regex = re.compile(var) regex = re.compile(var)
res = regex.match(line) res = regex.match(line)
@ -35,6 +35,9 @@ class Pyne:
) )
) )
break break
continue
else:
raise ParserError(f"[{self.path}:{row}] Token {line} not found.")
if len(objects) == 0: if len(objects) == 0:
objects.append(datatypes.NONE_TYPE) objects.append(datatypes.NONE_TYPE)
return objects return objects
@ -55,10 +58,12 @@ def main() -> int:
args = parser.parse_args() args = parser.parse_args()
print(args) print(args)
pyne = Pyne(args.file[0], None) pyne = Pyne(args.file[0], None)
try:
for obj in pyne.parse(): for obj in pyne.parse():
print(obj) print(obj)
return 0 return 0
except ParserError as e:
print(f"Found invalid token: {e}")
if __name__ == "__main__": if __name__ == "__main__":