diff --git a/.forgejo/workflows/uwu.yaml b/.forgejo/workflows/uwu.yaml index 0c9d537..5204dac 100644 --- a/.forgejo/workflows/uwu.yaml +++ b/.forgejo/workflows/uwu.yaml @@ -15,10 +15,10 @@ jobs: with: command: build args: --release - # - uses: https://github.com/actions-rs/cargo@v1 - # with: - # command: test - # args: --lib + - uses: https://github.com/actions-rs/cargo@v1 + with: + command: test + args: --lib clippy: runs-on: ubuntu-latest steps: diff --git a/src/lex/handlers.rs b/src/lex/handlers.rs index 376fd08..2b2b1dd 100644 --- a/src/lex/handlers.rs +++ b/src/lex/handlers.rs @@ -37,7 +37,7 @@ impl Lexer { if c.is_numeric() { number.push(c); self.advance(); - } else if c == '.' { + } else if c == '.' || c == 'e' { is_float = true; number.push(c); self.advance() diff --git a/src/lex/lexer.rs b/src/lex/lexer.rs index 8ce0a0e..448e828 100644 --- a/src/lex/lexer.rs +++ b/src/lex/lexer.rs @@ -1,9 +1,9 @@ -use crate::lex::util::populate_symbols; +use crate::lex::util::make_symbols; use crate::tokens::Token; use std::collections::HashMap; use std::sync::Arc; -use super::util::populate_keywords; +use super::util::make_keywords; pub struct Lexer { /// GLSL source @@ -29,8 +29,8 @@ impl Lexer { input: input.chars().collect(), position: 0, current_char: None, - keywords: populate_keywords(), - symbols: populate_symbols(), + keywords: make_keywords(), + symbols: make_symbols(), }; dbg!("{}", &lexer.keywords); lexer.current_char = if lexer.position < lexer.input.len() { diff --git a/src/lex/util.rs b/src/lex/util.rs index a917127..b87a0c9 100644 --- a/src/lex/util.rs +++ b/src/lex/util.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use crate::tokens::{Image, Material, Sampler, Token, Vector}; -pub fn populate_symbols() -> HashMap { +pub fn make_symbols() -> HashMap { let mut symbols = HashMap::new(); symbols.insert('{', Token::LEFT_BRACE); symbols.insert('}', Token::RIGHT_BRACE); @@ -17,7 +17,7 @@ pub fn populate_symbols() -> HashMap { symbols } -pub fn populate_keywords() -> HashMap<&'static str, Token> { +pub fn make_keywords() -> HashMap<&'static str, Token> { let mut keywords = HashMap::new(); keywords.insert("const", Token::CONST); keywords.insert("uniform", Token::UNIFORM); diff --git a/src/lib.rs b/src/lib.rs index 62e378d..2aa22ef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -112,6 +112,18 @@ mod tests { vec![Token::FLOATCONSTANT(".4504".to_string()), Token::EOF].into() ); } + + #[test] + fn float_with_e_strogen() { + let source_code = "1e38"; + let mut lexer = Lexer::new(source_code); + let tokens = lexer.get_tokens(); + assert_eq!( + tokens, + vec![Token::FLOATCONSTANT("1e38".to_string()), Token::EOF].into() + ); + } + #[test] fn integer_literal() { let source_code = "12345";