pest-parser/pest hiện có 5.4k sao trên GitHub, viết chủ yếu bằng Rust. The Elegant Parser
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
pest is a general purpose parser written in Rust with a focus on accessibility,
correctness, and performance. It uses parsing expression grammars
(or PEG) as input, which are similar in spirit to regular expressions, but
which offer the enhanced expressivity needed to parse complex languages.
Getting started
The recommended way to start parsing with pest is to read the official book.
Other helpful resources:
API reference on docs.rs
Resource limits and timeouts for untrusted input
play with grammars and share them on our fiddle
find previous common questions answered or ask questions on GitHub Discussions
leave feedback, ask questions, or greet us on Gitter or Discord
Native stack guard
With the default std feature, pest automatically checks native stack headroom
on these targets:
x86_64-unknown-linux-gnu
aarch64-unknown-linux-gnu
x86_64-apple-darwin
aarch64-apple-darwin
x86_64-pc-windows-msvc
aarch64-pc-windows-msvc
Other targets do not build stacker or psm by default. To opt into stack
checking on another target, enable stack-guard:
pest = { version = "2.9.5", features = ["stack-guard"] }
This feature enables std and requires a toolchain supported by stacker and
psm, including any required C/assembly compiler. Cross-compiling to one of the
default native targets may also require a cross C toolchain.
Stack checks are best-effort when stack bounds are unavailable; they are not
deadlines or portable stack-overflow guarantees. The cumulative
pest::set_call_limit budget works independently, including without the stack
guard. See the resource-limit guidance.
Example
The following is an example of a grammar for a list of alphanumeric identifiers
where all identifiers don't start with a digit:
alpha = { 'a'..'z' | 'A'..'Z' }
digit = { '0'..'9' }
ident = { !digit ~ (alpha | digit)+ }
ident_list = _{ ident ~ (" " ~ ident)* }
// ^
// ident_list rule is silent which means it produces no tokens
Grammars are saved in separate .pest files which are never mixed with procedural
code. This results in an always up-to-date formalization of a language that is
easy to read and maintain.
Meaningful error reporting
Based on the grammar definition, the parser also includes automatic error
reporting. For the example above, the input "123" will result in:
thread 'main' panicked at ' --> 1:1
|
1 | ab *
| ^---
|
= expected ident', src/main.rs:12
These error messages can be obtained from their default Display implementation,
e.g. panic!("{}", parser_result.unwrap_err()) or println!("{}", e).
Pairs API
The grammar can be used to derive a Parser implementation automatically.
Parsing returns an iterator of nested token pairs:
use pest_derive::Parser;
use pest::Parser;
#[derive(Parser)]
#[grammar = "ident.pest"]
struct IdentParser;
fn main() {
let pairs = IdentParser::parse(Rule::ident_list, "a1 b2").unwrap_or_else(|e| panic!("{}", e));
// Because ident_list is silent, the iterator will contain idents
for pair in pairs {
// A pair is a combination of the rule which matched and a span of input
println!("Rule: {:?}", pair.as_rule());
println!("Span: {:?}", pair.as_span());
println!("Text: {}", pair.as_str());
// A pair can be converted to an iterator of the tokens which make it up:
for inner_pair in pair.into_inner() {
match inner_pair.as_rule() {
Rule::alpha => println!("Letter: {}", inner_pair.as_str()),
Rule::digit => println!("Digit: {}", inner_pair.as_str()),
_ => unreachable!()
};
}
}
}
The current automatic Parser derivation will produce the Rule enum
which would have name conflicts if one tried to define multiple such structs
that automatically derive Parser. One possible way around it is to put each
parser struct in a separate namespace:
mod a {
#[derive(Parser)]
#[grammar = "a.pest"]
pub struct ParserA;
}
mod b {
#[derive(Parser)]
#[grammar = "b.pest"]
pub struct ParserB;
}
Other features
Precedence climbing
Input handling
Custom errors
Runs on stable Rust
Projects using pest
You can find more projects and ecosystem tools in the awesome-pest repo.
pest_meta (bootstrapped)
AshPaper
brain
cicada
comrak
elastic-rs
graphql-parser
handlebars-rust
hexdino
Huia
insta
jql
json5-rs
mt940
Myoxine
py_literal
rouler
RuSh
rs_pbrt
stache
tera
ui_gen
ukhasnet-parser
ZoKrates
Vector
AutoCorrect
yaml-peg
qubit
caith (a dice roller crate)
Melody
json5-nodes
prisma
ws2markdown (a WordStar to Markdown converter)
Minimum Supported Rust Version (MSRV)
This library should always compile with default features on Rust 1.88.0.
no_std support
The pest and pest_derive crates can be built without the Rust standard
library and target embedded environments. To do so, you need to disable
their default features. In your Cargo.toml, you can specify it as follows:
[dependencies]
# ...
pest = { version = "2", default-features = false }
pest_derive = { version = "2", default-features = false }
If you want to build these crates in the pest repository's workspace, you can
pass the --no-default-features flag to cargo and specify these crates using
the --package (-p) flag. For example:
pest-parser/pest thuộc nhóm Backend trên TopGit, cùng 3 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về pest-parser/pest ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/pest-parser/pest là nguồn chính thức.
pest-parser/pest có bao nhiêu sao?
pest-parser/pest có 5.4k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/pest-parser/pest. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
pest-parser/pest có phải mã nguồn mở không?
Có — pest-parser/pest phát hành theo license Apache-2.0, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/pest-parser/pest.
pest-parser/pest còn đang phát triển không?
Commit gần nhất trên pest-parser/pest là 3 ngày trước (theo timestamp GitHub). Repo có 318 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
pest-parser/pest dùng license gì?
pest-parser/pest phát hành theo license Apache-2.0. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
pest-parser/pest là gì?
pest-parser/pest (pest-parser/pest) là dự án Rust trên GitHub. Theo mô tả gốc: The Elegant Parser
pest-parser/pest viết bằng ngôn ngữ gì?
pest-parser/pest chủ yếu viết bằng Rust. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về pest?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về pest.