【问题标题】:A templating engine which supports generating a parser from a template支持从模板生成解析器的模板引擎
【发布时间】:2014-09-19 22:40:48
【问题描述】:

我正在尝试让我的 Python 模板引擎向后工作。即给定模板和数据不仅生成文档,还提取给定模板和文档的数据。

给定页面

<ul>
    <li><a href="/polls/456/">What is your name, stranger?</a></li>
</ul>

和模板

{% 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 %}

它将返回一个包含该项目的latest_question_list

您使用什么工具来执行此操作?它不必支持 Django 模板,其他模板引擎也可以。

【问题讨论】:

标签: python parsing templates django-templates template-engine


【解决方案1】:

这个突破已经发生了。这称为双向或可逆解析。请参阅此处讨论https://news.ycombinator.com/item?id=16392654

还有这篇论文https://dl.acm.org/doi/10.1145/1863523.1863525《可逆语法描述:统一解析和漂亮打印》

还有这个 Haskell 库 https://hackage.haskell.org/package/roundtrip 等等

来源:https://news.ycombinator.com/item?id=25319810

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-01
    • 1970-01-01
    • 2020-10-31
    • 2016-01-24
    • 2021-06-07
    • 2023-03-25
    相关资源
    最近更新 更多