Compare commits

..

No commits in common. "26e905d80204ca3cdc6e7a6e88adc2ca74b38c7b" and "9be2b973f03ed5fa882f7a63519f3fc4161dc535" have entirely different histories.

4 changed files with 27 additions and 50 deletions

View File

@ -25,7 +25,7 @@ version = "0.2.0"
edition = "2021"
license = "LGPL-3.0-or-later"
repository = "https://git.nerdcult.net/trinitrix/trinitry"
categories = ["parser-implementations"]
categories = ["programming-language", "library"]
keywords = ["language", "simple"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -24,19 +24,6 @@ If not, see <https://www.gnu.org/licenses/>.
> 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
This program is free software: you can redistribute it and/or modify it

View File

@ -47,27 +47,19 @@ If not, see <https://www.gnu.org/licenses/>.
crossorigin="anonymous"
></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 () {
renderMathInElement(document.body, {
delimiters: [
{ left: "\\(", right: "\\)", display: false},
{ left: "$", right: "$", display: false},
{ left: "\\[", right: "\\]", display: true},
],
preProcess: normalize_quotes,
{ left: "$$", right: "$$", display: true },
{ left: "\\(", right: "\\)", display: false },
{ left: "$", right: "$", display: false },
{ left: "\\[", right: "\\]", display: true },
]
// FIXME(@soispha): This removes the quotes completely <2023-10-31>
// macros: {
// "”": "\\noexpand ”",
// "“": "\\noexpand “",
// },
});
});
</script>

View File

@ -34,20 +34,18 @@
//!
//! 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 | "\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
//! 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.")]
//! \\[ \Sigma_{args} = \Sigma_{cmd} \cup{} \\{\\dots{}\\} \\]
//! listed in the [trinitry.pest](../../../src/trinitry.pest) file.
//! $$ \Sigma_{args} = \Sigma_{cmd} \cup{} \\{\\dots{}\\} $$
//!
//! 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
//! contain single quotes, or single quoted, and can contain double quotes.
//! \\[
//! \Sigma_{args-double-quoted} = \Sigma_{args} \cup \\{"\texttt{}", "\\ "\\} \\\\
//! \Sigma_{args-single-quoted} = \Sigma_{args} \cup \\{"\texttt{"}", "\\ "\\}
//! \\]
//! $$ \Sigma_{args-double-quoted} = \Sigma_{args} \cup \\{"\\text{\\texttt{'}}", "\\ "} $$
//! $$ \Sigma_{args-single-quoted} = \Sigma_{args} \cup \\{"\\text{\\texttt{"}}", "\\ "} $$
//!
//! # Examples
//! ## Command
@ -81,12 +79,12 @@ use pest::error::Error;
mod parsing;
pub struct Trinitry {
pub struct TrinitryInvokation {
command: String,
arguments: Vec<String>,
}
impl Trinitry {
impl TrinitryInvokation {
pub fn new(input: &str) -> Result<Self, <Self as FromStr>::Err> {
input.parse()
}
@ -100,7 +98,7 @@ impl Trinitry {
}
}
impl FromStr for Trinitry {
impl FromStr for TrinitryInvokation {
type Err = Error<Rule>;
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 {
let command = {
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 {
if self.arguments.is_empty() {
f.write_str(&self.command)
@ -179,12 +177,12 @@ mod tests;
#[cfg(test)]
mod test {
use crate::Trinitry;
use crate::TrinitryInvokation;
#[test]
fn parse_cmd() {
let string = "quit";
let p = Trinitry::new(string).unwrap_or_else(|e| {
let p = TrinitryInvokation::new(string).unwrap_or_else(|e| {
panic!("{}", e);
});
assert_eq!(&p.command, "quit");
@ -194,7 +192,7 @@ mod test {
#[test]
fn parse_arg_clean() {
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);
});
assert_eq!(&p.command, "lua");
@ -204,7 +202,7 @@ mod test {
#[test]
fn parse_arg_quote() {
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);
});
assert_eq!(&p.command, "write");
@ -214,7 +212,7 @@ mod test {
#[test]
fn parse_arg_single_quote() {
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);
});
assert_eq!(&p.command, "write");
@ -224,7 +222,7 @@ mod test {
#[test]
fn parse_arg_multi() {
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);
});