Compare commits

...

4 Commits

Author SHA1 Message Date
5ba801a756
feat: Add file parsing entry point and refine grammar rules
Signed-off-by: erick-alcachofa <erick@artichoke.dev>

- Updated `main.cpp` to read source files and invoke the parser using
  `MatcherRule<rules::Program>`, providing clear error output or success
  indication.
- Replaced `peek` with `peekExpect` in `Parser` to ensure expected token
  types.
- Replaced parentheses with curly braces for struct and enum definitions
  as specified on grammar.
- Fixed `StructMembers` and `EnumMembers` to allow zero or more entries
  as specified on grammar.
- Replaced `MatcherNoneOrOnce` with `MatcherNoneOrMore` in expression
  rules to support chained binary expressions as specified on grammar.
- Reorganized `PrimaryTypeExpression` to include all valid expression
  types, and reordered rules for better match accuracy.
- Fixed `TypesListR` to correctly refer to `Type` instead of
  `TypesListR` in its recursive rule.

These changes fixes language grammar coverage, fix structural parsing
bugs, and enable full file parsing from the frontend.
2025-10-05 22:55:49 -06:00
86d069d3d9
chore: Merge branch 'main' into tmp-parser
Signed-off-by: erick-alcachofa <erick@artichoke.dev>
2025-10-05 22:54:27 -06:00
ea067b6c54
chore: Merge branch 'main' into tmp-parser 2025-10-05 14:55:09 -06:00
701f0e595d
feat(parser): add recursive descent parser framework and grammar rules
Signed-off-by: erick-alcachofa <erick@artichoke.dev>

This commit introduces the initial implementation of the language
parser. It is designed as a compile-time, template-based recursive
descent parser using a system of parser combinators.

The new `Parser.hpp` header contains the core parsing infrastructure:
- A set of parser combinator structs (`MatcherSequence`, `MatcherAnyOf`,
  `MatcherNoneOrMore`, etc.) to build complex parsing logic.
- C++20 concepts (`ParserRule`, `ParserRuleDefinition`) to define and
  constrain grammar rules.
- A `GenericParser` to recursively dispatch parsing tasks.
- A `rules` namespace that defines the entire language grammar, with
  each rule implemented as a struct using the combinator framework.
- An initial `MatcherEOF` to ensure the entire input is consumed.

The parser currently validates the token stream against the defined
grammar but does not yet build a meaningful Abstract Syntax Tree (AST).

Placeholder structures are in place for future AST construction.

WARN: This is an experimental implementation just for fun and may not be
the implementation that might end up being used.
2025-10-04 10:37:24 -06:00
3 changed files with 1551 additions and 2 deletions

View File

@ -1,5 +1,45 @@
#include <print>
#include <fstream>
int main(int, char **) {
std::println("[LOG] Hello world");
#include <artichoke/Parser/Parser.hpp>
int main(int argc, char **argv) {
using namespace arti::lang;
if (argc < 2) {
std::println("Usage:\n {} <filename>", argv[0]);
return -1;
}
std::ifstream file;
file.open(argv[1]);
if (!file.is_open()) {
std::println("Failed to open file {}", argv[1]);
return -1;
}
std::string buffer{
std::istreambuf_iterator<char>(file),
std::istreambuf_iterator<char>()
};
Tokenizer tokenizer{buffer};
auto result = MatcherRule<rules::Program>::parse(&tokenizer, 0);
if (!result) {
auto err = std::move(result).error();
std::println(
"Error at line {}, column {}. {}",
err.line,
err.column,
err.message
);
}
else {
std::println("Valid source");
}
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
#include <artichoke/Parser/Parser.hpp>