3 Commits

Author SHA1 Message Date
8911702c0d
refactor(parser): overhaul parsing logic and enhance error reporting
Signed-off-by: erick-alcachofa <erick@artichoke.dev>

Major refactoring of the Parser and Tokenizer components to improve code
maintainability, strengthen error messaging, and streamline AST
generation.

This version intentionally focuses on top-level declarations, with
statement parsing stubbed for the next development phase.

- **Path Sanitization**: Added `sanitizePath` to extract filenames from
  input paths, ensuring consistent `unitName` identification regardless
  of directory depth.
- **Improved Output**: Wrapped AST string output in Markdown code blocks
  and added a commented-out entry for the new DOT graph visualization.

- **Unified Consumption**: Replaced manual token checks with a more
  robust `consume()` method that leverages `peekExpect()` for
  centralized error handling.
- **New Predicates**: Introduced `match()` and `matchAndConsume()`
  helpers to handle optional tokens and branching logic without
  redundant peek/consume calls.
- **Exception Handling**: Standardized the use of `langException` across
  all parsing functions, providing more descriptive "Expected X, found
  Y" messages.

- **Declarations**: Refactored `parseTopLevelDeclaration` and
  sub-parsers (Module, Struct, Enum, Fn) to use the new matching
  patterns.
- **Looping Logic**: Replaced recursive-style parsing loops with
  `while(keepParsing)` iterative blocks to prevent stack depth issues
  and clarify termination conditions (e.g., finding a closing brace or
  failing to find a comma).
- **Namespaced Identifiers**: Rewrote `parseNamespacedIdentifier` to
  correctly handle multi-part paths (`A::B::C`) and edge cases.
- **Generic Support**: Improved handling of generic parameter and
  argument lists, ensuring strict enforcement of delimiters like `<` and
  `>`.

- **Contextual Errors**: Updated `peekExpect` to accept a custom
  `message` string, allowing the parser to describe *what* it was
  looking for (e.g., "Expected ';'").
- **Token Lookahead**: Enhanced `peek` and `peekExpect` reliability with
  better bounds checking and buffer management.

- **Removed `lib/src/Parser/AST/AST.cpp`**: Deleted the monolithic AST
  stringification file in favor of the previously introduced modular
  implementations.
- **Build System**: Updated `.gitignore` to ignore
  `cpm-package-lock.cmake`.
2025-12-25 11:41:08 -06:00
0f4474821d
chore: Added CMake project setup
Added CMake files to set up project build, also added the file tree
structure of the project and clangd related settings
2025-03-04 12:50:53 -06:00
0f68b149da
chore: Initial commit
Initial commit for repo, added .gitignore, LICENSE, NOTICE and README.md
files
2025-03-01 01:27:46 -06:00