Add handler for operators; README
All checks were successful
/ build (push) Successful in 1m13s
/ clippy (push) Successful in 1m11s

This commit is contained in:
xqtc 2024-07-25 11:08:27 +02:00
parent c2966ce973
commit 483eb1885a
4 changed files with 39 additions and 4 deletions

12
README.md Normal file
View file

@ -0,0 +1,12 @@
# GLSL-LEXER
A library providing lexing capabilities for GLSL 460 and it's subsets.
---
## 👷🏻‍♀️ UNDER CONSTRUCTION 🚧
---
## Features
- [ ] Building Syntax Tree
- [ ] Exporting Syntax Tree as graphviz
- [ ] Integration with [epoqe demo toolchain](https://www.pouet.net/groups.php?which=15323)

View file

@ -49,6 +49,28 @@ impl Lexer {
todo!()
}
pub fn consume_operator(&mut self) -> crate::tokens::Token {
todo!()
let mut operator = String::new();
while let Some(c) = self.current_char {
operator.push(c);
match self.peek() {
Some('+') | Some('-') | Some('*') | Some('/') | Some('%') | Some('=')
| Some('!') | Some('<') | Some('>') => {
self.advance();
operator.push(
self.current_char
.expect("Critical error while lexing operators! Aborting..."),
);
}
None => {
self.advance();
break;
}
_ => {
self.advance();
break;
}
};
}
crate::tokens::Token::IDENTIFIER(operator)
}
}

View file

@ -2,7 +2,7 @@ use crate::tokens::Token;
use std::collections::HashMap;
use std::sync::Arc;
use super::util::populate_tokens;
use super::util::populate_keywords;
pub struct Lexer {
/// GLSL source
@ -29,7 +29,8 @@ impl Lexer {
current_char: None,
keywords: HashMap::new(),
};
populate_tokens(&mut lexer);
// Populate keywords HashMap
populate_keywords(&mut lexer);
dbg!("{}", &lexer.keywords);
lexer.current_char = if lexer.position < lexer.input.len() {
Some(lexer.input[lexer.position])

View file

@ -1,6 +1,6 @@
use crate::tokens::{Image, Material, Sampler, Token, Vector};
pub fn populate_tokens(lexer: &mut crate::lex::lexer::Lexer) {
pub fn populate_keywords(lexer: &mut crate::lex::lexer::Lexer) {
lexer.keywords.insert("const", Token::CONST);
lexer.keywords.insert("uniform", Token::UNIFORM);
lexer.keywords.insert("buffer", Token::BUFFER);