- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我很难理解允许在参数名称中使用“\”的语法(例如 net\<8>)。然而,“\”也可用作续行(参见例 2)。 Ex1 工作正常,但 linebreak 和 identifier 变量之间存在冲突。
subckt INVERTER A Z gnd gnds vdd vdds
M1 (Z A vdd vdds) pmos w=0.4 l=0.1
M2 (Z A gnd gnds) nmos w=0.2 l=0.1
ends INVERTER
I1 (net1 net2 0 gnds! vdd! vdds!) INVERTER
subckt INVERTER_2 A Z gnd gnds vdd vdds
M1 (Z A vdd vdds) pmos w=0.4 l=0.1
M2 (Z A gnd gnds) nmos w=0.2 l=0.1
ends INVERTER_2
I2 (net\<8\> net2 0 gnds! vdd! vdds!) INVERTER_2
I3 (net1 net2 0 gnds! vdd! vdds!) INVERTER_2
subckt INVERTER A Z gnd gnds vdd vdds
M1 (Z A vdd vdds) pmos w=0.4 l=0.1
M2 (Z A gnd gnds) nmos w=0.2 l=0.1
ends INVERTER
I1 (net1 net2 0 gnds! vdd! vdds!) INVERTER
subckt INVERTER_2 A Z gnd gnds \
vdd vdds
M1 (Z A vdd vdds) pmos w=0.4 l=0.1
M2 (Z A gnd gnds) nmos w=0.2 l=0.1
ends INVERTER_2
I2 (net\<8\> net2 0 gnds! vdd! vdds!) INVERTER_2
I3 (net1 net2 0 gnds! vdd! vdds!) INVERTER_2
import pyparsing as pp
import json
EOL = pp.LineEnd().suppress() # end of line
linebreak = pp.Suppress(pp.Keyword('\\') + pp.LineEnd())
identifier = pp.Word(pp.alphanums + '_!<>\\')
number = pp.pyparsing_common.number
net = identifier
instref = identifier
instname = identifier
subcktname = identifier
subcktname_end = pp.Keyword("ends").suppress()
comment = pp.Suppress("//" + pp.SkipTo(pp.LineEnd()))
expression = pp.Word(pp.alphanums + '._*+-/()')
input_file = open(netlist.sp,'r')
file_string = input_file.read()
input_file.close()
for t, s, e in parse_netlist().scanString(file_string):
print(json.dumps(t.asDict()['netlist'], indent=2))
def parse_netlist():
pp.ParserElement.setDefaultWhitespaceChars(' \t')
nets = (pp.Optional(pp.Suppress('('))
+ pp.OneOrMore(net('net') | linebreak)
+ pp.Optional(pp.Suppress(')'))
)
inst_param_value = expression('expression')
inst_parameter = pp.Dict(pp.Group(identifier('param_name')
+ pp.Suppress("=")
+ inst_param_value('param_value')
))
parameters = pp.Group(pp.OneOrMore(inst_parameter | linebreak)
).setResultsName('parameters')
instance = pp.Dict(pp.Group(instname('inst_name')
+ nets('nets')
+ instref('reference')
+ pp.Optional(parameters)
+ EOL
)).setResultsName('instance', listAllMatches=True)
subckt_core = pp.Group(pp.ZeroOrMore(instance | EOL | comment)
).setResultsName('subckt_core', listAllMatches=True)
subckt = pp.Group(pp.Keyword("subckt").suppress()
+ subcktname('subckt_name')
+ nets('nets')
+ EOL
+ subckt_core
+ subcktname_end
+ pp.matchPreviousExpr(subcktname).suppress()
+ EOL
).setResultsName('subcircuit', listAllMatches=True)
netlist = pp.OneOrMore(subckt
| instance
| comment('comment')
| EOL
).setResultsName('netlist') + pp.StringEnd()
return netlist
[
{
"subckt_name": "INVERTER",
"net": "vdds",
"nets": [
"A",
"Z",
"gnd",
"gnds",
"vdd",
"vdds"
],
"subckt_core": [
{
"instance": [
{
"M1": {
"inst_name": "M1",
"net": "vdds",
"nets": [
"Z",
"A",
"vdd",
"vdds"
],
"reference": "pmos",
"parameters": {
"w": "0.4",
"l": "0.1"
}
}
},
{
"M2": {
"inst_name": "M2",
"net": "gnds",
"nets": [
"Z",
"A",
"gnd",
"gnds"
],
"reference": "nmos",
"parameters": {
"w": "0.2",
"l": "0.1"
}
}
}
]
}
]
},
{
"I1": {
"inst_name": "I1",
"net": "vdds!",
"nets": [
"net1",
"net2",
"0",
"gnds!",
"vdd!",
"vdds!"
],
"reference": "INVERTER",
"parameters": []
}
},
{
"subckt_name": "INVERTER_2",
"net": "vdds",
"nets": [
"A",
"Z",
"gnd",
"gnds",
"vdd",
"vdds"
],
"subckt_core": [
{
"instance": [
{
"M1": {
"inst_name": "M1",
"net": "vdds",
"nets": [
"Z",
"A",
"vdd",
"vdds"
],
"reference": "pmos",
"parameters": {
"w": "0.4",
"l": "0.1"
}
}
},
{
"M2": {
"inst_name": "M2",
"net": "gnds",
"nets": [
"Z",
"A",
"gnd",
"gnds"
],
"reference": "nmos",
"parameters": {
"w": "0.2",
"l": "0.1"
}
}
}
]
}
]
},
{
"I2": {
"inst_name": "I2",
"net": "vdds!",
"nets": [
"net\\<8\\>",
"net2",
"0",
"gnds!",
"vdd!",
"vdds!"
],
"reference": "INVERTER_2",
"parameters": []
}
},
{
"I3": {
"inst_name": "I3",
"net": "vdds!",
"nets": [
"net1",
"net2",
"0",
"gnds!",
"vdd!",
"vdds!"
],
"reference": "INVERTER_2",
"parameters": []
}
}
]
[
{
"I2": {
"inst_name": "I2",
"net": "vdds!",
"nets": [
"INST_IN\\<8\\>",
"net2",
"0",
"gnds!",
"vdd!",
"vdds!"
],
"reference": "INVERTER2",
"parameters": []
}
},
{
"I3": {
"inst_name": "I3",
"net": "vdds!",
"nets": [
"net1",
"net2",
"0",
"gnds!",
"vdd!",
"vdds!"
],
"reference": "INVERTER3",
"parameters": []
}
}
]
格式化子电路定义:
subckt SubcircuitName [(] node1 ... nodeN [)]
[ parameters name1=value1 ... [nameN=valueN]]
.
.
.
instance, model, ic, or nodeset statements—or
further subcircuit definitions
.
.
.
ends [SubcircuitName]
格式化实例语句:
name [(]node1 ... nodeN[)] master [[param1=value1] ...[paramN=valueN]]
最佳答案
Word
是 pyparsing 中所有重复类型中最贪婪和最激进的类型之一。所以你的两个表达式:
linebreak = pp.Suppress(pp.Keyword('\\') + pp.LineEnd())
identifier = pp.Word(pp.alphanums + '_!<>\\')
将会发生冲突。一旦标识符开始扫描匹配字符,它就不会向前查看下一个表达式以查看是否应该停止。
为了区分标识符中的“\”和延续符,您可以从换行符
开始。接下来,我们需要从标识符单词中的字符中删除“\”:
identifier = pp.Word(pp.alphanums + '_!<>')
要在标识符中添加回“\”,我们需要更加具体。不仅仅是任何 '\' 都可以,我们只需要不是换行符的 '\'(即那些不在行尾的)。我们可以通过消极的前瞻来做到这一点。在接受反斜杠之前,首先确保它不是断行反斜杠:
backslash_that_is_not_a_linebreak = ~linebreak + '\\'
现在标识符将是一个或多个单词项的集合,可以是上面定义的标识符单词,也可以是不是换行符的反斜杠。
identifier_word = pp.Word(pp.alphanums + '_!<>')
identifier = pp.OneOrMore(identifier_word | backslash_that_is_not_a_linebreak)
这让我们很接近,但是如果你使用这个标识符来解析“net\<8>”,你会得到:
['net', '\\', '<8', '\\', '>']
如果您将标识符包装在 pyparsing Combine
中,那么一切都应该正常工作:
identifier = pp.Combine(pp.OneOrMore(identifier_word | backslash_that_is_not_a_linebreak))
print(identifier.parseString(r"net\<8\>"))
给出:
['net\\<8\\>']
编辑:总之,以下是此更改所需的模组:
backslash_that_is_not_a_linebreak = ~linebreak + '\\'
identifier_word = pp.Word(pp.alphanums + '_!<>')
identifier = pp.Combine(pp.OneOrMore(identifier_word | backslash_that_is_not_a_linebreak))
编辑2:这些行在您的方法 parse_netlist
中声明,需要位于模块的顶部,紧接在导入 pyparsing 之后。否则,所有表达式(例如换行符)都将使用默认的空白字符,包括 \n
。
ws = ' \t'
pp.ParserElement.setDefaultWhitespaceChars(ws)
如果没有它们,nets
的表达式会读取 subckt
第一行中的行尾,并包含“M2:作为另一个网络,而不是作为subckt_core
中第一个实例
的标识符。
不知道为什么你要这样分解你的解析器,最好将这些部分保持在一起。
关于python - Pyparsing 中单词中的反斜杠冲突和换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58959263/
我的工作是将每条记录写入 Hadoop 映射中的 DynamoDB。 我无法使用具有 httpclient-4.2.5.jar 和 httpcore-4.2.5.jar 的 Hadoop 2.6 运行
我在 JavaScript 中嵌套了循环开关,例如: for (var i = 0; i < checkBoxIds.length; i++) { if ($('#' + checkB
我有一个文件夹被重命名的分支。现在我正在尝试合并从主干到这个分支的更改,但是在主干中修改的文件仍然在原始文件夹名称下,因此 svn 引发了树冲突。我该如何解决这个问题? 该文件夹已使用 svn ren
我在使用 jquery 暴露插件和 Masked 输入插件时遇到了问题。问题是它们都占用 $.mask 函数,从而导致冲突。但我非常需要这两个插件一起工作。我会将其中一个中的 $.mask 重命名为.
我正在尝试为我所有的 INPUT 元素做一个简单的 :focus 效果,就像这样: INPUT:focus { border-color: orange; } 这很好用,直到我将这段 CSS 添加到样
我是 javascript 的新手。 在 wordpress 上工作,我在自定义 js 中为我的主题输入了以下函数: document.getElementsByName("empty_cart")[
为什么有些 javascript 会与其他的发生冲突?我的意思是我一直在为图片库使用 javascript 代码,然后尝试在 jquery 中获取文本水印。为什么在使用 jquery 之后,画廊完全消
是否可以根据已知的输入值创建 MD5 碰撞? 所以例如我有输入字符串 abc与 MD5 900150983cd24fb0d6963f7d28e17f72 . 现在我想将字节添加到字符串 def获得相同
我在我的项目中使用原型(prototype): NodeParser.prototype.getChildren = function(parentContainer) { return fl
根据我对 merge 冲突的理解,当两个人更改了同一文件和/或修改了该文件中的同一行时,就会发生 merge 冲突。所以当我做一个 git pull origin master 我期望 merge 冲
iPad 上 Mobile Safari 中的 HTML5 模板。带 iScroll 的 Div 工作正常。 if/else 语句中还包含一个 jQuery 函数。该函数测试用户是否在 iScroll
我一直在尝试使 2 个脚本(1 个 mootol 和 1 个 jquery)在同一页面上工作,但没有成功。我一直在研究许多论坛等,但我仍然无法使这两个脚本同时工作。 这就是它在我的标题中的样子: /w
我想克隆带标题的问号。一切正常,但是当我将鼠标悬停在新问号上时,第一个问号上会出现工具提示。有什么想法吗? 我正在使用 jQuery 和醉酒的工具提示。 Demo here click here
好吧,我已经在一个 friend 的网站上工作了一段时间了。我的编码技能......值得怀疑,而且我遇到了很多问题。 目前我网站上的 jQuery 停止工作了,我找不到原因,并且我已尽一切努力让它工作
我想使用一个文件来保存所有#define 和常量:示例 #ifndef CONSTANTS_H_ #define CONSTANTS_H_ #include //OVERALL DEFS
我在我的表单中的所有 HTML 下都有一些验证码,这似乎阻止了我的复选框验证码的工作,一旦我在我的 HTML 下的代码周围添加/* */(使其不活动),我就得出了这个结论) 复选框验证代码开始正常工作
我是新手。我的页面上有两个 javascript/jquery。如果我使用第一个脚本,第二个脚本将不起作用。如果我删除第一个脚本,第二个脚本就可以正常工作。我不知道如何解决这个问题。我知道有一个“无冲
我是 Bison 新手,在处理 Shift/Reduce 冲突时遇到了麻烦... 我正在为C语言编写语法规则:ID是标识变量的标记,我编写此规则是为了确保即使将标识符写在括号中,也可以考虑它。 id
我目前正在使用 LibGdx 开发我的第一个 Android 游戏项目。这是一款 2D 迷宫游戏,您可以使用触摸输入从其中一个入口到其中一个导出“画出”一条线。世界本身是一个 TiledMap,目前仅
我正在尝试通过 javascript 完成表单验证,并在 #form# 标记中放置一个要执行的 .py 文件操作。但问题是,当我提交数据后,它不会重定向到 .py 操作。所以我摆脱了 preventd
我是一名优秀的程序员,十分优秀!