66 lines
1.8 KiB
Python
66 lines
1.8 KiB
Python
from argparse import ArgumentParser
|
|
from dataclasses import dataclass
|
|
from decorators import deprecated, todo, wip
|
|
from enum import Enum
|
|
from pyne_errors import ParserError, FileError
|
|
import datatypes
|
|
import re
|
|
import sys
|
|
|
|
|
|
@dataclass
|
|
class PyneObject:
|
|
value: datatypes.Variable
|
|
|
|
|
|
class Pyne:
|
|
def __init__(self, path: str, args: list[str]):
|
|
self.args = args
|
|
self.path = path if self._validate(path) else None
|
|
|
|
@todo(
|
|
"Tokenize the parser so it doesn't try to match the whole line, gotta find a way for it to do the strings though"
|
|
)
|
|
def parse(self) -> list[PyneObject]:
|
|
objects: list[PyneObject] = []
|
|
with open(self.path) as f:
|
|
for line in f.readlines():
|
|
for var in datatypes.VAR_MATCH:
|
|
regex = re.compile(var)
|
|
res = regex.match(line)
|
|
if res:
|
|
objects.append(
|
|
PyneObject(
|
|
datatypes.Variable(None, datatypes.VAR_MATCH[var], line)
|
|
)
|
|
)
|
|
break
|
|
if len(objects) == 0:
|
|
objects.append(datatypes.NONE_TYPE)
|
|
return objects
|
|
|
|
def _validate(self, path: str) -> bool:
|
|
"""
|
|
Validates the path and checks if it exists or not.
|
|
"""
|
|
with open(path) as f:
|
|
f.seek(1)
|
|
return True
|
|
|
|
|
|
@todo("Project is a work in progress")
|
|
def main() -> int:
|
|
parser = ArgumentParser(description="A simple language written in Python")
|
|
parser.add_argument("file", nargs=1, help="The input file")
|
|
args = parser.parse_args()
|
|
print(args)
|
|
pyne = Pyne(args.file[0], None)
|
|
|
|
for obj in pyne.parse():
|
|
print(obj)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|