mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
use Arc<str> where applicable; use konst split_at
This commit is contained in:
parent
411fc0c4bc
commit
305481adee
35 changed files with 286 additions and 273 deletions
11
edn/Cargo.lock
generated
11
edn/Cargo.lock
generated
|
|
@ -770,19 +770,18 @@ dependencies = [
|
|||
"clojure-reader",
|
||||
"itertools 0.14.0",
|
||||
"konst",
|
||||
"tek_layout",
|
||||
"tek_tui",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tek_engine"
|
||||
name = "tek_input"
|
||||
version = "0.2.0"
|
||||
|
||||
[[package]]
|
||||
name = "tek_layout"
|
||||
name = "tek_output"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"tek_engine",
|
||||
"tek_edn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -795,8 +794,8 @@ dependencies = [
|
|||
"rand",
|
||||
"ratatui",
|
||||
"tek_edn",
|
||||
"tek_engine",
|
||||
"tek_layout",
|
||||
"tek_input",
|
||||
"tek_output",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ pub enum Token<'a> {
|
|||
impl<'a> Token<'a> {
|
||||
pub fn chomp (source: &'a str) -> Result<(&'a str, Self), ParseError> {
|
||||
use Token::*;
|
||||
let mut state = Self::default();
|
||||
use konst::string::{split_at, char_indices};
|
||||
let mut state = Self::Nil;
|
||||
for (index, c) in source.char_indices() {
|
||||
state = match state {
|
||||
// must begin expression
|
||||
|
|
@ -29,21 +30,33 @@ impl<'a> Token<'a> {
|
|||
Key(_, _, 0) => unreachable!(),
|
||||
Num(source, index, length) => match c {
|
||||
'0'..='9' => Num(source, index, length + 1),
|
||||
' '|'\n'|'\r'|'\t' => return Ok((&source[index+length..], Num(source, index, length))),
|
||||
' '|'\n'|'\r'|'\t' => return Ok((
|
||||
split_at(source, index+length).1,
|
||||
Num(source, index, length)
|
||||
)),
|
||||
_ => return Err(ParseError::Unexpected(c))
|
||||
},
|
||||
Sym(source, index, length) => match c {
|
||||
'a'..='z'|'0'..='9'|'-' => Sym(source, index, length + 1),
|
||||
' '|'\n'|'\r'|'\t' => return Ok((&source[index+length..], Sym(source, index, length))),
|
||||
' '|'\n'|'\r'|'\t' => return Ok((
|
||||
split_at(source, index+length).1,
|
||||
Sym(source, index, length)
|
||||
)),
|
||||
_ => return Err(ParseError::Unexpected(c))
|
||||
},
|
||||
Key(source, index, length) => match c {
|
||||
'a'..='z'|'0'..='9'|'-'|'/' => Key(source, index, length + 1),
|
||||
' '|'\n'|'\r'|'\t' => return Ok((&source[index+length..], Key(source, index, length))),
|
||||
' '|'\n'|'\r'|'\t' => return Ok((
|
||||
split_at(source, index+length).1,
|
||||
Key(source, index, length)
|
||||
)),
|
||||
_ => return Err(ParseError::Unexpected(c))
|
||||
},
|
||||
Exp(source, index, length, 0) => match c {
|
||||
' '|'\n'|'\r'|'\t' => return Ok((&source[index+length..], Exp(source, index, length, 0))),
|
||||
' '|'\n'|'\r'|'\t' => return Ok((
|
||||
split_at(source, index+length).1,
|
||||
Exp(source, index, length, 0)
|
||||
)),
|
||||
_ => return Err(ParseError::Unexpected(c))
|
||||
},
|
||||
Exp(source, index, length, depth) => match c {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue