parent
9b00529bbd
commit
c6b35b795b
6
.forgejo/workflows/uwu.yaml
Normal file
6
.forgejo/workflows/uwu.yaml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
on: [push]
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: docker
|
||||||
|
steps:
|
||||||
|
- run: echo All Good
|
|
@ -81,11 +81,11 @@
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1,
|
"lastModified": 1,
|
||||||
"narHash": "sha256-8wkkYGr1dPSnX9oVMX8D6dTOROXKOYpBTKfriA0sEBI=",
|
"narHash": "sha256-8wkkYGr1dPSnX9oVMX8D6dTOROXKOYpBTKfriA0sEBI=",
|
||||||
"path": "/nix/store/z4by2bx56bm456s77isfwvr59mqg9brg-source/flake.systems.nix",
|
"path": "/nix/store/7rlwm9hr4df367974cszjpbmjbd36jvn-source/flake.systems.nix",
|
||||||
"type": "path"
|
"type": "path"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"path": "/nix/store/z4by2bx56bm456s77isfwvr59mqg9brg-source/flake.systems.nix",
|
"path": "/nix/store/7rlwm9hr4df367974cszjpbmjbd36jvn-source/flake.systems.nix",
|
||||||
"type": "path"
|
"type": "path"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
44
src/lib.rs
44
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)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum Token {
|
pub enum Token {
|
||||||
|
/// Something like `float`
|
||||||
Identifier(String),
|
Identifier(String),
|
||||||
|
/// Something like `uniform`
|
||||||
Keyword(String),
|
Keyword(String),
|
||||||
|
/// Something like `13`
|
||||||
IntegerLiteral(i64),
|
IntegerLiteral(i64),
|
||||||
|
/// Something like `3.5` or `.5`
|
||||||
FloatLiteral(f64),
|
FloatLiteral(f64),
|
||||||
|
/// Something like `+`
|
||||||
Operator(String),
|
Operator(String),
|
||||||
|
/// Something like `{`
|
||||||
Symbol(char),
|
Symbol(char),
|
||||||
|
/// Should be self-explanatory
|
||||||
Whitespace,
|
Whitespace,
|
||||||
|
/// Something like `// uwu`
|
||||||
Comment(String),
|
Comment(String),
|
||||||
|
/// Shrouded in mystery
|
||||||
Unknown(char),
|
Unknown(char),
|
||||||
|
/// End Of File
|
||||||
EOF,
|
EOF,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Lexer {
|
pub struct Lexer {
|
||||||
input: Vec<char>,
|
/// GLSL source
|
||||||
position: usize,
|
pub input: Vec<char>,
|
||||||
current_char: Option<char>,
|
/// Position in source
|
||||||
|
pub position: usize,
|
||||||
|
/// [`char`] under position
|
||||||
|
pub current_char: Option<char>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Lexer {
|
impl Lexer {
|
||||||
|
/// Instantiates the [`Lexer`]
|
||||||
pub fn new(input: &str) -> Self {
|
pub fn new(input: &str) -> Self {
|
||||||
let mut lexer = Lexer {
|
let mut lexer = Lexer {
|
||||||
input: input.chars().collect(),
|
input: input.chars().collect(),
|
||||||
|
|
Loading…
Reference in a new issue