[英]A templating engine which supports generating a parser from a template
I am trying to make my templating engine for Python work backwards.我试图让我的 Python 模板引擎反向工作。 That is, not only generate a document given a template and data, but also extract the data given a template and a document.
即,不仅生成给定模板和数据的文档,还提取给定模板和文档的数据。
Given the page鉴于页面
<ul>
<li><a href="/polls/456/">What is your name, stranger?</a></li>
</ul>
and the template和模板
{% if latest_question_list %}
<ul>
{% for question in latest_question_list %}
<li><a href="/polls/{{ question.id }}/">{{ question.text }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No polls are available.</p>
{% endif %}
it will return a latest_question_list
containing that one item.它将返回一个包含该项目的
latest_question_list
。
What tool do you use to do this?你用什么工具来做到这一点? It does not have to support Django templates, other templating engines will do just fine.
它不必支持 Django 模板,其他模板引擎就可以了。
This breakthrough happened already.这个突破已经发生了。 This is called bidirectional or invertible parsing.
这称为双向或可逆解析。 See it discussed here https://news.ycombinator.com/item?id=16392654
请参阅此处讨论https://news.ycombinator.com/item?id=16392654
And this paper https://dl.acm.org/doi/10.1145/1863523.1863525 "Invertible syntax descriptions: unifying parsing and pretty printing"而这篇论文https://dl.acm.org/doi/10.1145/1863523.1863525 “可逆语法描述:统一解析和漂亮打印”
And this Haskell library https://hackage.haskell.org/package/roundtrip among others这个 Haskell 库https://hackage.haskell.org/package/roundtrip等等
source: https://news.ycombinator.com/item?id=25319810来源: https : //news.ycombinator.com/item?id=25319810
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.