Line data Source code
1 : #pragma once
2 :
3 : #include <string>
4 :
5 : #include "stax/lexer/lexer.hpp"
6 : #include "stax/lexer/tokens.hpp"
7 : #include "stax/parser/ast.hpp"
8 : #include "stax/utils/result.hpp"
9 :
10 : namespace stax::parser {
11 :
12 0 : DEFINE_ERROR("stax::parser", Error, Syntax, InvalidToken, ExpectedToken)
13 :
14 : class Parser {
15 : public:
16 : Parser(const std::string& input);
17 :
18 : auto ParseProgram() -> result_t<Program>;
19 :
20 : private:
21 : auto ParseStatement() -> result_t<ast_t>;
22 : auto ParseDeclaration() -> result_t<ast_t>;
23 : auto ParseFunctionDeclaration(const DataType& return_type,
24 : const Identifier& ident) -> result_t<ast_t>;
25 : auto ParseVariableDeclaration(const DataType& var_type,
26 : const Identifier& ident) -> result_t<ast_t>;
27 : auto ParseReturn() -> result_t<ast_t>;
28 : auto ParseExpressionStatement() -> result_t<ExpressionStatement>;
29 :
30 : auto ParseExpression() -> result_t<expression_t>;
31 :
32 : auto NextToken() -> result_t<void>;
33 :
34 : auto Expect(token::Type tok_type) -> result_t<void>;
35 : auto ExpectPeek(token::Type tok_type) -> result_t<void>;
36 :
37 : std::string input_;
38 : lexer::Lexer lexer_;
39 :
40 : token::Token curr_;
41 : token::Token peek_;
42 : };
43 :
44 : } // namespace stax::parser
|