From 4ac01099ce0f9128fbe53f4f47c7150ad5ea23c4 Mon Sep 17 00:00:00 2001 From: Araozu Date: Tue, 13 Aug 2024 15:19:18 -0500 Subject: [PATCH] chore: update changelog --- CHANGELOG.md | 16 ++++++++-------- src/lexic/scanner/number.rs | 15 ++++++--------- src/syntax/ast/functions.rs | 1 - src/syntax/ast/mod.rs | 6 +++++- src/syntax/parsers/expression/comparison.rs | 3 +-- src/syntax/parsers/expression/equality.rs | 3 +-- src/syntax/parsers/expression/factor.rs | 7 ++----- src/syntax/parsers/expression/term.rs | 7 ++----- 8 files changed, 25 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c822c9c..72c62ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,30 +5,30 @@ - Test correct operator precedence - Implement functions as first class citizens - Parse __more__ binary operators -- Store tokens for the semantic analysis phase, to have actual error reporting - Parse more complex bindings - Rework error messages - Parse other language constructions -- Type checking -- Check for conflicting identifiers - Namespace identifiers in the symbol table - Stdlib - Document code - Watch mode -- Formatter - Simple language server - Decide how to handle comments in the syntax (?)(should comments mean something like in rust?) -- Not ignore comments & whitespace, for code formatting +- Fix comment handling in the AST - Abstract the parsing of datatypes, such that in the future generics can be implemented in a single place -- Include the original tokens in the AST -- Include comments in the AST - Begin work on the code formatter +- Remove all panic! and todo! ## v0.1.1 - [x] Top level expressions as statements -- [ ] Naively transpile variable bindings +- [x] Naively transpile variable bindings +- [x] Store tokens in the AST, to have actual error reporting +- [x] Scan octal and binary numbers +- [x] Simple type checking +- [x] Check for conflicting identifiers at the current scope + ## v0.1.0 diff --git a/src/lexic/scanner/number.rs b/src/lexic/scanner/number.rs index 1186d38..b00c3a6 100755 --- a/src/lexic/scanner/number.rs +++ b/src/lexic/scanner/number.rs @@ -11,10 +11,8 @@ pub fn scan(chars: &Vec, start_pos: usize) -> LexResult { match (next_char_1, next_char_2) { // Test if the input contains a hex number - (Some('0'), Some('x'|'X')) => { - scan_hex(chars, start_pos + 2, String::from("0x")) - } - (Some('0'), Some('o'|'O')) => { + (Some('0'), Some('x' | 'X')) => scan_hex(chars, start_pos + 2, String::from("0x")), + (Some('0'), Some('o' | 'O')) => { // octal scan_octal(chars, start_pos + 2) } @@ -375,7 +373,7 @@ mod tests { assert_eq!(t.get_end_position(), 4); assert_eq!(next, 4); } - _ => panic!("Expected a token") + _ => panic!("Expected a token"), } } @@ -389,7 +387,7 @@ mod tests { assert_eq!(error.end_position, 2); assert_eq!(error.reason, "Found an incomplete octal number"); } - _ => panic!("Expected an error, got {:?}", result) + _ => panic!("Expected an error, got {:?}", result), } } @@ -404,7 +402,7 @@ mod tests { assert_eq!(t.get_end_position(), 6); assert_eq!(next, 6); } - _ => panic!("Expected a token") + _ => panic!("Expected a token"), } } @@ -418,11 +416,10 @@ mod tests { assert_eq!(error.end_position, 2); assert_eq!(error.reason, "Found an incomplete binary number"); } - _ => panic!("Expected an error, got {:?}", result) + _ => panic!("Expected an error, got {:?}", result), } } - // Should scan a double #[test] fn test_double_1() { diff --git a/src/syntax/ast/functions.rs b/src/syntax/ast/functions.rs index 5000e85..5b9b20b 100644 --- a/src/syntax/ast/functions.rs +++ b/src/syntax/ast/functions.rs @@ -14,7 +14,6 @@ impl Positionable for FunctionCall<'_> { } } - #[derive(Debug)] pub struct ArgumentsList<'a> { pub arguments: Vec>, diff --git a/src/syntax/ast/mod.rs b/src/syntax/ast/mod.rs index cd6d921..82cdc70 100644 --- a/src/syntax/ast/mod.rs +++ b/src/syntax/ast/mod.rs @@ -94,7 +94,11 @@ impl Positionable for Expression<'_> { let (_, end) = exp.get_position(); (start, end) } - Expression::BinaryOperator(_, _, _) => (0, 1), + Expression::BinaryOperator(left_expr, right_expr, _) => { + let (start, _) = left_expr.get_position(); + let (_, end) = right_expr.get_position(); + (start, end) + } } } } diff --git a/src/syntax/parsers/expression/comparison.rs b/src/syntax/parsers/expression/comparison.rs index 315a4b3..5e41e98 100644 --- a/src/syntax/parsers/expression/comparison.rs +++ b/src/syntax/parsers/expression/comparison.rs @@ -36,8 +36,7 @@ fn parse_many<'a>( tokens, next_pos, ) { Ok((expr, next_pos)) => { - let expr = - Expression::BinaryOperator(Box::new(prev_expr), Box::new(expr), &token); + let expr = Expression::BinaryOperator(Box::new(prev_expr), Box::new(expr), &token); parse_many(tokens, next_pos, expr, indentation_level + indent_count) } diff --git a/src/syntax/parsers/expression/equality.rs b/src/syntax/parsers/expression/equality.rs index f59d93a..cd641e4 100644 --- a/src/syntax/parsers/expression/equality.rs +++ b/src/syntax/parsers/expression/equality.rs @@ -36,8 +36,7 @@ fn parse_many<'a>( tokens, next_pos, ) { Ok((expr, next_pos)) => { - let expr = - Expression::BinaryOperator(Box::new(prev_expr), Box::new(expr), &token); + let expr = Expression::BinaryOperator(Box::new(prev_expr), Box::new(expr), &token); parse_many(tokens, next_pos, expr, indentation_level + indent_count) } diff --git a/src/syntax/parsers/expression/factor.rs b/src/syntax/parsers/expression/factor.rs index 5ef6c81..ea9354a 100644 --- a/src/syntax/parsers/expression/factor.rs +++ b/src/syntax/parsers/expression/factor.rs @@ -36,11 +36,8 @@ fn parse_many<'a>( // match next match super::unary::try_parse(tokens, next_pos) { Ok((expr, next_pos)) => { - let expr = Expression::BinaryOperator( - Box::new(prev_expr), - Box::new(expr), - &token, - ); + let expr = + Expression::BinaryOperator(Box::new(prev_expr), Box::new(expr), &token); parse_many(tokens, next_pos, expr, indentation_level + indent_count) } diff --git a/src/syntax/parsers/expression/term.rs b/src/syntax/parsers/expression/term.rs index 29c5fcc..6abeb75 100644 --- a/src/syntax/parsers/expression/term.rs +++ b/src/syntax/parsers/expression/term.rs @@ -36,11 +36,8 @@ fn parse_many<'a>( // Parse the next factor match super::factor::try_parse(tokens, pos) { Ok((expr, next_pos)) => { - let expr = Expression::BinaryOperator( - Box::new(prev_expr), - Box::new(expr), - &token, - ); + let expr = + Expression::BinaryOperator(Box::new(prev_expr), Box::new(expr), &token); parse_many(tokens, next_pos, expr, indentation_level + indent_count) }