From c34b2c57219aa496a202c2be1e12332b4eeea440 Mon Sep 17 00:00:00 2001
From: Ferenc Szontágh <szf@fsociety.hu>
Date: Mon, 14 Apr 2025 15:43:20 +0000
Subject: [PATCH] add function parameter handling and contextes

---
 src/ScriptException.hpp |   28 ++++++++++++++++++++++++++--
 1 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/ScriptException.hpp b/src/ScriptException.hpp
index 2d7d555..d1f88c2 100644
--- a/src/ScriptException.hpp
+++ b/src/ScriptException.hpp
@@ -37,6 +37,15 @@
 
     const Token & token() const { return token_; }
 
+    static ScriptException makeUnexpectedEndOfFileError(const Token & token, const std::string & file = "",
+                                                        int line = 0) {
+        std::string msg = "unexpected end of file";
+        if (!token.lexeme.empty()) {
+            msg += " near '" + token.lexeme + "'";
+        }
+        return ScriptException(ScriptErrorType::UnexpectedToken, msg, file, line, token);
+    }
+
     static ScriptException makeUnexpectedTokenError(const Token & token, const std::string & expected = "",
                                                     const std::string & file = "", int line = 0) {
         std::string msg = "unexpected token: '" + token.lexeme + "'";
@@ -46,7 +55,7 @@
 #endif
 
         if (!expected.empty()) {
-            msg += ", expected: '" + expected + "'";
+            msg += ", expected " + expected;
         }
         return ScriptException(ScriptErrorType::UnexpectedToken, msg, file, line, token);
     }
@@ -61,7 +70,7 @@
                                                       const std::string & file = "", int line = 0) {
         std::string msg = "undefined function: '" + name + "'";
 #if DEBUG_BUILD == 1
-        msg.append(", type: " + tokenTypeNames.at(token.type));
+        msg.append(", type: " + getTokenTypeAsString(token.type));
 #endif
         return ScriptException(ScriptErrorType::UndefinedFunction, msg, file, line, token);
     }
@@ -99,6 +108,21 @@
         return ScriptException(ScriptErrorType::Custom, msg, file, line, token);
     }
 
+    static ScriptException makeFunctionArgumentCountMismatchError(const std::string & functionName,
+                                                                  const size_t & expected, size_t actual,
+                                                                  const Token & token, const std::string & file = "",
+                                                                  int line = 0) {
+        std::string msg = "invalid argument count for function '" + functionName + "', expected " +
+                          std::to_string(expected) + ", got " + std::to_string(actual);
+        return ScriptException(ScriptErrorType::Custom, msg, file, line, token);
+    }
+
+    static ScriptException makeFunctionBodyEmptyError(const std::string & functionName, const Token & token,
+                                                      const std::string & file = "", int line = 0) {
+        std::string msg = "function '" + functionName + "' has no body";
+        return ScriptException(ScriptErrorType::Custom, msg, file, line, token);
+    }
+
   private:
     ScriptErrorType type_;
     std::string     file_;

--
Gitblit v1.9.3