diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
commit | 64d98f8ee037282c35007b64c2649055c56af1db (patch) | |
tree | 5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /vendor/pest_derive | |
parent | Adding debian version 1.67.1+dfsg1-1. (diff) | |
download | rustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/pest_derive')
-rw-r--r-- | vendor/pest_derive/.cargo-checksum.json | 2 | ||||
-rw-r--r-- | vendor/pest_derive/Cargo.lock | 195 | ||||
-rw-r--r-- | vendor/pest_derive/Cargo.toml | 10 | ||||
-rw-r--r-- | vendor/pest_derive/_README.md | 43 | ||||
-rw-r--r-- | vendor/pest_derive/examples/calc.pest | 16 | ||||
-rw-r--r-- | vendor/pest_derive/examples/calc.rs | 109 | ||||
-rw-r--r-- | vendor/pest_derive/src/lib.rs | 88 | ||||
-rw-r--r-- | vendor/pest_derive/tests/grammar.pest | 5 | ||||
-rw-r--r-- | vendor/pest_derive/tests/grammar.rs | 2 |
9 files changed, 422 insertions, 48 deletions
diff --git a/vendor/pest_derive/.cargo-checksum.json b/vendor/pest_derive/.cargo-checksum.json index b9c70e450..5423e76a2 100644 --- a/vendor/pest_derive/.cargo-checksum.json +++ b/vendor/pest_derive/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"3b10f9a7d7abd7529819a9c273e1e1fe6868225f3eb14fca998ede71e81d0d9c","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","_README.md":"01ba71f02581f9f5018962e083ca77bc8e8af2b6f8a73111bfa04e847a6440e2","src/lib.rs":"8a4edbd00a1ac7dddf041618bc088d095ade1647799fcb7621b71cc2660f0822","tests/grammar.pest":"23c99a141f9165d24f3c46cd40a15788056b87558398b80a757980fd6967f271","tests/grammar.rs":"1c583be001c7f627816507142324a465d6bd2c701e869a3382ff44e8c45050e9","tests/grammar_inline.rs":"349527e75a1fc10e0208d3d88cbac427dd5999b8a2a79d2b9c981e73af22da37","tests/lists.pest":"96d90ad5eb7b14648fa8720f0a48e680327080b07251a4dd74e1a023625e9c1a","tests/lists.rs":"2dc0cb9c07f5b077743ce9313488599347061ea486e0f5160bff50b3d07ca72c","tests/reporting.pest":"f5bc8405ea117b76338e0003e359731a8aaf1a36672f31a6a639a4e67a65e331","tests/reporting.rs":"8b88238dc33abff5dbc76434a7468dceeb9db3dfa8826d44c8ea1d13d52431e8"},"package":"905708f7f674518498c1f8d644481440f476d39ca6ecae83319bba7c6c12da91"}
\ No newline at end of file +{"files":{"Cargo.lock":"f4ef406536889c5b8f92fcae0e75388564476ce7fb2cb98343b2afe78b008a2e","Cargo.toml":"1e082a42fc3822c5abba13ee5e107ffc1059fd5cd3639590cfb01e20970f69c1","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","_README.md":"190b4279777e3cd3c5adf3258114b89be536fc647d819620ada15be39d2259cc","examples/calc.pest":"2b0147e136da04efd983bba4e6de82150f264e8b30766b97be65a585bb7e7377","examples/calc.rs":"39e03c6928bd6895853dec2aad726f053488c399252f0a28411f1fca6546ab3c","src/lib.rs":"ef3426de6a0c667066202be87f23a7605461884aba71eda8aae5f82b04846149","tests/grammar.pest":"00ae1134a07ddb3cb8cf748678039dffe719c25e0fc50dc36fc991f58ea3241d","tests/grammar.rs":"1c3edb14720066c8b19953d8c51f300dee454d107e70b8f83e55380347bef375","tests/grammar_inline.rs":"349527e75a1fc10e0208d3d88cbac427dd5999b8a2a79d2b9c981e73af22da37","tests/lists.pest":"96d90ad5eb7b14648fa8720f0a48e680327080b07251a4dd74e1a023625e9c1a","tests/lists.rs":"2dc0cb9c07f5b077743ce9313488599347061ea486e0f5160bff50b3d07ca72c","tests/reporting.pest":"f5bc8405ea117b76338e0003e359731a8aaf1a36672f31a6a639a4e67a65e331","tests/reporting.rs":"8b88238dc33abff5dbc76434a7468dceeb9db3dfa8826d44c8ea1d13d52431e8"},"package":"96504449aa860c8dcde14f9fba5c58dc6658688ca1fe363589d6327b8662c603"}
\ No newline at end of file diff --git a/vendor/pest_derive/Cargo.lock b/vendor/pest_derive/Cargo.lock new file mode 100644 index 000000000..9bf2a751a --- /dev/null +++ b/vendor/pest_derive/Cargo.lock @@ -0,0 +1,195 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "block-buffer" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" +dependencies = [ + "generic-array", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cpufeatures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "digest" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "generic-array" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "libc" +version = "0.2.139" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" + +[[package]] +name = "once_cell" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" + +[[package]] +name = "pest" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f6e86fb9e7026527a0d46bc308b841d73170ef8f443e1807f6ef88526a816d4" +dependencies = [ + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.5.2" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "798e0220d1111ae63d66cb66a5dcb3fc2d986d520b98e49e1852bfdb11d7c5e7" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pest_meta" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "984298b75898e30a843e278a9f2452c31e349a073a0ce6fd950a12a74464e065" +dependencies = [ + "once_cell", + "pest", + "sha1", +] + +[[package]] +name = "proc-macro2" +version = "1.0.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "sha1" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "syn" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "typenum" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" + +[[package]] +name = "ucd-trie" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" + +[[package]] +name = "unicode-ident" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" diff --git a/vendor/pest_derive/Cargo.toml b/vendor/pest_derive/Cargo.toml index 44212b499..df0a30325 100644 --- a/vendor/pest_derive/Cargo.toml +++ b/vendor/pest_derive/Cargo.toml @@ -10,13 +10,13 @@ # See Cargo.toml.orig for the original contents. [package] -edition = "2018" +edition = "2021" rust-version = "1.56" name = "pest_derive" -version = "2.3.0" +version = "2.5.2" authors = ["DragoČ™ Tiselice <dragostiselice@gmail.com>"] description = "pest's derive macro" -homepage = "https://pest-parser.github.io/" +homepage = "https://pest.rs/" documentation = "https://docs.rs/pest" readme = "_README.md" keywords = [ @@ -34,11 +34,11 @@ name = "pest_derive" proc-macro = true [dependencies.pest] -version = "2.3.0" +version = "2.5.2" default-features = false [dependencies.pest_generator] -version = "2.3.0" +version = "2.5.2" default-features = false [features] diff --git a/vendor/pest_derive/_README.md b/vendor/pest_derive/_README.md index f91188ccb..da30ab74e 100644 --- a/vendor/pest_derive/_README.md +++ b/vendor/pest_derive/_README.md @@ -5,8 +5,8 @@ # pest. The Elegant Parser -[![Join the chat at https://gitter.im/dragostis/pest](https://badges.gitter.im/dragostis/pest.svg)](https://gitter.im/dragostis/pest?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -[![Book](https://img.shields.io/badge/book-WIP-4d76ae.svg)](https://pest-parser.github.io/book) +[![Join the chat at https://gitter.im/pest-parser/pest](https://badges.gitter.im/dragostis/pest.svg)](https://gitter.im/pest-parser/pest?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![Book](https://img.shields.io/badge/book-WIP-4d76ae.svg)](https://pest.rs/book) [![Docs](https://docs.rs/pest/badge.svg)](https://docs.rs/pest) [![pest Continuous Integration](https://github.com/pest-parser/pest/actions/workflows/ci.yml/badge.svg)](https://github.com/pest-parser/pest/actions/workflows/ci.yml) @@ -31,25 +31,28 @@ Other helpful resources: * API reference on [docs.rs] * play with grammars and share them on our [fiddle] -* leave feedback, ask questions, or greet us on [Gitter] +* find previous common questions answered or ask questions on [GitHub Discussions] +* leave feedback, ask questions, or greet us on [Gitter] or [Discord] -[book]: https://pest-parser.github.io/book +[book]: https://pest.rs/book [docs.rs]: https://docs.rs/pest -[fiddle]: https://pest-parser.github.io/#editor -[Gitter]: https://gitter.im/dragostis/pest +[fiddle]: https://pest.rs/#editor +[Gitter]: https://gitter.im/pest-parser/pest +[Discord]: https://discord.gg/XEGACtWpT2 +[GitHub Discussions]: https://github.com/pest-parser/pest/discussions ## Example The following is an example of a grammar for a list of alphanumeric identifiers -where the first identifier does not start with a digit: +where all identifiers don't start with a digit: ```rust alpha = { 'a'..'z' | 'A'..'Z' } digit = { '0'..'9' } -ident = { (alpha | digit)+ } +ident = { !digit ~ (alpha | digit)+ } -ident_list = _{ !digit ~ ident ~ (" " ~ ident)+ } +ident_list = _{ ident ~ (" " ~ ident)* } // ^ // ident_list rule is silent which means it produces no tokens ``` @@ -81,6 +84,9 @@ thread 'main' panicked at ' --> 1:1 = 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. @@ -133,6 +139,25 @@ Letter: b Digit: 2 ``` +### Defining multiple parsers in a single file +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: + +```rust +mod a { + #[derive(Parser)] + #[grammar = "a.pest"] + pub struct ParserA; +} +mod b { + #[derive(Parser)] + #[grammar = "b.pest"] + pub struct ParserB; +} +``` + ## Other features * Precedence climbing diff --git a/vendor/pest_derive/examples/calc.pest b/vendor/pest_derive/examples/calc.pest new file mode 100644 index 000000000..9f2cc3b74 --- /dev/null +++ b/vendor/pest_derive/examples/calc.pest @@ -0,0 +1,16 @@ +WHITESPACE = _{ " " | "\t" | NEWLINE } + + program = { SOI ~ expr ~ EOI } + expr = { prefix* ~ primary ~ postfix* ~ (infix ~ prefix* ~ primary ~ postfix* )* } + infix = _{ add | sub | mul | div | pow } + add = { "+" } // Addition + sub = { "-" } // Subtraction + mul = { "*" } // Multiplication + div = { "/" } // Division + pow = { "^" } // Exponentiation + prefix = _{ neg } + neg = { "-" } // Negation + postfix = _{ fac } + fac = { "!" } // Factorial + primary = _{ int | "(" ~ expr ~ ")" } + int = @{ (ASCII_NONZERO_DIGIT ~ ASCII_DIGIT+ | ASCII_DIGIT) }
\ No newline at end of file diff --git a/vendor/pest_derive/examples/calc.rs b/vendor/pest_derive/examples/calc.rs new file mode 100644 index 000000000..efc6b7b22 --- /dev/null +++ b/vendor/pest_derive/examples/calc.rs @@ -0,0 +1,109 @@ +mod parser { + use pest_derive::Parser; + + #[derive(Parser)] + #[grammar = "../examples/calc.pest"] + pub struct Parser; +} + +use parser::Rule; +use pest::{ + iterators::Pairs, + pratt_parser::{Assoc::*, Op, PrattParser}, + Parser, +}; +use std::io::{stdin, stdout, Write}; + +fn parse_to_str(pairs: Pairs<Rule>, pratt: &PrattParser<Rule>) -> String { + pratt + .map_primary(|primary| match primary.as_rule() { + Rule::int => primary.as_str().to_owned(), + Rule::expr => parse_to_str(primary.into_inner(), pratt), + _ => unreachable!(), + }) + .map_prefix(|op, rhs| match op.as_rule() { + Rule::neg => format!("(-{})", rhs), + _ => unreachable!(), + }) + .map_postfix(|lhs, op| match op.as_rule() { + Rule::fac => format!("({}!)", lhs), + _ => unreachable!(), + }) + .map_infix(|lhs, op, rhs| match op.as_rule() { + Rule::add => format!("({}+{})", lhs, rhs), + Rule::sub => format!("({}-{})", lhs, rhs), + Rule::mul => format!("({}*{})", lhs, rhs), + Rule::div => format!("({}/{})", lhs, rhs), + Rule::pow => format!("({}^{})", lhs, rhs), + _ => unreachable!(), + }) + .parse(pairs) +} + +fn parse_to_i32(pairs: Pairs<Rule>, pratt: &PrattParser<Rule>) -> i128 { + pratt + .map_primary(|primary| match primary.as_rule() { + Rule::int => primary.as_str().parse().unwrap(), + Rule::expr => parse_to_i32(primary.into_inner(), pratt), + _ => unreachable!(), + }) + .map_prefix(|op, rhs| match op.as_rule() { + Rule::neg => -rhs, + _ => unreachable!(), + }) + .map_postfix(|lhs, op| match op.as_rule() { + Rule::fac => (1..lhs + 1).product(), + _ => unreachable!(), + }) + .map_infix(|lhs, op, rhs| match op.as_rule() { + Rule::add => lhs + rhs, + Rule::sub => lhs - rhs, + Rule::mul => lhs * rhs, + Rule::div => lhs / rhs, + Rule::pow => (1..rhs + 1).map(|_| lhs).product(), + _ => unreachable!(), + }) + .parse(pairs) +} + +fn main() { + let pratt = PrattParser::new() + .op(Op::infix(Rule::add, Left) | Op::infix(Rule::sub, Left)) + .op(Op::infix(Rule::mul, Left) | Op::infix(Rule::div, Left)) + .op(Op::infix(Rule::pow, Right)) + .op(Op::postfix(Rule::fac)) + .op(Op::prefix(Rule::neg)); + + let stdin = stdin(); + let mut stdout = stdout(); + + loop { + let source = { + print!("> "); + let _ = stdout.flush(); + let mut input = String::new(); + let _ = stdin.read_line(&mut input); + input.trim().to_string() + }; + + let pairs = match parser::Parser::parse(Rule::program, &source) { + Ok(mut parse_tree) => { + parse_tree + .next() + .unwrap() + .into_inner() // inner of program + .next() + .unwrap() + .into_inner() // inner of expr + } + Err(err) => { + println!("Failed parsing input: {:}", err); + continue; + } + }; + + print!("{} => ", source); + print!("{} => ", parse_to_str(pairs.clone(), &pratt)); + println!("{}", parse_to_i32(pairs.clone(), &pratt)); + } +} diff --git a/vendor/pest_derive/src/lib.rs b/vendor/pest_derive/src/lib.rs index d980c6ae9..a908897f9 100644 --- a/vendor/pest_derive/src/lib.rs +++ b/vendor/pest_derive/src/lib.rs @@ -6,7 +6,12 @@ // license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. All files in the project carrying such notice may not be copied, // modified, or distributed except according to those terms. - +#![doc( + html_root_url = "https://docs.rs/pest_derive", + html_logo_url = "https://raw.githubusercontent.com/pest-parser/pest/master/pest-logo.svg", + html_favicon_url = "https://raw.githubusercontent.com/pest-parser/pest/master/pest-logo.svg" +)] +#![warn(missing_docs, rust_2018_idioms, unused_qualifications)] //! # pest. The Elegant Parser //! //! pest is a general purpose parser written in Rust with a focus on accessibility, correctness, @@ -24,12 +29,16 @@ //! //! * API reference on [docs.rs] //! * play with grammars and share them on our [fiddle] -//! * leave feedback, ask questions, or greet us on [Gitter] +//! * find previous common questions answered or ask questions on [GitHub Discussions] +//! * leave feedback, ask questions, or greet us on [Gitter] or [Discord] //! -//! [book]: https://pest-parser.github.io/book +//! [book]: https://pest.rs/book //! [docs.rs]: https://docs.rs/pest -//! [fiddle]: https://pest-parser.github.io/#editor -//! [Gitter]: https://gitter.im/dragostis/pest +//! [fiddle]: https://pest.rs/#editor +//! [Gitter]: https://gitter.im/pest-parser/pest +//! [Discord]: https://discord.gg/XEGACtWpT2 +//! [GitHub Discussions]: https://github.com/pest-parser/pest/discussions +//! //! //! ## `.pest` files //! @@ -143,12 +152,12 @@ //! //! 1. Terminals //! -//! | Terminal | Usage | -//! |------------|----------------------------------------------------------------| -//! | `"a"` | matches the exact string `"a"` | -//! | `^"a"` | matches the exact string `"a"` case insensitively (ASCII only) | -//! | `'a'..'z'` | matches one character between `'a'` and `'z'` | -//! | `a` | matches rule `a` | +//! | Terminal | Usage | +//! |------------|----------------------------------------------------------------| +//! | `"a"` | matches the exact string `"a"` | +//! | `^"a"` | matches the exact string `"a"` case insensitively (ASCII only) | +//! | `'a'..'z'` | matches one character between `'a'` and `'z'` | +//! | `a` | matches rule `a` | //! //! Strings and characters follow //! [Rust's escape mechanisms](https://doc.rust-lang.org/reference/tokens.html#byte-escapes), while @@ -157,23 +166,36 @@ //! //! 2. Non-terminals //! -//! | Non-terminal | Usage | -//! |-----------------------|------------------------------------------------------------| -//! | `(e)` | matches `e` | -//! | `e1 ~ e2` | matches the sequence `e1` `e2` | -//! | <code>e1 \| e2</code> | matches either `e1` or `e2` | -//! | `e*` | matches `e` zero or more times | -//! | `e+` | matches `e` one or more times | -//! | `e{n}` | matches `e` exactly `n` times | -//! | `e{, n}` | matches `e` at most `n` times | -//! | `e{n,} ` | matches `e` at least `n` times | -//! | `e{m, n}` | matches `e` between `m` and `n` times inclusively | -//! | `e?` | optionally matches `e` | -//! | `&e` | matches `e` without making progress | -//! | `!e` | matches if `e` doesn't match without making progress | -//! | `PUSH(e)` | matches `e` and pushes it's captured string down the stack | -//! -//! where `e`, `e1`, and `e2` are expressions. +//! | Non-terminal | Usage | +//! |-----------------------|------------------------------------------------------------| +//! | `(e)` | matches `e` | +//! | `e1 ~ e2` | matches the sequence `e1` `e2` | +//! | <code>e1 \| e2</code> | matches either `e1` or `e2` | +//! | `e*` | matches `e` zero or more times | +//! | `e+` | matches `e` one or more times | +//! | `e{n}` | matches `e` exactly `n` times | +//! | `e{, n}` | matches `e` at most `n` times | +//! | `e{n,}` | matches `e` at least `n` times | +//! | `e{m, n}` | matches `e` between `m` and `n` times inclusively | +//! | `e?` | optionally matches `e` | +//! | `&e` | matches `e` without making progress | +//! | `!e` | matches if `e` doesn't match without making progress | +//! | `PUSH(e)` | matches `e` and pushes it's captured string down the stack | +//! +//! where `e`, `e1`, and `e2` are expressions. +//! +//! Matching is greedy, without backtracking. Note the difference in behavior for +//! these two rules in matching identifiers that don't end in an underscore: +//! +//! ```ignore +//! // input: ab_bb_b +//! +//! identifier = @{ "a" ~ ("b"|"_")* ~ "b" } +//! // matches: a b_bb_b nothing -> error! +//! +//! identifier = @{ "a" ~ ("_"* ~ "b")* } +//! // matches: a b, _bb, _b in three repetitions +//! ``` //! //! Expressions can modify the stack only if they match the input. For example, //! if `e1` in the compound expression `e1 | e2` does not match the input, then @@ -181,6 +203,10 @@ //! `e1` did. Repetitions and optionals (`e*`, `e+`, `e{, n}`, `e{n,}`, //! `e{m,n}`, `e?`) can modify the stack each time `e` matches. The `!e` and `&e` //! expressions are a special case; they never modify the stack. +//! Many languages have "keyword" tokens (e.g. if, for, while) as well as general +//! tokens (e.g. identifier) that matches any word. In order to match a keyword, +//! generally, you may need to restrict that is not immediately followed by another +//! letter or digit (otherwise it would be matched as an identifier). //! //! ## Special rules //! @@ -289,12 +315,10 @@ //! * `ASCII` - matches a character from \x00..\x7f //! * `NEWLINE` - matches either "\n" or "\r\n" or "\r" -#![doc(html_root_url = "https://docs.rs/pest_derive")] -extern crate pest_generator; -extern crate proc_macro; - use proc_macro::TokenStream; +/// The main method that's called by the proc macro +/// (a wrapper around `pest_generator::derive_parser`) #[proc_macro_derive(Parser, attributes(grammar, grammar_inline))] pub fn derive_parser(input: TokenStream) -> TokenStream { pest_generator::derive_parser(input.into(), true).into() diff --git a/vendor/pest_derive/tests/grammar.pest b/vendor/pest_derive/tests/grammar.pest index 126f112d3..b24d47747 100644 --- a/vendor/pest_derive/tests/grammar.pest +++ b/vendor/pest_derive/tests/grammar.pest @@ -63,6 +63,11 @@ newline = { NEWLINE+ } unicode = { XID_START ~ XID_CONTINUE* } SYMBOL = { "shadows builtin" } +han = { HAN+ } +hangul = { HANGUL+ } +hiragana = { HIRAGANA+ } +arabic = { ARABIC+ } + WHITESPACE = _{ " " } COMMENT = _{ "$"+ } diff --git a/vendor/pest_derive/tests/grammar.rs b/vendor/pest_derive/tests/grammar.rs index 57bed9072..cf5a4a60c 100644 --- a/vendor/pest_derive/tests/grammar.rs +++ b/vendor/pest_derive/tests/grammar.rs @@ -16,7 +16,7 @@ extern crate pest; extern crate pest_derive; #[derive(Parser)] -#[grammar = "../tests/grammar.pest"] +#[grammar = "tests/grammar.pest"] struct GrammarParser; #[test] |