summaryrefslogtreecommitdiffhomepage
path: root/dev/CompilerKit/Frontend.h
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-11-19 09:21:48 +0100
committerGitHub <noreply@github.com>2025-11-19 09:21:48 +0100
commit281bef7f35e63a9c5daf37cca5bb8eea64c12693 (patch)
tree43025631e922b4d61b4b19e0f84cde8b7dd785b2 /dev/CompilerKit/Frontend.h
parent893c7e2169bfce6211a23e865a1f7efb43d025c7 (diff)
parenta48098479269cdace4d9ce32264a73eef76994dc (diff)
Merge pull request #23 from nekernel-org/dev
feat: new documented codebase and improvements.
Diffstat (limited to 'dev/CompilerKit/Frontend.h')
-rw-r--r--dev/CompilerKit/Frontend.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/dev/CompilerKit/Frontend.h b/dev/CompilerKit/Frontend.h
index 4b03651..225de96 100644
--- a/dev/CompilerKit/Frontend.h
+++ b/dev/CompilerKit/Frontend.h
@@ -17,7 +17,10 @@ struct SyntaxLeafList;
struct SyntaxLeafList;
struct CompilerKeyword;
+/// =========================================================== ///
/// we want to do that because to separate keywords.
+/// =========================================================== ///
+
enum KeywordKind {
kKeywordKindNamespace,
kKeywordKindFunctionStart,
@@ -56,7 +59,9 @@ enum KeywordKind {
kKeywordKindPtr,
};
+/// =========================================================== ///
/// \brief Compiler keyword information struct.
+/// =========================================================== ///
struct CompilerKeyword {
CompilerKeyword(STLString name, KeywordKind kind) : keyword_name(name), keyword_kind(kind) {}
@@ -81,20 +86,26 @@ struct SyntaxLeafList final {
SyntaxLeaf& At(SizeType 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.
+/// =========================================================== ///
Bool find_word(STLString haystack, STLString needle) noexcept;
+/// =========================================================== ///
/// find a word within strict conditions and returns a range of it.
/// \param haystack
/// \param needle
/// \return position of needle.
+/// =========================================================== ///
SizeType find_word_range(STLString haystack, STLString needle) noexcept;
+/// =========================================================== ///
/// @brief Compiler backend, implements a frontend, such as C, C++...
/// See Toolchain, for some examples.
+/// =========================================================== ///
class CompilerFrontendInterface {
public:
explicit CompilerFrontendInterface() = default;
@@ -102,18 +113,26 @@ class CompilerFrontendInterface {
NECTI_COPY_DEFAULT(CompilerFrontendInterface);
+ /// =========================================================== ///
// 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 CompilerKit::SyntaxLeafList::SyntaxLeaf Compile(std::string text, std::string file) = 0;
+ /// =========================================================== ///
//! @brief What language are we dealing with?
+ /// =========================================================== ///
virtual const char* Language() { return kInvalidFrontend; }
+ /// =========================================================== ///
/// @brief Checks if language is a valid frontend.
+ /// =========================================================== ///
virtual bool IsValid() { return strcmp(this->Language(), kInvalidFrontend) > 0; }
};
} // namespace CompilerKit