diff --git a/hello-world.fddl b/hello-world.fddl new file mode 100644 index 0000000..c267dfe --- /dev/null +++ b/hello-world.fddl @@ -0,0 +1,3 @@ +func main() { + print(`hello, world in fddl`); +} diff --git a/readme.md b/readme.md index 8601d07..e1f3485 100644 --- a/readme.md +++ b/readme.md @@ -32,6 +32,12 @@ cargo run path/to/script.fddl ## Examples +```sh +func main() { + print(`hello, world in fddl`); +} +``` + ```sh ##! This is a sample module @@ -56,12 +62,13 @@ This project is licensed under the MIT License. ## **Notes and Next Steps** -- [x] Added first new set of tokens and features, added the first lexer tests. +- [x] Added first new set of tokens and features, added the first `lexer` tests. - [ ] `parser` module is a placeholder. - [ ] `interpreter` module is a placeholder. - [ ] Implement a more robust error handling mechanism instead of using `stderr`. - [ ] Imlement string interpolation (backticks with `$variable`) - [ ] Continue to expand tests to cover all new syntax and features. +- [x] Made a crappy website. --- diff --git a/src/lexer/lexer.rs b/src/lexer/lexer.rs index 98640e7..7bad899 100644 --- a/src/lexer/lexer.rs +++ b/src/lexer/lexer.rs @@ -139,6 +139,7 @@ impl Lexer { } // Helper methods + // function to consume the current character fn advance(&mut self) -> char { let c = if self.is_at_end() { '\0' @@ -149,6 +150,7 @@ impl Lexer { c } + // function to parse the current character if it matches the expected character fn match_char(&mut self, expected: char) -> bool { if self.is_at_end() { return false; @@ -162,6 +164,7 @@ impl Lexer { true } + // function to parse the current character without consuming it fn peek(&self) -> char { if self.is_at_end() { '\0' @@ -170,6 +173,7 @@ impl Lexer { } } + // function to parse the next character without consuming it fn peek_next(&self) -> char { if self.current + 1 >= self.source.len() { '\0' @@ -178,10 +182,12 @@ impl Lexer { } } + // function to check if we've reached the end of the source fn is_at_end(&self) -> bool { self.current >= self.source.len() } + // Function to handle different token types fn string(&mut self) -> Option { while self.peek() != '"' && !self.is_at_end() { if self.peek() == '\n' { @@ -206,6 +212,7 @@ impl Lexer { Some(Token::StringLiteral(value)) } + // Function to handle number literals fn number(&mut self) -> Option { while self.peek().is_ascii_digit() { self.advance(); @@ -228,6 +235,7 @@ impl Lexer { Some(Token::Number(value)) } + // Function to handle identifiers fn identifier(&mut self) -> Option { while self.is_alphanumeric(self.peek()) || self.peek() == '_' { self.advance(); @@ -275,20 +283,24 @@ impl Lexer { Some(token) } + // Function to check if a character is an alphabetic character or an underscore fn is_alpha(&self, c: char) -> bool { c.is_alphabetic() || c == '_' } + // Function to check if a character is an alphanumeric character or an underscore fn is_alphanumeric(&self, c: char) -> bool { c.is_alphanumeric() || c == '_' } + // Function to handle comments and documentation fn line_comment(&mut self) { while self.peek() != '\n' && !self.is_at_end() { self.advance(); } } + // Function to handle block comments fn block_comment(&mut self) { while !self.is_at_end() { if self.peek() == '*' && self.peek_next() == '/' { @@ -304,6 +316,7 @@ impl Lexer { } } + // Function to handle comments and documentation fn handle_comment_or_doc(&mut self) -> Option { // We have matched one '#' character so far let mut count = 1; @@ -348,7 +361,7 @@ impl Lexer { } } - + // Function to handle documentation comments fn doc_comment(&mut self, _kind: &str) -> Option { let mut comment = String::new(); while self.peek() != '\n' && !self.is_at_end() { diff --git a/src/lib.rs b/src/lib.rs index 8100f1d..9a09c5f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,3 @@ pub mod lexer; pub mod parser; -pub mod interpreter; - -// ohhhhh, this file puts your created files together \ No newline at end of file +pub mod interpreter; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 163f311..c051a33 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,7 +21,7 @@ fn main() { } fn run_repl() { - println!("fiddle REPL"); + println!("fddl REPL"); loop { print!("> "); io::stdout().flush().unwrap(); diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 949d0c2..638d966 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -1,4 +1,3 @@ // pub mod ast; // pub use ast::*; -// don't fully understand this re-export \ No newline at end of file