# 处理转义字符
# 看看每个token中是否包含转义字符,仅替换转义字符
for i in range(len(tokens)):
if tokens[i].is_str():
if "$n" in tokens[i]:
tokens[i] = tokens[i].replace("$n", "\n")
if "$s" in tokens[i]:
tokens[i] = tokens[i].replace("$s", " ")
if "$t" in tokens[i]:
tokens[i] = tokens[i].replace("$t", "\t")
if "$p" in tokens[i]:
tokens[i] = tokens[i].replace("$p", "#")
if "$l" in tokens[i]:
tokens[i] = tokens[i].replace("$l", "{")
if "$r" in tokens[i]:
tokens[i] = tokens[i].replace("$r", "}")
if "$b" in tokens[i]:
tokens[i] = tokens[i].replace("$b", "\r")
if "$k" in tokens[i]:
tokens[i] = tokens[i].replace("$k", "/")
目前的编译器不能处理任何转义字符。
猜测是来自tokenizer的以下代码的问题:
这里似乎将tokens[i]当作字符串了,可是当我print(type(tokens[i]))时,输出了:
<class 'parser.alice_types.token_types.Token'>