我有类似于YAML的数据,需要使用Pyparsing为其创建语法。像Python,YAML的数据范围由空白如何使用Pyparsing为以下数据创建语法
数据定义:
object : object_name
comment : this object is created first
methods:
method_name:
input:
arg1: arg_type
arg2: arg2_type
output:
methond2_name:
input:
output:
arg1 : arg_type
解析在上述过程之后,它应该与此类似输出的东西:
{'comment': 'this object is created first',
'object': 'object_name',
'methods': {'method_name': {'input': {'arg1': 'arg_type', 'arg2': 'arg2_type'},
'output': None}, 'methond2_name': {'input': None, 'output': {'arg1': 'arg_type'}}}}
[编辑] 数据与YAML类似,但不完全相同。所以YAML Python解析器不能解析它。我留下了一些细节,使示例数据更简单
是的,这是太宽没有附加信息和代码的问题。 – 2012-04-05 00:50:55
lepl有一个几乎是这样的例子 - http://www.acooke.org/lepl/offside.html#example - 但pyparsing有一个*更大的社区支持,所以我不会建议改变,除非有pyparsing无法处理缩进。 – 2012-04-05 03:10:08
空白敏感文本是pyparsing的弱点。 pyparsing wiki上的这个例子(http://pyparsing.wikispaces.com/file/view/indentedGrammarExample.py)显示了一种方式,但它仍然是一个尴尬的去处。 – PaulMcG 2012-04-06 05:03:33