Signed-off-by: erick-alcachofa <erick@artichoke.dev> - Create lib/include/artichoke/Util/Common.hpp for shared types. - Migrate SourceLocation, Mutability, and TypeQualifier from AST. - Update Parser and AST files to use unified aliases (Ptr, Vector, etc.). - Clean up includes across the Parser module.
212 lines
5.7 KiB
C++
212 lines
5.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<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<Vector<ast::GenericParamNode>>
|
|
parseGenericParamsList();
|
|
|
|
Expected<ast::GenericParamNode>
|
|
parseGenericParam();
|
|
|
|
Expected<Vector<ast::StructMemberNode>>
|
|
parseStructMembersList();
|
|
|
|
Expected<ast::StructMemberNode>
|
|
parseStructMember();
|
|
|
|
Expected<Vector<ast::EnumMemberNode>>
|
|
parseEnumMembersList();
|
|
|
|
Expected<ast::EnumMemberNode>
|
|
parseEnumMember();
|
|
|
|
Expected<ast::FunctionDeclNode>
|
|
parseFunctionDeclaration();
|
|
|
|
Expected<ast::NamespacedIdentifierNode>
|
|
parseNamespacedIdentifier();
|
|
|
|
Expected<ast::TypeNode>
|
|
parseType();
|
|
|
|
Expected<Vector<TypeQualifier>>
|
|
parseTypeQualifiers();
|
|
|
|
Expected<Vector<ast::TypeNode>>
|
|
parseGenericArgumentsList();
|
|
|
|
Expected<Vector<ast::FunctionParamNode>>
|
|
parseFunctionParamsList();
|
|
|
|
Expected<ast::FunctionParamNode>
|
|
parseFunctionParam();
|
|
|
|
Expected<ast::FunctionParamNode>
|
|
parseFunctionParamThis();
|
|
|
|
Expected<ast::CodeBlockStmtNode>
|
|
parseCodeBlock();
|
|
|
|
Expected<Optional<ast::StatementNode>>
|
|
parseStatement();
|
|
|
|
Expected<ast::VariableStmtNode>
|
|
parseVariableStatement();
|
|
|
|
Expected<ast::IfStmtNode>
|
|
parseIfStatement();
|
|
|
|
Expected<ast::ElseBranchNode>
|
|
parseElseStatement();
|
|
|
|
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::StatementNode>
|
|
parseForLoopStatement();
|
|
|
|
Expected<ast::CForStmtNode>
|
|
parseCForStatement();
|
|
|
|
Expected<ast::RangeForStmtNode>
|
|
parseRangeForStatement();
|
|
|
|
Expected<ast::WhileStmtNode>
|
|
parseWhileStatement();
|
|
|
|
Expected<ast::DoWhileStmtNode>
|
|
parseDoWhileStatement();
|
|
|
|
Expected<ast::InfLoopStmtNode>
|
|
parseInfLoopStatement();
|
|
|
|
Expected<ast::ExpressionStmtNode>
|
|
parseExpressionStatement();
|
|
|
|
Expected<ast::ExpressionNode>
|
|
parseExpression(std::uint16_t p = 0);
|
|
|
|
Expected<Optional<ast::ExpressionNode>>
|
|
parsePrimaryExpression();
|
|
|
|
Expected<ast::ExpressionNode>
|
|
parsePrefixExpression();
|
|
|
|
Expected<ast::ExpressionNode>
|
|
parseInfixExpression(ast::ExpressionNode lhs);
|
|
|
|
Expected<ast::ExpressionNode>
|
|
parsePostfixExpression(ast::ExpressionNode lhs);
|
|
|
|
Expected<ast::IdentifierExprNode>
|
|
parseIdentifierExpression();
|
|
|
|
Expected<ast::CharLtrlNode>
|
|
parseCharLiteral();
|
|
|
|
Expected<ast::NullLtrlNode>
|
|
parseNullLiteral();
|
|
|
|
Expected<ast::StringLtrlNode>
|
|
parseStringLiteral();
|
|
|
|
Expected<ast::FloatLtrlNode>
|
|
parseFloatLiteral();
|
|
|
|
Expected<ast::IntegerLtrlNode>
|
|
parseIntegerLiteral();
|
|
|
|
Expected<ast::BooleanLtrlNode>
|
|
parseBooleanLiteral();
|
|
|
|
private:
|
|
std::string unitName;
|
|
std::string sourceCode;
|
|
Tokenizer tokenizer;
|
|
};
|
|
|
|
}
|