Some refactoring
All checks were successful
/ build (push) Successful in 1m34s
/ clippy (push) Successful in 1m10s

This commit is contained in:
xqtc 2024-07-25 20:01:35 +02:00
parent 1561375d38
commit 513f2f86f2
5 changed files with 23 additions and 11 deletions

View file

@ -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:

View file

@ -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()

View file

@ -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() {

View file

@ -2,7 +2,7 @@ use std::collections::HashMap;
use crate::tokens::{Image, Material, Sampler, Token, Vector};
pub fn populate_symbols() -> HashMap<char, Token> {
pub fn make_symbols() -> HashMap<char, Token> {
let mut symbols = HashMap::new();
symbols.insert('{', Token::LEFT_BRACE);
symbols.insert('}', Token::RIGHT_BRACE);
@ -17,7 +17,7 @@ pub fn populate_symbols() -> HashMap<char, Token> {
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);

View file

@ -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";