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 - 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网站:
- Installation and Getting Started
- Paxter Language Tutorial
- Python Authoring Mode Tutorial
- Custom Renderer Tutorial
- Syntax Reference
- Core API Reference
- 更多的很快就要来了!在
未来计划
- 用不同类型的变压器进行实验,并将其应用于实际生活中
- 在Rust中重新实现lexer和解析器以获得更好的性能 以及可移植到其他环境(如WASM)。在
- 还有更多!在
发展
Makefile
包含许多实用程序脚本。
只需运行make
或make help
,即可查看帮助命令。在
- 项目
标签: