Files
highground/preprocessor.py

36 lines
906 B
Python
Raw Normal View History

2025-09-01 20:41:41 +10:00
import token
delimiters = ["=", ">", "<", "+", "-", "*", "/", " "]
def doNothing():
return
def process_line(process: str) -> list[token.Token]:
buf = ""
tokens: list[token.Token] = []
prevEquals = False
for c in process:
if c in delimiters and buf != "":
tokens.append(token.Token(buf))
buf = ""
if prevEquals and c != '=':
tokens.append(token.Token("="))
prevEquals = False
match c:
case '\n':
doNothing()
case ' ':
doNothing()
case '=':
if prevEquals:
prevEquals = False
tokens.append(token.Token(buf))
else:
prevEquals = True
case _:
buf += c
if buf != "":
tokens.append(token.Token(buf))
return tokens