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

View file

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

View file

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

View file

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