From dae7bb272bace95576374b8a3a002c135e33c3c3 Mon Sep 17 00:00:00 2001 From: Soispha Date: Sat, 23 Dec 2023 22:13:28 +0100 Subject: [PATCH] chore(trinitry): Extract to separate repository --- trinitry/.gitignore | 6 - trinitry/Cargo.toml | 14 - trinitry/docs-header.html | 45 -- trinitry/src/lib.rs | 192 ----- trinitry/src/tests.rs | 1365 ------------------------------------ trinitry/src/trinitry.pest | 25 - trinitry/update.sh | 88 --- update.sh | 13 - 8 files changed, 1748 deletions(-) delete mode 100644 trinitry/.gitignore delete mode 100644 trinitry/Cargo.toml delete mode 100644 trinitry/docs-header.html delete mode 100644 trinitry/src/lib.rs delete mode 100644 trinitry/src/tests.rs delete mode 100644 trinitry/src/trinitry.pest delete mode 100755 trinitry/update.sh diff --git a/trinitry/.gitignore b/trinitry/.gitignore deleted file mode 100644 index 4424904..0000000 --- a/trinitry/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -# build -/target -/result - -# It is a library -Cargo.lock diff --git a/trinitry/Cargo.toml b/trinitry/Cargo.toml deleted file mode 100644 index 7e5737c..0000000 --- a/trinitry/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "trinitry" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -pest = "2.7.5" -pest_derive = {version = "2.7.5", features = ["grammar-extras"]} - -# The header imports katex, a js latex parser, into the doc comments -[package.metadata.docs.rs] -rustdoc-args = [ "--html-in-header", "./docs-header.html" ] diff --git a/trinitry/docs-header.html b/trinitry/docs-header.html deleted file mode 100644 index beafd4d..0000000 --- a/trinitry/docs-header.html +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - - - - diff --git a/trinitry/src/lib.rs b/trinitry/src/lib.rs deleted file mode 100644 index 2af4dd3..0000000 --- a/trinitry/src/lib.rs +++ /dev/null @@ -1,192 +0,0 @@ -//! This crate is a parser for the 'Trinitry' (not 'Trinity') language, used to map all sort of -//! Functions to a memorable command. -//! -//! This parser is more of a validator, as Trinitry does not support any language features besides -//! the aforementioned commands and arguments. That includes some simple constructs like: '||' (OR) -//! or '&&' (AND). If you need these features, simple write them in the language, you've written your -//! Function in. -//! -//! # General specification -//! ## Command -//! Basically every command can be a series of alphanumeric ASCII values. -//! -//! Correctly spoken, the Language, containing all valid command names, is just the Kleene closure -//! over an Alphabet $\Sigma$, which contains all alphanumeric characters: -//! $$ \Sigma_{cmd} = \\{x | 0 \leqslant x \leqslant 9\\} \cup \\{x | "a" \leqslant x \leqslant "z"\\} \cup \\{x | "A" \leqslant x \leqslant "Z"\\} \cup \\{"\\_", "\text{-}", "."\\} $$ -//! -//! ## Argument -//! Arguments are similar to the command, although they can also contain spaces and quotes, -//! if it's quoted and additional characters (here notated as "$\\dots{}$"): -//! $$ \Sigma_{args-quoted} = \Sigma_{cmd} \cup \\{"\\text{"}", "\\ ", \\dots{}\\} $$ -//! $$ \Sigma_{args-single-quoted} = \Sigma_{cmd} \cup \\{"'", "\\ ", \\dots{}\\} $$ -//! $$ \Sigma_{args} = \Sigma_{cmd} \cup \\{\\dots{}\\} $$ -//! Look at the [trinitry.pest](../../../src/trinitry.pest) file for a full list of the additional -//! allowed characters. -//! -//! # Examples -//! ## Command -//! A valid command would be something like that: -//! ```text -//! quit -//! ``` -//! something like that would not be valid however, as Trinitry does not support these 'complex' -//! language features: -//! ```text -//! write && quit -//! ``` -//! ## Arguments -//! A valid argumented command would be: -//! ```text -//! lua "function() print('Hi!') end" -//! ``` -//! Whilst this would not be valid (that is, it would very likely not be what you want): -//! ```text -//! lua "function() print("Hi!") end" -//! ``` -//! as the double quotes in the print statement actually unquote the argument, leaving you with -//! three arguments: -//! 1. `function() print(` -//! 1. `Hi!` -//! 1. `) end` -use std::fmt::Display; - -use pest::{error::Error, Parser}; -use pest_derive::Parser; - -#[derive(Parser)] -#[grammar = "trinitry.pest"] -pub struct Trinitry { - command: String, - arguments: Vec, -} - -impl Trinitry { - pub fn new(input: &str) -> Result> { - let parsed = Self::parse(Rule::trinitry, input)?; - - let command = { - let command: Vec<_> = parsed.clone().find_tagged("command").collect(); - - // Ensure that we have only one command - // This should be ensured by the grammar, thus the 'debug_assert' - debug_assert_eq!(command.len(), 1); - - // PERFORMANCE(@soispha): Replace this with `mem::take` (when pairs implements Default) - // <2023-11-01> - command - .first() - .expect("This should contain exactly one element") - .to_owned() - }; - let arguments: Vec<_> = parsed.clone().find_tagged("argument").collect(); - - Ok(Trinitry { - command: command.as_str().to_owned(), - arguments: arguments - .iter() - .map(|arg| { - let mut arg = arg.as_str().trim(); - arg = if let Some(new_arg) = arg.strip_prefix("\"") { - new_arg - } else { - arg - }; - arg = if let Some(new_arg) = arg.strip_suffix("\"") { - new_arg - } else { - arg - }; - - arg = if let Some(new_arg) = arg.strip_prefix("'") { - new_arg - } else { - arg - }; - arg = if let Some(new_arg) = arg.strip_suffix("'") { - new_arg - } else { - arg - }; - arg.to_owned() - }) - .collect(), - }) - } -} - -impl Display for Trinitry { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - if self.arguments.is_empty() { - f.write_str(&self.command) - } else { - f.write_fmt(format_args!( - "{} {}", - &self.command, - &self.arguments.join(" ") - )) - } - } -} - -mod tests; - -#[cfg(test)] -mod test { - use crate::Trinitry; - - #[test] - fn parse_cmd() { - let string = "quit"; - let p = Trinitry::new(string).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(&p.command, "quit"); - assert!(&p.arguments.is_empty()); - } - - #[test] - fn parse_arg_clean() { - let string = r##"lua print("Hi")"##; - let p = Trinitry::new(string).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(&p.command, "lua"); - assert_eq!(&p.arguments[0], r#"print("Hi")"#); - } - - #[test] - fn parse_arg_quote() { - let string = r##"write "some 'file' name""##; - let p = Trinitry::new(string).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(&p.command, "write"); - assert_eq!(&p.arguments[0], "some 'file' name"); - } - - #[test] - fn parse_arg_single_quote() { - let string = r##"write 'some "file" name'"##; - let p = Trinitry::new(string).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(&p.command, "write"); - assert_eq!(&p.arguments[0], "some \"file\" name"); - } - - #[test] - fn parse_arg_multi() { - let string = r##"write 'some "file" name' "other name" last"##; - let p = Trinitry::new(string).unwrap_or_else(|e| { - panic!("{}", e); - }); - - let expected_args = vec!["some \"file\" name", "other name", "last"] - .iter() - .map(|str| (*str).to_owned()) - .collect::>(); - - assert_eq!(&p.command, "write"); - assert_eq!(&p.arguments, &expected_args); - } -} diff --git a/trinitry/src/tests.rs b/trinitry/src/tests.rs deleted file mode 100644 index 4a65b94..0000000 --- a/trinitry/src/tests.rs +++ /dev/null @@ -1,1365 +0,0 @@ -// DO NOT EDIT -// This file is automatically generated by the 'update.sh' file, with data from: -// https://raw.githubusercontent.com/minimaxir/big-list-of-naughty-strings/master/blns.txt - -#[cfg(test)] -mod test { - use crate::Trinitry; - #[test] - fn parse_0() { - let p = Trinitry::new(r##"undefined"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"undefined"##, &p.to_string()); - } - #[test] - fn parse_1() { - let p = Trinitry::new(r##"undef"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"undef"##, &p.to_string()); - } - #[test] - fn parse_2() { - let p = Trinitry::new(r##"null"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"null"##, &p.to_string()); - } - #[test] - fn parse_3() { - let p = Trinitry::new(r##"NULL"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"NULL"##, &p.to_string()); - } - #[test] - fn parse_4() { - let p = Trinitry::new(r##"(null)"##); - assert!(p.is_err()); - } - #[test] - fn parse_5() { - let p = Trinitry::new(r##"nil"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"nil"##, &p.to_string()); - } - #[test] - fn parse_6() { - let p = Trinitry::new(r##"NIL"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"NIL"##, &p.to_string()); - } - #[test] - fn parse_7() { - let p = Trinitry::new(r##"true"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"true"##, &p.to_string()); - } - #[test] - fn parse_8() { - let p = Trinitry::new(r##"True"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"True"##, &p.to_string()); - } - #[test] - fn parse_9() { - let p = Trinitry::new(r##"TRUE"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"TRUE"##, &p.to_string()); - } - #[test] - fn parse_10() { - let p = Trinitry::new(r##"FALSE"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"FALSE"##, &p.to_string()); - } - #[test] - fn parse_11() { - let p = Trinitry::new(r##"None"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"None"##, &p.to_string()); - } - #[test] - fn parse_12() { - let p = Trinitry::new(r##"then"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"then"##, &p.to_string()); - } - #[test] - fn parse_13() { - let p = Trinitry::new(r##"\"##); - assert!(p.is_err()); - } - #[test] - fn parse_14() { - let p = Trinitry::new(r##"\\"##); - assert!(p.is_err()); - } - #[test] - fn parse_15() { - let p = Trinitry::new(r##"0"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"0"##, &p.to_string()); - } - #[test] - fn parse_16() { - let p = Trinitry::new(r##"1"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"1"##, &p.to_string()); - } - #[test] - fn parse_17() { - let p = Trinitry::new(r##"1.00"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"1.00"##, &p.to_string()); - } - #[test] - fn parse_18() { - let p = Trinitry::new(r##"$1.00"##); - assert!(p.is_err()); - } - #[test] - fn parse_19() { - let p = Trinitry::new(r##"1/2"##); - assert!(p.is_err()); - } - #[test] - fn parse_20() { - let p = Trinitry::new(r##"1E2"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"1E2"##, &p.to_string()); - } - #[test] - fn parse_21() { - let p = Trinitry::new(r##"1E02"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"1E02"##, &p.to_string()); - } - #[test] - fn parse_22() { - let p = Trinitry::new(r##"1E+02"##); - assert!(p.is_err()); - } - #[test] - fn parse_23() { - let p = Trinitry::new(r##"-1"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"-1"##, &p.to_string()); - } - #[test] - fn parse_24() { - let p = Trinitry::new(r##"-1.00"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"-1.00"##, &p.to_string()); - } - #[test] - fn parse_25() { - let p = Trinitry::new(r##"-$1.00"##); - assert!(p.is_err()); - } - #[test] - fn parse_26() { - let p = Trinitry::new(r##"-1/2"##); - assert!(p.is_err()); - } - #[test] - fn parse_27() { - let p = Trinitry::new(r##"-1E2"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"-1E2"##, &p.to_string()); - } - #[test] - fn parse_28() { - let p = Trinitry::new(r##"-1E02"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"-1E02"##, &p.to_string()); - } - #[test] - fn parse_29() { - let p = Trinitry::new(r##"-1E+02"##); - assert!(p.is_err()); - } - #[test] - fn parse_30() { - let p = Trinitry::new(r##"1/0"##); - assert!(p.is_err()); - } - #[test] - fn parse_31() { - let p = Trinitry::new(r##"0/0"##); - assert!(p.is_err()); - } - #[test] - fn parse_32() { - let p = Trinitry::new(r##"-2147483648/-1"##); - assert!(p.is_err()); - } - #[test] - fn parse_33() { - let p = Trinitry::new(r##"-9223372036854775808/-1"##); - assert!(p.is_err()); - } - #[test] - fn parse_34() { - let p = Trinitry::new(r##"-0"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"-0"##, &p.to_string()); - } - #[test] - fn parse_35() { - let p = Trinitry::new(r##"-0.0"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"-0.0"##, &p.to_string()); - } - #[test] - fn parse_36() { - let p = Trinitry::new(r##"+0"##); - assert!(p.is_err()); - } - #[test] - fn parse_37() { - let p = Trinitry::new(r##"+0.0"##); - assert!(p.is_err()); - } - #[test] - fn parse_38() { - let p = Trinitry::new(r##"0.00"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"0.00"##, &p.to_string()); - } - #[test] - fn parse_39() { - let p = Trinitry::new(r##"0..0"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"0..0"##, &p.to_string()); - } - #[test] - fn parse_40() { - let p = Trinitry::new(r##"."##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"."##, &p.to_string()); - } - #[test] - fn parse_41() { - let p = Trinitry::new(r##"0.0.0"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"0.0.0"##, &p.to_string()); - } - #[test] - fn parse_42() { - let p = Trinitry::new(r##"0,00"##); - assert!(p.is_err()); - } - #[test] - fn parse_43() { - let p = Trinitry::new(r##"0,,0"##); - assert!(p.is_err()); - } - #[test] - fn parse_44() { - let p = Trinitry::new(r##","##); - assert!(p.is_err()); - } - #[test] - fn parse_45() { - let p = Trinitry::new(r##"0,0,0"##); - assert!(p.is_err()); - } - #[test] - fn parse_46() { - let p = Trinitry::new(r##"0.0/0"##); - assert!(p.is_err()); - } - #[test] - fn parse_47() { - let p = Trinitry::new(r##"1.0/0.0"##); - assert!(p.is_err()); - } - #[test] - fn parse_48() { - let p = Trinitry::new(r##"0.0/0.0"##); - assert!(p.is_err()); - } - #[test] - fn parse_49() { - let p = Trinitry::new(r##"1,0/0,0"##); - assert!(p.is_err()); - } - #[test] - fn parse_50() { - let p = Trinitry::new(r##"0,0/0,0"##); - assert!(p.is_err()); - } - #[test] - fn parse_51() { - let p = Trinitry::new(r##"--1"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"--1"##, &p.to_string()); - } - #[test] - fn parse_52() { - let p = Trinitry::new(r##"-"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"-"##, &p.to_string()); - } - #[test] - fn parse_53() { - let p = Trinitry::new(r##"-."##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"-."##, &p.to_string()); - } - #[test] - fn parse_54() { - let p = Trinitry::new(r##"-,"##); - assert!(p.is_err()); - } - #[test] - fn parse_55() { - let p = Trinitry::new(r##"999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"##, &p.to_string()); - } - #[test] - fn parse_56() { - let p = Trinitry::new(r##"NaN"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"NaN"##, &p.to_string()); - } - #[test] - fn parse_57() { - let p = Trinitry::new(r##"Infinity"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"Infinity"##, &p.to_string()); - } - #[test] - fn parse_58() { - let p = Trinitry::new(r##"-Infinity"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"-Infinity"##, &p.to_string()); - } - #[test] - fn parse_59() { - let p = Trinitry::new(r##"INF"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"INF"##, &p.to_string()); - } - #[test] - fn parse_60() { - let p = Trinitry::new(r##"1#INF"##); - assert!(p.is_err()); - } - #[test] - fn parse_61() { - let p = Trinitry::new(r##"-1#IND"##); - assert!(p.is_err()); - } - #[test] - fn parse_62() { - let p = Trinitry::new(r##"1#QNAN"##); - assert!(p.is_err()); - } - #[test] - fn parse_63() { - let p = Trinitry::new(r##"1#SNAN"##); - assert!(p.is_err()); - } - #[test] - fn parse_64() { - let p = Trinitry::new(r##"1#IND"##); - assert!(p.is_err()); - } - #[test] - fn parse_65() { - let p = Trinitry::new(r##"0x0"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"0x0"##, &p.to_string()); - } - #[test] - fn parse_66() { - let p = Trinitry::new(r##"0xffffffff"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"0xffffffff"##, &p.to_string()); - } - #[test] - fn parse_67() { - let p = Trinitry::new(r##"0xffffffffffffffff"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"0xffffffffffffffff"##, &p.to_string()); - } - #[test] - fn parse_68() { - let p = Trinitry::new(r##"0xabad1dea"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"0xabad1dea"##, &p.to_string()); - } - #[test] - fn parse_69() { - let p = Trinitry::new(r##"123456789012345678901234567890123456789"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"123456789012345678901234567890123456789"##, &p.to_string()); - } - #[test] - fn parse_70() { - let p = Trinitry::new(r##"1,000.00"##); - assert!(p.is_err()); - } - #[test] - fn parse_71() { - let p = Trinitry::new(r##"1 000.00"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"1 000.00"##, &p.to_string()); - } - #[test] - fn parse_72() { - let p = Trinitry::new(r##"1'000.00"##); - assert!(p.is_err()); - } - #[test] - fn parse_73() { - let p = Trinitry::new(r##"1,000,000.00"##); - assert!(p.is_err()); - } - #[test] - fn parse_74() { - let p = Trinitry::new(r##"1 000 000.00"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"1 000 000.00"##, &p.to_string()); - } - #[test] - fn parse_75() { - let p = Trinitry::new(r##"1'000'000.00"##); - assert!(p.is_err()); - } - #[test] - fn parse_76() { - let p = Trinitry::new(r##"1.000,00"##); - assert!(p.is_err()); - } - #[test] - fn parse_77() { - let p = Trinitry::new(r##"1 000,00"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"1 000,00"##, &p.to_string()); - } - #[test] - fn parse_78() { - let p = Trinitry::new(r##"1'000,00"##); - assert!(p.is_err()); - } - #[test] - fn parse_79() { - let p = Trinitry::new(r##"1.000.000,00"##); - assert!(p.is_err()); - } - #[test] - fn parse_80() { - let p = Trinitry::new(r##"1 000 000,00"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"1 000 000,00"##, &p.to_string()); - } - #[test] - fn parse_81() { - let p = Trinitry::new(r##"1'000'000,00"##); - assert!(p.is_err()); - } - #[test] - fn parse_82() { - let p = Trinitry::new(r##"01000"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"01000"##, &p.to_string()); - } - #[test] - fn parse_83() { - let p = Trinitry::new(r##"08"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"08"##, &p.to_string()); - } - #[test] - fn parse_84() { - let p = Trinitry::new(r##"09"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"09"##, &p.to_string()); - } - #[test] - fn parse_85() { - let p = Trinitry::new(r##"2.2250738585072011e-308"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"2.2250738585072011e-308"##, &p.to_string()); - } - #[test] - fn parse_86() { - let p = Trinitry::new(r##",./;'[]\-="##); - assert!(p.is_err()); - } - #[test] - fn parse_87() { - let p = Trinitry::new(r##"<>?:"{}|_+"##); - assert!(p.is_err()); - } - #[test] - fn parse_88() { - let p = Trinitry::new(r##"!@#$%^&*()`~"##); - assert!(p.is_err()); - } - #[test] - fn parse_89() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_90() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_91() { - let p = Trinitry::new(r##" "##); - assert!(p.is_err()); - } - #[test] - fn parse_92() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_93() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_94() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_95() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_96() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_97() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_98() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_99() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_100() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_101() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_102() { - let p = Trinitry::new(r##"`"##); - assert!(p.is_err()); - } - #[test] - fn parse_103() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_104() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_105() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_106() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_107() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_108() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_109() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_110() { - let p = Trinitry::new(r##"'"##); - assert!(p.is_err()); - } - #[test] - fn parse_111() { - let p = Trinitry::new(r##"""##); - assert!(p.is_err()); - } - #[test] - fn parse_112() { - let p = Trinitry::new(r##"''"##); - assert!(p.is_err()); - } - #[test] - fn parse_113() { - let p = Trinitry::new(r##""""##); - assert!(p.is_err()); - } - #[test] - fn parse_114() { - let p = Trinitry::new(r##"'"'"##); - assert!(p.is_err()); - } - #[test] - fn parse_115() { - let p = Trinitry::new(r##""''''"'""##); - assert!(p.is_err()); - } - #[test] - fn parse_116() { - let p = Trinitry::new(r##""'"'"''''""##); - assert!(p.is_err()); - } - #[test] - fn parse_117() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_118() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_119() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_120() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_121() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_122() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_123() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_124() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_125() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_126() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_127() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_128() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_129() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_130() { - let p = Trinitry::new(r##"/"##); - assert!(p.is_err()); - } - #[test] - fn parse_131() { - let p = Trinitry::new(r##"A"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"A"##, &p.to_string()); - } - #[test] - fn parse_132() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_133() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_134() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_135() { - let p = Trinitry::new(r##"( )"##); - assert!(p.is_err()); - } - #[test] - fn parse_136() { - let p = Trinitry::new(r##"("##); - assert!(p.is_err()); - } - #[test] - fn parse_137() { - let p = Trinitry::new(r##"__(,_,*)"##); - assert!(p.is_err()); - } - #[test] - fn parse_138() { - let p = Trinitry::new(r##"():*:"##); - assert!(p.is_err()); - } - #[test] - fn parse_139() { - let p = Trinitry::new(r##"()"##); - assert!(p.is_err()); - } - #[test] - fn parse_140() { - let p = Trinitry::new(r##",:*:( ):*:"##); - assert!(p.is_err()); - } - #[test] - fn parse_141() { - let p = Trinitry::new(r##"( )"##); - assert!(p.is_err()); - } - #[test] - fn parse_142() { - let p = Trinitry::new(r##"("##); - assert!(p.is_err()); - } - #[test] - fn parse_143() { - let p = Trinitry::new(r##"( _ )"##); - assert!(p.is_err()); - } - #[test] - fn parse_144() { - let p = Trinitry::new(r##"( )"##); - assert!(p.is_err()); - } - #[test] - fn parse_145() { - let p = Trinitry::new(r##"\_()_/"##); - assert!(p.is_err()); - } - #[test] - fn parse_146() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_147() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_148() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_149() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_150() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_151() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_152() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_153() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_154() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_155() { - let p = Trinitry::new(r##"0 1 2 3 4 5 6 7 8 9"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"0 1 2 3 4 5 6 7 8 9"##, &p.to_string()); - } - #[test] - fn parse_156() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_157() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_158() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_159() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_160() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_161() { - let p = Trinitry::new(r##", . . - . , , ."##); - assert!(p.is_err()); - } - #[test] - fn parse_162() { - let p = Trinitry::new(r##", , ,"##); - assert!(p.is_err()); - } - #[test] - fn parse_163() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_164() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_165() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_166() { - let p = Trinitry::new(r##"(5)"##); - assert!(p.is_err()); - } - #[test] - fn parse_167() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_168() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_169() { - let p = Trinitry::new(r##"ZGO"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"ZGO"##, &p.to_string()); - } - #[test] - fn parse_170() { - let p = Trinitry::new(r##"00$-"##); - assert!(p.is_err()); - } - #[test] - fn parse_171() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_172() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_173() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_174() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_175() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_176() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_177() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_178() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_179() { - let p = Trinitry::new(r##"";alert(15);t=""##); - assert!(p.is_err()); - } - #[test] - fn parse_180() { - let p = Trinitry::new(r##"';alert(16);t='"##); - assert!(p.is_err()); - } - #[test] - fn parse_181() { - let p = Trinitry::new(r##"JavaSCript:alert(17)"##); - assert!(p.is_err()); - } - #[test] - fn parse_182() { - let p = Trinitry::new(r##";alert(18);"##); - assert!(p.is_err()); - } - #[test] - fn parse_183() { - let p = Trinitry::new(r##"">"##); - assert!(p.is_err()); - } - #[test] - fn parse_184() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_185() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_186() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_187() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_188() { - let p = Trinitry::new(r##"<"##); - assert!(p.is_err()); - } - #[test] - fn parse_189() { - let p = Trinitry::new(r##"\";alert('223');//"##); - assert!(p.is_err()); - } - #[test] - fn parse_190() { - let p = Trinitry::new(r##" Copy me"##); - assert!(p.is_err()); - } - #[test] - fn parse_191() { - let p = Trinitry::new(r##" Scroll over me "##); - assert!(p.is_err()); - } - #[test] - fn parse_192() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_193() { - let p = Trinitry::new(r##"http://a/%%30%30"##); - assert!(p.is_err()); - } - #[test] - fn parse_194() { - let p = Trinitry::new(r##"' OR 1=1 -- 1"##); - assert!(p.is_err()); - } - #[test] - fn parse_195() { - let p = Trinitry::new(r##"' OR '1'='1"##); - assert!(p.is_err()); - } - #[test] - fn parse_196() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_197() { - let p = Trinitry::new(r##"%"##); - assert!(p.is_err()); - } - #[test] - fn parse_198() { - let p = Trinitry::new(r##"_"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"_"##, &p.to_string()); - } - #[test] - fn parse_199() { - let p = Trinitry::new(r##"-"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"-"##, &p.to_string()); - } - #[test] - fn parse_200() { - let p = Trinitry::new(r##"--"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"--"##, &p.to_string()); - } - #[test] - fn parse_201() { - let p = Trinitry::new(r##"--help"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"--help"##, &p.to_string()); - } - #[test] - fn parse_202() { - let p = Trinitry::new(r##"$USER"##); - assert!(p.is_err()); - } - #[test] - fn parse_203() { - let p = Trinitry::new(r##"Kernel.exit(1)"##); - assert!(p.is_err()); - } - #[test] - fn parse_204() { - let p = Trinitry::new(r##"$HOME"##); - assert!(p.is_err()); - } - #[test] - fn parse_205() { - let p = Trinitry::new(r##"$ENV{'HOME'}"##); - assert!(p.is_err()); - } - #[test] - fn parse_206() { - let p = Trinitry::new(r##"%d"##); - assert!(p.is_err()); - } - #[test] - fn parse_207() { - let p = Trinitry::new(r##"{0}"##); - assert!(p.is_err()); - } - #[test] - fn parse_208() { - let p = Trinitry::new(r##"%@"##); - assert!(p.is_err()); - } - #[test] - fn parse_209() { - let p = Trinitry::new(r##"%n"##); - assert!(p.is_err()); - } - #[test] - fn parse_210() { - let p = Trinitry::new(r##"File:///"##); - assert!(p.is_err()); - } - #[test] - fn parse_211() { - let p = Trinitry::new(r##"+++ATH0"##); - assert!(p.is_err()); - } - #[test] - fn parse_212() { - let p = Trinitry::new(r##"CON"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"CON"##, &p.to_string()); - } - #[test] - fn parse_213() { - let p = Trinitry::new(r##"PRN"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"PRN"##, &p.to_string()); - } - #[test] - fn parse_214() { - let p = Trinitry::new(r##"AUX"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"AUX"##, &p.to_string()); - } - #[test] - fn parse_215() { - let p = Trinitry::new(r##"CLOCK$"##); - assert!(p.is_err()); - } - #[test] - fn parse_216() { - let p = Trinitry::new(r##"NUL"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"NUL"##, &p.to_string()); - } - #[test] - fn parse_217() { - let p = Trinitry::new(r##"A:"##); - assert!(p.is_err()); - } - #[test] - fn parse_218() { - let p = Trinitry::new(r##"ZZ:"##); - assert!(p.is_err()); - } - #[test] - fn parse_219() { - let p = Trinitry::new(r##"COM1"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"COM1"##, &p.to_string()); - } - #[test] - fn parse_220() { - let p = Trinitry::new(r##"LPT1"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"LPT1"##, &p.to_string()); - } - #[test] - fn parse_221() { - let p = Trinitry::new(r##"LPT2"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"LPT2"##, &p.to_string()); - } - #[test] - fn parse_222() { - let p = Trinitry::new(r##"LPT3"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"LPT3"##, &p.to_string()); - } - #[test] - fn parse_223() { - let p = Trinitry::new(r##"COM2"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"COM2"##, &p.to_string()); - } - #[test] - fn parse_224() { - let p = Trinitry::new(r##"COM3"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"COM3"##, &p.to_string()); - } - #[test] - fn parse_225() { - let p = Trinitry::new(r##"COM4"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"COM4"##, &p.to_string()); - } - #[test] - fn parse_226() { - let p = Trinitry::new(r##"DCC SEND STARTKEYLOGGER 0 0 0"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"DCC SEND STARTKEYLOGGER 0 0 0"##, &p.to_string()); - } - #[test] - fn parse_227() { - let p = Trinitry::new(r##"Lightwater Country Park"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"Lightwater Country Park"##, &p.to_string()); - } - #[test] - fn parse_228() { - let p = Trinitry::new(r##"Jimmy Clitheroe"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"Jimmy Clitheroe"##, &p.to_string()); - } - #[test] - fn parse_229() { - let p = Trinitry::new(r##"http://www.cum.qc.ca/"##); - assert!(p.is_err()); - } - #[test] - fn parse_230() { - let p = Trinitry::new(r##"Linda Callahan"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"Linda Callahan"##, &p.to_string()); - } - #[test] - fn parse_231() { - let p = Trinitry::new(r##"magna cum laude"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"magna cum laude"##, &p.to_string()); - } - #[test] - fn parse_232() { - let p = Trinitry::new(r##"Super Bowl XXX"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"Super Bowl XXX"##, &p.to_string()); - } - #[test] - fn parse_233() { - let p = Trinitry::new(r##"evaluate"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"evaluate"##, &p.to_string()); - } - #[test] - fn parse_234() { - let p = Trinitry::new(r##"mocha"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"mocha"##, &p.to_string()); - } - #[test] - fn parse_235() { - let p = Trinitry::new(r##"Dick Van Dyke"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"Dick Van Dyke"##, &p.to_string()); - } - #[test] - fn parse_236() { - let p = Trinitry::new(r##"The quick brown fox... [Beeeep]"##); - assert!(p.is_err()); - } - #[test] - fn parse_237() { - let p = Trinitry::new(r##"0"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"0"##, &p.to_string()); - } - #[test] - fn parse_238() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_239() { - let p = Trinitry::new(r##""##); - assert!(p.is_err()); - } - #[test] - fn parse_240() { - let p = Trinitry::new(r##"{% print 'x' * 64 * 1024**3 %}"##); - assert!(p.is_err()); - } -} diff --git a/trinitry/src/trinitry.pest b/trinitry/src/trinitry.pest deleted file mode 100644 index c868a6d..0000000 --- a/trinitry/src/trinitry.pest +++ /dev/null @@ -1,25 +0,0 @@ -chars = { ASCII_ALPHANUMERIC | "_" | "-" | "." } - -// TODO(@soispha): Are these all the valid characters? <2023-11-01> -argument_chars = { chars | "(" | ")" | "{" | "}" | "<" | ">" | "?" | "!" | "+" | "^" | "@" -| "&" | "*" | "~" | "|" | "=" | "," | "\\" | "/" } -whitespace = _{ " " } // lower case to avoid special treatment of 'WHITESPACE' - -quote = _{ "\"" } -q = _{ quote } - -single_quote = _{ "'" } -sq = _{ single_quote } - - - -command = { chars+ } - -arg_quoted = { q ~ (!q ~ (argument_chars | " " | "'" ))+ ~ q } -arg_single_quoted = { sq ~ (!sq ~ (argument_chars | " " | "\"" ))+ ~ sq } -arg = { (argument_chars | "\"" | "'")+ } - -argument = { whitespace+ ~ (arg_quoted | arg_single_quoted | arg )} - - -trinitry = { SOI ~ #command = command ~ (#argument = argument)* ~ EOI } diff --git a/trinitry/update.sh b/trinitry/update.sh deleted file mode 100755 index 51f1f58..0000000 --- a/trinitry/update.sh +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/env sh - -# Library {{{ -mktmp() { - ensure_tmp_dir - mktemp -p "$LIB_TEMP_DIR_FOR_SCRIPT" -} -ensure_tmp_dir() { - if ! [ -d "$LIB_TEMP_DIR_FOR_SCRIPT" ]; then - LIB_TEMP_DIR_FOR_SCRIPT="$(mktemp -d)" - export LIB_TEMP_DIR_FOR_SCRIPT - fi -} -remove_tmp_dir() { - # The test is here because some scripts still delete this on their own - if [ -d "$LIB_TEMP_DIR_FOR_SCRIPT" ]; then - rm -r "$LIB_TEMP_DIR_FOR_SCRIPT" - fi -} - -trap remove_tmp_dir EXIT -ensure_tmp_dir # ensure that the variable has been set, even in subshells -# }}} - -tmp="$(mktmp)" - -curl https://raw.githubusercontent.com/minimaxir/big-list-of-naughty-strings/master/blns.txt | - awk '!/^#/' | - awk '!/^[\s\t]*$/' | - awk -v s="'" '!/.*s.*/' | - - # This entry contains duplicated spaces, just ignore it - awk '!/Power/' | - iconv -c -f utf-8 -t ascii \ - >"$tmp" - -counter=0 - -cat <<EOF -// DO NOT EDIT -// This file is automatically generated by the 'update.sh' file, with data from: -// https://raw.githubusercontent.com/minimaxir/big-list-of-naughty-strings/master/blns.txt - -#[cfg(test)] -mod test { - use crate::Trinitry; -EOF - -while read -r name; do - tmp2="$(mktmp)" - printf "%s" "$name" >"$tmp2" - if rg '^[A-Za-z0-9_.-]+$' "$tmp2" -q; then - cat <<EOF - #[test] - fn parse_$counter() { - let p = Trinitry::new(r##"$name"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"$name"##, &p.to_string()); - } -EOF - elif rg '^[A-Za-z0-9_.-]+ [A-Za-z0-9_.(){}<>?!+^@&*~|=,/\\ -]*$' "$tmp2" -q; then - cat <<EOF - #[test] - fn parse_$counter() { - let p = Trinitry::new(r##"$name"##).unwrap_or_else(|e| { - panic!("{}", e); - }); - assert_eq!(r##"$name"##, &p.to_string()); - } -EOF - else - cat <<EOF - #[test] - fn parse_$counter() { - let p = Trinitry::new(r##"$name"##); - assert!(p.is_err()); - } -EOF - fi - counter=$((counter + 1)) -done <"$tmp" - -cat <<EOF -} -EOF - -# vim: ft=sh diff --git a/update.sh b/update.sh index e3875ce..1e69bf0 100755 --- a/update.sh +++ b/update.sh @@ -1,19 +1,6 @@ #!/usr/bin/env sh -update() { - cd "$1" || (echo "No '$1' directory" && exit 1) - - cargo update && cargo upgrade - - [ "$1" = "." ] || cd .. -} - -update . - -cd ./trinitry || (echo "No trinitry directory" && exit 1) cargo update && cargo upgrade -./update.sh > ./src/tests.rs -cd .. git add Cargo.lock Cargo.toml flake.lock