handling comments is for losers
This commit is contained in:
parent
b389d28a0d
commit
030c448077
11
lexer.py
11
lexer.py
|
@ -15,8 +15,8 @@ identifier = nfa.compile("(" + letter + ")(" + letter + "+" + digit + ")*") # le
|
|||
identifier.type = "identifier"
|
||||
string = nfa.compile("(\"(" + any_string + ")\")+('("+any_string+")')")
|
||||
string.type = "string"
|
||||
comment = nfa.compile("--(" + any_char + ")*")
|
||||
comment.type = "comment"
|
||||
# comment = nfa.compile("--(" + any_char + ")*\n") # BROKEN AF
|
||||
# comment.type = "comment"
|
||||
keyword = nfa.compile("+".join(["class", "else", "false", "fi", "if", "in", "inherits", "isvoid", "let", "loop", "pool", "then", "while", "case", "esac", "new", "of", "not", "true"]))
|
||||
keyword.type = "keyword"
|
||||
assign = nfa.compile("<-")
|
||||
|
@ -35,7 +35,7 @@ test_data = """
|
|||
if x = y then
|
||||
x <- 10;
|
||||
else
|
||||
x <- 20;
|
||||
x <- 20; -- comment
|
||||
print("string literal test");
|
||||
fi
|
||||
"""
|
||||
|
@ -52,7 +52,10 @@ class token():
|
|||
self.type = False
|
||||
|
||||
def lex(data):
|
||||
priority_order = [whitespace_nfa, comment, parens, semicolon, keyword, assign, relop, integer, string, identifier]
|
||||
import subprocess
|
||||
process = subprocess.Popen(["gpp", "+c", "--", "\\n"], stdin = subprocess.PIPE, stdout = subprocess.PIPE)
|
||||
data = process.communicate(input=data.encode("utf-8"))[0].decode("utf-8")
|
||||
priority_order = [whitespace_nfa, parens, semicolon, keyword, assign, relop, integer, string, identifier]
|
||||
done = []
|
||||
data_ptr = 0
|
||||
while data_ptr < len(data):
|
||||
|
|
Loading…
Reference in New Issue