diff --git a/bong_grammar.txt b/bong_grammar.txt index bac29da..04becae 100644 --- a/bong_grammar.txt +++ b/bong_grammar.txt @@ -103,15 +103,25 @@ MultiLineWhitespace -> [ \t\n\r\f\v]+ SingleLineComment -> \/\/[^\n]+ MultiLineComment -> \/\*.*?\*\/ -Name -> [a-zA-Z_][a-zA-Z0-9_]* -Id -> #[a-zA-Z0-9_]+ -Class \.[a-zA-Z0-9_]+ - -Int -> [0-9]+ Float -> [0-9]+\.[0-9]* +Int -> [0-9]+ String -> " Null -> "null" False -> "false" True -> "true" + +Name -> [a-zA-Z_][a-zA-Z0-9_]* +Id -> #[a-zA-Z0-9_]+ +Class \.[a-zA-Z0-9_]+ + +LBrace -> "(" +RBrace -> ")" +LBracket -> "[" +RBracket -> "]" + +Equal -> "=" +Colon -> ":" +SemiColon -> ";" +Comma -> "," diff --git a/src/bong/lexer.rs b/src/bong/lexer.rs new file mode 100644 index 0000000..8ef23db --- /dev/null +++ b/src/bong/lexer.rs @@ -0,0 +1,68 @@ +use std::{iter::Peekable, str::Chars}; + +pub enum TokenType { + SinglelineWhitespace, + MultilineWhitespace, + SinglelineComment, + MultilineComment, + + Name, + Id, + Class, + + Int, + Float, + String, + Null, + False, + True, + + LBrace, + RBrace, + LBracket, + RBracket, + + Equal, + Colon, + SemiColon, + Comma, +} + +pub struct Token<'a> { + token_type: TokenType, + value: &'a str, + line: u32, + col: u32, +} + +pub struct LexerError { + line: u32, + col: u32, + message: String, +} + +impl LexerError { + pub fn new(line: u32, col: u32, message: String) -> Self { + Self { line, col, message } + } +} + +pub struct Lexer<'a> { + phantom: std::marker::PhantomData<&'a u32>, +} + +impl<'a> Lexer<'a> { + pub fn new(text: &'a str) -> Self { + Self { + phantom: std::marker::PhantomData {}, + } + } +} + +impl<'a> Iterator for Lexer<'a> { + type Item = Result, String>; + + fn next(&mut self) -> Option { + todo!() + } +} diff --git a/src/bong/mod.rs b/src/bong/mod.rs new file mode 100644 index 0000000..5333bc7 --- /dev/null +++ b/src/bong/mod.rs @@ -0,0 +1,2 @@ +mod lexer; +mod parser; diff --git a/src/bong/parser.rs b/src/bong/parser.rs new file mode 100644 index 0000000..95b8dfe --- /dev/null +++ b/src/bong/parser.rs @@ -0,0 +1,29 @@ +use std::iter::Map; + +use crate::bong::lexer::Lexer; + +pub enum Node { + Element { + name: String, + ids: Vec, + classes: Vec, + properties: Map>, + values: Vec, + }, + Object(Map>), + Array(Vec), + Int(i64), + Float(f64), + String(String), + Bool(bool), +} + +pub struct Parser<'a> { + lexer: Lexer<'a>, +} + +impl<'a> Parser<'a> { + pub fn new(lexer: Lexer<'a>) -> Self { + Self { lexer } + } +} diff --git a/src/main.rs b/src/main.rs index e7a11a9..13371d6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +mod bong; + fn main() { println!("Hello, world!"); }