2020-11-10 15:26:38 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <hex.hpp>
|
|
|
|
#include "token.hpp"
|
|
|
|
#include "ast_node.hpp"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace hex::lang {
|
|
|
|
|
|
|
|
class Parser {
|
|
|
|
public:
|
|
|
|
Parser();
|
|
|
|
|
2020-11-27 21:20:23 +01:00
|
|
|
using TokenIter = std::vector<Token>::const_iterator;
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
std::optional<std::vector<ASTNode*>> parse(const std::vector<Token> &tokens);
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2020-11-27 21:20:23 +01:00
|
|
|
const std::pair<u32, std::string>& getError() { return this->m_error; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::pair<u32, std::string> m_error;
|
|
|
|
|
|
|
|
|
2020-12-06 21:40:57 +01:00
|
|
|
ASTNode* parseBuiltinVariableDecl(TokenIter &curr, bool hasEndianDef);
|
|
|
|
ASTNode* parseCustomTypeVariableDecl(TokenIter &curr, bool hasEndianDef);
|
|
|
|
ASTNode* parseBuiltinPointerVariableDecl(TokenIter &curr, bool hasEndianDef);
|
|
|
|
ASTNode* parseCustomTypePointerVariableDecl(TokenIter &curr, bool hasEndianDef);
|
|
|
|
ASTNode* parseBuiltinArrayDecl(TokenIter &curr, bool hasEndianDef);
|
|
|
|
ASTNode* parseCustomTypeArrayDecl(TokenIter &curr, bool hasEndianDef);
|
|
|
|
ASTNode* parseBuiltinVariableArrayDecl(TokenIter &curr, bool hasEndianDef);
|
|
|
|
ASTNode* parseCustomTypeVariableArrayDecl(TokenIter &curr, bool hasEndianDef);
|
2020-11-27 21:20:23 +01:00
|
|
|
ASTNode* parsePaddingDecl(TokenIter &curr);
|
2020-12-06 21:40:57 +01:00
|
|
|
ASTNode* parseFreeBuiltinVariableDecl(TokenIter &curr, bool hasEndianDef);
|
|
|
|
ASTNode* parseFreeCustomTypeVariableDecl(TokenIter &curr, bool hasEndianDef);
|
|
|
|
|
2020-11-27 21:20:23 +01:00
|
|
|
ASTNode* parseStruct(TokenIter &curr);
|
|
|
|
ASTNode* parseUnion(TokenIter &curr);
|
|
|
|
ASTNode* parseEnum(TokenIter &curr);
|
|
|
|
ASTNode *parseBitField(TokenIter &curr);
|
|
|
|
ASTNode *parseScope(TokenIter &curr);
|
|
|
|
std::optional<ASTNode*> parseUsingDeclaration(TokenIter &curr);
|
|
|
|
std::optional<std::vector<ASTNode*>> parseStatement(TokenIter &curr);
|
|
|
|
|
|
|
|
std::vector<ASTNode*> parseTillToken(TokenIter &curr, Token::Type endTokenType);
|
|
|
|
bool tryConsume(TokenIter &curr, std::initializer_list<Token::Type> tokenTypes);
|
2020-11-10 15:26:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|