Compare commits

..

3 Commits

Author SHA1 Message Date
Benedikt Peetz 26e905d802
build(Cargo.toml): Use correct category slugs 2024-05-18 19:59:28 +02:00
Benedikt Peetz 4b270733c3
refactor(src): Rename `TrinitryInvokation` to just `Trinitry` for simplicity 2024-05-18 19:57:30 +02:00
Benedikt Peetz 7dd5da97f6
docs(src): Improve rendering of quotation marks
I have used a unicode lookalike for the single quote, as the normal
latex way to include it is not supported by katex (`\textquotesingle`).
2024-05-18 19:56:22 +02:00
4 changed files with 50 additions and 27 deletions

View File

@ -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 = ["programming-language", "library"] categories = ["parser-implementations"]
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

View File

@ -24,6 +24,19 @@ 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

View File

@ -47,19 +47,27 @@ 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},
] ],
// FIXME(@soispha): This removes the quotes completely <2023-10-31> preProcess: normalize_quotes,
// macros: {
// "”": "\\noexpand ”",
// "“": "\\noexpand “",
// },
}); });
}); });
</script> </script>

View File

@ -34,18 +34,20 @@
//! //!
//! 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 | "a" \leqslant x \leqslant "z"\\} \cup \\{x | "A" \leqslant x \leqslant "Z"\\} \cup \\{"\\_", "\text{-}", "."\\} $$ //! \\[ \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{-}", "."\\} \\]
//! //!
//! ## 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
//! listed in the [trinitry.pest](../../../src/trinitry.pest) file. #![doc = concat!("listed in the [trinitry.pest](https://docs.rs/crate/trinitry/", env!("CARGO_PKG_VERSION"), "/source/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-single-quoted} = \Sigma_{args} \cup \\{"\\text{\\texttt{"}}", "\\ "} $$ //! \Sigma_{args-double-quoted} = \Sigma_{args} \cup \\{"\texttt{}", "\\ "\\} \\\\
//! \Sigma_{args-single-quoted} = \Sigma_{args} \cup \\{"\texttt{"}", "\\ "\\}
//! \\]
//! //!
//! # Examples //! # Examples
//! ## Command //! ## Command
@ -79,12 +81,12 @@ use pest::error::Error;
mod parsing; mod parsing;
pub struct TrinitryInvokation { pub struct Trinitry {
command: String, command: String,
arguments: Vec<String>, arguments: Vec<String>,
} }
impl TrinitryInvokation { impl Trinitry {
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()
} }
@ -98,7 +100,7 @@ impl TrinitryInvokation {
} }
} }
impl FromStr for TrinitryInvokation { impl FromStr for Trinitry {
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> {
@ -107,7 +109,7 @@ impl FromStr for TrinitryInvokation {
} }
} }
impl From<TrinitryParser<'_>> for TrinitryInvokation { impl From<TrinitryParser<'_>> for Trinitry {
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();
@ -159,7 +161,7 @@ impl From<TrinitryParser<'_>> for TrinitryInvokation {
} }
} }
impl Display for TrinitryInvokation { impl Display for Trinitry {
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)
@ -177,12 +179,12 @@ mod tests;
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::TrinitryInvokation; use crate::Trinitry;
#[test] #[test]
fn parse_cmd() { fn parse_cmd() {
let string = "quit"; let string = "quit";
let p = TrinitryInvokation::new(string).unwrap_or_else(|e| { let p = Trinitry::new(string).unwrap_or_else(|e| {
panic!("{}", e); panic!("{}", e);
}); });
assert_eq!(&p.command, "quit"); assert_eq!(&p.command, "quit");
@ -192,7 +194,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 = TrinitryInvokation::new(string).unwrap_or_else(|e| { let p = Trinitry::new(string).unwrap_or_else(|e| {
panic!("{}", e); panic!("{}", e);
}); });
assert_eq!(&p.command, "lua"); assert_eq!(&p.command, "lua");
@ -202,7 +204,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 = TrinitryInvokation::new(string).unwrap_or_else(|e| { let p = Trinitry::new(string).unwrap_or_else(|e| {
panic!("{}", e); panic!("{}", e);
}); });
assert_eq!(&p.command, "write"); assert_eq!(&p.command, "write");
@ -212,7 +214,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 = TrinitryInvokation::new(string).unwrap_or_else(|e| { let p = Trinitry::new(string).unwrap_or_else(|e| {
panic!("{}", e); panic!("{}", e);
}); });
assert_eq!(&p.command, "write"); assert_eq!(&p.command, "write");
@ -222,7 +224,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 = TrinitryInvokation::new(string).unwrap_or_else(|e| { let p = Trinitry::new(string).unwrap_or_else(|e| {
panic!("{}", e); panic!("{}", e);
}); });