Compare commits
No commits in common. "26e905d80204ca3cdc6e7a6e88adc2ca74b38c7b" and "9be2b973f03ed5fa882f7a63519f3fc4161dc535" have entirely different histories.
26e905d802
...
9be2b973f0
|
@ -25,7 +25,7 @@ version = "0.2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "LGPL-3.0-or-later"
|
license = "LGPL-3.0-or-later"
|
||||||
repository = "https://git.nerdcult.net/trinitrix/trinitry"
|
repository = "https://git.nerdcult.net/trinitrix/trinitry"
|
||||||
categories = ["parser-implementations"]
|
categories = ["programming-language", "library"]
|
||||||
keywords = ["language", "simple"]
|
keywords = ["language", "simple"]
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
13
README.md
13
README.md
|
@ -24,19 +24,6 @@ If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
> A very simple programming language, used to map functions to commands
|
> A very simple programming language, used to map functions to commands
|
||||||
|
|
||||||
## Docs
|
|
||||||
If you want to generate the docs locally use this command, as they need KaTeX:
|
|
||||||
```sh
|
|
||||||
# Generate documentation for the dependencies
|
|
||||||
cargo doc
|
|
||||||
|
|
||||||
# Generate the documentation for this crate with the KaTeX header.
|
|
||||||
RUSTDOCFLAGS="--html-in-header ./docs/docs-header.html" cargo doc --no-deps
|
|
||||||
```
|
|
||||||
|
|
||||||
`docs.rs` already does this automatically because of the attribute in the `Cargo.toml`
|
|
||||||
file.
|
|
||||||
|
|
||||||
## Licence
|
## Licence
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify it
|
This program is free software: you can redistribute it and/or modify it
|
||||||
|
|
|
@ -47,27 +47,19 @@ If not, see <https://www.gnu.org/licenses/>.
|
||||||
crossorigin="anonymous"
|
crossorigin="anonymous"
|
||||||
></script>
|
></script>
|
||||||
<script>
|
<script>
|
||||||
// Workaround for rustdoc's "smart" quotation mark replacement feature
|
|
||||||
function normalize_quotes(math) {
|
|
||||||
// const orig = math;
|
|
||||||
|
|
||||||
math = math.replace(/”/g, "\"");
|
|
||||||
math = math.replace(/“/g, "\"");
|
|
||||||
|
|
||||||
math = math.replace(/’/g, "'");
|
|
||||||
math = math.replace(/‘/g, "'");
|
|
||||||
// console.log(`[\n${orig}\n] -> [\n${math}\n].`);
|
|
||||||
return math;
|
|
||||||
}
|
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", function () {
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
renderMathInElement(document.body, {
|
renderMathInElement(document.body, {
|
||||||
delimiters: [
|
delimiters: [
|
||||||
|
{ left: "$$", right: "$$", display: true },
|
||||||
{ left: "\\(", right: "\\)", display: false },
|
{ left: "\\(", right: "\\)", display: false },
|
||||||
{ left: "$", right: "$", display: false },
|
{ left: "$", right: "$", display: false },
|
||||||
{ left: "\\[", right: "\\]", display: true },
|
{ left: "\\[", right: "\\]", display: true },
|
||||||
],
|
]
|
||||||
preProcess: normalize_quotes,
|
// FIXME(@soispha): This removes the quotes completely <2023-10-31>
|
||||||
|
// macros: {
|
||||||
|
// "”": "\\noexpand ”",
|
||||||
|
// "“": "\\noexpand “",
|
||||||
|
// },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
34
src/lib.rs
34
src/lib.rs
|
@ -34,20 +34,18 @@
|
||||||
//!
|
//!
|
||||||
//! Correctly spoken, the Language, containing all valid command names, is just the Kleene closure
|
//! Correctly spoken, the Language, containing all valid command names, is just the Kleene closure
|
||||||
//! over an Alphabet $\Sigma$, which contains all alphanumeric characters:
|
//! over an Alphabet $\Sigma$, which contains all alphanumeric characters:
|
||||||
//! \\[ \Sigma_{cmd} = \\{x | 0 \leqslant x \leqslant 9\\} \cup \\{x | "\text{a}" \leqslant x \leqslant "\text{z}"\\} \cup \\{x | "\text{A}" \leqslant x \leqslant "\text{Z}"\\} \cup \\{"\text{\\_}", "\text{-}", "."\\} \\]
|
//! $$ \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
|
//! ## Argument
|
||||||
//! Arguments constructed from the same alphabet as the commands, but can contain additional chars
|
//! Arguments constructed from the same alphabet as the commands, but can contain additional chars
|
||||||
#![doc = concat!("listed in the [trinitry.pest](https://docs.rs/crate/trinitry/", env!("CARGO_PKG_VERSION"), "/source/src/trinitry.pest) file.")]
|
//! listed in the [trinitry.pest](../../../src/trinitry.pest) file.
|
||||||
//! \\[ \Sigma_{args} = \Sigma_{cmd} \cup{} \\{\\dots{}\\} \\]
|
//! $$ \Sigma_{args} = \Sigma_{cmd} \cup{} \\{\\dots{}\\} $$
|
||||||
//!
|
//!
|
||||||
//! Besides the extra chars outlined above the arguments can also contain
|
//! Besides the extra chars outlined above the arguments can also contain
|
||||||
//! spaces and quotes, if they are quoted. Quoted args are either double quoted, and can thus
|
//! spaces and quotes, if they are quoted. Quoted args are either double quoted, and can thus
|
||||||
//! contain single quotes, or single quoted, and can contain double quotes.
|
//! contain single quotes, or single quoted, and can contain double quotes.
|
||||||
//! \\[
|
//! $$ \Sigma_{args-double-quoted} = \Sigma_{args} \cup \\{"\\text{\\texttt{'}}", "\\ "} $$
|
||||||
//! \Sigma_{args-double-quoted} = \Sigma_{args} \cup \\{"\texttt{ꞌ}", "\\ "\\} \\\\
|
//! $$ \Sigma_{args-single-quoted} = \Sigma_{args} \cup \\{"\\text{\\texttt{"}}", "\\ "} $$
|
||||||
//! \Sigma_{args-single-quoted} = \Sigma_{args} \cup \\{"\texttt{"}", "\\ "\\}
|
|
||||||
//! \\]
|
|
||||||
//!
|
//!
|
||||||
//! # Examples
|
//! # Examples
|
||||||
//! ## Command
|
//! ## Command
|
||||||
|
@ -81,12 +79,12 @@ use pest::error::Error;
|
||||||
|
|
||||||
mod parsing;
|
mod parsing;
|
||||||
|
|
||||||
pub struct Trinitry {
|
pub struct TrinitryInvokation {
|
||||||
command: String,
|
command: String,
|
||||||
arguments: Vec<String>,
|
arguments: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Trinitry {
|
impl TrinitryInvokation {
|
||||||
pub fn new(input: &str) -> Result<Self, <Self as FromStr>::Err> {
|
pub fn new(input: &str) -> Result<Self, <Self as FromStr>::Err> {
|
||||||
input.parse()
|
input.parse()
|
||||||
}
|
}
|
||||||
|
@ -100,7 +98,7 @@ impl Trinitry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for Trinitry {
|
impl FromStr for TrinitryInvokation {
|
||||||
type Err = Error<Rule>;
|
type Err = Error<Rule>;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
@ -109,7 +107,7 @@ impl FromStr for Trinitry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<TrinitryParser<'_>> for Trinitry {
|
impl From<TrinitryParser<'_>> for TrinitryInvokation {
|
||||||
fn from(parsed: TrinitryParser) -> Self {
|
fn from(parsed: TrinitryParser) -> Self {
|
||||||
let command = {
|
let command = {
|
||||||
let command: Vec<_> = parsed.0.clone().find_tagged("command").collect();
|
let command: Vec<_> = parsed.0.clone().find_tagged("command").collect();
|
||||||
|
@ -161,7 +159,7 @@ impl From<TrinitryParser<'_>> for Trinitry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Trinitry {
|
impl Display for TrinitryInvokation {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
if self.arguments.is_empty() {
|
if self.arguments.is_empty() {
|
||||||
f.write_str(&self.command)
|
f.write_str(&self.command)
|
||||||
|
@ -179,12 +177,12 @@ mod tests;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::Trinitry;
|
use crate::TrinitryInvokation;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_cmd() {
|
fn parse_cmd() {
|
||||||
let string = "quit";
|
let string = "quit";
|
||||||
let p = Trinitry::new(string).unwrap_or_else(|e| {
|
let p = TrinitryInvokation::new(string).unwrap_or_else(|e| {
|
||||||
panic!("{}", e);
|
panic!("{}", e);
|
||||||
});
|
});
|
||||||
assert_eq!(&p.command, "quit");
|
assert_eq!(&p.command, "quit");
|
||||||
|
@ -194,7 +192,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_arg_clean() {
|
fn parse_arg_clean() {
|
||||||
let string = r##"lua print("Hi")"##;
|
let string = r##"lua print("Hi")"##;
|
||||||
let p = Trinitry::new(string).unwrap_or_else(|e| {
|
let p = TrinitryInvokation::new(string).unwrap_or_else(|e| {
|
||||||
panic!("{}", e);
|
panic!("{}", e);
|
||||||
});
|
});
|
||||||
assert_eq!(&p.command, "lua");
|
assert_eq!(&p.command, "lua");
|
||||||
|
@ -204,7 +202,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_arg_quote() {
|
fn parse_arg_quote() {
|
||||||
let string = r##"write "some 'file' name""##;
|
let string = r##"write "some 'file' name""##;
|
||||||
let p = Trinitry::new(string).unwrap_or_else(|e| {
|
let p = TrinitryInvokation::new(string).unwrap_or_else(|e| {
|
||||||
panic!("{}", e);
|
panic!("{}", e);
|
||||||
});
|
});
|
||||||
assert_eq!(&p.command, "write");
|
assert_eq!(&p.command, "write");
|
||||||
|
@ -214,7 +212,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_arg_single_quote() {
|
fn parse_arg_single_quote() {
|
||||||
let string = r##"write 'some "file" name'"##;
|
let string = r##"write 'some "file" name'"##;
|
||||||
let p = Trinitry::new(string).unwrap_or_else(|e| {
|
let p = TrinitryInvokation::new(string).unwrap_or_else(|e| {
|
||||||
panic!("{}", e);
|
panic!("{}", e);
|
||||||
});
|
});
|
||||||
assert_eq!(&p.command, "write");
|
assert_eq!(&p.command, "write");
|
||||||
|
@ -224,7 +222,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_arg_multi() {
|
fn parse_arg_multi() {
|
||||||
let string = r##"write 'some "file" name' "other name" last"##;
|
let string = r##"write 'some "file" name' "other name" last"##;
|
||||||
let p = Trinitry::new(string).unwrap_or_else(|e| {
|
let p = TrinitryInvokation::new(string).unwrap_or_else(|e| {
|
||||||
panic!("{}", e);
|
panic!("{}", e);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue