From c6b35b795b4ad56cb0a09dac6fe7f4e3ddd6e25b Mon Sep 17 00:00:00 2001 From: xqtc161 Date: Thu, 11 Jul 2024 12:03:42 +0200 Subject: [PATCH] sillyyyy :P --- .forgejo/workflows/uwu.yaml | 6 +++++ flake.lock | 4 ++-- src/lib.rs | 44 +++++++++++++++++++++++++++++++++---- 3 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 .forgejo/workflows/uwu.yaml diff --git a/.forgejo/workflows/uwu.yaml b/.forgejo/workflows/uwu.yaml new file mode 100644 index 0000000..d470cda --- /dev/null +++ b/.forgejo/workflows/uwu.yaml @@ -0,0 +1,6 @@ +on: [push] +jobs: + test: + runs-on: docker + steps: + - run: echo All Good diff --git a/flake.lock b/flake.lock index eaffa04..b894095 100644 --- a/flake.lock +++ b/flake.lock @@ -81,11 +81,11 @@ "locked": { "lastModified": 1, "narHash": "sha256-8wkkYGr1dPSnX9oVMX8D6dTOROXKOYpBTKfriA0sEBI=", - "path": "/nix/store/z4by2bx56bm456s77isfwvr59mqg9brg-source/flake.systems.nix", + "path": "/nix/store/7rlwm9hr4df367974cszjpbmjbd36jvn-source/flake.systems.nix", "type": "path" }, "original": { - "path": "/nix/store/z4by2bx56bm456s77isfwvr59mqg9brg-source/flake.systems.nix", + "path": "/nix/store/7rlwm9hr4df367974cszjpbmjbd36jvn-source/flake.systems.nix", "type": "path" } }, diff --git a/src/lib.rs b/src/lib.rs index fcb6df4..322af8d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,26 +1,62 @@ -// WIP THAT SHIT STILL WONKY AF +//! A simple lexer for GLSL. +//! +//! Adheres to the GLSL 440. Read the spec +//! [here](https://registry.khronos.org/OpenGL/specs/gl/GLSLangSpec.4.40.pdf). +//! ## Example +//! ``` +//! use glsl_lexer::*; +//! +//! fn main() { +//! let source = r#" +//! #version 440 +//! uniform float time; +//! void main() { +//! gl_FragColor = vec4(1.0, 0.5, 0.2, 1.0); +//! } +//! "#; +//! let mut lexer = glsl_lexer::Lexer::new(&source); +//! let tokens = lexer.get_tokens(); +//! dbg!("{}", tokens); +//! } +//! ``` + +//! # WIP THAT SHIT STILL WONKY AF #[derive(Debug, PartialEq)] pub enum Token { + /// Something like `float` Identifier(String), + /// Something like `uniform` Keyword(String), + /// Something like `13` IntegerLiteral(i64), + /// Something like `3.5` or `.5` FloatLiteral(f64), + /// Something like `+` Operator(String), + /// Something like `{` Symbol(char), + /// Should be self-explanatory Whitespace, + /// Something like `// uwu` Comment(String), + /// Shrouded in mystery Unknown(char), + /// End Of File EOF, } pub struct Lexer { - input: Vec, - position: usize, - current_char: Option, + /// GLSL source + pub input: Vec, + /// Position in source + pub position: usize, + /// [`char`] under position + pub current_char: Option, } impl Lexer { + /// Instantiates the [`Lexer`] pub fn new(input: &str) -> Self { let mut lexer = Lexer { input: input.chars().collect(),