2439905184 / bkscr-parser

bkengine脚本的解析器(开源实现)基于python3.8.4
https://github.com/2439905184/bkengine_interpreter_godot
GNU General Public License v2.0
2 stars 0 forks source link

备份 不使用折返功能 而是使用状态机进行分词处理 #5

Closed 2439905184 closed 2 years ago

2439905184 commented 2 years ago
code = "@addto index=1280 p2=6\n"
start = 0
current = 0
end = len(code) - 1
tokens = []

def peekNext():
    global current
    current += 1
    return code[current]

def readNext():

    pass
action = "scanParamName" #scanParamValue
print("启动为",action)
for index,char in enumerate(code):
    if char == "@":
        while peekNext() != " " and index != end:
            pass
        vc = code[index:current]
        tokens.append(vc)

    if char == " " and action == "scanParamName":
        sp_start = index + 1
        while peekNext() != "=" and index != end:
            #print(code[current])
            pass
        if code[current] == "=":
            action = "scanParamValue"
            vc = code[sp_start:current]
            tokens.append(vc)
            print(vc)
            print("切换为",action)

    if char == "=" and action == "scanParamValue":
        vc = ""
        while peekNext() != " " and current != end:
            #print(code[current])
            vc += code[current]
        print(vc)
        tokens.append(vc)
        if code[current] == "\n":
            break
        if code[current] == " " and current == end:
            break
        if code[current] == " ":
            action = "scanParamName"
            print("切换为",action)
print(tokens)
for i in tokens:
    print(i)
2439905184 commented 2 years ago

已完成