make ) a closer from num/sym/key, and we run again! borkenly

This commit is contained in:
🪞👃🪞 2025-01-19 00:02:22 +01:00
parent a595e2e895
commit 323afe4c89
2 changed files with 17 additions and 20 deletions

View file

@ -15,41 +15,38 @@ impl<'a> TokenIter<'a> {
} }
} }
pub const fn peek_src <'a> (source: &'a str) -> Option<Token<'a>> { pub const fn peek_src <'a> (source: &'a str) -> Option<Token<'a>> {
let mut token: Token<'a> = Token::new(source, Nil, 0, 0); let mut token: Token<'a> = Token::new(source, 0, 0, Nil);
iterate!(char_indices(source) => (start, c) => token = match token.value() { iterate!(char_indices(source) => (start, c) => token = match token.value() {
Err(_) => return Some(token), Err(_) => return Some(token),
Nil => match c { Nil => match c {
' '|'\n'|'\r'|'\t' => token.grow(), ' '|'\n'|'\r'|'\t' =>
'(' => Token { source, start, length: 1, token.grow(),
value: Value::Exp(1, TokenIter(str_range(source, start, start + 1))), '(' =>
}, Token::new(source, start, 1, Exp(1, TokenIter(str_range(source, start, start + 1)))),
':'|'@' => Token { source, start, length: 1, ':'|'@' =>
value: Value::Sym(str_range(source, start, start + 1)), Token::new(source, start, 1, Sym(str_range(source, start, start + 1))),
}, '/'|'a'..='z' =>
'/'|'a'..='z' => Token { source, start, length: 1, Token::new(source, start, 1, Key(str_range(source, start, start + 1))),
value: Value::Key(str_range(source, start, start + 1)), '0'..='9' =>
}, Token::new(source, start, 1, match to_digit(c) {
'0'..='9' => Token { source, start, length: 1,
value: match to_digit(c) {
Ok(c) => Value::Num(c), Ok(c) => Value::Num(c),
Result::Err(e) => Value::Err(e) Result::Err(e) => Value::Err(e)
} }),
},
_ => token.error(Unexpected(c)) _ => token.error(Unexpected(c))
}, },
Num(n) => match c { Num(n) => match c {
'0'..='9' => token.grow_num(n, c), '0'..='9' => token.grow_num(n, c),
' '|'\n'|'\r'|'\t' => return Some(token), ' '|'\n'|'\r'|'\t'|')' => return Some(token),
_ => token.error(Unexpected(c)) _ => token.error(Unexpected(c))
}, },
Sym(_) => match c { Sym(_) => match c {
'a'..='z'|'0'..='9'|'-' => token.grow_sym(), 'a'..='z'|'0'..='9'|'-' => token.grow_sym(),
' '|'\n'|'\r'|'\t' => return Some(token), ' '|'\n'|'\r'|'\t'|')' => return Some(token),
_ => token.error(Unexpected(c)) _ => token.error(Unexpected(c))
}, },
Key(_) => match c { Key(_) => match c {
'a'..='z'|'0'..='9'|'-'|'/' => token.grow_key(), 'a'..='z'|'0'..='9'|'-'|'/' => token.grow_key(),
' '|'\n'|'\r'|'\t' => return Some(token), ' '|'\n'|'\r'|'\t'|')' => return Some(token),
_ => token.error(Unexpected(c)) _ => token.error(Unexpected(c))
}, },
Exp(depth, _) => match depth { Exp(depth, _) => match depth {

View file

@ -15,8 +15,8 @@ use self::Value::*;
Exp(usize, TokenIter<'a>), Exp(usize, TokenIter<'a>),
} }
impl<'a> Token<'a> { impl<'a> Token<'a> {
pub const fn new (source: &'a str, value: Value<'a>, start: usize, length: usize) -> Self { pub const fn new (source: &'a str, start: usize, length: usize, value: Value<'a>) -> Self {
Self { source, value, start, length } Self { source, start, length, value }
} }
pub const fn end (&self) -> usize { pub const fn end (&self) -> usize {
self.start + self.length self.start + self.length