用python编写DSL的编译器 [英] Writing a compiler for a DSL in python
问题描述
我正在用python编写游戏,因此决定为地图数据文件创建DSL.我知道我可以用regex编写自己的解析器,但是我想知道是否有现有的python工具可以更轻松地完成此操作,例如PHP引擎中使用的re2c.
I am writing a game in python and have decided to create a DSL for the map data files. I know I could write my own parser with regex, but I am wondering if there are existing python tools which can do this more easily, like re2c which is used in the PHP engine.
一些额外的信息:
- 是的,我需要,但即使我不想要DSL,我仍然想要在项目中构建和使用一个DSL的经验.
-
DSL仅包含数据(声明式?),不会执行".大多数行看起来像:
- Yes, I do need a DSL, and even if I didn't I still want the experience of building and using one in a project.
The DSL contains only data (declarative?), it doesn't get "executed". Most lines look like:
SOMETHING: !abc @123 #xyz/123
我只需要读取数据树即可.
I just need to read the tree of data.
推荐答案
pyparsing >.作者Paul McGuire在 python列表/ comp.lang.python ,对于与此有关的任何查询一直非常有帮助.
I've always been impressed by pyparsing. The author, Paul McGuire, is active on the python list/comp.lang.python and has always been very helpful with any queries concerning it.
这篇关于用python编写DSL的编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!