Vendor dependencies

This commit is contained in:
2026-08-01 16:11:49 +03:00
parent 7f139a0241
commit 6b5e7f0f8b
29706 changed files with 9575646 additions and 0 deletions
+96
View File
@@ -0,0 +1,96 @@
// 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 }
neg_pred_with_tag = { (!neg_pred_tag_bar ~ #tag_foo = string)+ }
neg_pred_tag_bar = _{ #tag_bar = range }
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" }
*/
File diff suppressed because it is too large Load Diff
@@ -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
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
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
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
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)
]
};
}
+5
View File
@@ -0,0 +1,5 @@
WHITESPACE = _{ " " | "\r" | "\n" | "\t" }
identifier = { (ASCII_ALPHA | "_")+ }
assign = { identifier ~ "<-" ~ identifier }
+29
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
View File
@@ -0,0 +1,8 @@
expr = {
SOI ~
#prefix=(STAR)? ~ #suffix=DOT?
~ EOI
}
STAR={"*"}
DOT={"."}
+42
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
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
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
};
}
+9
View File
@@ -0,0 +1,9 @@
Quote = _{ _QuoteStart ~ QuoteChars ~ _QuoteEnd }
_QuoteStart = _{
( "(" ~ PUSH_LITERAL(")") )
| ( "<" ~ PUSH_LITERAL(">") )
}
_QuoteEnd = _{ POP }
QuoteChars = { (!PEEK ~ ANY)* }
+74
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
}
}