TODO


温馨提示:本文可能已经过时

  • 更新日期:June 21st, 2022 Tuesday
  • 版本:0x01
  • 编号:245

嗯,7月4日就期末考了,看

元旦快乐


祝各位读到这篇小记的人,元旦快乐!在新的一年里万事如意,身体健康,学业有成!祝祖国繁荣昌盛,祝新冠疫情早日过去!

【接单日志 01】txtx解析工具


温馨提示:程序接单目前已经不再开放,但您仍然可以在issue中为新项目提供想法

详细信息

  • 单号:PYLIB-ORD-20211101
  • 委托人(QQ):3627035438
  • 项目:TXTX解析工具
  • 类型:Python库-ORD
  • 收费:1.0/1.0 CNY(付款方式:QQ)

代码:

./txtx.py

# Powered By XD(www.thisisxd.tk)
import os

def delzhushi(l,start = 0):
    s = l[start].find("#")
    li = l
    if s != -1:
        li[start] = li[start][0:s]
    if start == l.__len__()-1:
        return li
    else:
        return delzhushi(li,start+1)

def run(txt):
    t = txt
    le = 0
    for tx in t:
        where_w = tx.find("[Run_Windows]")
        where_u = tx.find("[Run_Unix](")
        if os.name == "nt":
            if where_w != -1:
                t.pop(le)
                #print(tx[where_w+14:tx.find(")",where_w)])
                os.popen(tx[where_w+14:tx.find(")",where_w)])
        else:
            if where_u != -1:
                t.pep(le)
                os.popen(tx[where_u+14:tx.find(")",where_u)])
        le += 1
    return t

def get_home(txtx):
    tx = txtx
    l = 0
    for t in tx:
        w = t.find("<[")
        if w != -1:
            home = t[w+2:t.find("]",w)]
            for i in range(l):
                tx.pop(0)
            if  home == "":
                raise TypeError("跟声明不能为空")
            else:
                return tx,home

def load(t):
    txtx = {}
    # 逐行分割
    t1 = t.split("\n")
    # 删除注释
    t1 = delzhushi(t1)
    # 跑命令
    t1 = run(t1)
    # 获取跟声明
    temp = get_home(t1)
    t1 = temp[0]
    home = temp[1]
    # 解析
    f = 1
    s = 0
    tw = [False]
    tg = False
    txtx[home] = {}
    y = 0
    for t in t1:
        s += 1
        temp = {}
        k_start = t.find("[")
        if k_start != -1 and tg == False and t.find("<[") == -1:
            k_end = t.find("]",k_start)
            if k_end != -1:
                v_start = t.find("(",k_end)
                if v_start != -1:
                    v_end = t.find(")",v_start)
                    if v_end == -1:
                        raise KeyError(f"行0{s}:这个值没有结尾")
                else:
                     raise KeyError(f"行0{s}:一个没有意义的键")
            else:
                raise KeyError(f"行0{s}:这个键没有结尾")
            # 能执行到这里这行基本就是有效的了
            print(1,t.find("<["),tg,home)
            # 分析键
            key = t[k_start+1:k_end]
            value = t[v_start+1:v_end]
            # 储存
            txtx[home][key] = value
        else:
            tmp = t.find("<[")
            if tmp != -1 and t[tmp+2:t.find("]",tmp)] != home:
                tg = True
                tw[0] = True
                if y != 1:
                    tw  += [[s,t[tmp+2:t.find("]",tmp)]]]
                y += 1
            elif t.find(">") != -1:
                tg = False
                if y == 1:
                    try:
                        tw[tw.__len__()-1] += [s]
                    except:
                        pass
                    y -= 1
                else:
                    y -= 1
                print(t[tmp:t.find("]",tmp)],tw)
            print("y",y)
    if tw[0] == True:
        for tn in tw:
            print("tn",tn,t1)
            if tn != True:
                cs = ""
                for i in t1[tn[0]-1:tn[2]]:
                    cs += str(i)
                    cs += "\n"
                print("cs",cs)
                print("递归后输出:")
                # txtx[home][t[2]] = load(cs)
                tmp114514  =  load(cs)
                print(tmp114514)
                txtx[home][tmp114514[1]] = tmp114514[0][tn[1]]#[[tmp114514[1]]]   #[tmp114514[1]]
    else:
        print("ELSE")
                
        
    # 返回
    return [txtx,home]

def loads(txtx):
    return load(txtx)[0]

def open(path,encoding = "utf-8"):
    with open(path,encoding = encoding) as f:
        return loads(f.read())

用法

import txtx
函数参数函数描述返回说明
txtx.open(path,ecoding="utf-8")[path] txtx文件路径 (String)
[encoding] 文件编码(默认=utf-8)(string)
打开txtx文件返回解析结果(dictionary)
txtx.loads(txtx)[txtx] txtx内容 (String)解析txtx字符串返回解析结果(dictionary)
txtx解析器主要函数说明

世界,您好!


警告:本文可能已经过时

欢迎使用WordPress。这是您的第一篇文章。编辑或删除它,然后开始写作吧!