【发布时间】:2013-09-23 05:23:58
【问题描述】:
我想解析 LaTeX 文件中可能嵌套的组:像这样:
import pyparsing as pp
qs = pp.QuotedString(quoteChar='{', endQuoteChar='}')
s = r'''{ This is a \textbf{\texttt{example}} of \textit{some $\mb{y}$ text} to parse.}'''
print qs.parseString(s)
但这不可能是正确的(它停在第一个右括号上)。输出是:
([' This is a \\textbf{\\texttt{example'], {})
如果我想要的只是组,我如何获得可以迭代的结果,我正在考虑这样的返回:
{ This is a \textbf{\texttt{example}} of \textit{some $\mb{y}$ text} to parse.}
{\texttt{example}}
{example}
{some $\mb{y}$ text}
{y}
用例是测试 LaTeX 源文件的常见标记错误。
【问题讨论】:
-
看看 pyparsing 的
nestedExpr是否比QuotedString更好。