Initial commit
This commit is contained in:
36
preprocessor.py
Normal file
36
preprocessor.py
Normal file
@@ -0,0 +1,36 @@
|
||||
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
|
Reference in New Issue
Block a user