1 Star 1 Fork 2

XYLITOL/kicad_tools

forked from linbinzl/kicad_tools 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
kisexp.py 1.83 KB
一键复制 编辑 原始数据 按行查看 历史
xiongyi 提交于 2020-05-28 13:54 . remove test coe
# -*- coding: utf-8 -*-
"""
Created on Tue May 12 10:08:59 2020
"""
import io
QUOTE = {
"'":"'",
'"':'"',
}
BRACKETS = {'(': ')'}
BRACKETS_END = {')':1}
SPACE = {' ':1, '\t':1, '\r':1, '\n':1}
def quoteData(content, index):
data = ""
q_e = QUOTE[content[index]]
c_len = len(content)
escape = False
index+=1;
while index < c_len:
c = content[index]
if c == '\\':
escape = True
elif c == q_e:
if(not escape):
return data, index+1
else:
data += c;
else:
escape = False
data += c
index+=1
return data, index+1
def normalData(content, index):
data = ""
c_len = len(content)
while index < c_len:
c = content[index]
if c in SPACE:
index +=1
break
elif c in BRACKETS:
break
elif c in BRACKETS_END:
break
else:
data += c
index+=1
return data, index
def parseSexp(content, index = 0):
res = []
c_len = len(content)
data = ""
bracket_end = ""
while index < c_len:
c = content[index]
if c in BRACKETS:
bracket_end = BRACKETS[c]
data, index = parseSexp(content, index+1)
res.append(data)
elif c in QUOTE:
data, index = quoteData(content, index)
res.append(data)
elif c in SPACE:
index+=1;
elif c in BRACKETS_END:
index+=1
break
else:
data, index = normalData(content, index)
res.append(data)
return res, index
def loadKicadNet(filename):
file = io.open(filename, "r", encoding="utf-8")
data = file.read()
res = parseSexp(data)
return res[0][0]
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liao-shengyu/kicad_tools.git
git@gitee.com:liao-shengyu/kicad_tools.git
liao-shengyu
kicad_tools
kicad_tools
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385