Browse Source

interface changes

Kajetan Johannes Hammerle 7 years ago
parent
commit
ef81247b67

+ 7 - 1
src/me/hammerle/code/Code.java

@@ -411,7 +411,13 @@ public class Code
         while(true)
         {
             pos = sb.indexOf(keyWord, pos);
-            if(pos == -1)
+            if(pos + length >= sb.length())
+            {
+                throw new PreScriptException(scriptName, countChar('\n', pos, sb), "unexpected keyword"); 
+            }
+            else if(pos == -1 || 
+                (pos >= 1 && Character.isLetterOrDigit(sb.charAt(pos - 1))) ||
+                (Character.isLetterOrDigit(sb.charAt(pos + length))))
             {
                 break;
             }

+ 1 - 1
src/me/hammerle/code/ISnuviLogger.java

@@ -2,7 +2,7 @@ package me.hammerle.code;
 
 public interface ISnuviLogger 
 {
-    public void printException(Exception ex);
+    public void printException(Exception ex, String scriptname, int line);
     public void printException(Exception ex, Script s, int line);
     
     public void printWarning(String s);

+ 12 - 2
src/me/hammerle/code/SnuviParser.java

@@ -535,7 +535,12 @@ public class SnuviParser
                 Throwable t = ((InvocationTargetException) ex).getCause();
                 if(t != null && t instanceof Exception)
                 {
-                    logger.printException((Exception) t);
+                    if(t instanceof PreScriptException)
+                    {
+                        logger.printException((Exception) t, scriptName, ((PreScriptException) t).getLine());
+                        return null;
+                    }
+                    logger.printException((Exception) t, scriptName, -1);
                     return null;
                 }
             }
@@ -645,6 +650,11 @@ public class SnuviParser
     
     private void scheduleGoto(Object[] args, Script sc)
     {
+        int time = getInt(args[0]);
+        if(time < 0)
+        {
+            throw new IllegalArgumentException("time units can't be negative");
+        }
         scheduler.scheduleTask(() -> 
         {
             if(!sc.isValid() && !sc.isHalt())
@@ -660,7 +670,7 @@ public class SnuviParser
             {
                 logger.printException(ex, sc, sc.getActiveRealCodeLine());
             }
-        }, getInt(args[0]));
+        }, time);
     }
     
     @SuppressWarnings("")

+ 4 - 16
src/me/hammerle/snuviscript/SnuviScript.java

@@ -20,9 +20,9 @@ public class SnuviScript
             }
 
             @Override
-            public void printException(Exception ex) 
+            public void printException(Exception ex, String s, int line) 
             {
-                System.out.println("Exception " + ex);
+                System.out.println("Exception " + ex + " " + s + " " + line);
             }
 
             @Override
@@ -79,19 +79,7 @@ public class SnuviScript
         }
         sb.append("debug(wusi);");*/
         
-        String s = "debug(\"Das ist ein test\");\n" +
-"if(5 < 6)\n" +
-"{\n" +
-"    debug(\"hehe\");\n" +
-"}\n" +
-"else\n" +
-"{\n" +
-"    deb.ug(\"muhahah\");\n" +
-"    debug(\"ich bin auch da\");\n" +
-"}\n" +
-"{\n" +
-"debug(\"wir sind fertig\");\n" +
-"}";
+        String s = "debug(catcher);";
         //System.out.println(s);
         //System.out.println("___________");
         //parser.startScript(Script.class, "test", sb.toString(), true);
@@ -102,7 +90,7 @@ public class SnuviScript
         catch(PreScriptException ex)
         {
             //ex.printStackTrace();
-            logger.printException(ex);
+            logger.printException(ex, "test", ex.getLine());
         }
         //parser.getScript(0).runCode();