slight improvement

This commit is contained in:
mlokr 2024-06-25 19:22:49 +02:00
parent 8442b55aa6
commit c835317287
No known key found for this signature in database
GPG key ID: DEA147DDEE644993

View file

@ -1,4 +1,4 @@
use std::simd::cmp::SimdPartialEq; use std::{convert::identity, simd::cmp::SimdPartialEq};
const fn ascii_mask(chars: &[u8]) -> u128 { const fn ascii_mask(chars: &[u8]) -> u128 {
let mut eq = 0; let mut eq = 0;
@ -285,11 +285,6 @@ impl<'a> Lexer<'a> {
let kind = match c { let kind = match c {
..=b' ' => continue, ..=b' ' => continue,
b'@' | b'$' => {
start += 1;
advance_ident(self);
identity(c)
}
b'0'..=b'9' => { b'0'..=b'9' => {
while let Some(b'0'..=b'9') = self.peek() { while let Some(b'0'..=b'9') = self.peek() {
self.advance(); self.advance();
@ -301,23 +296,28 @@ impl<'a> Lexer<'a> {
let ident = &self.bytes[start as usize..self.pos as usize]; let ident = &self.bytes[start as usize..self.pos as usize];
T::from_ident(ident) T::from_ident(ident)
} }
b'"' => { b'"' | b'\'' => {
while let Some(c) = self.advance() { while let Some(nc) = self.advance() {
match c { match nc {
b'"' => break,
b'\\' => _ = self.advance(), b'\\' => _ = self.advance(),
nc if nc == c => break,
_ => {} _ => {}
} }
} }
T::String identity(c)
} }
b'.' if self.advance_if(b'{') => T::Ctor, b'.' if self.advance_if(b'{') => T::Ctor,
b'.' if self.advance_if(b'(') => T::Tupl, b'.' if self.advance_if(b'(') => T::Tupl,
b'&' if self.advance_if(b'&') => T::And,
b'|' if self.advance_if(b'|') => T::Or,
b'@' | b'$' => {
start += 1;
advance_ident(self);
identity(c)
}
b'<' | b'>' if self.advance_if(c) => { b'<' | b'>' if self.advance_if(c) => {
identity(c - 5 + 128 * self.advance_if(b'=') as u8) identity(c - 5 + 128 * self.advance_if(b'=') as u8)
} }
b'&' if self.advance_if(b'&') => T::And,
b'|' if self.advance_if(b'|') => T::Or,
b':' | b'=' | b'!' | b'<' | b'>' | b'|' | b'+' | b'-' | b'*' | b'/' | b'%' b':' | b'=' | b'!' | b'<' | b'>' | b'|' | b'+' | b'-' | b'*' | b'/' | b'%'
| b'^' | b'&' | b'^' | b'&'
if self.advance_if(b'=') => if self.advance_if(b'=') =>
@ -327,8 +327,6 @@ impl<'a> Lexer<'a> {
_ => identity(c), _ => identity(c),
}; };
println!("{kind}");
return Token { return Token {
kind, kind,
start, start,