summaryrefslogtreecommitdiffhomepage
path: root/Private/CompilerKit/ParserKit.hpp
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-30 13:25:42 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-30 13:26:33 +0100
commitbe73d82eff113e6a6723d6fb4bd80f56f0ef88ef (patch)
tree93425f2d183c3ea7e5e1b50374ee6548c383ab78 /Private/CompilerKit/ParserKit.hpp
parent7c8afc0e15e54ae9e0f1a393bb52eed804d34edc (diff)
Compiler: Breaking changes, will work on C++ compiler from now on.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private/CompilerKit/ParserKit.hpp')
-rw-r--r--Private/CompilerKit/ParserKit.hpp180
1 files changed, 84 insertions, 96 deletions
diff --git a/Private/CompilerKit/ParserKit.hpp b/Private/CompilerKit/ParserKit.hpp
index 49907e5..614e56c 100644
--- a/Private/CompilerKit/ParserKit.hpp
+++ b/Private/CompilerKit/ParserKit.hpp
@@ -11,101 +11,89 @@
#include <CompilerKit/AsmKit/AsmKit.hpp>
-namespace ParserKit
-{
- using namespace CompilerKit;
-
- class CompilerBackend
- {
- public:
- explicit CompilerBackend() = default;
- virtual ~CompilerBackend() = default;
-
- CXXKIT_COPY_DEFAULT(CompilerBackend);
-
- // NOTE: cast this to your user defined ast.
- typedef void* AstType;
-
- //! @brief Compile a syntax tree ouf of the text.
- //! Also takes the source file name for metadata.
-
- virtual bool Compile(const std::string& text, const char* file) = 0;
-
- //! @brief What language are we dealing with?
- virtual const char* Language() { return "Generic Language"; }
-
- };
-
- struct SyntaxLeafList;
- struct SyntaxLeafList;
-
- struct SyntaxLeafList final
- {
- struct SyntaxLeaf final
- {
- Int32 fUserType;
- std::string fUserData;
- std::string fUserValue;
- struct SyntaxLeaf* fNext;
- };
-
- std::vector<SyntaxLeaf> fLeafList;
- SizeType fNumLeafs;
-
- size_t SizeOf() { return fNumLeafs; }
- std::vector<SyntaxLeaf>& Get() { return fLeafList; }
- SyntaxLeaf& At(size_t index) { return fLeafList[index]; }
-
- };
-
- /// find the perfect matching word in a haystack.
- /// \param haystack base string
- /// \param needle the string we search for.
- /// \return if we found it or not.
- inline bool find_word(const std::string& haystack,const std::string& needle) noexcept
- {
- auto index = haystack.find(needle);
-
- // check for needle validity.
- if (index == std::string::npos)
- return false;
-
- // declare lambda
- auto not_part_of_word = [&](int index){
- if (std::isspace(haystack[index]) || std::ispunct(haystack[index]))
- return true;
-
- if (index < 0 || index >= haystack.size())
- return true;
-
- return false;
- };
-
- return not_part_of_word(index - 1) &&
- not_part_of_word(index + needle.size());
- }
-
- /// find a word within strict conditions and returns a range of it.
- /// \param haystack
- /// \param needle
- /// \return position of needle.
- inline std::size_t find_word_range(const std::string& haystack, const std::string& needle) noexcept
- {
- auto index = haystack.find(needle);
-
- // check for needle validity.
- if (index == std::string::npos)
- return false;
-
- if (!isalnum((haystack[index + needle.size() + 1])) &&
- !isdigit(haystack[index + needle.size() + 1]) &&
- !isalnum((haystack[index - needle.size() - 1])) &&
- !isdigit(haystack[index - needle.size() - 1]))
- {
- return index;
- }
-
- return false;
- }
+namespace ParserKit {
+using namespace CompilerKit;
+
+class CompilerBackend {
+ public:
+ explicit CompilerBackend() = default;
+ virtual ~CompilerBackend() = default;
+
+ CXXKIT_COPY_DEFAULT(CompilerBackend);
+
+ // NOTE: cast this to your user defined ast.
+ typedef void* AstType;
+
+ //! @brief Compile a syntax tree ouf of the text.
+ //! Also takes the source file name for metadata.
+
+ virtual bool Compile(const std::string& text, const char* file) = 0;
+
+ //! @brief What language are we dealing with?
+ virtual const char* Language() { return "Generic Language"; }
+};
+
+struct SyntaxLeafList;
+struct SyntaxLeafList;
+
+struct SyntaxLeafList final {
+ struct SyntaxLeaf final {
+ Int32 fUserType;
+ std::string fUserData;
+ std::string fUserValue;
+ struct SyntaxLeaf* fNext;
+ };
+
+ std::vector<SyntaxLeaf> fLeafList;
+ SizeType fNumLeafs;
+
+ size_t SizeOf() { return fNumLeafs; }
+ std::vector<SyntaxLeaf>& Get() { return fLeafList; }
+ SyntaxLeaf& At(size_t index) { return fLeafList[index]; }
+};
+
+/// find the perfect matching word in a haystack.
+/// \param haystack base string
+/// \param needle the string we search for.
+/// \return if we found it or not.
+inline bool find_word(const std::string& haystack,
+ const std::string& needle) noexcept {
+ auto index = haystack.find(needle);
+
+ // check for needle validity.
+ if (index == std::string::npos) return false;
+
+ // declare lambda
+ auto not_part_of_word = [&](int index) {
+ if (std::isspace(haystack[index]) || std::ispunct(haystack[index]))
+ return true;
+
+ if (index < 0 || index >= haystack.size()) return true;
+
+ return false;
+ };
+
+ return not_part_of_word(index - 1) && not_part_of_word(index + needle.size());
}
+/// find a word within strict conditions and returns a range of it.
+/// \param haystack
+/// \param needle
+/// \return position of needle.
+inline std::size_t find_word_range(const std::string& haystack,
+ const std::string& needle) noexcept {
+ auto index = haystack.find(needle);
+
+ // check for needle validity.
+ if (index == std::string::npos) return false;
+
+ if (!isalnum((haystack[index + needle.size() + 1])) &&
+ !isdigit(haystack[index + needle.size() + 1]) &&
+ !isalnum((haystack[index - needle.size() - 1])) &&
+ !isdigit(haystack[index - needle.size() - 1])) {
+ return index;
+ }
+
+ return false;
+}
+} // namespace ParserKit