Skip to content

转义字符处理出现问题 #5

Description

@xiaomi2023

目前的编译器不能处理任何转义字符。
猜测是来自tokenizer的以下代码的问题:

# 处理转义字符
    # 看看每个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", "/")

这里似乎将tokens[i]当作字符串了,可是当我print(type(tokens[i]))时,输出了:
<class 'parser.alice_types.token_types.Token'>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions