2020-11-10 15:26:38 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <hex.hpp>
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
#include <hex/pattern_language/token.hpp>
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
#include <optional>
|
2020-11-10 15:26:38 +01:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
namespace hex::pl {
|
2020-11-10 15:26:38 +01:00
|
|
|
|
|
|
|
class Lexer {
|
|
|
|
public:
|
2021-01-10 13:40:07 +01:00
|
|
|
using LexerError = std::pair<u32, std::string>;
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
Lexer() = default;
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
std::optional<std::vector<Token>> lex(const std::string &code);
|
|
|
|
const std::optional<LexerError> &getError() { return this->m_error; }
|
2020-11-27 21:20:23 +01:00
|
|
|
|
|
|
|
private:
|
2021-10-20 11:06:24 +02:00
|
|
|
std::optional<LexerError> m_error;
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
[[noreturn]] void throwLexerError(const std::string &error, u32 lineNumber) const {
|
|
|
|
throw LexerError(lineNumber, "Lexer: " + error);
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
|
|
|
}
|
2020-11-10 15:26:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|