chore: checkpoint before Python removal

This commit is contained in:
2026-03-26 22:33:59 +00:00
parent 683cec9307
commit e568ddf82a
29972 changed files with 11269302 additions and 2 deletions

View File

@@ -0,0 +1 @@
{"files":{".cargo_vcs_info.json":"f25d45c4f0feb4c25064bb1507bd5d5e4e3125ee8665608f05209d2ba6b968ba","Cargo.lock":"3891ce78088db867ad7f5ac0ebadcd1d53f676cd38b58e1e005f1c3389a84923","Cargo.toml":"ad41778f6bbd80134a97a7ab379218cf619c1ced9572f64e582da76e64cbe128","Cargo.toml.orig":"e2e70658381e98c8d255c9504b57d9ed2aecea886a948a840f1a5d1fff50cd85","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","_README.md":"214e60d12802a3c5990520ff21e6e8a788b800cb49b16663e45ebdc417202ac4","examples/base.pest":"949b57af96904b47da714890dd1ab5ce8937a92aac71be1b5cc3c3573198ad24","examples/calc.pest":"4347730e9c77c74545b205e8aa5a1128c064056eb6bfe47d31d3e0f76d9c25ea","examples/calc.rs":"0ded248d3d04adde5eafc69e1ed5d8c120400f7a01181db4a30408c4b777b641","examples/help-menu.pest":"901550581cf040a346c78b64a3320e34da5e4b3941b127ba81820de0dedd2906","examples/help-menu.rs":"c6b9b4d860101a4e3ef0f9e59d967dc5ed9bd3ed4acd4b2e8f30ed2a61a899c9","src/lib.rs":"6cf6eee80ce0d6773bf584eb39b2e5cd978c7f853ba7976b94203e256c1a9f47","tests/grammar.pest":"4d172b9d3851292aed1b8e5ce95c49ef10fda2b3b269baaf5ad2c333fe3744b0","tests/grammar.rs":"fca526a09e4a6ebd27641be7377caae5a867a720e256ef60c324825cc19e5ea1","tests/grammar_inline.rs":"349527e75a1fc10e0208d3d88cbac427dd5999b8a2a79d2b9c981e73af22da37","tests/implicit.pest":"18cd082b71214f7d6bbf32fcf4cd9e3a0b10f99212a640db5327deddb434925e","tests/implicit.rs":"6837f56f6bf72e1c3de74339d4be19371b797b753b502958cde71bcbce11bc60","tests/lists.pest":"96d90ad5eb7b14648fa8720f0a48e680327080b07251a4dd74e1a023625e9c1a","tests/lists.rs":"2dc0cb9c07f5b077743ce9313488599347061ea486e0f5160bff50b3d07ca72c","tests/oneormore.pest":"6599ad31c3e81da6abf05929d7c1a2c8ba63ffea7fa41898e9385f8142d765ad","tests/oneormore.rs":"0379e54652714b6434560707961da2fd679f964bd9700408452fa6b57d6d1a1c","tests/opt.pest":"d9197350c125110e621ddc6c9ee7f558b3faca41dd57f5e86a94aa6ede724175","tests/opt.rs":"bdb2c883d8d474ade53a68a3e2f407b5d422c9b951a3e468ba853fa1d27a12e7","tests/reporting.pest":"f5bc8405ea117b76338e0003e359731a8aaf1a36672f31a6a639a4e67a65e331","tests/reporting.rs":"8b88238dc33abff5dbc76434a7468dceeb9db3dfa8826d44c8ea1d13d52431e8","tests/surround.pest":"943148555184b0e96cafd76993965e9b9ce20bfddde32fb9b0864e94c08f1dab","tests/surround.rs":"48043e98704fd00bbde04556d4408b47b2f96bc28da3523c4569f083908ddae6"},"package":"11f486f1ea21e6c10ed15d5a7c77165d0ee443402f0780849d1768e7d9d6fe77"}

View File

@@ -0,0 +1,6 @@
{
"git": {
"sha1": "79dd30d11aab6f0fba3cd79bd48f456209b966b3"
},
"path_in_vcs": "derive"
}

3980
vendor/pest_derive/Cargo.lock generated vendored Normal file

File diff suppressed because it is too large Load Diff

98
vendor/pest_derive/Cargo.toml vendored Normal file
View File

@@ -0,0 +1,98 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2021"
rust-version = "1.83"
name = "pest_derive"
version = "2.8.6"
authors = ["Dragoș Tiselice <dragostiselice@gmail.com>"]
build = false
autolib = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "pest's derive macro"
homepage = "https://pest.rs/"
documentation = "https://docs.rs/pest"
readme = "_README.md"
keywords = [
"pest",
"parser",
"peg",
"grammar",
]
categories = ["parsing"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/pest-parser/pest"
[features]
default = ["std"]
grammar-extras = ["pest_generator/grammar-extras"]
not-bootstrap-in-src = ["pest_generator/not-bootstrap-in-src"]
std = [
"pest/std",
"pest_generator/std",
]
[lib]
name = "pest_derive"
path = "src/lib.rs"
proc-macro = true
[[example]]
name = "calc"
path = "examples/calc.rs"
[[example]]
name = "help-menu"
path = "examples/help-menu.rs"
[[test]]
name = "grammar"
path = "tests/grammar.rs"
[[test]]
name = "grammar_inline"
path = "tests/grammar_inline.rs"
[[test]]
name = "implicit"
path = "tests/implicit.rs"
[[test]]
name = "lists"
path = "tests/lists.rs"
[[test]]
name = "oneormore"
path = "tests/oneormore.rs"
[[test]]
name = "opt"
path = "tests/opt.rs"
[[test]]
name = "reporting"
path = "tests/reporting.rs"
[[test]]
name = "surround"
path = "tests/surround.rs"
[dependencies.pest]
version = "2.8.6"
default-features = false
[dependencies.pest_generator]
version = "2.8.6"
default-features = false

201
vendor/pest_derive/LICENSE-APACHE vendored Normal file
View File

@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

23
vendor/pest_derive/LICENSE-MIT vendored Normal file
View File

@@ -0,0 +1,23 @@
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

233
vendor/pest_derive/_README.md vendored Normal file
View File

@@ -0,0 +1,233 @@
<p align="center">
<img src="https://raw.github.com/pest-parser/pest/master/pest-logo.svg?sanitize=true" width="80%"/>
</p>
# pest. The Elegant Parser
[![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)
[![codecov](https://codecov.io/gh/pest-parser/pest/branch/master/graph/badge.svg)](https://codecov.io/gh/pest-parser/pest)
<a href="https://blog.rust-lang.org/2024/11/28/Rust-1.83.0/"><img alt="Rustc Version 1.83.0+" src="https://img.shields.io/badge/rustc-1.83.0%2B-lightgrey.svg"/></a>
[![Crates.io](https://img.shields.io/crates/d/pest.svg)](https://crates.io/crates/pest)
[![Crates.io](https://img.shields.io/crates/v/pest.svg)](https://crates.io/crates/pest)
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.
[PEG]: https://en.wikipedia.org/wiki/Parsing_expression_grammar
## Getting started
The recommended way to start parsing with pest is to read the official [book].
Other helpful resources:
* API reference on [docs.rs]
* 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]
[book]: https://pest.rs/book
[docs.rs]: https://docs.rs/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 all identifiers don't start with a digit:
```rust
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 | 123
| ^---
|
= unexpected digit', src/main.rs:12
```
while `"ab *"` 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:
```rust
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!()
};
}
}
}
```
This produces the following output:
```
Rule: ident
Span: Span { start: 0, end: 2 }
Text: a1
Letter: a
Digit: 1
Rule: ident
Span: Span { start: 3, end: 5 }
Text: b2
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
* Input handling
* Custom errors
* Runs on stable Rust
## Projects using pest
You can find more projects and ecosystem tools in the [awesome-pest](https://github.com/pest-parser/awesome-pest) repo.
* [pest_meta](https://github.com/pest-parser/pest/blob/master/meta/src/grammar.pest) (bootstrapped)
* [AshPaper](https://github.com/shnewto/ashpaper)
* [brain](https://github.com/brain-lang/brain)
* [cicada](https://github.com/mitnk/cicada)
* [comrak](https://github.com/kivikakk/comrak)
* [elastic-rs](https://github.com/cch123/elastic-rs)
* [graphql-parser](https://github.com/Keats/graphql-parser)
* [handlebars-rust](https://github.com/sunng87/handlebars-rust)
* [hexdino](https://github.com/Luz/hexdino)
* [Huia](https://gitlab.com/jimsy/huia/)
* [insta](https://github.com/mitsuhiko/insta)
* [jql](https://github.com/yamafaktory/jql)
* [json5-rs](https://github.com/callum-oakley/json5-rs)
* [mt940](https://github.com/svenstaro/mt940-rs)
* [Myoxine](https://github.com/d3bate/myoxine)
* [py_literal](https://github.com/jturner314/py_literal)
* [rouler](https://github.com/jarcane/rouler)
* [RuSh](https://github.com/lwandrebeck/RuSh)
* [rs_pbrt](https://github.com/wahn/rs_pbrt)
* [stache](https://github.com/dgraham/stache)
* [tera](https://github.com/Keats/tera)
* [ui_gen](https://github.com/emoon/ui_gen)
* [ukhasnet-parser](https://github.com/adamgreig/ukhasnet-parser)
* [ZoKrates](https://github.com/ZoKrates/ZoKrates)
* [Vector](https://github.com/timberio/vector)
* [AutoCorrect](https://github.com/huacnlee/autocorrect)
* [yaml-peg](https://github.com/aofdev/yaml-peg)
* [qubit](https://github.com/abhimanyu003/qubit)
* [caith](https://github.com/Geobert/caith) (a dice roller crate)
* [Melody](https://github.com/yoav-lavi/melody)
* [json5-nodes](https://github.com/jlyonsmith/json5-nodes)
* [prisma](https://github.com/prisma/prisma)
* [ws2markdown](https://code.rosaelefanten.org/ws2markdown) (a WordStar to Markdown converter)
## Minimum Supported Rust Version (MSRV)
This library should always compile with default features on **Rust 1.83.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:
```toml
[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:
```bash
$ cargo build --target thumbv7em-none-eabihf --no-default-features -p pest
$ cargo bootstrap
$ cargo build --target thumbv7em-none-eabihf --no-default-features -p pest_derive
```
## Special thanks
A special round of applause goes to prof. Marius Minea for his guidance and all
pest contributors, some of which being none other than my friends.

2
vendor/pest_derive/examples/base.pest vendored Normal file
View File

@@ -0,0 +1,2 @@
WHITESPACE = _{ " " | "\t" | NEWLINE }
int = @{ (ASCII_NONZERO_DIGIT ~ ASCII_DIGIT+ | ASCII_DIGIT) }

13
vendor/pest_derive/examples/calc.pest vendored Normal file
View File

@@ -0,0 +1,13 @@
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 ~ ")" }

110
vendor/pest_derive/examples/calc.rs vendored Normal file
View File

@@ -0,0 +1,110 @@
mod parser {
use pest_derive::Parser;
#[derive(Parser)]
#[grammar = "../examples/base.pest"]
#[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::prefix(Rule::neg))
.op(Op::postfix(Rule::fac));
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));
}
}

View File

@@ -0,0 +1,36 @@
WHITESPACE = _{ " " }
Rew = ! { ( ASCII_DIGIT | ASCII_ALPHA_UPPER | "_" | "-" ) + }
Lit = ! { ( ASCII_ALPHANUMERIC | "_" | "-" ) + }
Word = _ { Rew | Lit }
WordGroup = _ { Word ~ ( " " ~ Word ) * }
// Argument groups are nonatomic;
// "<whitespace |between|the|bar|or|braces |is | OK>"
ArgOptChoiceGroup = { ( "[" ~ Word + ~
( "|" ~ ( Word
| ArgChoiceGroup ) + ) * ~
"]" ) + }
ArgReqChoiceGroup = { ( "<" ~ Word + ~
( "|" ~ ( Word
| ArgChoiceGroup ) + ) * ~
">" ) + }
ArgChoiceGroup = _ { ArgOptChoiceGroup
| ArgReqChoiceGroup }
Command = {
( WordGroup ) ~
( ArgChoiceGroup ) *
}
HelpMenu = {
SOI ~
(
Command ~
NEWLINE
) * ~
EOI
}

View File

@@ -0,0 +1,28 @@
#[macro_use]
extern crate pest_derive;
extern crate pest;
use pest::Parser;
#[derive(Parser)]
#[grammar = "../examples/help-menu.pest"]
struct HelpMenuGrammar;
const INPUT: &str = r"cli help
cli positional-command <required-single-argument> [optional-single-argument]
cli [choice | of | one | or | none | of | these | options]
cli <choice | of | one | of | these | options>
cli [nesting | <is | ok>]
";
fn main() {
HelpMenuGrammar::parse(Rule::HelpMenu, INPUT)
.expect("Error parsing file")
.next()
.expect("Infallible")
.into_inner()
.filter(|pair| Rule::Command == pair.as_rule())
.for_each(|pair| {
println!("{:#?}", pair);
});
}

325
vendor/pest_derive/src/lib.rs vendored Normal file
View File

@@ -0,0 +1,325 @@
// pest. The Elegant Parser
// Copyright (c) 2018 Dragoș Tiselice
//
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
// 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,
//! 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.
//!
//! [PEG]: https://en.wikipedia.org/wiki/Parsing_expression_grammar
//!
//! ## Getting started
//!
//! The recommended way to start parsing with pest is to read the official [book].
//!
//! Other helpful resources:
//!
//! * API reference on [docs.rs]
//! * 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]
//!
//! [book]: https://pest.rs/book
//! [docs.rs]: https://docs.rs/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
//!
//! Grammar definitions reside in custom `.pest` files located in the `src` directory. Their path is
//! relative to `src` and is specified between the `derive` attribute and empty `struct` that
//! `Parser` will be derived on.
//!
//! ```ignore
//! #[derive(Parser)]
//! #[grammar = "path/to/my_grammar.pest"] // relative to src
//! struct MyParser;
//! ```
//!
//! ## Inline grammars
//!
//! Grammars can also be inlined by using the `#[grammar_inline = "..."]` attribute.
//!
//! ## Grammar
//!
//! A grammar is a series of rules separated by whitespace, possibly containing comments.
//!
//! ### Comments
//!
//! Comments start with `//` and end at the end of the line.
//!
//! ```text
//! // a comment
//! ```
//!
//! ### Rules
//!
//! Rules have the following form:
//!
//! ```ignore
//! name = optional_modifier { expression }
//! ```
//!
//! The name of the rule is formed from alphanumeric characters or `_` with the condition that the
//! first character is not a digit and is used to create token pairs. When the rule starts being
//! parsed, the starting part of the token is being produced, with the ending part being produced
//! when the rule finishes parsing.
//!
//! The following token pair notation `a(b(), c())` denotes the tokens: start `a`, start `b`, end
//! `b`, start `c`, end `c`, end `a`.
//!
//! #### Modifiers
//!
//! Modifiers are optional and can be one of `_`, `@`, `$`, or `!`. These modifiers change the
//! behavior of the rules.
//!
//! 1. Silent (`_`)
//!
//! Silent rules do not create token pairs during parsing, nor are they error-reported.
//!
//! ```ignore
//! a = _{ "a" }
//! b = { a ~ "b" }
//! ```
//!
//! Parsing `"ab"` produces the token pair `b()`.
//!
//! 2. Atomic (`@`)
//!
//! Atomic rules do not accept whitespace or comments within their expressions and have a
//! cascading effect on any rule they call. I.e. rules that are not atomic but are called by atomic
//! rules behave atomically.
//!
//! Any rules called by atomic rules do not generate token pairs.
//!
//! ```ignore
//! a = { "a" }
//! b = @{ a ~ "b" }
//!
//! WHITESPACE = _{ " " }
//! ```
//!
//! Parsing `"ab"` produces the token pair `b()`, while `"a b"` produces an error.
//!
//! 3. Compound-atomic (`$`)
//!
//! Compound-atomic are identical to atomic rules with the exception that rules called by them are
//! not forbidden from generating token pairs.
//!
//! ```ignore
//! a = { "a" }
//! b = ${ a ~ "b" }
//!
//! WHITESPACE = _{ " " }
//! ```
//!
//! Parsing `"ab"` produces the token pairs `b(a())`, while `"a b"` produces an error.
//!
//! 4. Non-atomic (`!`)
//!
//! Non-atomic are identical to normal rules with the exception that they stop the cascading effect
//! of atomic and compound-atomic rules.
//!
//! ```ignore
//! a = { "a" }
//! b = !{ a ~ "b" }
//! c = @{ b }
//!
//! WHITESPACE = _{ " " }
//! ```
//!
//! Parsing both `"ab"` and `"a b"` produce the token pairs `c(a())`.
//!
//! #### Expressions
//!
//! Expressions can be either terminals or non-terminals.
//!
//! 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` |
//!
//! Strings and characters follow
//! [Rust's escape mechanisms](https://doc.rust-lang.org/reference/tokens.html#byte-escapes), while
//! identifiers can contain alphanumeric characters and underscores (`_`), as long as they do not
//! start with a digit.
//!
//! 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 its 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
//! it does not modify the stack, so `e2` sees the stack in the same state as
//! `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
//!
//! Special rules can be called within the grammar. They are:
//!
//! * `WHITESPACE` - runs between rules and sub-rules
//! * `COMMENT` - runs between rules and sub-rules
//! * `ANY` - matches exactly one `char`
//! * `SOI` - (start-of-input) matches only when a `Parser` is still at the starting position
//! * `EOI` - (end-of-input) matches only when a `Parser` has reached its end
//! * `POP` - pops a string from the stack and matches it
//! * `POP_ALL` - pops the entire state of the stack and matches it
//! * `PEEK` - peeks a string from the stack and matches it
//! * `PEEK[a..b]` - peeks part of the stack and matches it
//! * `PEEK_ALL` - peeks the entire state of the stack and matches it
//! * `DROP` - drops the top of the stack (fails to match if the stack is empty)
//!
//! `WHITESPACE` and `COMMENT` should be defined manually if needed. All other rules cannot be
//! overridden.
//!
//! ## `WHITESPACE` and `COMMENT`
//!
//! When defined, these rules get matched automatically in sequences (`~`) and repetitions
//! (`*`, `+`) between expressions. Atomic rules and those rules called by atomic rules are exempt
//! from this behavior.
//!
//! These rules should be defined so as to match one whitespace character and one comment only since
//! they are run in repetitions.
//!
//! If both `WHITESPACE` and `COMMENT` are defined, this grammar:
//!
//! ```ignore
//! a = { b ~ c }
//! ```
//!
//! is effectively transformed into this one behind the scenes:
//!
//! ```ignore
//! a = { b ~ WHITESPACE* ~ (COMMENT ~ WHITESPACE*)* ~ c }
//! ```
//!
//! ## `PUSH`, `POP`, `DROP`, and `PEEK`
//!
//! `PUSH(e)` simply pushes the captured string of the expression `e` down a stack. This stack can
//! then later be used to match grammar based on its content with `POP` and `PEEK`.
//!
//! `PEEK` always matches the string at the top of stack. So, if the stack contains `["b", "a"]`
//! (`"a"` being on top), this grammar:
//!
//! ```ignore
//! a = { PEEK }
//! ```
//!
//! is effectively transformed into at parse time:
//!
//! ```ignore
//! a = { "a" }
//! ```
//!
//! `POP` works the same way with the exception that it pops the string off of the stack if the
//! match worked. With the stack from above, if `POP` matches `"a"`, the stack will be mutated
//! to `["b"]`.
//!
//! `DROP` makes it possible to remove the string at the top of the stack
//! without matching it. If the stack is nonempty, `DROP` drops the top of the
//! stack. If the stack is empty, then `DROP` fails to match.
//!
//! ### Advanced peeking
//!
//! `PEEK[start..end]` and `PEEK_ALL` allow to peek deeper into the stack. The syntax works exactly
//! like Rusts exclusive slice syntax. Additionally, negative indices can be used to indicate an
//! offset from the top. If the end lies before or at the start, the expression matches (as does
//! a `PEEK_ALL` on an empty stack). With the stack `["c", "b", "a"]` (`"a"` on top):
//!
//! ```ignore
//! fill = PUSH("c") ~ PUSH("b") ~ PUSH("a")
//! v = { PEEK_ALL } = { "a" ~ "b" ~ "c" } // top to bottom
//! w = { PEEK[..] } = { "c" ~ "b" ~ "a" } // bottom to top
//! x = { PEEK[1..2] } = { PEEK[1..-1] } = { "b" }
//! y = { PEEK[..-2] } = { PEEK[0..1] } = { "a" }
//! z = { PEEK[1..] } = { PEEK[-2..3] } = { "c" ~ "b" }
//! n = { PEEK[2..-2] } = { PEEK[2..1] } = { "" }
//! ```
//!
//! For historical reasons, `PEEK_ALL` matches from top to bottom, while `PEEK[start..end]` matches
//! from bottom to top. There is currently no syntax to match a slice of the stack top to bottom.
//!
//! ## `Rule`
//!
//! All rules defined or used in the grammar populate a generated `enum` called `Rule`. This
//! implements `pest`'s `RuleType` and can be used throughout the API.
//!
//! ## `Built-in rules`
//!
//! Pest also comes with a number of built-in rules for convenience. They are:
//!
//! * `ASCII_DIGIT` - matches a numeric character from 0..9
//! * `ASCII_NONZERO_DIGIT` - matches a numeric character from 1..9
//! * `ASCII_BIN_DIGIT` - matches a numeric character from 0..1
//! * `ASCII_OCT_DIGIT` - matches a numeric character from 0..7
//! * `ASCII_HEX_DIGIT` - matches a numeric character from 0..9 or a..f or A..F
//! * `ASCII_ALPHA_LOWER` - matches a character from a..z
//! * `ASCII_ALPHA_UPPER` - matches a character from A..Z
//! * `ASCII_ALPHA` - matches a character from a..z or A..Z
//! * `ASCII_ALPHANUMERIC` - matches a character from a..z or A..Z or 0..9
//! * `ASCII` - matches a character from \x00..\x7f
//! * `NEWLINE` - matches either "\n" or "\r\n" or "\r"
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()
}

Binary file not shown.

View File

@@ -0,0 +1 @@
{"name":"pest_derive","vers":"2.8.6","deps":[{"name":"pest","req":"^2.8.6","features":[],"optional":false,"default_features":false,"target":null,"kind":"normal","registry":"https://github.com/rust-lang/crates.io-index","package":null,"public":null,"artifact":null,"bindep_target":null,"lib":false},{"name":"pest_generator","req":"^2.8.6","features":[],"optional":false,"default_features":false,"target":null,"kind":"normal","registry":"https://github.com/rust-lang/crates.io-index","package":null,"public":null,"artifact":null,"bindep_target":null,"lib":false}],"features":{"default":["std"],"grammar-extras":["pest_generator/grammar-extras"],"not-bootstrap-in-src":["pest_generator/not-bootstrap-in-src"],"std":["pest/std","pest_generator/std"]},"features2":null,"cksum":"72c164985c499a4224a5cf02bbdaf6458b0a67b918e253be22311439a9414c16","yanked":null,"links":null,"rust_version":null,"v":2}

94
vendor/pest_derive/tests/grammar.pest vendored Normal file
View File

@@ -0,0 +1,94 @@
// pest. The Elegant Parser
// Copyright (c) 2018 Dragoș Tiselice
//
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
// 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.
string = { "abc" }
insensitive = { ^"abc" }
range = { '0'..'9' }
ident = { string }
pos_pred = { &string }
neg_pred = { !string }
double_neg_pred = { !!string }
sequence = !{ string ~ string }
sequence_compound = ${ string ~ string }
sequence_atomic = @{ string ~ string }
sequence_non_atomic = @{ sequence }
sequence_atomic_compound = @{ sequence_compound }
sequence_nested = { string ~ string }
sequence_compound_nested = ${ sequence_nested }
node_tag = { #string = string }
choice = { string | range }
choice_prefix = { | string | range }
optional = { string? }
repeat = { string* }
repeat_atomic = @{ string* }
repeat_once = { string+ }
repeat_once_atomic = @{ string+ }
repeat_min_max = { string{2, 3} }
repeat_min_max_atomic = @{ string{2, 3} }
repeat_exact = { string{2} }
repeat_min = { string{2,} }
repeat_min_atomic = @{ string{2,} }
repeat_max = { string{, 2} }
repeat_max_atomic = @{ string{, 2} }
soi_at_start = { SOI ~ string }
repeat_mutate_stack = { (PUSH('a'..'c') ~ ",")* ~ POP ~ POP ~ POP }
repeat_mutate_stack_pop_all = { (PUSH('a'..'c') ~ ",")* ~ POP_ALL }
will_fail = { repeat_mutate_stack_pop_all ~ "FAIL" }
stack_resume_after_fail = { will_fail | repeat_mutate_stack_pop_all }
peek_ = { PUSH(range) ~ PUSH(range) ~ PEEK ~ PEEK }
peek_all = { PUSH(range) ~ PUSH(range) ~ PEEK_ALL }
peek_slice_23 = { PUSH(range) ~ PUSH(range) ~ PUSH(range) ~ PUSH(range) ~ PUSH(range) ~ PEEK[1..-2] }
pop_ = { PUSH(range) ~ PUSH(range) ~ POP ~ POP }
pop_all = { PUSH(range) ~ PUSH(range) ~ POP_ALL }
pop_fail = { PUSH(range) ~ !POP ~ range ~ POP }
checkpoint_restore = ${
PUSH("") ~ (PUSH("a") ~ "b" ~ POP | DROP ~ "b" | POP ~ "a") ~ EOI
}
ascii_digits = { ASCII_DIGIT+ }
ascii_nonzero_digits = { ASCII_NONZERO_DIGIT+ }
ascii_bin_digits = { ASCII_BIN_DIGIT+ }
ascii_oct_digits = { ASCII_OCT_DIGIT+ }
ascii_hex_digits = { ASCII_HEX_DIGIT+ }
ascii_alpha_lowers = { ASCII_ALPHA_LOWER+ }
ascii_alpha_uppers = { ASCII_ALPHA_UPPER+ }
ascii_alphas = { ASCII_ALPHA+ }
ascii_alphanumerics = { ASCII_ALPHANUMERIC+ }
asciis = { ASCII+ }
newline = { NEWLINE+ }
unicode = { XID_START ~ XID_CONTINUE* }
SYMBOL = { "shadows builtin" }
han = { HAN+ }
hangul = { HANGUL+ }
hiragana = { HIRAGANA+ }
arabic = { ARABIC+ }
emoji = { EMOJI+ }
WHITESPACE = _{ " " }
COMMENT = _{ "$"+ }
// Line comment
/* 1-line multiline comment */
/*
N-line multiline comment
*/
/*
// Line comment inside multiline
/*
(Multiline inside) multiline
*/
Invalid segment of grammar below (repeated rule)
WHITESPACE = _{ "hi" }
*/

996
vendor/pest_derive/tests/grammar.rs vendored Normal file
View File

@@ -0,0 +1,996 @@
// pest. The Elegant Parser
// Copyright (c) 2018 Dragoș Tiselice
//
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
// 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.
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
use alloc::{format, vec::Vec};
#[macro_use]
extern crate pest;
#[macro_use]
extern crate pest_derive;
#[derive(Parser)]
#[grammar = "tests/grammar.pest"]
struct GrammarParser;
#[test]
fn string() {
parses_to! {
parser: GrammarParser,
input: "abc",
rule: Rule::string,
tokens: [
string(0, 3)
]
};
}
#[test]
fn insensitive() {
parses_to! {
parser: GrammarParser,
input: "aBC",
rule: Rule::insensitive,
tokens: [
insensitive(0, 3)
]
};
}
#[test]
fn range() {
parses_to! {
parser: GrammarParser,
input: "6",
rule: Rule::range,
tokens: [
range(0, 1)
]
};
}
#[test]
fn ident() {
parses_to! {
parser: GrammarParser,
input: "abc",
rule: Rule::ident,
tokens: [
ident(0, 3, [
string(0, 3)
])
]
};
}
#[test]
fn pos_pred() {
parses_to! {
parser: GrammarParser,
input: "abc",
rule: Rule::pos_pred,
tokens: [
pos_pred(0, 0)
]
};
}
#[test]
fn neg_pred() {
parses_to! {
parser: GrammarParser,
input: "",
rule: Rule::neg_pred,
tokens: [
neg_pred(0, 0)
]
};
}
#[test]
fn double_neg_pred() {
parses_to! {
parser: GrammarParser,
input: "abc",
rule: Rule::double_neg_pred,
tokens: [
double_neg_pred(0, 0)
]
};
}
#[test]
fn sequence() {
parses_to! {
parser: GrammarParser,
input: "abc abc",
rule: Rule::sequence,
tokens: [
sequence(0, 9, [
string(0, 3),
string(6, 9)
])
]
};
}
#[test]
fn sequence_compound() {
parses_to! {
parser: GrammarParser,
input: "abcabc",
rule: Rule::sequence_compound,
tokens: [
sequence_compound(0, 6, [
string(0, 3),
string(3, 6)
])
]
};
}
#[test]
fn sequence_atomic() {
parses_to! {
parser: GrammarParser,
input: "abcabc",
rule: Rule::sequence_atomic,
tokens: [
sequence_atomic(0, 6)
]
};
}
#[test]
fn sequence_non_atomic() {
parses_to! {
parser: GrammarParser,
input: "abc abc",
rule: Rule::sequence_non_atomic,
tokens: [
sequence_non_atomic(0, 9, [
sequence(0, 9, [
string(0, 3),
string(6, 9)
])
])
]
};
}
#[test]
#[should_panic]
fn sequence_atomic_space() {
parses_to! {
parser: GrammarParser,
input: "abc abc",
rule: Rule::sequence_atomic,
tokens: []
};
}
#[test]
fn sequence_atomic_compound() {
parses_to! {
parser: GrammarParser,
input: "abcabc",
rule: Rule::sequence_atomic_compound,
tokens: [
sequence_atomic_compound(0, 6, [
sequence_compound(0, 6, [
string(0, 3),
string(3, 6)
])
])
]
};
}
#[test]
fn sequence_compound_nested() {
parses_to! {
parser: GrammarParser,
input: "abcabc",
rule: Rule::sequence_compound_nested,
tokens: [
sequence_compound_nested(0, 6, [
sequence_nested(0, 6, [
string(0, 3),
string(3, 6)
])
])
]
};
}
#[test]
#[should_panic]
fn sequence_compound_nested_space() {
parses_to! {
parser: GrammarParser,
input: "abc abc",
rule: Rule::sequence_compound_nested,
tokens: []
};
}
#[test]
fn choice_string() {
parses_to! {
parser: GrammarParser,
input: "abc",
rule: Rule::choice,
tokens: [
choice(0, 3, [
string(0, 3)
])
]
};
}
#[test]
fn choice_range() {
parses_to! {
parser: GrammarParser,
input: "0",
rule: Rule::choice,
tokens: [
choice(0, 1, [
range(0, 1)
])
]
};
}
#[test]
fn choice_prefix() {
parses_to! {
parser: GrammarParser,
input: "abc",
rule: Rule::choice_prefix,
tokens: [
choice_prefix(0, 3, [
string(0, 3)
])
]
};
}
#[test]
fn node_tag() {
parses_to! {
parser: GrammarParser,
input: "abc",
rule: Rule::node_tag,
tokens: [
node_tag(0, 3, [
string(0, 3)
])
]
};
}
#[test]
fn optional_string() {
parses_to! {
parser: GrammarParser,
input: "abc",
rule: Rule::optional,
tokens: [
optional(0, 3, [
string(0, 3)
])
]
};
}
#[test]
fn optional_empty() {
parses_to! {
parser: GrammarParser,
input: "",
rule: Rule::optional,
tokens: [
optional(0, 0)
]
};
}
#[test]
fn repeat_empty() {
parses_to! {
parser: GrammarParser,
input: "",
rule: Rule::repeat,
tokens: [
repeat(0, 0)
]
};
}
#[test]
fn repeat_strings() {
parses_to! {
parser: GrammarParser,
input: "abc abc",
rule: Rule::repeat,
tokens: [
repeat(0, 9, [
string(0, 3),
string(6, 9)
])
]
};
}
#[test]
fn repeat_atomic_empty() {
parses_to! {
parser: GrammarParser,
input: "",
rule: Rule::repeat_atomic,
tokens: [
repeat_atomic(0, 0)
]
};
}
#[test]
fn repeat_atomic_strings() {
parses_to! {
parser: GrammarParser,
input: "abcabc",
rule: Rule::repeat_atomic,
tokens: [
repeat_atomic(0, 6)
]
};
}
#[test]
#[should_panic]
fn repeat_atomic_space() {
parses_to! {
parser: GrammarParser,
input: "abc abc",
rule: Rule::repeat_atomic,
tokens: []
};
}
#[test]
#[should_panic]
fn repeat_once_empty() {
parses_to! {
parser: GrammarParser,
input: "",
rule: Rule::repeat_once,
tokens: []
};
}
#[test]
fn repeat_once_strings() {
parses_to! {
parser: GrammarParser,
input: "abc abc",
rule: Rule::repeat_once,
tokens: [
repeat_once(0, 9, [
string(0, 3),
string(6, 9)
])
]
};
}
#[test]
#[should_panic]
fn repeat_once_atomic_empty() {
parses_to! {
parser: GrammarParser,
input: "",
rule: Rule::repeat_once_atomic,
tokens: []
};
}
#[test]
fn repeat_once_atomic_strings() {
parses_to! {
parser: GrammarParser,
input: "abcabc",
rule: Rule::repeat_once_atomic,
tokens: [
repeat_once_atomic(0, 6)
]
};
}
#[test]
#[should_panic]
fn repeat_once_atomic_space() {
parses_to! {
parser: GrammarParser,
input: "abc abc",
rule: Rule::repeat_once_atomic,
tokens: []
};
}
#[test]
fn repeat_min_max_twice() {
parses_to! {
parser: GrammarParser,
input: "abc abc",
rule: Rule::repeat_min_max,
tokens: [
repeat_min_max(0, 7, [
string(0, 3),
string(4, 7)
])
]
};
}
#[test]
fn repeat_min_max_thrice() {
parses_to! {
parser: GrammarParser,
input: "abc abc abc",
rule: Rule::repeat_min_max,
tokens: [
repeat_min_max(0, 11, [
string(0, 3),
string(4, 7),
string(8, 11)
])
]
};
}
#[test]
fn repeat_min_max_atomic_twice() {
parses_to! {
parser: GrammarParser,
input: "abcabc",
rule: Rule::repeat_min_max_atomic,
tokens: [
repeat_min_max_atomic(0, 6)
]
};
}
#[test]
fn repeat_min_max_atomic_thrice() {
parses_to! {
parser: GrammarParser,
input: "abcabcabc",
rule: Rule::repeat_min_max_atomic,
tokens: [
repeat_min_max_atomic(0, 9)
]
};
}
#[test]
#[should_panic]
fn repeat_min_max_atomic_space() {
parses_to! {
parser: GrammarParser,
input: "abc abc",
rule: Rule::repeat_min_max_atomic,
tokens: []
};
}
#[test]
fn repeat_exact() {
parses_to! {
parser: GrammarParser,
input: "abc abc",
rule: Rule::repeat_exact,
tokens: [
repeat_exact(0, 7, [
string(0, 3),
string(4, 7)
])
]
};
}
#[test]
#[should_panic]
fn repeat_min_once() {
parses_to! {
parser: GrammarParser,
input: "abc",
rule: Rule::repeat_min,
tokens: []
};
}
#[test]
fn repeat_min_twice() {
parses_to! {
parser: GrammarParser,
input: "abc abc",
rule: Rule::repeat_min,
tokens: [
repeat_min(0, 7, [
string(0, 3),
string(4, 7)
])
]
};
}
#[test]
fn repeat_min_thrice() {
parses_to! {
parser: GrammarParser,
input: "abc abc abc",
rule: Rule::repeat_min,
tokens: [
repeat_min(0, 12, [
string(0, 3),
string(4, 7),
string(9, 12)
])
]
};
}
#[test]
#[should_panic]
fn repeat_min_atomic_once() {
parses_to! {
parser: GrammarParser,
input: "abc",
rule: Rule::repeat_min_atomic,
tokens: []
};
}
#[test]
fn repeat_min_atomic_twice() {
parses_to! {
parser: GrammarParser,
input: "abcabc",
rule: Rule::repeat_min_atomic,
tokens: [
repeat_min_atomic(0, 6)
]
};
}
#[test]
fn repeat_min_atomic_thrice() {
parses_to! {
parser: GrammarParser,
input: "abcabcabc",
rule: Rule::repeat_min_atomic,
tokens: [
repeat_min_atomic(0, 9)
]
};
}
#[test]
#[should_panic]
fn repeat_min_atomic_space() {
parses_to! {
parser: GrammarParser,
input: "abc abc",
rule: Rule::repeat_min_atomic,
tokens: []
};
}
#[test]
fn repeat_max_once() {
parses_to! {
parser: GrammarParser,
input: "abc",
rule: Rule::repeat_max,
tokens: [
repeat_max(0, 3, [
string(0, 3)
])
]
};
}
#[test]
fn repeat_max_twice() {
parses_to! {
parser: GrammarParser,
input: "abc abc",
rule: Rule::repeat_max,
tokens: [
repeat_max(0, 7, [
string(0, 3),
string(4, 7)
])
]
};
}
#[test]
#[should_panic]
fn repeat_max_thrice() {
parses_to! {
parser: GrammarParser,
input: "abc abc",
rule: Rule::repeat_max,
tokens: []
};
}
#[test]
fn repeat_max_atomic_once() {
parses_to! {
parser: GrammarParser,
input: "abc",
rule: Rule::repeat_max_atomic,
tokens: [
repeat_max_atomic(0, 3)
]
};
}
#[test]
fn repeat_max_atomic_twice() {
parses_to! {
parser: GrammarParser,
input: "abcabc",
rule: Rule::repeat_max_atomic,
tokens: [
repeat_max_atomic(0, 6)
]
};
}
#[test]
#[should_panic]
fn repeat_max_atomic_thrice() {
parses_to! {
parser: GrammarParser,
input: "abcabcabc",
rule: Rule::repeat_max_atomic,
tokens: []
};
}
#[test]
#[should_panic]
fn repeat_max_atomic_space() {
parses_to! {
parser: GrammarParser,
input: "abc abc",
rule: Rule::repeat_max_atomic,
tokens: []
};
}
#[test]
fn repeat_comment() {
parses_to! {
parser: GrammarParser,
input: "abc$$$ $$$abc",
rule: Rule::repeat_once,
tokens: [
repeat_once(0, 13, [
string(0, 3),
string(10, 13)
])
]
};
}
#[test]
fn soi_at_start() {
parses_to! {
parser: GrammarParser,
input: "abc",
rule: Rule::soi_at_start,
tokens: [
soi_at_start(0, 3, [
string(0, 3)
])
]
};
}
#[test]
fn peek() {
parses_to! {
parser: GrammarParser,
input: "0111",
rule: Rule::peek_,
tokens: [
peek_(0, 4, [
range(0, 1),
range(1, 2)
])
]
};
}
#[test]
fn peek_all() {
parses_to! {
parser: GrammarParser,
input: "0110",
rule: Rule::peek_all,
tokens: [
peek_all(0, 4, [
range(0, 1),
range(1, 2)
])
]
};
}
#[test]
fn peek_slice_23() {
parses_to! {
parser: GrammarParser,
input: "0123412",
rule: Rule::peek_slice_23,
tokens: [
peek_slice_23(0, 7, [
range(0, 1),
range(1, 2),
range(2, 3),
range(3, 4),
range(4, 5),
])
]
};
}
#[test]
fn pop() {
parses_to! {
parser: GrammarParser,
input: "0110",
rule: Rule::pop_,
tokens: [
pop_(0, 4, [
range(0, 1),
range(1, 2)
])
]
};
}
#[test]
fn pop_all() {
parses_to! {
parser: GrammarParser,
input: "0110",
rule: Rule::pop_all,
tokens: [
pop_all(0, 4, [
range(0, 1),
range(1, 2)
])
]
};
}
#[test]
fn pop_fail() {
parses_to! {
parser: GrammarParser,
input: "010",
rule: Rule::pop_fail,
tokens: [
pop_fail(0, 3, [
range(0, 1),
range(1, 2)
])
]
};
}
#[test]
fn repeat_mutate_stack() {
parses_to! {
parser: GrammarParser,
input: "a,b,c,cba",
rule: Rule::repeat_mutate_stack,
tokens: [
repeat_mutate_stack(0, 9)
]
};
}
#[test]
fn stack_resume_after_fail() {
parses_to! {
parser: GrammarParser,
input: "a,b,c,cba",
rule: Rule::stack_resume_after_fail,
tokens: [
stack_resume_after_fail(0, 9, [
repeat_mutate_stack_pop_all(0, 9)
])
]
};
}
#[test]
fn checkpoint_restore() {
parses_to! {
parser: GrammarParser,
input: "a",
rule: Rule::checkpoint_restore,
tokens: [
checkpoint_restore(0, 1, [EOI(1, 1)])
]
};
}
#[test]
fn ascii_digits() {
parses_to! {
parser: GrammarParser,
input: "6",
rule: Rule::ascii_digits,
tokens: [
ascii_digits(0, 1)
]
};
}
#[test]
fn ascii_nonzero_digits() {
parses_to! {
parser: GrammarParser,
input: "5",
rule: Rule::ascii_nonzero_digits,
tokens: [
ascii_nonzero_digits(0, 1)
]
};
}
#[test]
fn ascii_bin_digits() {
parses_to! {
parser: GrammarParser,
input: "1",
rule: Rule::ascii_bin_digits,
tokens: [
ascii_bin_digits(0, 1)
]
};
}
#[test]
fn ascii_oct_digits() {
parses_to! {
parser: GrammarParser,
input: "3",
rule: Rule::ascii_oct_digits,
tokens: [
ascii_oct_digits(0, 1)
]
};
}
#[test]
fn ascii_hex_digits() {
parses_to! {
parser: GrammarParser,
input: "6bC",
rule: Rule::ascii_hex_digits,
tokens: [
ascii_hex_digits(0, 3)
]
};
}
#[test]
fn ascii_alpha_lowers() {
parses_to! {
parser: GrammarParser,
input: "a",
rule: Rule::ascii_alpha_lowers,
tokens: [
ascii_alpha_lowers(0, 1)
]
};
}
#[test]
fn ascii_alpha_uppers() {
parses_to! {
parser: GrammarParser,
input: "K",
rule: Rule::ascii_alpha_uppers,
tokens: [
ascii_alpha_uppers(0, 1)
]
};
}
#[test]
fn ascii_alphas() {
parses_to! {
parser: GrammarParser,
input: "wF",
rule: Rule::ascii_alphas,
tokens: [
ascii_alphas(0, 2)
]
};
}
#[test]
fn ascii_alphanumerics() {
parses_to! {
parser: GrammarParser,
input: "4jU",
rule: Rule::ascii_alphanumerics,
tokens: [
ascii_alphanumerics(0, 3)
]
};
}
#[test]
fn asciis() {
parses_to! {
parser: GrammarParser,
input: "x02",
rule: Rule::asciis,
tokens: [
asciis(0, 3)
]
};
}
#[test]
fn newline() {
parses_to! {
parser: GrammarParser,
input: "\n\r\n\r",
rule: Rule::newline,
tokens: [
newline(0, 4)
]
};
}
#[test]
fn unicode() {
parses_to! {
parser: GrammarParser,
input: "نامهای",
rule: Rule::unicode,
tokens: [
unicode(0, 12)
]
}
}
#[test]
fn shadowing() {
parses_to! {
parser: GrammarParser,
input: "shadows builtin",
rule: Rule::SYMBOL,
tokens: [
SYMBOL(0, 15)
]
}
}

View File

@@ -0,0 +1,30 @@
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
// 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.
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
use alloc::{format, vec::Vec};
#[macro_use]
extern crate pest;
#[macro_use]
extern crate pest_derive;
#[derive(Parser)]
#[grammar_inline = "string = { \"abc\" }"]
struct GrammarParser;
#[test]
fn inline_string() {
parses_to! {
parser: GrammarParser,
input: "abc",
rule: Rule::string,
tokens: [
string(0, 3)
]
};
}

14
vendor/pest_derive/tests/implicit.pest vendored Normal file
View File

@@ -0,0 +1,14 @@
program = _{ SOI ~ implicit ~ EOI }
implicit= ${ #head = or ~ #tail = (WHITESPACE+ ~ or)* }
or = !{ #more_and = and ~ (or_op ~ and)+ | #one_and = and }
and = { #more_comp = comp ~ (and_op ~ comp)+ | #one_comp = comp }
comp = { #more_array = array ~ eq_op ~ array | #one_array = array }
array = ${ term }
term = _{ ASCII_ALPHANUMERIC+ }
or_op = { "||" }
and_op = { "&&" }
eq_op = { "=" }
WHITESPACE = _{ " " | "\t" | NEWLINE }

46
vendor/pest_derive/tests/implicit.rs vendored Normal file
View File

@@ -0,0 +1,46 @@
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
// 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.
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
extern crate pest;
extern crate pest_derive;
#[cfg(feature = "grammar-extras")]
use pest::Parser;
use pest_derive::Parser;
#[derive(Parser)]
#[grammar = "../tests/implicit.pest"]
struct TestImplicitParser;
#[test]
#[cfg(feature = "grammar-extras")]
fn test_implicit_whitespace() {
// this failed to parse due to a bug in the optimizer
// see: https://github.com/pest-parser/pest/issues/762#issuecomment-1375374868
let successful_parse = TestImplicitParser::parse(Rule::program, "a a");
assert!(successful_parse.is_ok());
// dbg!(&successful_parse);
let pairs = successful_parse.unwrap();
assert!(pairs.find_first_tagged("head").is_some());
assert!(pairs.find_first_tagged("tail").is_some());
assert!(pairs.find_first_tagged("more_and").is_none());
assert!(pairs.find_first_tagged("more_comp").is_none());
assert!(pairs.find_first_tagged("more_array").is_none());
assert_eq!(pairs.clone().find_tagged("one_and").count(), 2);
assert_eq!(pairs.clone().find_tagged("one_comp").count(), 2);
assert_eq!(pairs.find_tagged("one_array").count(), 2);
}
#[test]
#[cfg(feature = "grammar-extras")]
fn test_implicit_whitespace_multitag() {
let successful_parse = TestImplicitParser::parse(Rule::program, "a a a");
assert!(successful_parse.is_ok());
let pairs = successful_parse.unwrap();
assert_eq!(pairs.clone().find_tagged("tail").count(), 2);
}

18
vendor/pest_derive/tests/lists.pest vendored Normal file
View File

@@ -0,0 +1,18 @@
// pest. The Elegant Parser
// Copyright (c) 2018 Dragoș Tiselice
//
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
// 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.
item = { (!"\n" ~ ANY)* }
lists = _{ lines ~ EOI }
lines = _{ top_first ~ ("\n" ~ top_continue)* }
top_first = _{ "- " ~ item ~ ("\n" ~ children)? }
top_continue = _{ PEEK_ALL ~ "- " ~ item ~ ("\n" ~ children)? }
indentation = _{ (" " | "\t")+ }
children = { PEEK_ALL ~ PUSH(indentation) ~ lines ~ DROP }

125
vendor/pest_derive/tests/lists.rs vendored Normal file
View File

@@ -0,0 +1,125 @@
// pest. The Elegant Parser
// Copyright (c) 2018 Dragoș Tiselice
//
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
// 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.
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
use alloc::{format, vec::Vec};
#[macro_use]
extern crate pest;
#[macro_use]
extern crate pest_derive;
#[derive(Parser)]
#[grammar = "../tests/lists.pest"]
struct ListsParser;
#[test]
fn item() {
parses_to! {
parser: ListsParser,
input: "- a",
rule: Rule::lists,
tokens: [
item(2, 3)
]
};
}
#[test]
fn items() {
parses_to! {
parser: ListsParser,
input: "- a\n- b",
rule: Rule::lists,
tokens: [
item(2, 3),
item(6, 7)
]
};
}
#[test]
fn children() {
parses_to! {
parser: ListsParser,
input: " - b",
rule: Rule::children,
tokens: [
children(0, 5, [
item(4, 5)
])
]
};
}
#[test]
fn nested_item() {
parses_to! {
parser: ListsParser,
input: "- a\n - b",
rule: Rule::lists,
tokens: [
item(2, 3),
children(4, 9, [
item(8, 9)
])
]
};
}
#[test]
fn nested_items() {
parses_to! {
parser: ListsParser,
input: "- a\n - b\n - c",
rule: Rule::lists,
tokens: [
item(2, 3),
children(4, 15, [
item(8, 9),
item(14, 15)
])
]
};
}
#[test]
fn nested_two_levels() {
parses_to! {
parser: ListsParser,
input: "- a\n - b\n - c",
rule: Rule::lists,
tokens: [
item(2, 3),
children(4, 17, [
item(8, 9),
children(10, 17, [
item(16, 17)
])
])
]
};
}
#[test]
fn nested_then_not() {
parses_to! {
parser: ListsParser,
input: "- a\n - b\n- c",
rule: Rule::lists,
tokens: [
item(2, 3),
children(4, 9, [
item(8, 9)
]),
item(12, 13)
]
};
}

View File

@@ -0,0 +1,5 @@
WHITESPACE = _{ " " | "\r" | "\n" | "\t" }
identifier = { (ASCII_ALPHA | "_")+ }
assign = { identifier ~ "<-" ~ identifier }

29
vendor/pest_derive/tests/oneormore.rs vendored Normal file
View File

@@ -0,0 +1,29 @@
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
#[cfg(not(feature = "std"))]
use alloc::{format, vec::Vec};
#[cfg(feature = "grammar-extras")]
use pest::Parser;
use pest_derive::Parser;
#[derive(Parser)]
#[grammar = "../tests/oneormore.pest"]
pub struct OneOrMoreParser;
#[test]
#[cfg(feature = "grammar-extras")]
pub fn test_one_or_more() {
let result = OneOrMoreParser::parse(Rule::assign, "k <- b\n");
assert!(result.is_ok());
let mut pairs = result.unwrap();
let pair = pairs.next().unwrap();
assert_eq!(pair.as_rule(), Rule::assign);
let mut inner = pair.into_inner();
let lhs = inner.next().unwrap();
assert_eq!(lhs.as_rule(), Rule::identifier);
assert_eq!(lhs.as_str(), "k");
let rhs = inner.next().unwrap();
assert_eq!(rhs.as_rule(), Rule::identifier);
assert_eq!(rhs.as_str(), "b");
}

8
vendor/pest_derive/tests/opt.pest vendored Normal file
View File

@@ -0,0 +1,8 @@
expr = {
SOI ~
#prefix=(STAR)? ~ #suffix=DOT?
~ EOI
}
STAR={"*"}
DOT={"."}

42
vendor/pest_derive/tests/opt.rs vendored Normal file
View File

@@ -0,0 +1,42 @@
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
// 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.
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
extern crate pest;
extern crate pest_derive;
#[cfg(feature = "grammar-extras")]
use pest::Parser;
use pest_derive::Parser;
#[derive(Parser)]
#[grammar = "../tests/opt.pest"]
struct TestOptParser;
#[test]
#[cfg(feature = "grammar-extras")]
fn test_opt_tag() {
let successful_parse = TestOptParser::parse(Rule::expr, "*");
assert!(successful_parse.is_ok());
let pairs = successful_parse.unwrap();
assert!(pairs.find_first_tagged("prefix").is_some());
assert!(pairs.find_first_tagged("suffix").is_none());
// Test with no STAR or DOT
let parse_no_components = TestOptParser::parse(Rule::expr, "");
assert!(parse_no_components.is_ok());
let pairs_no_components = parse_no_components.unwrap();
assert!(pairs_no_components.find_first_tagged("prefix").is_none());
assert!(pairs_no_components.find_first_tagged("suffix").is_none());
// Test with only DOT
let parse_only_dot = TestOptParser::parse(Rule::expr, ".");
assert!(parse_only_dot.is_ok());
let pairs_only_dot = parse_only_dot.unwrap();
assert!(pairs_only_dot.find_first_tagged("prefix").is_none());
assert!(pairs_only_dot.find_first_tagged("suffix").is_some());
}

27
vendor/pest_derive/tests/reporting.pest vendored Normal file
View File

@@ -0,0 +1,27 @@
// pest. The Elegant Parser
// Copyright (c) 2018 Dragoș Tiselice
//
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
// 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.
a = { "a" }
b = { "b" }
c = { "c" }
d = { ANY }
choices = _{ a | b | c }
choices_no_progress = { a | b | c }
choices_a_progress = { a ~ a | b | c }
choices_b_progress = { a | b ~ b | c }
level1 = _{ level2 }
level2 = _{ a | b | c }
negative = _{ !d }
negative_match = _{ !a ~ b }
mixed = _{ !d | a }
mixed_progress = _{ (!d | a | b) ~ a }

129
vendor/pest_derive/tests/reporting.rs vendored Normal file
View File

@@ -0,0 +1,129 @@
// pest. The Elegant Parser
// Copyright (c) 2018 Dragoș Tiselice
//
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
// 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.
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
use alloc::vec;
#[macro_use]
extern crate pest;
#[macro_use]
extern crate pest_derive;
#[derive(Parser)]
#[grammar = "../tests/reporting.pest"]
struct ReportingParser;
#[test]
fn choices() {
fails_with! {
parser: ReportingParser,
input: "x",
rule: Rule::choices,
positives: vec![Rule::a, Rule::b, Rule::c],
negatives: vec![],
pos: 0
};
}
#[test]
fn choices_no_progress() {
fails_with! {
parser: ReportingParser,
input: "x",
rule: Rule::choices_no_progress,
positives: vec![Rule::choices_no_progress],
negatives: vec![],
pos: 0
};
}
#[test]
fn choices_a_progress() {
fails_with! {
parser: ReportingParser,
input: "a",
rule: Rule::choices_a_progress,
positives: vec![Rule::a],
negatives: vec![],
pos: 1
};
}
#[test]
fn choices_b_progress() {
fails_with! {
parser: ReportingParser,
input: "b",
rule: Rule::choices_b_progress,
positives: vec![Rule::b],
negatives: vec![],
pos: 1
};
}
#[test]
fn nested() {
fails_with! {
parser: ReportingParser,
input: "x",
rule: Rule::level1,
positives: vec![Rule::a, Rule::b, Rule::c],
negatives: vec![],
pos: 0
};
}
#[test]
fn negative() {
fails_with! {
parser: ReportingParser,
input: "x",
rule: Rule::negative,
positives: vec![],
negatives: vec![Rule::d],
pos: 0
};
}
#[test]
fn negative_match() {
fails_with! {
parser: ReportingParser,
input: "x",
rule: Rule::negative_match,
positives: vec![Rule::b],
negatives: vec![],
pos: 0
};
}
#[test]
fn mixed() {
fails_with! {
parser: ReportingParser,
input: "x",
rule: Rule::mixed,
positives: vec![Rule::a],
negatives: vec![Rule::d],
pos: 0
};
}
#[test]
fn mixed_progress() {
fails_with! {
parser: ReportingParser,
input: "b",
rule: Rule::mixed_progress,
positives: vec![Rule::a],
negatives: vec![],
pos: 1
};
}

View File

@@ -0,0 +1,9 @@
Quote = _{ _QuoteStart ~ QuoteChars ~ _QuoteEnd }
_QuoteStart = _{
( "(" ~ PUSH_LITERAL(")") )
| ( "<" ~ PUSH_LITERAL(">") )
}
_QuoteEnd = _{ POP }
QuoteChars = { (!PEEK ~ ANY)* }

74
vendor/pest_derive/tests/surround.rs vendored Normal file
View File

@@ -0,0 +1,74 @@
// pest. The Elegant Parser
//
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
// 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.
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
#[cfg(not(feature = "std"))]
use alloc::{format, vec, vec::Vec};
#[macro_use]
extern crate pest;
extern crate pest_derive;
#[cfg(feature = "grammar-extras")]
use pest_derive::Parser;
/// Surround-string parser.
///
/// This is a simple grammar of string parsing, where the strings end with a different delimiter char than what they
/// start with. The allowable forms are:
///
/// ```text
/// (foo)
/// <bar>
/// ```
///
/// To keep things simple, strings do not support any escape sequences.
#[derive(Parser)]
#[grammar = "../tests/surround.pest"]
#[cfg(feature = "grammar-extras")]
pub struct SurroundParser;
#[test]
#[cfg(feature = "grammar-extras")]
fn surround_parenthesis() {
parses_to! {
parser: SurroundParser,
input: "(hello world)",
rule: Rule::Quote,
tokens: [
QuoteChars(1, 12)
]
}
}
#[test]
#[cfg(feature = "grammar-extras")]
fn surround_angle_brackets() {
parses_to! {
parser: SurroundParser,
input: "<hello world>",
rule: Rule::Quote,
tokens: [
QuoteChars(1, 12)
]
}
}
#[test]
#[cfg(feature = "grammar-extras")]
fn start_with_one_end_with_other() {
fails_with! {
parser: SurroundParser,
input: "(hello world>",
rule: Rule::Quote,
positives: vec![],
negatives: vec![],
pos: 0
}
}