1
0
mirror of synced 2024-11-19 05:17:12 +01:00
ImHex/include/lang/parser.hpp
WerWolv dbbc525174
Added Plugin support (#102)
* Build refactoring and initial plugin support

* Possibly fixed linux / mac build

* Added libdl to libglad build script

* Add glfw to imgui dependencies

* Refactored common functionality into "libimhex" for plugins

* Added plugin loading and example plugin

* Added proper API for creating a custom view and a custom tools entry with plugins
2020-12-22 18:10:01 +01:00

49 lines
1.9 KiB
C++

#pragma once
#include <hex.hpp>
#include "token.hpp"
#include "ast_node.hpp"
#include <vector>
namespace hex::lang {
class Parser {
public:
Parser();
using TokenIter = std::vector<Token>::const_iterator;
std::optional<std::vector<ASTNode*>> parse(const std::vector<Token> &tokens);
const std::pair<u32, std::string>& getError() { return this->m_error; }
private:
std::pair<u32, std::string> m_error;
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);
ASTNode* parsePaddingDecl(TokenIter &curr);
ASTNode* parseFreeBuiltinVariableDecl(TokenIter &curr, bool hasEndianDef);
ASTNode* parseFreeCustomTypeVariableDecl(TokenIter &curr, bool hasEndianDef);
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);
};
}