summaryrefslogtreecommitdiffhomepage
path: root/src/CompilerKit/AST.inl
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-12-04 16:22:22 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2025-12-04 16:25:57 +0100
commit654c31b94d547e8d83be378eb5d5ab16a820dcdd (patch)
tree96b33b2722401bf556de941617b085905b371789 /src/CompilerKit/AST.inl
parentcd3092186eb698a9ed175dacb6884f0404e7c062 (diff)
chore:: breaking structural changes of CompilerKit.
The Kit has been redesigned to be expandable to new language frontends. Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'src/CompilerKit/AST.inl')
-rw-r--r--src/CompilerKit/AST.inl63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/CompilerKit/AST.inl b/src/CompilerKit/AST.inl
new file mode 100644
index 0000000..3dc9456
--- /dev/null
+++ b/src/CompilerKit/AST.inl
@@ -0,0 +1,63 @@
+/* ========================================
+
+ Copyright (C) 2025 Amlal El Mahrouss, Licensed under the Apache 2.0 license
+
+======================================== */
+
+namespace CompilerKit {
+/// 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(STLString haystack, STLString needle) noexcept {
+ auto index = haystack.find(needle);
+
+ // check for needle validity.
+ if (index == STLString::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 SizeType find_word_range(STLString haystack, STLString needle) noexcept {
+ auto index = haystack.find(needle);
+
+ // check for needle validity.
+ if (index == STLString::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 STLString::npos;
+}
+
+/// =========================================================== ///
+//! @brief What language are we dealing with?
+/// =========================================================== ///
+inline const char* CompilerFrontendInterface::Language() {
+ return kInvalidFrontend;
+}
+
+/// =========================================================== ///
+/// @brief Checks if language is a valid frontend.
+/// =========================================================== ///
+inline bool CompilerFrontendInterface::IsValid() {
+ return strcmp(this->Language(), kInvalidFrontend) > 0;
+}
+} // namespace CompilerKit \ No newline at end of file