ich weiss doch auch nicht
Some checks failed
/ clippy (push) Has been cancelled
/ build (push) Has been cancelled

This commit is contained in:
xqtc 2024-08-08 14:24:11 +02:00
parent 020c0a4544
commit 256fb1cd93
5 changed files with 141 additions and 30 deletions

2
.config/nextest.toml Normal file
View file

@ -0,0 +1,2 @@
[profile.default]
slow-timeout = "1m"

View file

@ -52,11 +52,7 @@
shellHook = ''
# For rust-analyzer 'hover' tooltips to work.
export RUST_SRC_PATH=${pkgs.rustPlatform.rustLibSrc}
echo $RUST_SRC_PATH
echo
echo "Run 'just <recipe>' to get started"
just
nu
'';
buildInputs = nonRustDeps;
nativeBuildInputs = with pkgs; [

View file

@ -1,3 +1,4 @@
use core::panic;
use crate::lex::lexer::Lexer;
impl Lexer {
@ -35,17 +36,12 @@ impl Lexer {
let mut number = String::new();
let mut is_float = false;
let mut is_swizzle = false;
while let Some(c) = self.current_char {
if c.is_ascii_digit()
/* && self.peek().unwrap_or_else(|| ' ') == 'f' */
{
if c.is_ascii_digit() {
number.push(c);
self.advance();
} else if c == '.' || c == 'e' || c == 'f' {
////////////////////////////////////
//ALLES HIER DRIN IST NICHT SCHÖN//
////////////////////////////////////
match self.peek().unwrap_or(' ') {
'x' | 'y' | 'z' | 'w' | 'r' | 'g' | 'b' | 'a' => {
is_swizzle = true;
@ -57,27 +53,40 @@ impl Lexer {
number.push(c);
self.advance();
}
'f' => {
is_float = true;
number.push(c);
self.advance();
break;
}
'.' => {
if self.peek().unwrap_or(' ') == 'f' {
is_float = true;
number.push(c);
self.advance();
number.push(self.current_char.unwrap()); // Push the 'f'
self.advance();
break;
}
}
_ => {}
}
if c == 'f' {
is_float = true;
number.push(c);
self.advance();
dbg!(&number);
break;
}
} else if c.is_alphabetic() {
if c == '.' && self.peek().unwrap_or(' ') == 'e' {
is_float = true;
self.advance();
dbg!("break in alphabetic");
break;
} else {
match self.peek().unwrap_or(' ') {
'f' => {
is_float = true;
number.push(c);
self.advance();
break;
}
_ => {}
}
is_swizzle = true;
number.push(c);
self.advance();
}
}
if is_float {
return crate::tokens::Token::FLOATCONSTANT(number);
}
@ -90,6 +99,91 @@ impl Lexer {
crate::tokens::Token::INTCONSTANT(number)
}
// ORIGINAL
// pub fn consume_number(&mut self) -> crate::tokens::Token {
// let mut number = String::new();
// let mut is_float = false;
// let mut is_swizzle = false;
// while let Some(c) = self.current_char {
// if c.is_ascii_digit()
// /* && self.peek().unwrap_or_else(|| ' ') == 'f' */
// {
// number.push(c);
// self.advance();
// } else if c == '.' || c == 'e' || c == 'f' {
// ////////////////////////////////////
// //ALLES HIER DRIN IST NICHT SCHÖN//
// ////////////////////////////////////
//
// match self.peek().unwrap_or(' ') {
// 'x' | 'y' | 'z' | 'w' | 'r' | 'g' | 'b' | 'a' => {
// is_swizzle = true;
// number.push(c);
// self.advance();
// }
// '0'..='9' | 'e' => {
// is_float = true;
// number.push(c);
// self.advance();
// }
// '.' => {
// if self.peek().unwrap_or(' ') == 'f' {
// is_float = true;
// number.push(c);
// self.advance();
// break;
// }
// // is_float = true;
// // number.push(c);
// // self.advance();
// }
// _ => {}
// }
// // if c == 'f' {
// // is_float = true;
// // number.push(c);
// // self.advance();
// // dbg!(&number);
// // break;
// // }
// match c {
// 'f' => {
// is_float = true;
// number.push(c);
// self.advance();
// break;
// }
// _ => {}
// }
// } else
// /* if c.is_alphabetic() */
// {
// match self.peek().unwrap_or(' ') {
// 'f' => {
// is_float = true;
// number.push(c);
// self.advance();
// break;
// }
// _ => {}
// }
// is_swizzle = true;
// number.push(c);
// self.advance();
// }
// }
// if is_float {
// return crate::tokens::Token::FLOATCONSTANT(number);
// }
// if is_swizzle {
// let split: Vec<&str> = number.split('.').collect();
// let ident2 = split[1];
// return crate::tokens::Token::Swizzle(vec![".".to_string(), ident2.to_string()]);
// }
//
// crate::tokens::Token::INTCONSTANT(number)
// }
pub fn consume_comment(&mut self) -> crate::tokens::Token {
let mut comment = String::new();
while let Some(c) = self.current_char {

View file

@ -2,7 +2,6 @@ use crate::tokens::Token;
use std::collections::HashMap;
use std::sync::Arc;
pub struct Lexer {
/// GLSL source
pub input: Vec<char>,
@ -17,9 +16,10 @@ pub struct Lexer {
#[macro_export]
macro_rules! lex {
($source:expr) => {{
$crate::lexer::Lexer::get_tokens(&mut $crate::Lexer::new($source))
$crate::lex::lexer::Lexer::get_tokens(&mut $crate::lex::lexer::Lexer::new($source))
}};
}
pub use lex;
impl Lexer {
pub fn new(input: &str) -> Self {

View file

@ -25,20 +25,39 @@ mod tokens;
#[cfg(test)]
mod tests {
use super::lex;
use super::lex::lexer::Lexer;
use super::tokens::{Image, Token};
#[test]
fn float_with_f_aggot() {
let source = "5f";
let mut lexer = Lexer::new(source);
let tokens = Lexer::get_tokens(&mut lexer);
let tokens = lex!(source);
assert_eq!(
tokens,
vec![Token::FLOATCONSTANT("5f".to_string()), Token::EOF].into()
)
}
#[test]
fn float_with_f_aggot_two() {
let source = "5.1f";
let tokens = lex!(source);
assert_eq!(
tokens,
vec![Token::FLOATCONSTANT("5.1f".to_string()), Token::EOF].into()
)
}
#[test]
fn float_with_f_aggot_three() {
let source = "5.f";
let tokens = lex!(source);
assert_eq!(
tokens,
vec![Token::FLOATCONSTANT("5.f".to_string()), Token::EOF].into()
)
}
#[test]
fn keyword() {
let source = "image1D";