Bibtex 中字符串的正则表达式
我正在尝试使用 lex/yacc 解析 Bibtex 文件。 bibtex 数据库中的字符串可以用引号“...”或大括号括起来 - {...}
但每个条目也用大括号括起来。如何区分条目和大括号括起来的字符串?
@Book{sweig42,
Author = { Stefan Sweig },
title = { The impossible book },
publisher = { Dead Poet Society},
year = 1942,
month = mar
}
I'm trying to parse Bibtex files using lex/yacc. Strings in the bibtex database can be surrounded by quotes "..." or with braces - {...}
But every entry is also enclosed in braces. How do differentiate between an entry and a string surrounded by braces?
@Book{sweig42,
Author = { Stefan Sweig },
title = { The impossible book },
publisher = { Dead Poet Society},
year = 1942,
month = mar
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您有多种选择:
词法分析器启动条件(来自 Lex 教程)
基于greg ward的想法,增强您的 lex 规则具有启动条件(在引用的源中称为“模式”)。
具体来说,您将拥有启动条件
BASIC ENTRY STRING
和以下规则(示例取自 此处):请注意,规则集并不完整,但应该可以帮助您入门。更多详细信息请参见此处。
bt解析
这些文档以相当详细的方式解释了这些复杂性解析 bibtex 格式并附带一个“python 解析器”。
圣经
您可能还对使用 biblex 和 bibparse 的 unix 工具链感兴趣。这些工具分别生成和解析 bibtex 令牌流。
更多信息可以在此处找到。
最好的问候,卡斯滕
you have various options:
lexer start conditions (from a Lex tutorial)
building on the ideas from greg ward, enhance your lex rules with start conditions ('modes' as they are called in the referenced source).
specifically, you would have the start conditions
BASIC ENTRY STRING
and the following rules (example taken and slightly enhanced from here):please note that the rule set is by no means complete but should get you started. more details to be found here.
btparse
These docs explain in a fairly detailed fashion thenintricacies of parsing the bibtex formats and comes with a 'python parser.
biblex
you might also be interested in employing the unix toolchain of biblex and bibparse. these tools generate and parse a bibtex token stream, respectively.
more info can be found here.
best regards, carsten