Compare commits
3 Commits
9be2b973f0
...
26e905d802
Author | SHA1 | Date |
---|---|---|
Benedikt Peetz | 26e905d802 | |
Benedikt Peetz | 4b270733c3 | |
Benedikt Peetz | 7dd5da97f6 |
|
@ -25,7 +25,7 @@ version = "0.2.0"
|
|||
edition = "2021"
|
||||
license = "LGPL-3.0-or-later"
|
||||
repository = "https://git.nerdcult.net/trinitrix/trinitry"
|
||||
categories = ["programming-language", "library"]
|
||||
categories = ["parser-implementations"]
|
||||
keywords = ["language", "simple"]
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
|
13
README.md
13
README.md
|
@ -24,6 +24,19 @@ 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
|
||||
|
|
|
@ -47,19 +47,27 @@ 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: 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 “",
|
||||
// },
|
||||
{ left: "\\(", right: "\\)", display: false},
|
||||
{ left: "$", right: "$", display: false},
|
||||
{ left: "\\[", right: "\\]", display: true},
|
||||
],
|
||||
preProcess: normalize_quotes,
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
34
src/lib.rs
34
src/lib.rs
|
@ -34,18 +34,20 @@
|
|||
//!
|
||||
//! 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{-}", "."\\} $$
|
||||
//! \\[ \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
|
||||
//! Arguments constructed from the same alphabet as the commands, but can contain additional chars
|
||||
//! listed in the [trinitry.pest](../../../src/trinitry.pest) file.
|
||||
//! $$ \Sigma_{args} = \Sigma_{cmd} \cup{} \\{\\dots{}\\} $$
|
||||
#![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{}\\} \\]
|
||||
//!
|
||||
//! 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 \\{"\\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
|
||||
//! ## Command
|
||||
|
@ -79,12 +81,12 @@ use pest::error::Error;
|
|||
|
||||
mod parsing;
|
||||
|
||||
pub struct TrinitryInvokation {
|
||||
pub struct Trinitry {
|
||||
command: String,
|
||||
arguments: Vec<String>,
|
||||
}
|
||||
|
||||
impl TrinitryInvokation {
|
||||
impl Trinitry {
|
||||
pub fn new(input: &str) -> Result<Self, <Self as FromStr>::Err> {
|
||||
input.parse()
|
||||
}
|
||||
|
@ -98,7 +100,7 @@ impl TrinitryInvokation {
|
|||
}
|
||||
}
|
||||
|
||||
impl FromStr for TrinitryInvokation {
|
||||
impl FromStr for Trinitry {
|
||||
type Err = Error<Rule>;
|
||||
|
||||
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 {
|
||||
let command = {
|
||||
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 {
|
||||
if self.arguments.is_empty() {
|
||||
f.write_str(&self.command)
|
||||
|
@ -177,12 +179,12 @@ mod tests;
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::TrinitryInvokation;
|
||||
use crate::Trinitry;
|
||||
|
||||
#[test]
|
||||
fn parse_cmd() {
|
||||
let string = "quit";
|
||||
let p = TrinitryInvokation::new(string).unwrap_or_else(|e| {
|
||||
let p = Trinitry::new(string).unwrap_or_else(|e| {
|
||||
panic!("{}", e);
|
||||
});
|
||||
assert_eq!(&p.command, "quit");
|
||||
|
@ -192,7 +194,7 @@ mod test {
|
|||
#[test]
|
||||
fn parse_arg_clean() {
|
||||
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);
|
||||
});
|
||||
assert_eq!(&p.command, "lua");
|
||||
|
@ -202,7 +204,7 @@ mod test {
|
|||
#[test]
|
||||
fn parse_arg_quote() {
|
||||
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);
|
||||
});
|
||||
assert_eq!(&p.command, "write");
|
||||
|
@ -212,7 +214,7 @@ mod test {
|
|||
#[test]
|
||||
fn parse_arg_single_quote() {
|
||||
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);
|
||||
});
|
||||
assert_eq!(&p.command, "write");
|
||||
|
@ -222,7 +224,7 @@ mod test {
|
|||
#[test]
|
||||
fn parse_arg_multi() {
|
||||
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);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue