#asciimath #parser #extensible #parse-tree #expression #tokens #memory-efficient

asciimath-parser

快速、可扩展、内存高效的 asciimath 解析器

2 个版本

0.1.1 2023 年 3 月 5 日
0.1.0 2023 年 3 月 5 日

1176算法

21 次每月下载
用于 2 crates

MIT 许可证

74KB
1.5K SLoC

Asciimath 解析器

crates.io docs license tests

快速、可扩展、内存高效的 asciimath 解析器

此解析器生成以 Expression 为根的解析树表示。解析结构保持对底层字符串的引用,以避免复制,但必须将这些字符串解释为正确的令牌才能使用该结构。

使用方法

cargo add asciimath-parser

then

asciimath_parser::parse("x / y");

比较

这个库旨在成为一个快速、可扩展的解析器。有许多 Rust 库可以解析和格式化,或解析和评估,但不会公开其底层解析逻辑。只有 asciimath_rs 实际解析表达式。然而,该解析器分配了额外的字符串,并生成相对复杂的解析树。这创建了一个相对简单的解析树,其中字符串切片作为令牌。这使这个解析器比 asciimath_rs 快几倍。

test asciimath_parser::example ... bench:       7,912 ns/iter (+/- 1,348)
test asciimath_rs::example     ... bench:      41,605 ns/iter (+/- 14,262)

test asciimath_parser::random  ... bench:     360,495 ns/iter (+/- 32,231)
test asciimath_rs::random      ... bench:   2,522,810 ns/iter (+/- 168,133)

依赖关系

~94–495KB