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`.
⚠️ WIP Highly Experimental Project
- The language, compiler, and tools are under active development and may be very unstable.
- There will likely be breaking changes and periods where no work is done on the project.
The artichoke Programming Language
artichoke is a modern, statically-typed programming language designed to
satisfy my personal preferences and requirements for programming, combining the
low-level control and powerful modern features like a robust type system,
generics, integrated error handling, and a clean, ergonomic syntax.
The goal of artichoke is to provide a language that is simple, safe, and
productive for programming, eliminating common pitfalls without sacrificing
performance or control.
For a detailed guide to the language, please see the project wiki.
Core Philosophy & Features
artichoke is built around a few core principles to create a safer, more
productive programming experience:
- Explicitness: Type conversions and error handling are explicit.
- Safety: Non-nullable pointers, a robust type system, and deterministic resource management are prioritized.
- Modern Ergonomics: Features like generics, defer, and a clean module system reduce boilerplate and improve readability.
The language includes a powerful generic type system, first-class error handling, a full suite of control flow statements (including match), a true module system, and compile-time reflection.
Project Status
artichoke is currently in the design and grammar-specification phase. The
grammar is stable, and the next step is the implementation of a compiler
(parser, semantic analyzer, and code generator).
Building from Source
# Get the source code
git clone https://git.artichoke.dev/me/artichoke-lang.git
# Configure cmake
# Optionally add -DENABLE_TESTING=ON for building tests
cmake -DCMAKE_BUILD_TYPE=Release -S . -B build
# Build the project
cmake --build build
# Run the binary
./build/frontend/artichoke-c
# Run the tests if enabled
ctest --test-dir build/tests --output-on-failure
# Install if wanted
cmake --install build --prefix=/usr/local
# Run the installed binary
arti-c
Contributing
The artichoke project is hosted on a personal, self-hosted Gitea instance. If
you are interested in contributing, you have two options:
- Request an Account: Please contact support@artichoke.dev to request an account on the Gitea instance.
- Submit Patches: Alternatively, you can send patches or diffs directly to the same email address.
In all cases, proper attribution will be given for your contributions in the source files and/or the project wiki.
License
This project is licensed under the GNU Affero General Public License v3.0. The full license text can be found in the LICENSE file in this repository.