我写这个来解析我自己的.dotf文件:
def parseFromDOTF(file_path):
comment = "%" + restOfLine
typeToken = CaselessKeyword("@TYPE")
attrToken = CaselessKeyword('@ATTRIBUTE')
ident = Word(alphas,alphanums)
type = Suppress(typeToken) + ident
columnList = Group(delimitedList(nums))
attribute = Group(Suppress(attrToken) + ident("attribute") + columnList("column"))
DOTF = type('type') + OneOrMore(attribute)("attributes")
DOTF.ignore(comment)
return DOTF.parseFile(file_path)
下面是.dotf文件的示例
^{pr2}$但它有问题:
pyparsing.ParseException: Expected "0123456789" (at char 79), (line:3, col:15)
第3行的第15列是空白,不是吗?在
那么,怎么了?在
谢谢!在
nums
等于字符串'0123456789'
。 那么定义呢告诉pyparsing
columnList
应该是逗号分隔的字符串列表, 每个字符串都是'0123456789'
。在要匹配由字符串
^{pr2}$nums
中的字符组成的逗号分隔的“单词”列表,请使用Word(nums)
:相关问题 更多 >
编程相关推荐