one less library
Signed-off-by: Ava Affine <ava@sunnypup.io>
This commit is contained in:
parent
d79e87dbd2
commit
7800b483da
2 changed files with 11 additions and 14 deletions
|
|
@ -5,10 +5,8 @@ authors = ["Ava <ava@sunnypup.io>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
# cant have math without libc I guess...
|
||||||
libm = "0.2.8"
|
libm = "0.2.8"
|
||||||
# this one provides a global constant lookup table for simple
|
|
||||||
# string escaping in the lexer
|
|
||||||
phf = { version = "0.11", default-features = false, features = ["macros"] }
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "flesh"
|
name = "flesh"
|
||||||
|
|
|
||||||
|
|
@ -19,17 +19,19 @@ use alloc::boxed::Box;
|
||||||
use alloc::string::{String, ToString};
|
use alloc::string::{String, ToString};
|
||||||
use crate::segment::{Ctr, Seg};
|
use crate::segment::{Ctr, Seg};
|
||||||
use crate::error::{Traceback, start_trace};
|
use crate::error::{Traceback, start_trace};
|
||||||
use phf::{Map, phf_map};
|
|
||||||
|
|
||||||
const UNMATCHED_STR_DELIM: &str = "Unmatched string delimiter in input";
|
const UNMATCHED_STR_DELIM: &str = "Unmatched string delimiter in input";
|
||||||
const UNMATCHED_LIST_DELIM: &str = "Unmatched list delimiter in input";
|
const UNMATCHED_LIST_DELIM: &str = "Unmatched list delimiter in input";
|
||||||
|
|
||||||
|
#[inline]
|
||||||
static ESCAPES: Map<char, char> = phf_map! {
|
fn escape(input: &char) -> char {
|
||||||
'n' => '\n',
|
match input {
|
||||||
't' => '\t',
|
'n' => '\n',
|
||||||
'\\' => '\\',
|
't' => '\t',
|
||||||
};
|
'\\' => '\\',
|
||||||
|
_ => input.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* takes a line of user input
|
/* takes a line of user input
|
||||||
* returns an unsimplified tree of tokens.
|
* returns an unsimplified tree of tokens.
|
||||||
|
|
@ -86,10 +88,7 @@ fn process(document: &String) -> Result<Box<Seg>, String> {
|
||||||
delim = *d;
|
delim = *d;
|
||||||
|
|
||||||
if delim == '*' {
|
if delim == '*' {
|
||||||
token.push(ESCAPES.get(&c)
|
token.push(escape(&c));
|
||||||
.cloned()
|
|
||||||
.or(Some(c))
|
|
||||||
.unwrap());
|
|
||||||
delim_stack.pop();
|
delim_stack.pop();
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue