Paxter是一个documentfirst、文本预处理的小型语言工具链,其灵感来源于Racket中的@expressions

paxter的Python项目详细描述


帕克斯特

Paxter是一个文档优先、文本预处理的迷你语言工具链, 松散地灵感来自@-expressions in Racket。在

  • Paxter库包定义Paxter语言的语法 并提供了一个用于解析输入文本的工具链 用Paxter语言编写到一个中间解析树。在
  • 但是,Paxter语言的语义没有明确说明, 这意味着图书馆的用户有一切自由 不管他们喜欢渲染或转换中间解析的树 变成他们希望达到的最终成果。在
  • 或者,代替实现解释器 对于中间解析树本身, 用户可以选择使用预置的parsed tree renderers, 也由这个库包提供。在

示例

假设我们有一个用Paxter语言编写的文本文档,如下所示。在

@python##"
    import statistics
    from datetime import datetime

    _symbols_ = {
        '@': '@',
        '.': ' ',
        ',': ' ',
    }
    name = "Ashley"
    birth_year = 1987
    age = datetime.now().year - birth_year
"##\
My name is @name and I am @age years old.
My email is ashley@@example.com.
My shop opens Monday@,-@,Friday.

@python##"
    from itertools import count
    counter = count(start=1)
"##\
Counting is as easy as @|next(counter)|, @|next(counter)|, @|next(counter)|.
Arithmetic? Not a problem: 7 * 11 * 13 = @|7 * 11 * 13|.

@python##"
    def tag(text, name='span'):
        return f'<{name}>{flatten(text)}</{name}>'
"##\
This is a very @tag["b"]{important @tag["i"]{feature}}:
@@-expressions are allowed to be nested within the main argument
using fragment list syntax (section surrounded by a pair of curly braces).

To escape right curly braces literal characters with the fragment list main argument,
simply enclose the main argument with as many #...# as you like
(@tag##{such as {this}!}##).

@python##"
    def is_odd(value):
        return value % 2 == 1
"##\
Odd digits are@flatten{@for[i in @|range(10)|]{@if[@|is_odd(i)|]{ @i}}}.
Expected outcome for rolling a die is @|statistics.mean|[@|range(1, 7)|].

使用Paxter库包中的解析器处理此文档, 我们得到以下结果。在

^{pr2}$

如果我们使用Python编写模式 (Paxter库包提供的渲染器扩展) 要处理来自上面的中间解析树结果, 然后将返回以下输出结果。在

My name is Ashley and I am 33 years old.
My email is ashley@example.com.
My shop opens Monday&thinsp;-&thinsp;Friday.

Counting is as easy as 1, 2, 3.
Arithmetic? Not a problem: 7 * 11 * 13 = 1001.

This is a very <b>important <i>feature</i></b>:
@-expressions are allowed to be nested within the main argument
using fragment list syntax (section surrounded by a pair of curly braces).

To escape right curly braces literal characters with the fragment list main argument,
simply enclose the main argument with as many #...# as you like
(<span>such as {this}!</span>).

Odd digits are 1 3 5 7 9.
Expected outcome for rolling a die is 3.5.

文件

通过以下链接了解Paxter的更多信息 ReadTheDocs documentation网站:

未来计划

  • 用不同类型的变压器进行实验,并将其应用于实际生活中
  • 在Rust中重新实现lexer和解析器以获得更好的性能 以及可移植到其他环境(如WASM)。在
  • 还有更多!在

发展

Makefile包含许多实用程序脚本。
只需运行makemake help,即可查看帮助命令。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
如何使用java创建灰度图像   java Android VideoView在长时间运行(超过24小时)后冻结   javaxml到XSL格式   servlets如何在Java中获取POST变量值   java给加入indtantly jda的用户jda一个角色的最佳方式是什么   java在读取带有列表的文件时获取所有空值   java在无管理员权限的NetBeans中使用JavaFX场景生成器2.0   java如何通过JSON API实现复杂的条件批量部分更新?   java使用ApacheLucene索引大文件时,如何避免内存不足错误?   使用协议“mapi://”从java对outlook中打开的邮件进行编码   java trywithresources详细信息   java在对JTable进行排序后无法从中获取正确的行(Swing)   单元测试如何在测试类(java)中的main中存根函数   oauth 0auth_签名在java中使用SHA1RSA   java重写equals和hashCode只是为了调用super。等于/哈希代码还是抛出断言错误?