16 Commits

Author SHA1 Message Date
66eca2f24a
feat(Parser): Expanding parser capabilities (might clean later)
Signed-off-by: erick-alcachofa <erick@artichoke.dev>
2025-10-16 23:22:19 -06:00
552cda58e7
feat(Parser): Introduce AST toString and basic parser structure
Signed-off-by: erick-alcachofa <erick@artichoke.dev>

This commit introduces the foundational structure for the parser and
Abstract Syntax Tree (AST). It includes a new `Parser.hpp` header that
outlines the primary parsing functions for top-level declarations like
`modules`, `structs`, `enums`, and `functions`. It also adds a
`toString` function for the AST to aid in debugging and visualization.

The commit also updates the `Expected.hpp` utility by adding new error
codes like `ecUnexpectedToken`, `ecExpectedSemicolon`,
`ecImportInsideModule`, and `ecUnimplemented` to provide more granular
and descriptive parsing errors. The `Tokenizer` has been updated to use
these new, more specific exceptions.
2025-10-15 16:12:19 -06:00
583b20230d
fix(Utils): Inherit from Ts in OverloadSet
Signed-off-by: erick-alcachofa <erick@artichoke.dev>

This commit changes the `OverloadSet` utility class to publicly inherit
from its template parameters `Ts...`. This allows the `operator()` from
each provided type to be brought into the overload set, efectively
fixing it's functionality that would be broken otherwise.

It also includes the missing `<ranges>` header in the test utilities.
2025-10-15 16:02:27 -06:00
9626ac07c8
refactor(AST): Make optional some fields in AST nodes
Signed-off-by: erick-alcachofa <erick@artichoke.dev>

This commit refactors several AST nodes to use `Optional<T>` for fields
that are not always present. This includes `attribute` in
`ReflectionExpression`, `elseBranch` in `IfStatement` and
`WhileStatement`, `defaultCase` in `MatchStatement` and
`SwitchStatement`, and `preLoop` and `postLoop` in `CForStatement`. This
change improves the robustness and clarity of the AST by explicitly
modeling optionality.
2025-10-15 15:58:06 -06:00
d979b10bee
feat(AST): Add Uninitialized and missing binary operators to common enums
Signed-off-by: erick-alcachofa <erick@artichoke.dev>

This commit adds `Uninitialized` to several enums in `Common.hpp` to
ensure they are properly initialized.

It also adds missing binary operators like `BitAnd`, `BitXor`,
`Adition`, and `Multiplication`. This change improves the robustness and
functionality of the AST parser.
2025-10-15 15:53:37 -06:00
5e94021ae5
feat(AST): Add node factory helper and missing identifier node
Signed-off-by: erick-alcachofa <erick@artichoke.dev>

This commit introduces an utility factory function and structural
improvements to the Abstract Syntax Tree (AST).

* Adds a new `ASTNodePtr` C++20 concept to constrain template types to
  be `std::unique_ptr`s pointing to AST nodes.
* Introduces a `MakeNode<T>()` factory function that uses this concept
  to simplify and standardize the creation of new nodes.
* Fixed `NamespacedType` and added the missing `NamespacedIdentifier`
  node.
2025-10-12 18:55:34 -06:00
91aefc27b3
chore: Remove unused headers in Generator.hpp
Signed-off-by: erick-alcachofa <erick@artichoke.dev>

Removed the unused <ranges> and <generator> includes from the
Generator.hpp header file.
2025-10-12 18:54:03 -06:00
c4c3d71cc4
feat(AST): Refactor AST nodes into a multi-file structure
Signed-off-by: erick-alcachofa <erick@artichoke.dev>

This commit refactors the AST (Abstract Syntax Tree) to improve code
organization, clarity, and maintainability. The large single-file AST
definition has been split into multiple, logically grouped header files.

The key changes are:

- **New File Structure**: The single `Node.hpp` file is replaced by a
  modular structure consisting of `Common.hpp`, `Declarations.hpp`,
  `Expressions.hpp`, `Literals.hpp`, `Statements.hpp`, and a new central
  `AST.hpp` header.
- **Improved Naming**: All AST node structs and their aliases have been
  renamed to follow a consistent `[NodeName][NodeType]` convention, such
  as `StructDeclaration` and `StructDeclNode`.
- **Namespace Change**: The `node` namespace has been replaced by
  `arti::lang::ast::nodes` to provide better encapsulation and prevent
  naming conflicts.
- **Type Aliases**: Helper aliases like `String`, `Vector`, and
  `Variant` have been introduced to simplify the code.
2025-10-12 17:40:29 -06:00
9dcd5490e3
feat(AST): Define complete set of AST nodes
Signed-off-by: erick-alcachofa <erick@artichoke.dev>

Introduces the comprehensive header file for the Abstract Syntax Tree,
providing the foundational structures for the parser and subsequent
compiler stages.

This initial version defines all node types required to represent the
language's grammar, including:
- Top-level program structure and module declarations.
- All statement types, including control flow, loops, and deferrals.
- A semantic expression tree designed for a Pratt parser (Unary, Binary,
  Function Calls, etc.).
- A robust, recursive type system for handling complex type signatures.

The design employs modern C++ for safety and clarity:
- `std::unique_ptr` establishes clear ownership of child nodes.
- `std::variant` provides type-safe polymorphism for Statement,
  Expression, and Declaration nodes.
- `std::optional` is used to accurately model optional grammar rules.
- `SourceLocation` is included in every node to support detailed error
  reporting.
2025-10-12 02:07:01 -06:00
ffd66f1f86
feat: Added peekExpect method for token type validation in tokenizer
Signed-off-by: erick-alcachofa <erick@artichoke.dev>

Introduced `peekExpect(std::size_t, TokenV)` to the Tokenizer class, enabling
token lookahead with explicit token type checks. This method returns an
`Unexpected` error with diagnostic info if the expected token type does not
match the peeked token.

Includes a special case handling (workaround) for distinguishing between
`>` and `>>` tokens when parsing the token stream.
2025-10-05 22:51:16 -06:00
bb58b17528
fix: Fixed typo in keyword and added missing do and typename keywords
Signed-off-by: erick-alcachofa <erick@artichoke.dev>
2025-10-04 10:35:03 -06:00
e1b9e054f3
feat(test, tokenizer): Add test suite, in Tokenizer fixed catched issues and range-based API
Signed-off-by: erick-alcachofa <erick@artichoke.dev>

This commit introduces a comprehensive test suite for the tokenizer
using the Catch2 framework. To support this and improve the project
structure, the build system and the tokenizer's API have been
significantly updated.

- Removed `cmake/testing.cmake` as it's no longer needed.
- A new `TokenizerRange` class provides a C++20-style range interface,
  allowing for simple `for-each` loop iteration over tokens. This is
  used extensively in the new tests.

- The CMake build system has been refactored:
    - An `ENABLE_TESTING` option (OFF by default) now controls whether
      the test suite is built.
    - The core library is now compiled into an object library, which is
      then used to produce both a shared (`.so`/`.dll`) and a static
      (`.a`/`.lib`) library. This improves build efficiency and provides
      more flexible linkage options.
    - The frontend executable now links against the static version of
      the library.

- Implemented tests for tokenizer using Catch2 framework, covering
  various cases like identifiers, keywords, numbers, etc. that already
  catched some issues in current implementation.

- Several parsing bugs and edge cases in the tokenizer were fixed,
  including the handling of unterminated strings and invalid numeric
  literals. The README has been updated with instructions for building
  and running tests.
2025-10-03 12:54:41 -06:00
d0599d374f
feat: Add language grammar and adjusted tokenizer
Signed-off-by: erick-alcachofa <erick@artichoke.dev>

This commit lays the foundational groundwork for the artichoke language
parser by introducing the formal language grammar specification.

The tokenizer was updated to include new operators and keywords, also
added the posibility to handle comments.

Key Additions:
- Implemented support for C-style block comments (`/* ... */`),
  including error handling for unclosed comments.
- Added all necessary tokens for missing keywords (e.g., `module`,
  `export`, `using`, `match`, `loop`) and operators (e.g., `+=`, `:=`,
  `.#`, `.*`, `.@`).
- The `Token` enum has been expanded to reflect the full language
  feature set.

Documentation:
- Added `docs/grammar.ebnf` which contains the official, well-structured
  EBNF grammar for the language.
- Added `docs/readme.md` providing a detailed technical overview of the
  language's features, syntax, and semantics.

BREAKING CHANGE: The `kwVariant` and `kwMut` tokens have been removed to
align with the updated language design defined in the new grammar.
2025-10-01 18:51:09 -06:00
f9051e1c21
fix: Minor fixes
Fixed some minor mistakes (wrong messages/errors) due to copy/pasting
code.

Fixed that digits weren't allowed in identifiers before.

Also minor improvements in some functions/code parts.
2025-06-30 00:31:10 -06:00
85a34bdd65
feat: Added Token, Tokenizer, Generator, and some utilities
Initial version of Tokenizer and Token
Generator template for coroutines (used in tokenizer)
Utilities like string related functions, TrieMap, and error handling

TODO: Add tests for Tokenizer
TODO: Add tests for Generator
2025-03-10 01:20:23 -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