erick-alcachofa 923b8d7e2d
refactor(parser): move parser utility methods to source file
Signed-off-by: erick-alcachofa <erick@artichoke.dev>

Relocate core parsing utility methods from the header to the
implementation file to reduce header bloat and improve compilation
times.

- **Parser API**: Moved the definitions of `consume()`,
  `matchAndConsume()`, and `match()` from `Parser.hpp` to `Parser.cpp`.
- **Cleanup**: Removed an unused `<print>` include in `Types.cpp`
  discovered during the refactor.
- **Organization**: Methods are now declared in the header and defined
  in the source file, maintaining a cleaner separation between interface
  and implementation.
2025-12-25 13:35:50 -06:00

167 lines
4.7 KiB
C++

//============================================================================//
// //
// artichoke programming language //
// //
// Copyright (C) 2025 Erick Saul Guzman Ramos, whoami.artichoke.dev //
// //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as published //
// by the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
// //
//============================================================================//
#pragma once
#include <artichoke/Parser/AST/AST.hpp>
#include <artichoke/Tokenizer/Tokenizer.hpp>
namespace arti::lang {
struct Parser {
Parser(std::string source) noexcept;
Parser(std::string unitName, std::string source) noexcept;
Parser(Parser &&) noexcept;
Parser &operator=(Parser &&) noexcept;
Parser(const Parser &) noexcept = delete;
Parser &operator=(const Parser &) noexcept = delete;
Expected<ast::AST> parse();
Expected<Token>
consume(TokenV type, std::string_view message);
Expected<bool>
matchAndConsume(TokenV type);
Expected<bool>
match(TokenV type, std::size_t offset = 0);
Expected<ast::Optional<ast::TopLevelDeclNode>>
parseTopLevelDeclaration();
Expected<ast::ImportDeclNode>
parseImportDeclaration();
Expected<ast::AliasDeclNode>
parseAliasDeclaration();
Expected<ast::ModuleDeclNode>
parseModuleDeclaration();
Expected<ast::StructDeclNode>
parseStructDeclaration();
Expected<ast::EnumDeclNode>
parseEnumDeclaration();
Expected<ast::Vector<ast::GenericParamNode>>
parseGenericParamsList();
Expected<ast::GenericParamNode>
parseGenericParam();
Expected<ast::Vector<ast::StructMemberNode>>
parseStructMembersList();
Expected<ast::StructMemberNode>
parseStructMember();
Expected<ast::Vector<ast::EnumMemberNode>>
parseEnumMembersList();
Expected<ast::EnumMemberNode>
parseEnumMember();
Expected<ast::FunctionDeclNode>
parseFunctionDeclaration();
Expected<ast::NamespacedIdentifierNode>
parseNamespacedIdentifier();
Expected<ast::TypeNode>
parseType();
Expected<ast::Vector<ast::TypeQualifier>>
parseTypeQualifiers();
Expected<ast::Vector<ast::TypeNode>>
parseGenericArgumentsList();
Expected<ast::Vector<ast::FunctionParamNode>>
parseFunctionParamsList();
Expected<ast::FunctionParamNode>
parseFunctionParam();
Expected<ast::FunctionParamNode>
parseFunctionParamThis();
Expected<ast::CodeBlockStmtNode>
parseCodeBlock();
Expected<ast::Optional<ast::StatementNode>>
parseStatement();
Expected<ast::VariableStmtNode>
parseVariableStatement();
Expected<ast::IfStmtNode>
parseIfStatement();
Expected<ast::DeferStmtNode>
parseDeferStatement();
Expected<ast::ErrDeferStmtNode>
parseErrDeferStatement();
Expected<ast::ReturnStmtNode>
parseReturnStatement();
Expected<ast::BreakStmtNode>
parseBreakStatement();
Expected<ast::ContinueStmtNode>
parseContinueStatement();
Expected<ast::MatchStmtNode>
parseMatchStatement();
Expected<ast::SwitchStmtNode>
parseSwitchStatement();
Expected<ast::CForStmtNode>
parseCForStatement();
Expected<ast::RangeForStmtNode>
parseRangeForStatement();
Expected<ast::WhileStmtNode>
parseWhileStatement();
Expected<ast::DoWhileStmtNode>
parseDoWhileStatement();
Expected<ast::InfLoopStmtNode>
parseInfLoopStatement();
private:
std::string unitName;
std::string sourceCode;
Tokenizer tokenizer;
};
}