Files
highground/preprocessor.py

44 lines
1.2 KiB
Python
Raw Normal View History

2025-09-01 20:41:41 +10:00
import token
delimiters = ["=", ">", "<", "+", "-", "*", "/", " "]
2025-09-01 21:06:05 +10:00
quick_tokens = [">", "<", "+", "-", "*", "/"]
2025-09-01 20:41:41 +10:00
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
2025-09-01 21:06:05 +10:00
if c in quick_tokens:
tokens.append(token.Token(c))
if buf != "":
tokens.append(token.Token(buf))
buf = ""
else:
match c:
case '\n':
doNothing()
case ' ':
doNothing()
case '=':
if prevEquals:
prevEquals = False
tokens.append(token.Token("=="))
else:
prevEquals = True
case _:
buf += c
2025-09-01 20:41:41 +10:00
if buf != "":
tokens.append(token.Token(buf))
return tokens