Browse Source

Moved console stuff into snuvi-console, snuvi-script is now a library, can be plugged in into kajetans-mod/plugin

Kajetan Johannes Hammerle 7 years ago
parent
commit
b63685a396
35 changed files with 640 additions and 1397 deletions
  1. BIN
      .DS_Store
  2. 1 3
      nbproject/private/private.xml
  3. 231 225
      src/me/hammerle/code/Code.java
  4. 8 0
      src/me/hammerle/code/ISnuviLogger.java
  5. 7 0
      src/me/hammerle/code/ISnuviScheduler.java
  6. 36 51
      src/me/hammerle/code/Script.java
  7. 0 66
      src/me/hammerle/code/ScriptControl.java
  8. 2 51
      src/me/hammerle/code/ScriptUtils.java
  9. 231 254
      src/me/hammerle/code/SnuviParser.java
  10. 9 2
      src/me/hammerle/code/Variable.java
  11. 0 82
      src/me/hammerle/console/BlackBox.java
  12. 0 36
      src/me/hammerle/console/Console.java
  13. 0 22
      src/me/hammerle/console/ConsoleUtils.java
  14. 0 85
      src/me/hammerle/console/InputBox.java
  15. 0 25
      src/me/hammerle/console/OutputBox.java
  16. 7 2
      src/me/hammerle/exceptions/CodeTooLongException.java
  17. 0 9
      src/me/hammerle/exceptions/FileException.java
  18. 4 2
      src/me/hammerle/exceptions/GotoLabelNotFoundException.java
  19. 1 1
      src/me/hammerle/exceptions/HoldCodeException.java
  20. 5 2
      src/me/hammerle/exceptions/IllegalStringException.java
  21. 3 3
      src/me/hammerle/exceptions/NoSuchMethodException.java
  22. 7 7
      src/me/hammerle/exceptions/PrescriptException.java
  23. 54 0
      src/me/hammerle/exceptions/SnuviException.java
  24. 0 35
      src/me/hammerle/graphics/Colorable.java
  25. 0 12
      src/me/hammerle/graphics/Graphic.java
  26. 0 96
      src/me/hammerle/graphics/GraphicFrame.java
  27. 0 46
      src/me/hammerle/graphics/GraphicPanel.java
  28. 0 63
      src/me/hammerle/graphics/Image.java
  29. 0 82
      src/me/hammerle/graphics/Line.java
  30. 0 25
      src/me/hammerle/graphics/Oval.java
  31. 0 39
      src/me/hammerle/graphics/Point.java
  32. 0 25
      src/me/hammerle/graphics/Rectangle.java
  33. 0 20
      src/me/hammerle/scheduler/SnuviScheduler.java
  34. 34 20
      src/me/hammerle/snuviscript/SnuviScript.java
  35. 0 6
      todo.txt

BIN
.DS_Store


+ 1 - 3
nbproject/private/private.xml

@@ -3,9 +3,7 @@
     <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
     <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
         <group>
-            <file>file:/Users/kajetanjohannes/Dropbox/Projekte/Informatik/SnuviScript/src/me/hammerle/console/ConsoleUtils.java</file>
-            <file>file:/Users/kajetanjohannes/Dropbox/Projekte/Informatik/SnuviScript/src/me/hammerle/console/InputBox.java</file>
-            <file>file:/Users/kajetanjohannes/Dropbox/Projekte/Informatik/SnuviScript/src/me/hammerle/code/Script.java</file>
+            <file>file:/Users/kajetanjohannes/Dropbox/Projekte/Informatik/SnuviScript/src/me/hammerle/code/Code.java</file>
         </group>
     </open-files>
 </project-private>

+ 231 - 225
src/me/hammerle/code/Code.java

@@ -6,10 +6,11 @@ import java.util.Map.Entry;
 import java.util.Stack;
 import java.util.TreeSet;
 import me.hammerle.exceptions.PrescriptException;
+import me.hammerle.exceptions.NoSuchMethodException;
 
 public class Code implements Comparable<Code>
 {
-    private final int line;
+    protected final int line;
     private int subline;
     
     private final String function;
@@ -47,9 +48,9 @@ public class Code implements Comparable<Code>
         this(null, level, pars, line, subline, value, 0);
     }
     
-    public void executeFunction(Script sc, Stack<Object> stack)
+    public void executeFunction(SnuviParser parser, Script sc, Stack<Object> stack)
     {
-        //System.out.println("AUSFÜHRUNG: " + this.toString());
+        //System.out.println("Executing: " + this.toString());
         if(value != null)
         {
             if(value.getClass() == Variable.class)
@@ -73,7 +74,7 @@ public class Code implements Comparable<Code>
         {
             input = new Object[0];
         }
-        Object output = CodeParser.parseFunction(sc, function, input);
+        Object output = parser.parseFunction(sc, function, input);
         if(output != Void.TYPE)
         {
             stack.push(output);
@@ -91,7 +92,7 @@ public class Code implements Comparable<Code>
         StringBuilder sb = new StringBuilder(">>>");
         for(int i = 1; i < level; i++)
         {
-            sb.append(">>>");
+            sb.append(">");
         }
         sb.append(" (");
         sb.append(line);
@@ -147,9 +148,11 @@ public class Code implements Comparable<Code>
     }
     
     // -----------------------------------------------------------------------------------
-    // Code-Builder
+    // code builder
     // -----------------------------------------------------------------------------------
     
+    private static SnuviParser parser = null;
+    private static String scriptName = null;
     private static int sublines = 0;
     
     private static int findEndOfLine(String code, int pos)
@@ -186,7 +189,7 @@ public class Code implements Comparable<Code>
         int bracketCounter = 0;
         char c;
         boolean text = false;
-        while(code.charAt(pos) == ' ')
+        while(pos >= 0 && code.charAt(pos) == ' ')
         {
             pos--;
         }
@@ -205,7 +208,7 @@ public class Code implements Comparable<Code>
                 case '}':
                     if(bracketCounter != 0)
                     {
-                        throw new PrescriptException("unbalanced ()", code.substring(pos - 1, Math.min(code.length(), pos + 10))); 
+                        throw new PrescriptException(scriptName, code.substring(pos - 1, Math.min(code.length(), pos + 20)), "unbalanced ()"); 
                     }
                     return pos + 1;
                 case ' ':
@@ -251,7 +254,7 @@ public class Code implements Comparable<Code>
         int bracketCounter = 0;
         char c;
         boolean text = false;
-        while(code.charAt(pos) == ' ')
+        while(pos < code.length() && code.charAt(pos) == ' ')
         {
             pos++;
         }
@@ -270,7 +273,7 @@ public class Code implements Comparable<Code>
                 case '}':
                     if(bracketCounter != 0)
                     {
-                        throw new PrescriptException("unbalanced ()", code.substring(pos - 1, Math.min(code.length(), pos + 10))); 
+                        throw new PrescriptException(scriptName, code.substring(pos - 1, Math.min(code.length(), pos + 20)), "unbalanced ()"); 
                     }
                     return pos;
                 case ' ':
@@ -332,7 +335,7 @@ public class Code implements Comparable<Code>
                 continue;
             }
             s = code.substring(pos);
-            // Additionel check for e.g. difference between + and +=
+            // additionel check for e.g. difference between + and +=
             if(s.startsWith(find) && !s.startsWith(find + "=") && code.charAt(pos - 1) != '=') 
             {
                 return pos;
@@ -342,13 +345,12 @@ public class Code implements Comparable<Code>
         return -1;
     }
     
-    private static String changeBiSyntax(String syntax, String f, String code, boolean b)
+    private static void changeBiSyntax(String syntax, String f, StringBuilder sb, boolean b)
     {
         int pos = -1;
         int end;
         int start;
         int slength = syntax.length();
-        StringBuilder sb = new StringBuilder(code);
         StringBuilder newSyntax;
         while(pos < sb.length())
         {
@@ -380,17 +382,15 @@ public class Code implements Comparable<Code>
             //System.out.println(sb.substring(start, end) + "   ===>    " + newSyntax);
             sb.replace(start, end, newSyntax.toString());
         }
-        return sb.toString();
     }
     
-    private static String changeUnSyntax(String syntax, String f, String code)
+    private static void changeUnSyntax(String syntax, String f, StringBuilder sb)
     {
         int pos = -1;
         int end;
         int start;
         int slength = syntax.length();
         String first;
-        StringBuilder sb = new StringBuilder(code);
         StringBuilder newSyntax;
         while(pos < sb.length())
         {
@@ -414,7 +414,6 @@ public class Code implements Comparable<Code>
             pos -= end - start - newSyntax.length();
             sb.replace(start, end, newSyntax.toString());
         }
-        return sb.toString();
     }
     
     private static String replaceChar(char find, char replacement, String code)
@@ -447,7 +446,7 @@ public class Code implements Comparable<Code>
         return new String(chars);
     }
     
-    private static void keyWordBrackets(String keyWord, StringBuilder sb)
+    private static void addKeyWordBrackets(String keyWord, StringBuilder sb)
     {
         String with = keyWord + "()";
         int length = keyWord.length();
@@ -467,246 +466,235 @@ public class Code implements Comparable<Code>
         }
     }
     
-    public static Code[] generate(String code, HashMap<String, Integer> gotos)
+    public static Code[] generate(SnuviParser parser, String scriptName, String code, HashMap<String, Integer> gotos)
     {
-        try
+        Code.scriptName = scriptName;
+        Code.parser = parser;
+        // comments
+        int old = 0;
+        int pos;
+        StringBuilder sb = new StringBuilder(code);
+        while(true)
         {
-            // Kommentare
-            int old = 0;
-            int pos;
-            StringBuilder sb = new StringBuilder(code);
-            while(true)
+            old = findSyntax("/*", sb.toString(), old);
+            if(old == -1)
             {
-                old = findSyntax("/*", sb.toString(), old);
-                if(old == -1)
-                {
-                    break;
-                }
-                pos = findSyntax("*/", sb.toString(), old);
-                if(pos == -1)
-                {
-                    throw new PrescriptException("/* without */", sb.substring(old, Math.min(old + 20, sb.length())));
-                }
-                sb.replace(old, pos + 2, "");
+                break;
             }
-            old = 0;
-            while(true)
+            pos = findSyntax("*/", sb.toString(), old);
+            if(pos == -1)
             {
-                old = findSyntax("//", sb.toString(), old);
-                if(old == -1)
-                {
-                    break;
-                }
-                pos = findSyntax("\n", sb.toString(), old);
-                if(pos == -1)
-                {
-                    sb.replace(old, sb.length(), "");
-                    break;
-                }
-                sb.replace(old, pos + 1, "");
+                throw new PrescriptException(scriptName, sb.substring(old, Math.min(old + 20, sb.length())), "/* without */");
             }
-            // Ende Kommentare
-            
-            // Schlüsselwörter ohne ()
-            keyWordBrackets("else", sb);        
-            keyWordBrackets("try", sb);   
-            keyWordBrackets("catch", sb);   
-            // Ende Schlüsselwörter
-            code = sb.toString();
-            //System.out.println(code);
-            
-            // Anfängliches Austauschen mit Functionssyntax
-            code = changeBiSyntax("^", "math.pow", code, false);
-            code = changeBiSyntax("/", "div", code, false);
-            code = changeBiSyntax("%", "math.mod", code, false);
-            code = changeBiSyntax("*", "mul", code, false);
-            code = changeBiSyntax("-", "sub", code, false);
-            code = changeBiSyntax("+", "add", code, false);
+            sb.replace(old, pos + 2, "");
+        }
+        old = 0;
+        while(true)
+        {
+            old = findSyntax("//", sb.toString(), old);
+            if(old == -1)
+            {
+                break;
+            }
+            pos = findSyntax("\n", sb.toString(), old);
+            if(pos == -1)
+            {
+                sb.replace(old, sb.length(), "");
+                break;
+            }
+            sb.replace(old, pos + 1, "");
+        }
+        // end comments
 
-            code = changeBiSyntax("==", "equal", code, false);
-            code = changeBiSyntax("!=", "notequal", code, false);
-            code = changeBiSyntax("<", "less", code, false);
-            code = changeBiSyntax(">", "greater", code, false);
-            code = changeBiSyntax(">=", "greaterequal", code, false);
-            code = changeBiSyntax("<=", "lessequal", code, false);
-            
-            code = changeBiSyntax("||", "or", code, false);
-            code = changeBiSyntax("&&", "and", code, false);
+        // key words without ()
+        addKeyWordBrackets("else", sb);        
+        addKeyWordBrackets("try", sb);   
+        addKeyWordBrackets("catch", sb);   
+        // end key words
 
-            code = changeUnSyntax("+=", "add", code);
-            code = changeUnSyntax("-=", "sub", code);
-            code = changeUnSyntax("/=", "div", code);
-            code = changeUnSyntax("*=", "mul", code);
+        // replacing of function syntax
+        changeBiSyntax("^", "math.pow", sb, false);
+        changeBiSyntax("/", "div", sb, false);
+        changeBiSyntax("%", "math.mod", sb, false);
+        changeBiSyntax("*", "mul", sb, false);
+        changeBiSyntax("-", "sub", sb, false);
+        changeBiSyntax("+", "add", sb, false);
 
-            code = changeBiSyntax("=", "setvar", code, true);
+        changeBiSyntax("==", "equal", sb, false);
+        changeBiSyntax("!=", "notequal", sb, false);
+        changeBiSyntax("<", "less", sb, false);
+        changeBiSyntax(">", "greater", sb, false);
+        changeBiSyntax(">=", "greaterequal", sb, false);
+        changeBiSyntax("<=", "lessequal", sb, false);
 
-            //code = replaceChar('[', '(', code);
-            //code = replaceChar(']', ')', code);
+        changeBiSyntax("||", "or", sb, false);
+        changeBiSyntax("&&", "and", sb, false);
 
-            //System.out.println(code);
-            //System.exit(0);
-            // Ende des Austauschen
-            // Zerlegen des Codes in Zeilen
-            ArrayList<Code> list = new ArrayList<>();
-            sublines = 0;
-            String actual;
-            int length = code.length();
-            int level = 1;
-            pos = 0;
-            int line = 0;
-            while(pos < length)
-            {
-                old = pos;
-                pos = findEndOfLine(code, pos);
-                actual = code.substring(old, pos).trim();
-                //System.out.println("WUSI: " + actual);
-                if(actual.startsWith("@"))
-                {
-                    // Setzt nur die richtige Ebene des Gotos, die genaue Position wird noch gesetzt
-                    gotos.put(actual.substring(1), line);
-                    pos++;
-                    continue;
-                }
-                switch(code.charAt(pos))
+        changeUnSyntax("+=", "add", sb);
+        changeUnSyntax("-=", "sub", sb);
+        changeUnSyntax("/=", "div", sb);
+        changeUnSyntax("*=", "mul", sb);
+
+        changeBiSyntax("=", "setvar", sb, true);
+
+        code = sb.toString();
+        // end of substitution
+        // split code into lines
+        ArrayList<Code> list = new ArrayList<>();
+        sublines = 0;
+        String actual;
+        int length = code.length();
+        int level = 1;
+        pos = 0;
+        int line = 0;
+        while(pos < length)
+        {
+            old = pos;
+            pos = findEndOfLine(code, pos);
+            actual = code.substring(old, pos).trim();
+            if(actual.startsWith("@"))
+            {
+                // sets the right layer of the goto, the exact position is set later
+                if(gotos.put(actual.substring(1), line) != null)
                 {
-                    case '{':
-                        line++;
-                        splitFunctions(list, actual, level, line);
-                        level++;
-                        break;
-                    case '}': 
-                        level--;
-                        break;
-                    case ';': 
-                        line++;
-                        splitFunctions(list, actual, level, line);
-                        break;
+                    throw new PrescriptException(scriptName, code.substring(old, Math.min(code.length(), pos + 20)), "double goto");
                 }
                 pos++;
+                continue;
+            }
+            switch(code.charAt(pos))
+            {
+                case '{':
+                    line++;
+                    splitFunctions(list, actual, level, line);
+                    level++;
+                    break;
+                case '}': 
+                    level--;
+                    break;
+                case ';': 
+                    line++;
+                    splitFunctions(list, actual, level, line);
+                    break;
             }
-            // Ende der Zeilenzerlegung
+            pos++;
+        }
+        // end of code splitting
 
-            // Anlegen eines Trees zum sortieren und einfügen von Code
-            TreeSet<Code> tree = new TreeSet(list);
-            Code[] c = tree.toArray(new Code[tree.size()]);
+        // tree for sorting and inserting of code
+        TreeSet<Code> tree = new TreeSet(list);
+        Code[] c = tree.toArray(new Code[tree.size()]);
 
-            // Einfügen von "gotoline" bei while-Schleifen
-            String function;
-            int baseLevel;
-            boolean lastLineChecker;
-            for(int i = 0; i < c.length; i++)
-            {
-                function = c[i].function;
-                if(function == null || !function.equals("while"))
-                {
-                    continue;
-                }
-                baseLevel = c[i].level;
-                lastLineChecker = true;
-                for(int j = i + 1; j < c.length; j++)
-                {
-                    if(c[j].level <= baseLevel)
-                    {
-                        Code gotoLine = new Code("gotoline", c[i].level, 0, c[j].line, c[j].subline + 1);
-                        while(tree.contains(gotoLine)) // Damit keine Whiles, die gleich enden, sich überschreiben
-                        {
-                            gotoLine.subline++;
-                        }
-                        tree.add(gotoLine);
-                        lastLineChecker = false;
-                        break;
-                    }
-                }
-                if(lastLineChecker)
+        // insert "gotoline" at while
+        String function;
+        int baseLevel;
+        boolean lastLineChecker;
+        for(int i = 0; i < c.length; i++)
+        {
+            function = c[i].function;
+            if(function == null || !function.equals("while"))
+            {
+                continue;
+            }
+            baseLevel = c[i].level;
+            // keeping sure "gotoline" is inserted at least at the end of the code
+            lastLineChecker = true;
+            for(int j = i + 1; j < c.length; j++)
+            {
+                if(c[j].level <= baseLevel)
                 {
-                    sublines++;
-                    Code gotoLine = new Code("gotoline", c[i].level, 0, c[c.length - 1].line + 1, sublines);
-                    while(tree.contains(gotoLine)) // Damit keine Whiles, die gleich enden, sich überschreiben
+                    Code gotoLine = new Code("gotoline", c[i].level, 0, c[j].line, c[j].subline + 1);
+                    while(tree.contains(gotoLine)) // prevent whiles from overwriting other whiles
                     {
                         gotoLine.subline++;
                     }
                     tree.add(gotoLine);
+                    lastLineChecker = false;
+                    break;
                 }
             }
-            // Ende des While-Handlings
-            // Erstellen der Sprungmarken der Schlüsselwörter
-            c = tree.toArray(new Code[tree.size()]);
-
-            boolean whileCheck = false;
-            int lastLineChange = 0;
-            line = 0;
-            for(int i = 0; i < c.length; i++)
+            if(lastLineChecker)
             {
-                function = c[i].function;
-                if(c[i].line != line)
+                sublines++;
+                Code gotoLine = new Code("gotoline", c[i].level, 0, c[c.length - 1].line + 1, sublines);
+                while(tree.contains(gotoLine)) // prevent whiles from overwriting other whiles
                 {
-                    line = c[i].line;
-                    lastLineChange = i;
+                    gotoLine.subline++;
                 }
-                if(function == null)
-                {
+                tree.add(gotoLine);
+            }
+        }
+        // end of while handling
+        // generating gotos of key words
+        c = tree.toArray(new Code[tree.size()]);
+
+        boolean whileCheck = false;
+        int lastLineChange = 0;
+        line = 0;
+        for(int i = 0; i < c.length; i++)
+        {
+            function = c[i].function;
+            if(c[i].line != line)
+            {
+                line = c[i].line;
+                lastLineChange = i;
+            }
+            if(function == null)
+            {
+                continue;
+            }
+            switch(function)
+            {
+                case "if":
+                case "else":
+                case "try":
+                case "catch":
+                    break;
+                case "while":
+                    whileCheck = true;
+                    break;
+                default:
                     continue;
-                }
-                switch(function)
-                {
-                    case "if":
-                    case "else":
-                    case "try":
-                    case "catch":
-                        break;
-                    case "while":
-                        whileCheck = true;
-                        break;
-                    default:
-                        continue;
-                }
-                baseLevel = c[i].level;
-                for(int j = i + 1; j < c.length; j++)
-                {
-                    if(c[j].level <= baseLevel)
-                    {
-                        c[i].jump = j - i;
-                        if(whileCheck)
-                        {
-                            // Setzt die Position von GotoLine bei While
-                            whileCheck = false;
-                            c[j].jump = lastLineChange - j;
-                        }
-                        break;
-                    }
-                }
-                if(c[i].jump == 0)
-                {
-                   c[i].jump = tree.size() - i; 
-                }
             }
-            // Ende der Sprungmarken
-            // Korrektur der Gotos
-            for(Entry<String, Integer> i : gotos.entrySet())
+            baseLevel = c[i].level;
+            for(int j = i + 1; j < c.length; j++)
             {
-                int value = i.getValue() + 1;
-                for(int j = value - 1; j < c.length; j++)
+                if(c[j].level <= baseLevel)
                 {
-                    if(c[j].line == value)
+                    c[i].jump = j - i; // key word pos - end pos = jump
+                    if(whileCheck)
                     {
-                        //System.out.println("KORREKTUR VON " + i.getValue() + " AUF " + j);
-                        i.setValue(j);
-                        break;
+                        // setting right jump for gotoline of while
+                        whileCheck = false;
+                        c[j].jump = lastLineChange - j;
                     }
+                    break;
                 }
             }
-            // Ende
-            //java.util.Arrays.stream(c).forEach(co -> System.out.println(co.toString()));
-            //gotos.forEach((k, v) -> System.out.println(k + "   " + v));
-            //System.exit(0);
-            return c;
+            if(c[i].jump == 0)
+            {
+               c[i].jump = tree.size() - i; 
+            }
         }
-        catch(PrescriptException ex)
+        // end of key word jumps
+        // correct wrong gotos
+        for(Entry<String, Integer> i : gotos.entrySet())
         {
-            ScriptUtils.printError("PrescriptException");
-            ScriptUtils.printError(ex.getBadString() + " - " + ex.getException());
-            return null;
+            int value = i.getValue() + 1;
+            for(int j = value - 1; j < c.length; j++)
+            {
+                if(c[j].line == value)
+                {
+                    i.setValue(j);
+                    break;
+                }
+            }
         }
+        // end
+        //java.util.Arrays.stream(c).forEach(co -> System.out.println(co.toString()));
+        //gotos.forEach((k, v) -> System.out.println(k + "   " + v));
+        //System.exit(0);
+        return c;
     } 
     
     private static int findOpenBracket(String code, int pos)
@@ -827,7 +815,7 @@ public class Code implements Comparable<Code>
         int end = findClosingBracket(f, start);
         if((start != -1 || end != -1) && (((start == -1 || end == -1) && start != end) || end != f.length() - 1))
         {
-            throw new PrescriptException("unbalanced ()", f);
+            throw new PrescriptException(scriptName, "unbalanced ()", f);
         }
         if(start == -1)
         {
@@ -836,11 +824,21 @@ public class Code implements Comparable<Code>
         }
         else if(start >= end - 1)
         {
-            list.add(new Code(f.substring(0, start), level, 0, line, sublines));
+            String functionName = f.substring(0, start).trim();
+            if(!parser.isRegisteredFunction(functionName))
+            {
+                throw new NoSuchMethodException(scriptName, f, functionName);
+            }
+            list.add(new Code(functionName, level, 0, line, sublines));
             return;
         }
         ArrayList<String> splitted = splitComma(f.substring(start + 1, end));
-        list.add(new Code(f.substring(0, start), level, splitted.size(), line, sublines));
+        String functionName = f.substring(0, start).trim();
+        if(!parser.isRegisteredFunction(functionName))
+        {
+            throw new NoSuchMethodException(scriptName, f, functionName);
+        }
+        list.add(new Code(functionName, level, splitted.size(), line, sublines));
         splitted.forEach(s -> splitFunctions(list, s, level, line));
     }
     
@@ -851,12 +849,20 @@ public class Code implements Comparable<Code>
             return null;
         }
         s = s.trim();
-        if(s.startsWith("\"") && s.endsWith("\""))
+        if(s.length() == 0)
         {
-            if(s.length() <= 1)
+            return "";
+        }  
+        if(s.charAt(0) == '"' && s.charAt(s.length() - 1) == '"')
+        {
+            if(s.length() == 1)
             {
                 return "\"";
             }
+            else if(s.charAt(1) == '$')
+            {
+                return s.substring(2, s.length() - 1);
+            }
             return s.substring(1, s.length() - 1);
         }
         else if(s.equals("true"))

+ 8 - 0
src/me/hammerle/code/ISnuviLogger.java

@@ -0,0 +1,8 @@
+package me.hammerle.code;
+
+import me.hammerle.exceptions.SnuviException;
+
+public interface ISnuviLogger 
+{
+    public void printException(SnuviException ex);
+}

+ 7 - 0
src/me/hammerle/code/ISnuviScheduler.java

@@ -0,0 +1,7 @@
+package me.hammerle.code;
+
+public interface ISnuviScheduler 
+{
+    public void scheduleTask(Runnable r);  
+    public void scheduleTask(Runnable r, long delay);
+}

+ 36 - 51
src/me/hammerle/code/Script.java

@@ -1,18 +1,20 @@
 package me.hammerle.code;
 
-import java.awt.Graphics;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Stack;
-import me.hammerle.console.ConsoleUtils;
 import me.hammerle.exceptions.CodeTooLongException;
 import me.hammerle.exceptions.GotoLabelNotFoundException;
 import me.hammerle.exceptions.HoldCodeException;
-import me.hammerle.graphics.GraphicFrame;
-import me.hammerle.graphics.GraphicPanel;
+import me.hammerle.exceptions.SnuviException;
 
 public class Script 
 {
+    private final SnuviParser parser;
+    protected final boolean receiveEventBroadcast;
+    protected final ArrayList<String> eventVars;
+    
     private final int id;
     private final String name;  
 
@@ -32,12 +34,11 @@ public class Script
     
     private int tryJumpLine;
     
-    private GraphicFrame frame;
-    private GraphicPanel panel;
-    
-    @SuppressWarnings("LeakingThisInConstructor")
-    public Script(int id, String name, String code)
+    public Script(SnuviParser parser, int id, String name, String code, boolean receiveEventBroadcast)
     {       
+        this.eventVars = new ArrayList<>();
+        this.receiveEventBroadcast = receiveEventBroadcast;
+        this.parser = parser;
         this.id = id;
         this.name = name;
         
@@ -47,12 +48,7 @@ public class Script
         valueStack = new Stack<>();
         returnStack = new Stack<>();
         
-        this.code = Code.generate(code, gotos);
-        if(this.code == null)
-        {
-            ScriptControl.term(this);
-            return;
-        }
+        this.code = Code.generate(parser, name, code, gotos);
         
         position = 0;
 
@@ -62,8 +58,16 @@ public class Script
         valid = true;
         
         tryJumpLine = -1;
+    }
+    
+    public Script(SnuviParser parser, int id, String name, String code)
+    {       
+        this(parser, id, name, code, true);
+    }
+    
+    protected void initExpansion(Object... o)
+    {
         
-        frame = null;
     }
     
     // -----------------------------------------------------------------------------------
@@ -102,7 +106,7 @@ public class Script
     
     public int getActiveCodeLine()
     {
-        return position;
+        return code[position].line;
     }
     
     // -----------------------------------------------------------------------------------
@@ -128,6 +132,10 @@ public class Script
     // Script-Flow
     // -----------------------------------------------------------------------------------
     
+    public void onTerm()
+    {
+    }
+    
     public void runCode() 
     {
         if(this.isValid())
@@ -136,25 +144,22 @@ public class Script
             {
                 while(position < code.length)
                 {
-                    code[position].executeFunction(this, valueStack);
+                    code[position].executeFunction(parser, this, valueStack);
                     position++;
                     if(isHalt())
                     {
-                        ConsoleUtils.scrollToBottom();
                         return;
                     }
                 }
-                ConsoleUtils.scrollToBottom();
-                ScriptControl.term(this);
+                parser.termSafe(this);
             }
             catch(Exception ex)
             {
                 if(ex.getClass() != HoldCodeException.class)
                 {
-                    CodeParser.printQuestException(this, ex, code[position].toString());
+                    parser.logger.printException(new SnuviException(ex, this));
                 }
                 position++;
-                ConsoleUtils.scrollToBottom();
             }
         }
     }
@@ -163,6 +168,12 @@ public class Script
     // Variablen
     // -----------------------------------------------------------------------------------
     
+    public void setEventVar(String var, Object value)
+    {
+        variables.put(var, value);   
+        eventVars.add(var);
+    }
+    
     public void setVar(String var, Object value)
     {
         variables.put(var, value);   
@@ -188,7 +199,7 @@ public class Script
         if(loopCounter > 50)
         {
             resetLoopCounter();
-            throw new CodeTooLongException();
+            throw new CodeTooLongException(this);
         }
     }
     
@@ -202,7 +213,7 @@ public class Script
         }
         catch(NullPointerException ex)
         {
-            throw new GotoLabelNotFoundException(label);
+            throw new GotoLabelNotFoundException(this, label);
         }
     }  
     
@@ -269,30 +280,4 @@ public class Script
     {
         return tryJumpLine; 
     }
-    
-    // -----------------------------------------------------------------------------------
-    // Frame
-    // -----------------------------------------------------------------------------------
-    
-    public void newFrame(int width, int height)
-    {
-        if(frame == null)
-        {
-            frame = new GraphicFrame(width, height, this);
-            panel = frame.graphics;
-        }
-    }
-    
-    public GraphicPanel getGraphicPanel()
-    {
-        return panel;
-    }
-    
-    public void closeFrame()
-    {
-        if(frame != null)
-        {
-            frame.dispose();
-        }
-    }
 }

+ 0 - 66
src/me/hammerle/code/ScriptControl.java

@@ -1,66 +0,0 @@
-package me.hammerle.code;
-
-import java.util.Collection;
-import java.util.HashMap;
-import me.hammerle.scheduler.SnuviScheduler;
-
-public class ScriptControl
-{
-    private static int idCounter = 0;
-    private final static HashMap<Integer, Script> SCRIPTS = new HashMap<>();
-    
-    // -------------------------------------------------------------------------
-    // Script - Verwaltung
-    // -------------------------------------------------------------------------
-
-    public static Script getScript(int id)
-    {
-        return SCRIPTS.get(id);
-    }
-    
-    public static void term(Script sc)
-    {
-        if(sc == null)
-        {
-            return;
-        }
-        sc.setInvalid();
-        sc.closeFrame();
-        SnuviScheduler.doScheduledTask(() -> SCRIPTS.remove(sc.getId()));
-    }
-    
-    public static void termScripts()
-    {
-        SCRIPTS.values().forEach(sc -> 
-        {
-            sc.setInvalid();
-            sc.closeFrame();
-        });
-        SnuviScheduler.doScheduledTask(() -> SCRIPTS.clear());
-    }
-    
-    public static Collection<Script> getScripts()
-    {
-        return SCRIPTS.values();
-    }
-    
-    // -----------------------
-    // Scripts laden und starten
-    // -----------------------
-  
-    public static void startScriptFromFile(String scriptName)
-    { 
-        Script sd = new Script(idCounter, scriptName, String.join("\n", ScriptUtils.readCode(scriptName)));
-        SCRIPTS.put(idCounter, sd);
-        idCounter++;
-        sd.runCode();
-    }
-    
-    public static void startScriptFromCode(String code)
-    { 
-        Script sd = new Script(idCounter, "CONSOLE-" + idCounter, code);
-        SCRIPTS.put(idCounter, sd);
-        idCounter++;
-        sd.runCode();
-    }
-}

+ 2 - 51
src/me/hammerle/code/ScriptUtils.java

@@ -1,69 +1,20 @@
 package me.hammerle.code;
 
-import java.awt.Color;
-import java.io.File;
-import java.io.IOException;
-import java.nio.charset.MalformedInputException;
-import java.nio.file.Files;
 import java.util.Arrays;
-import java.util.List;
 import java.util.Random;
 import java.util.stream.Collectors;
-import me.hammerle.console.ConsoleUtils;
-import me.hammerle.exceptions.FileException;
 
 public class ScriptUtils
 {
-    public static void printError(Object message)
-    { 
-        ConsoleUtils.sendMessage(String.valueOf(message), Color.RED);
-    }
-    
-    public static void printErrorList(Object message, Object message2)
-    {
-        ConsoleUtils.sendMessage(" - " + message + " " + message2, Color.RED);
-    }
-    
-    public static void print(Object message)
-    {
-        ConsoleUtils.sendMessage(String.valueOf(message), null);
-    }
-    
-    public static void printDebug(Object message)
-    {
-        ConsoleUtils.sendMessage(String.valueOf(message), Color.yellow);
-    }
+    private static final Random RANDOM = new Random();
     
     public static int randomInt(int min, int max)
     {
-        Random rand = new Random();
-        int randomNum = rand.nextInt((max - min) + 1) + min;
-        return randomNum;
+        return RANDOM.nextInt((max - min) + 1) + min;
     }
     
     public static String connect(Object[] o, int skip)
     {
         return Arrays.stream(o, skip, o.length).map(ob -> String.valueOf(ob)).collect(Collectors.joining());
     }
-    
-    public static List<String> readCode(String filename)
-    {
-        File script = new File("./" + filename + ".snuvi");  
-        if(script.exists())
-        {
-            try
-            {
-                return Files.readAllLines(script.toPath());
-            } 
-            catch (MalformedInputException ex) 
-            {
-                throw new FileException("file contains an illegal character, change file encoding");
-            }
-            catch (IOException ex) 
-            {
-                throw new FileException("file '" + filename + "' cannot be read");
-            }
-                   }
-        throw new FileException("file '" + filename + "' does not exist");
-    }
 }

+ 231 - 254
src/me/hammerle/code/CodeParser.java → src/me/hammerle/code/SnuviParser.java

@@ -1,77 +1,99 @@
 package me.hammerle.code;
 
-import java.awt.Color;
+import java.lang.reflect.InvocationTargetException;
 import me.hammerle.exceptions.HoldCodeException;
-import me.hammerle.exceptions.IllegalStringException;
-import me.hammerle.exceptions.NoSuchMethodException;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.time.ZonedDateTime;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Calendar;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.GregorianCalendar;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.function.BiFunction;
 import java.util.function.BiConsumer;
+import java.util.function.Consumer;
 import java.util.stream.Collectors;
-import me.hammerle.console.ConsoleUtils;
-import me.hammerle.graphics.*;
-import me.hammerle.scheduler.SnuviScheduler;
+import me.hammerle.exceptions.PrescriptException;
+import me.hammerle.exceptions.SnuviException;
 
-public class CodeParser 
+public class SnuviParser 
 {
-    private final static HashMap<String, BiFunction<Object[], Script, Object>> METHODS = new HashMap<>();
+    protected final ISnuviLogger logger;
+    private final ISnuviScheduler scheduler;
+    private final HashMap<String, BiFunction<Object[], Script, Object>> functions;
+    private boolean printStack;
     
-    private static void registerFunction(String s, BiFunction<Object[], Script, Object> f)
+    private int idCounter;
+    private final HashMap<Integer, Script> scripts;
+    private final ArrayList<Integer> termQueue;
+    
+    public SnuviParser(ISnuviLogger logger, ISnuviScheduler scheduler)
+    {
+        this.logger = logger;
+        this.scheduler = scheduler;
+        functions = new HashMap<>(); 
+        registerStandardLibraries();
+        
+        printStack = false;
+        
+        scripts = new HashMap<>();
+        termQueue = new ArrayList<>();
+        idCounter = 0;
+    }
+    
+    // -----------------------------------------------------------------------------------
+    // function registry
+    // -----------------------------------------------------------------------------------
+    
+    public boolean isRegisteredFunction(String s)
     {
-        METHODS.put(s, f);
+        return functions.containsKey(s);
     }
     
-    private static void registerConsumer(String s, BiConsumer<Object[], Script> f)
+    public void registerFunction(String s, BiFunction<Object[], Script, Object> f)
     {
-        METHODS.put(s, (BiFunction<Object[], Script, Object>) (args, sc) -> 
+        functions.put(s, f);
+    }
+    
+    public void registerConsumer(String s, BiConsumer<Object[], Script> f)
+    {
+        functions.put(s, (BiFunction<Object[], Script, Object>) (args, sc) -> 
         {
             f.accept(args, sc);
             return Void.TYPE;
         });
     }
     
-    private static void registerAlias(String s, String original)
+    public void registerAlias(String alias, String original)
     {
-        registerFunction(s, METHODS.get(original)); 
+        BiFunction<Object[], Script, Object> f = functions.get(original);
+        if(f == null)
+        {
+            throw new IllegalArgumentException("registering alias for non existent function");
+        }
+        registerFunction(alias, functions.get(original)); 
     }
     
     @SuppressWarnings("unchecked")
-    public static void initCodeParser()
+    private void registerStandardLibraries()
     {
-        registerConsumer("test", (args, sc) -> 
-                test(args, sc));
         registerFunction("nothing", (args, sc) -> 
                 0);
         registerFunction("", (args, sc) -> 
                 args[0]);
         registerConsumer("error", (args, sc) -> 
-                printStack = !printStack);
+                printStack = !printStack);       
         
-        // -------------------------------------------------------------    
-        // Script-Consolen-Bibliothek 
-        // -------------------------------------------------------------  
-        registerConsumer("script.list", (args, sc) -> 
-                { ScriptUtils.print("The following scripts are active:"); ScriptControl.getScripts().forEach(s -> ScriptUtils.print(s.getId() + " | " + s.getName()));}); 
-        registerConsumer("script.load", (args, sc) -> 
-                ScriptControl.startScriptFromFile(args[0].toString())); 
-        registerConsumer("clear", (args, sc) -> 
-                ConsoleUtils.clear()); 
-        registerConsumer("script.term", (args, sc) -> 
-                termScript(args, sc)); 
-        
-        // -------------------------------------------------------------    
-        // Event-Bibliothek 
-        // -------------------------------------------------------------  
+        // -------------------------------------------------------------------------------    
+        // event
+        // -------------------------------------------------------------------------------  
         registerConsumer("event.load", (args, sc) -> 
                 sc.loadEvent(args[0].toString())); 
         registerConsumer("event.unload", (args, sc) -> 
@@ -79,9 +101,9 @@ public class CodeParser
         registerFunction("event.isloaded", (args, sc) -> 
                 sc.isLoadedEvent(args[0].toString())); 
 
-        // -------------------------------------------------------------    
-        // Mathe-Bibliothek 
-        // -------------------------------------------------------------    
+        // -------------------------------------------------------------------------------    
+        // math
+        // -------------------------------------------------------------------------------    
         registerFunction("math.mod", (args, sc) -> 
                 ((double) args[0]) % ((double) args[1]));
         registerFunction("math.abs", (args, sc) -> 
@@ -121,9 +143,9 @@ public class CodeParser
         registerFunction("math.roundcomma", (args, sc) -> 
                 new BigDecimal(((double) args[0])).setScale(getInt(args[1]), RoundingMode.HALF_UP).doubleValue());
         
-        // -------------------------------------------------------------  
-        // Listen-Bibliothek   
-        // -------------------------------------------------------------    
+        // -------------------------------------------------------------------------------  
+        // lists
+        // -------------------------------------------------------------------------------    
         registerConsumer("list.new", (args, sc) ->                                                
                 sc.setVar(args[0].toString(), new ArrayList<>()));
         registerFunction("list.exists", (args, sc) ->                                                
@@ -153,13 +175,13 @@ public class CodeParser
         registerConsumer("list.shuffle", (args, sc) ->                            
                 Collections.shuffle((List<Object>) args[0]));
 
-        // -------------------------------------------------------------  
-        // Map-Bibliothek   
-        // ------------------------------------------------------------- 
+        // -------------------------------------------------------------------------------  
+        // maps
+        // ------------------------------------------------------------------------------- 
         registerConsumer("map.new", (args, sc) ->                                                
                 sc.setVar(args[0].toString(), new HashMap<>())); 
         registerFunction("map.exists", (args, sc) ->                                                
-                args[0] instanceof HashMap);  
+                args[0] instanceof Map);  
         registerConsumer("map.add", (args, sc) ->                            
                 ((HashMap) args[0]).put(args[1], args[2]));
         registerConsumer("map.remove", (args, sc) ->                            
@@ -173,13 +195,13 @@ public class CodeParser
         registerConsumer("map.clear", (args, sc) ->                            
                 ((HashMap) args[0]).clear());
         
-        // -------------------------------------------------------------  
-        // Set-Bibliothek   
-        // ------------------------------------------------------------- 
+        // -------------------------------------------------------------------------------  
+        // sets
+        // ------------------------------------------------------------------------------- 
         registerConsumer("set.new", (args, sc) ->                                                
                 sc.setVar(args[0].toString(), new HashSet<>())); 
         registerFunction("set.exists", (args, sc) ->                                                
-                args[0] instanceof HashSet);  
+                args[0] instanceof Set);  
         registerConsumer("set.add", (args, sc) ->                            
                 ((HashSet) args[0]).add(args[1]));
         registerConsumer("set.remove", (args, sc) ->                            
@@ -189,9 +211,9 @@ public class CodeParser
         registerFunction("set.getsize", (args, sc) ->                            
                 ((HashSet) args[0]).size());
 
-        // -------------------------------------------------------------  
-        // Time-Bibliothek   
-        // -------------------------------------------------------------
+        // -------------------------------------------------------------------------------  
+        // time
+        // -------------------------------------------------------------------------------
         registerFunction("time.get", (args, sc) ->                            
                 (double) System.currentTimeMillis());
         registerFunction("time.nextday", (args, sc) ->         
@@ -208,48 +230,10 @@ public class CodeParser
                 (double) getMinute(args));   
         registerFunction("time.getsecond", (args, sc) ->         
                 (double) getSecond(args));                   
-
-        // -------------------------------------------------------------    
-        // Graphic-Bibliothek 
-        // -------------------------------------------------------------
-        registerConsumer("g.new", (args, sc) ->                            
-                sc.newFrame(getInt(args[0]), getInt(args[1])));
-        registerFunction("g.get", (args, sc) ->                            
-                sc.getGraphicPanel().getGraphic(getInt(args[0])));
-        registerConsumer("g.repaint", (args, sc) ->                            
-                sc.getGraphicPanel().repaint());
-        registerConsumer("g.newpoint", (args, sc) ->                            
-                newPoint(args, sc));
-        registerConsumer("g.newline", (args, sc) ->                            
-                newLine(args, sc));
-        registerConsumer("g.newoval", (args, sc) ->                            
-                newOval(args, sc));
-        registerConsumer("g.newrectangle", (args, sc) ->                            
-                newRectangle(args, sc));
-        registerConsumer("g.translate", (args, sc) ->                            
-                ((Graphic) args[0]).translate(getInt(args[1]), getInt(args[2])));
-        registerConsumer("g.setcolor", (args, sc) ->                            
-                ((Colorable) args[0]).setColor((Color) args[1]));
-        registerConsumer("g.setfilled", (args, sc) ->                            
-                ((Colorable) args[0]).setFilled((boolean) args[1]));
-        registerConsumer("g.setx1", (args, sc) ->                            
-                ((Line) args[0]).setFirstX(getInt(args[1])));
-        registerConsumer("g.setx2", (args, sc) ->                            
-                ((Line) args[0]).setSecondX(getInt(args[1])));
-        registerConsumer("g.sety1", (args, sc) ->                            
-                ((Line) args[0]).setFirstY(getInt(args[1])));
-        registerConsumer("g.sety2", (args, sc) ->                            
-                ((Line) args[0]).setSecondY(getInt(args[1])));
-        
-        // -------------------------------------------------------------    
-        // Read-Bibliothek
-        // -------------------------------------------------------------  
-        registerFunction("read.color", (args, sc) ->         
-                getColor(args, sc));
-        
-        // -------------------------------------------------------------    
-        // Ohne Bibliothek
-        // -------------------------------------------------------------    
+               
+        // -------------------------------------------------------------------------------    
+        // commands without library
+        // -------------------------------------------------------------------------------    
         registerFunction("add", (args, sc) -> 
                 Arrays.stream(args).mapToDouble(s -> (double) s).sum());
         registerFunction("sub", (args, sc) -> 
@@ -268,10 +252,6 @@ public class CodeParser
                 sc.setVar(args[0].toString(), args[1]));
         registerConsumer("removevar", (args, sc) -> 
                 sc.removeVar(args[0].toString()));
-        registerConsumer("debug", (args, sc) -> 
-                ScriptUtils.printDebug(ScriptUtils.connect(args, 0)));
-        registerConsumer("print", (args, sc) -> 
-                print(args, sc));
         registerConsumer("reset", (args, sc) -> 
                 sc.resetLoopCounter());
         registerConsumer("wait", (args, sc) -> 
@@ -327,28 +307,23 @@ public class CodeParser
                 ScriptUtils.connect(args, 0).toUpperCase());   
         registerConsumer("waitfor", (args, sc) ->     
                 waitFor(args, sc));
+        registerConsumer("term", (args, sc) -> 
+                { termSafe(sc); throw new HoldCodeException(); }); 
     }
     
-    public static boolean printStack = false;
-
     @SuppressWarnings("unchecked")
-    public static Object parseFunction(Script sc, String function, Object[] args) throws HoldCodeException
+    protected Object parseFunction(Script sc, String function, Object[] args) throws HoldCodeException
     {
         try
         {
-            BiFunction<Object[], Script, Object> f = METHODS.get(function);
-            if(f == null)
-            {
-                throw new NoSuchMethodException(function);
-            }
-            return METHODS.get(function).apply(args, sc);
+            return functions.get(function).apply(args, sc);
+        }
+        catch(HoldCodeException ex)
+        {
+            throw ex;
         }
         catch(Exception ex)
         {
-            if(ex instanceof HoldCodeException)
-            {
-                throw ex;
-            }
             if(printStack)
             {
                 ex.printStackTrace();
@@ -360,85 +335,161 @@ public class CodeParser
                 sc.resetTryJumpLine();
                 return Void.TYPE;
             }
-            printQuestException(sc, ex, function + "(" + Arrays.stream(args).map(o -> String.valueOf(o)).collect(Collectors.joining(", ")) + ")");  
+            if(ex instanceof SnuviException)
+            {
+                logger.printException((SnuviException) ex);
+            }
+            else
+            {
+                logger.printException(new SnuviException(ex, sc));
+            }
+            sc.resetLoopCounter();
             throw new HoldCodeException();
         }
     }
     
-    public static void printQuestException(Script sc, Exception ex, String line)
+    // -----------------------------------------------------------------------------------
+    // script controller
+    // -----------------------------------------------------------------------------------
+    
+    public Script getScript(int id)
     {
-        sc.resetLoopCounter();
-        ScriptUtils.printError("Error in");
-        ScriptUtils.printErrorList("script:", sc.getName());
-        ScriptUtils.printErrorList("line:", line);
-        ScriptUtils.printErrorList("line number:", sc.getActiveCodeLine());
-        if(ex.getLocalizedMessage() == null)
+        return scripts.get(id);
+    }
+    
+    public void termSafe(Script sc)
+    {
+        if(sc == null)
         {
-            ScriptUtils.printErrorList("exception:", ex.getClass().getSimpleName());
+            return;
         }
-        else
+        sc.setInvalid();
+        termQueue.add(sc.getId());
+    }
+    
+    private void term()
+    {
+        if(!termQueue.isEmpty())
         {
-            ScriptUtils.printErrorList("exception:", ex.getClass().getSimpleName() + " - " + ex.getLocalizedMessage());
+            termQueue.forEach(i -> scripts.remove(i));
+            termQueue.clear();
+        }
+    }
+    
+    public void termAllUnsafe()
+    {
+        scripts.values().forEach(sc -> sc.setInvalid());
+        scripts.clear();
+    }
+    
+    public Collection<Script> getScripts()
+    {
+        return scripts.values();
+    }
+    
+    private Script startScript(Script script, Object... o)
+    { 
+        try
+        {            
+            script.initExpansion(o);
+            scripts.put(idCounter, script);
+            idCounter++;
+            script.runCode();
+            term();
+            return script;
         }
-        if(ex instanceof IllegalStringException)
+        catch(PrescriptException ex)
         {
-            ScriptUtils.printErrorList("illegal value:", ((IllegalStringException) ex).getBadString());
+            logger.printException(ex);
+            return null;
         }
     }
     
-    // -----------------------------------------------------------------------------------
-    // Functions
-    // -----------------------------------------------------------------------------------
+    public Script startScript(String scriptName, String code)
+    { 
+        return startScript(new Script(this, idCounter, scriptName, code));
+    }
     
-    private static void termScript(Object[] args, Script sc)
-    {
-        if(args.length == 0)
+    public Script startScript(Class<? extends Script> c, String scriptName, String code, boolean b, Object... o)
+    { 
+        try
         {
-            ScriptControl.term(sc);
-            throw new HoldCodeException();
+            return startScript(c.getDeclaredConstructor(
+                    SnuviParser.class, int.class, String.class, String.class, boolean.class)
+                    .newInstance(this, idCounter, scriptName, code, b), o);
         }
-        else if(args[0].toString().equals("all"))
+        catch(IllegalAccessException | IllegalArgumentException | InstantiationException |
+                InvocationTargetException | NoSuchMethodException | SecurityException ex)
         {
-            ScriptControl.termScripts();
-            throw new HoldCodeException();
+            return null;
         }
-        else
+    }
+    
+    // -----------------------------------------------------------------------------------
+    // event
+    // -----------------------------------------------------------------------------------
+    
+    public void callEvent(String name, Consumer<Script> before, Consumer<Script> after)
+    {
+        scripts.values().stream()
+                .filter(script -> script.receiveEventBroadcast)
+                .filter(script -> script.isLoadedEvent(name))
+                .forEach(sc -> 
+                {
+                    sc.setVar("event", name);
+                    before.accept(sc);
+                    sc.runCode();
+                    after.accept(sc);
+                    sc.eventVars.forEach(s -> sc.removeVar(s));
+                    sc.eventVars.clear();
+                });
+        term();
+    }
+    
+    public void callEvent(String name, Script sc, Consumer<Script> before, Consumer<Script> after)
+    {
+        if(sc.isLoadedEvent(name))
         {
-            int i = getInt(args[0]);
-            ScriptControl.term(ScriptControl.getScript(i));
-            if(sc.getId() == i)
-            {
-                throw new HoldCodeException();
-            }
+            sc.setVar("event", name);
+            before.accept(sc);
+            sc.runCode();
+            after.accept(sc);
+            sc.eventVars.forEach(s -> sc.removeVar(s));
+            sc.eventVars.clear();
+            term();
         }
     }
     
-    private static void ifFunction(Object[] args, Script sc)
+    // -----------------------------------------------------------------------------------
+    // functions
+    // -----------------------------------------------------------------------------------
+    
+    private void ifFunction(Object[] args, Script sc)
     {
-        if(Arrays.stream(args).anyMatch(s -> (boolean) s == false))
+        if(Arrays.stream(args).anyMatch(s -> !((boolean) s)))
         {
             sc.gotoSpecialJumpLine();
             sc.jumpNextIfElse();
         }
     }  
     
-    private static void whileFunction(Object[] args, Script sc)
+    private void whileFunction(Object[] args, Script sc)
     {
-        if(Arrays.stream(args).anyMatch(s -> (boolean) s == false))
+        if(Arrays.stream(args).anyMatch(s -> !((boolean) s)))
         {
             sc.gotoSpecialJumpLine(0);
         }
     } 
                   
-    @SuppressWarnings(value = "unchecked")
-    private static void sortList(List<Object> args, Script sc) 
+    @SuppressWarnings("unchecked")
+    private void sortList(List<Object> args, Script sc) 
     {
         Collections.sort(args, (Object o1, Object o2) -> ((Comparable) o1).compareTo(o2));
     }
     
-    private static void scheduleGoto(Object[] args, Script sc)
+    private void scheduleGoto(Object[] args, Script sc)
     {
-        SnuviScheduler.doScheduledTask(() -> 
+        scheduler.scheduleTask(() -> 
         {
             if(!sc.isValid())
             {
@@ -452,21 +503,22 @@ public class CodeParser
             }
             catch(Exception ex)
             {
-                printQuestException(sc, ex, "(Scheduled Goto)");
+                logger.printException(new SnuviException(ex, sc.getName(), "scheduled goto"));
             }
         }, getInt(args[0]));
     }
     
-    private static void waitFor(Object[] args, Script sc) throws UnsupportedOperationException
+    @SuppressWarnings("")
+    private void waitFor(Object[] args, Script sc) throws UnsupportedOperationException
     {           
         sc.resetLoopCounter();
-        int i = getInt(args[0]);
-        if(i < 1)
+        long l = getLong(args[0]);
+        if(l < 0)
         {
-            throw new UnsupportedOperationException();
+            throw new IllegalArgumentException("time units can't be negative");
         }
         sc.setHalt(true);
-        SnuviScheduler.doScheduledTask(() -> 
+        scheduler.scheduleTask(() -> 
         {                   
             if(sc == null || !sc.isValid())
             {
@@ -474,10 +526,10 @@ public class CodeParser
             }
             sc.setHalt(false);
             sc.runCode();
-        }, i); 
+        }, l); 
     }   
     
-    private static Number increaseVar(Object var, Script sc, int value)
+    private Number increaseVar(Object var, Script sc, int value)
     {
         double n = ((double) sc.getVar(var.toString())) + value;
         sc.setVar(var.toString(), n);
@@ -492,8 +544,9 @@ public class CodeParser
         }
         else if(args[1] == null)
         {
-            return args[0] == null;
+            return false;
         }
+        // this is needed for comparing different number types (e.g. Integer and Double)
         else if(args[1] instanceof Number && args[0] instanceof Number)
         {
             return ((Number) args[0]).doubleValue() == ((Number) args[1]).doubleValue();
@@ -501,108 +554,32 @@ public class CodeParser
         return args[0].equals(args[1]);
     }
     
-    private static void split(Object[] args, Script sc)
-    {
-        String[] parts = ScriptUtils.connect(args, 2).split(args[1].toString());
-        ArrayList<Object> list = new ArrayList<>();
-        for(String s : parts)
-        {
-            list.add(Code.convertInput(s));
-        }
-        sc.setVar(args[0].toString(), list);
-    }   
-    
-    private static void print(Object[] args, Script sc)
+    private void split(Object[] args, Script sc)
     {
-        if(args.length == 0)
-        {
-            ScriptUtils.print("");
-        } 
-        else if(args[0] instanceof Color)
-        {
-            ConsoleUtils.sendMessage(ScriptUtils.connect(args, 1), (Color) args[0]);
-        }
-        else
-        {
-            ScriptUtils.print(ScriptUtils.connect(args, 0));
-        }
+        sc.setVar(args[0].toString(), 
+                Arrays.stream(ScriptUtils.connect(args, 2).split(args[1].toString()))
+                        .map(s -> Code.convertInput(s)).collect(Collectors.toList()));
     }
     
-    // -------------------------------------------------------------------------    
-    // Read-Handler
-    // ------------------------------------------------------------------------- 
-    
-    private static Color getColor(Object[] args, Script sc)
-    {
-        int r = getInt(args[0]);
-        int g = getInt(args[1]);
-        int b = getInt(args[2]);
-        int a;
-        if(args.length >= 4)
-        {
-            a = getInt(args[3]);
-        }
-        else
-        {
-            a = 255;
-        }
-        return new Color(r, g, b, a);
-    }
-    
-    // -------------------------------------------------------------------------    
-    // Graphics
-    // ------------------------------------------------------------------------- 
-    
-    private static void newLine(Object[] args, Script sc)
-    {
-        sc.getGraphicPanel().addGraphic(getInt(args[0]), new Line((Color) args[1], getInt(args[2]), getInt(args[3]), getInt(args[4]), getInt(args[5])));
-    }
-    
-    private static void newPoint(Object[] args, Script sc)
-    {
-        sc.getGraphicPanel().addGraphic(getInt(args[0]), new Point((Color) args[1], getInt(args[2]), getInt(args[3])));
-    }
-    
-    private static void newOval(Object[] args, Script sc)
-    {
-        Oval oval = new Oval((Color) args[1], getInt(args[2]), getInt(args[3]), getInt(args[4]), getInt(args[5]));
-        if(args.length >= 7)
-        {
-            oval.setFilled((boolean) args[6]);
-        }
-        sc.getGraphicPanel().addGraphic(getInt(args[0]), oval);
-    }
-    
-    private static void newRectangle(Object[] args, Script sc)
-    {
-        Rectangle rec = new Rectangle((Color) args[1], getInt(args[2]), getInt(args[3]), getInt(args[4]), getInt(args[5]));
-        if(args.length >= 7)
-        {
-            rec.setFilled((boolean) args[6]);
-        }
-        sc.getGraphicPanel().addGraphic(getInt(args[0]), rec);
-    }
+    // -----------------------------------------------------------------------------------   
+    // number handlers, cause primitive types transform into their classes all the time
+    // -----------------------------------------------------------------------------------
     
-    private static void test(Object[] args, Script sc)
+    private int getInt(Object o)
     {
-        //sc.getGraphicPanel().objects.clear();
-        //sc.getGraphicPanel().getGraphics().drawLine(20, 20, 30, 30);
+        return ((Number) o).intValue();
     }
     
-    // -------------------------------------------------------------------------    
-    // Int-Handler, weil die Objekte double immer zu Double konvertieren
-    // ------------------------------------------------------------------------- 
-    
-    private static int getInt(Object o)
+    private long getLong(Object o)
     {
-        return ((Number) o).intValue();
+        return ((Number) o).longValue();
     }
     
-    // -------------------------------------------------------------------------    
-    // Zeit-Handler
-    // ------------------------------------------------------------------------- 
+    // -----------------------------------------------------------------------------------    
+    // time handler
+    // -----------------------------------------------------------------------------------
     
-    private static long getNextDay(Object[] args)       
+    private long getNextDay(Object[] args)       
     {
         GregorianCalendar cal = GregorianCalendar.from(ZonedDateTime.now());
         cal.setTimeInMillis((long) args[0]);
@@ -614,42 +591,42 @@ public class CodeParser
         return cal.getTimeInMillis();   
     } 
     
-    private static int getYear(Object[] args)       
+    private int getYear(Object[] args)       
     {
         GregorianCalendar cal = GregorianCalendar.from(ZonedDateTime.now());
         cal.setTimeInMillis((long) args[0]);
         return cal.get(Calendar.YEAR);   
     }
     
-    private static int getMonth(Object[] args)       
+    private int getMonth(Object[] args)       
     {
         GregorianCalendar cal = GregorianCalendar.from(ZonedDateTime.now());
         cal.setTimeInMillis((long) args[0]);
         return cal.get(Calendar.MONTH) + 1;   
     }
     
-    private static int getDay(Object[] args)       
+    private int getDay(Object[] args)       
     {
         GregorianCalendar cal = GregorianCalendar.from(ZonedDateTime.now());
         cal.setTimeInMillis((long) args[0]);
         return cal.get(Calendar.DAY_OF_MONTH);   
     }
     
-    private static int getHour(Object[] args)       
+    private int getHour(Object[] args)       
     {
         GregorianCalendar cal = GregorianCalendar.from(ZonedDateTime.now());
         cal.setTimeInMillis((long) args[0]);
         return cal.get(Calendar.HOUR_OF_DAY);   
     }
     
-    private static int getMinute(Object[] args)       
+    private int getMinute(Object[] args)       
     {
         GregorianCalendar cal = GregorianCalendar.from(ZonedDateTime.now());
         cal.setTimeInMillis((long) args[0]);
         return cal.get(Calendar.MINUTE);   
     }
     
-    private static int getSecond(Object[] args)       
+    private int getSecond(Object[] args)       
     {
         GregorianCalendar cal = GregorianCalendar.from(ZonedDateTime.now());
         cal.setTimeInMillis((long) args[0]);

+ 9 - 2
src/me/hammerle/code/Variable.java

@@ -5,8 +5,15 @@ public class Variable
     private final String name;
   
     public Variable(String name)
-    {
-        this.name = name;
+    {       
+        if(name.length() == 0 || name.charAt(0) != '$')
+        {
+            this.name = name;
+        }
+        else
+        {
+            this.name = name.substring(1);
+        }
     }
     
     public String getName()

+ 0 - 82
src/me/hammerle/console/BlackBox.java

@@ -1,82 +0,0 @@
-package me.hammerle.console;
-
-import java.awt.Color;
-import java.awt.Font;
-import javax.swing.JScrollBar;
-import javax.swing.JScrollPane;
-import javax.swing.JTextPane;
-import javax.swing.text.BadLocationException;
-import javax.swing.text.Style;
-import javax.swing.text.StyleConstants;
-import javax.swing.text.StyledDocument;
-import me.hammerle.scheduler.SnuviScheduler;
-
-public class BlackBox extends JScrollPane
-{
-    private final StyledDocument doc;
-    protected final JTextPane area;
-    protected final Console c;
-    
-    public BlackBox(Console c)
-    {
-        this.c = c;
-        
-        area = new JTextPane();
-        //area.setLineWrap(true);
-        area.setBackground(Color.black);
-        area.setFont(new Font("Monaco", Font.PLAIN, 14));
-        area.setForeground(Color.white);
-        area.setCaretColor(Color.white);
-        area.setAutoscrolls(true);
-        /*area.selectAll();
-        MutableAttributeSet set = new SimpleAttributeSet(area.getParagraphAttributes());
-        StyleConstants.setLineSpacing(set, -0.17f);
-        area.setParagraphAttributes(set, true);*/
-        
-        super.setViewportView(area);
-        super.setBackground(Color.black);
-        super.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
-        
-        doc = area.getStyledDocument();
-    }
-    
-    public void insert(String s, Color c, int pos)
-    {
-        Style style = null;
-        if(c != null)
-        {
-            style = doc.getStyle(s);
-            if(style == null)
-            {
-                style = area.addStyle(c.toString(), null);
-                StyleConstants.setForeground(style, c);
-                /*StyleConstants.setLineSpacing(style, 0);
-                StyleConstants.setSpaceAbove(style, 20);
-                StyleConstants.setSpaceBelow(style, 0);*/
-            }
-        }
-        try 
-        {
-            doc.insertString(pos, s, style);
-        } 
-        catch (BadLocationException ex) 
-        {
-        }
-    }
-    
-    public void append(String s, Color c)
-    {
-        insert(s, c, doc.getLength());
-    }
-    
-    public void insertAtCaret(String s, Color c)
-    {
-        insert(s, c, area.getCaretPosition());
-    }
-    
-    protected void scrollToBottom()
-    {
-        JScrollBar v = this.getVerticalScrollBar();
-        v.setValue(v.getMaximum());
-    }
-}

+ 0 - 36
src/me/hammerle/console/Console.java

@@ -1,36 +0,0 @@
-package me.hammerle.console;
-
-import java.awt.BorderLayout;
-import java.awt.Dimension;
-import javax.swing.JFrame;
-
-public class Console extends JFrame
-{
-    protected final OutputBox output;
-    protected final InputBox input;
-    
-    public Console()
-    {
-        super.setDefaultCloseOperation(EXIT_ON_CLOSE);
-        super.setTitle("SnuviScript - 0.0.1 - Konsole");
-        super.setPreferredSize(new Dimension(660, 460));
-        super.setLayout(new BorderLayout(0, 1));
-        
-        // -------------------------------------------------------------------------------
-        // Input
-        // -------------------------------------------------------------------------------
-        
-        input = new InputBox(this);
-        super.add(input, BorderLayout.CENTER);
-        
-        // -------------------------------------------------------------------------------
-        // Output
-        // -------------------------------------------------------------------------------
-        
-        output = new OutputBox(this);
-        super.add(output, BorderLayout.PAGE_START);
-
-        super.pack();
-        super.setVisible(true);
-    }
-}

+ 0 - 22
src/me/hammerle/console/ConsoleUtils.java

@@ -1,22 +0,0 @@
-package me.hammerle.console;
-
-import java.awt.Color;
-import me.hammerle.snuviscript.SnuviScript;
-
-public class ConsoleUtils 
-{
-    public static void sendMessage(String s, Color c)
-    {
-        SnuviScript.console.output.pushText(s, c);
-    }
-    
-    public static void clear()
-    {
-        SnuviScript.console.output.clear();
-    }
-    
-    public static void scrollToBottom()
-    {
-        SnuviScript.console.output.scrollToBottom();
-    }
-}

+ 0 - 85
src/me/hammerle/console/InputBox.java

@@ -1,85 +0,0 @@
-package me.hammerle.console;
-
-import java.awt.Color;
-import java.awt.event.KeyAdapter;
-import java.awt.event.KeyEvent;
-import java.util.ArrayList;
-import me.hammerle.code.ScriptControl;
-
-public class InputBox extends BlackBox
-{
-    private final ArrayList<String> history;
-    private int historyPosition;
-    
-    public InputBox(Console c)
-    {
-        super(c);
-        history = new ArrayList<>();
-        historyPosition = -1;
-        area.addKeyListener(new KeyAdapter() 
-        {
-            @Override
-            public void keyPressed(KeyEvent e) 
-            {
-                //System.out.println(e.getKeyCode());
-                switch(e.getKeyCode())
-                {
-                    case KeyEvent.VK_ENTER:
-                    {
-                        if(e.isShiftDown())
-                        {
-                            insertAtCaret("\n", null);
-                            e.consume();
-                        }
-                        else
-                        {
-                            ConsoleUtils.sendMessage("> " + area.getText(), Color.GRAY);
-                            history.add(area.getText());
-                            ScriptControl.startScriptFromCode(area.getText());
-                            area.setText(null);
-                            e.consume();
-                            historyPosition = -1;
-                        }
-                        break;
-                    }
-                    case KeyEvent.VK_UP:
-                    {
-                        if(e.isShiftDown())
-                        {
-                            if(historyPosition == -1)
-                            {
-                                historyPosition = history.size();
-                            }
-                            else if(historyPosition == 0)
-                            {
-                                return;
-                            }
-                            historyPosition--;
-                            area.setText(history.get(historyPosition));
-                        }
-                        break;
-                    }
-                    case KeyEvent.VK_DOWN:
-                    {
-                        if(e.isShiftDown())
-                        {
-                            if(historyPosition == -1)
-                            {
-                                return;
-                            }
-                            else if(historyPosition >= history.size() - 1)
-                            {
-                                historyPosition = -1;
-                                area.setText("");
-                                return;
-                            }
-                            historyPosition++;
-                            area.setText(history.get(historyPosition));
-                        }
-                        break;
-                    }
-                }
-            }
-        });
-    }
-}

+ 0 - 25
src/me/hammerle/console/OutputBox.java

@@ -1,25 +0,0 @@
-package me.hammerle.console;
-
-import java.awt.Color;
-import java.awt.Dimension;
-
-public class OutputBox extends BlackBox
-{
-    public OutputBox(Console c)
-    {
-        super(c);
-        super.setPreferredSize(new Dimension(660, 345));
-        area.setEditable(false);
-        area.setText("--- Hello " + System.getProperty("user.name") + " ---\n");
-    }
-    
-    public void pushText(String s, Color c)
-    {
-        append(s + "\n", c);
-    }
-    
-    public void clear()
-    {
-        area.setText("");
-    }
-}

+ 7 - 2
src/me/hammerle/exceptions/CodeTooLongException.java

@@ -1,6 +1,11 @@
 package me.hammerle.exceptions;
 
-public class CodeTooLongException extends RuntimeException
+import me.hammerle.code.Script;
+
+public class CodeTooLongException extends SnuviException
 {
-    
+    public CodeTooLongException(Script sc)
+    {
+        super(null, sc);
+    }
 }

+ 0 - 9
src/me/hammerle/exceptions/FileException.java

@@ -1,9 +0,0 @@
-package me.hammerle.exceptions;
-
-public class FileException extends IllegalStringException
-{
-    public FileException(String s) 
-    {
-        super(s);
-    }
-}

+ 4 - 2
src/me/hammerle/exceptions/GotoLabelNotFoundException.java

@@ -1,9 +1,11 @@
 package me.hammerle.exceptions;
 
+import me.hammerle.code.Script;
+
 public class GotoLabelNotFoundException extends IllegalStringException
 {
-    public GotoLabelNotFoundException(String s) 
+    public GotoLabelNotFoundException(Script sc, String s) 
     {
-        super(s);
+        super(sc, s);
     }  
 }

+ 1 - 1
src/me/hammerle/exceptions/HoldCodeException.java

@@ -1,6 +1,6 @@
 package me.hammerle.exceptions;
 
-public class HoldCodeException extends RuntimeException
+public final class HoldCodeException extends RuntimeException
 {
     
 }

+ 5 - 2
src/me/hammerle/exceptions/IllegalStringException.java

@@ -1,11 +1,14 @@
 package me.hammerle.exceptions;
 
-public class IllegalStringException extends RuntimeException
+import me.hammerle.code.Script;
+
+public class IllegalStringException extends SnuviException
 {
     private final String s;
     
-    public IllegalStringException(String s)
+    public IllegalStringException(Script sc, String s)
     {
+        super(null, sc);
         this.s = s;
     }
     

+ 3 - 3
src/me/hammerle/exceptions/NoSuchMethodException.java

@@ -1,9 +1,9 @@
 package me.hammerle.exceptions;
 
-public class NoSuchMethodException extends IllegalStringException
+public class NoSuchMethodException extends PrescriptException
 {
-    public NoSuchMethodException(String s) 
+    public NoSuchMethodException(String scriptName, String code, String error) 
     {
-        super(s);
+        super(scriptName, code, error);
     }
 }

+ 7 - 7
src/me/hammerle/exceptions/PrescriptException.java

@@ -1,17 +1,17 @@
 package me.hammerle.exceptions;
 
-public class PrescriptException extends IllegalStringException
+public class PrescriptException extends SnuviException
 {
-    private final String s2;
+    private final String error;
     
-    public PrescriptException(String s, String s2) 
+    public PrescriptException(String scriptName, String code, String error) 
     {
-        super(s);
-        this.s2 = s2;
+        super(null, scriptName, code);
+        this.error = error;
     }
     
     public String getException()
     {
-        return s2;
+        return error;
     }
-}
+}

+ 54 - 0
src/me/hammerle/exceptions/SnuviException.java

@@ -0,0 +1,54 @@
+package me.hammerle.exceptions;
+
+import me.hammerle.code.Script;
+
+public class SnuviException extends RuntimeException
+{
+    private final Exception ex;
+    private final String scriptName;
+    private final String code;
+    private final int line;
+    
+    public SnuviException(Exception ex, String scriptName, int line, String code)
+    {
+        this.ex = ex;
+        this.scriptName = scriptName;
+        this.code = code;
+        this.line = line;
+    }
+    
+    public SnuviException(Exception ex, String scriptName, String code)
+    {
+        this(ex, scriptName, -1, code);
+    }
+    
+    public SnuviException(Exception ex, String scriptName, int line)
+    {
+        this(ex, scriptName, line, null);
+    }
+    
+    public SnuviException(Exception ex, Script sc)
+    {
+        this(ex, sc.getName(), sc.getActiveCodeLine());
+    }
+    
+    public Exception getOriginalException()
+    {
+        return ex;
+    }
+    
+    public int getLine()
+    {
+        return line;
+    }
+    
+    public String getCode()
+    {
+        return code;
+    }
+    
+    public String getScriptName()
+    {
+        return scriptName;
+    }
+}

+ 0 - 35
src/me/hammerle/graphics/Colorable.java

@@ -1,35 +0,0 @@
-package me.hammerle.graphics;
-
-import java.awt.Color;
-
-public abstract class Colorable 
-{
-    private Color c;
-    private boolean filled;
-    
-    public Colorable(Color c)
-    {
-        this.c = c; 
-        this.filled = false;
-    }
-    
-    public Color getColor()
-    {
-        return c;
-    }
-    
-    public void setColor(Color c)
-    {
-        this.c = c;
-    }
-    
-    public boolean isFilled()
-    {
-        return filled;
-    }
-    
-    public void setFilled(boolean filled)
-    {
-        this.filled = filled;
-    }
-}

+ 0 - 12
src/me/hammerle/graphics/Graphic.java

@@ -1,12 +0,0 @@
-package me.hammerle.graphics;
-
-import java.awt.Graphics;
-
-public interface Graphic 
-{
-    public void paint(Graphics g);
-    
-    public boolean hasColor();
-    
-    public void translate(int x, int y);
-}

+ 0 - 96
src/me/hammerle/graphics/GraphicFrame.java

@@ -1,96 +0,0 @@
-package me.hammerle.graphics;
-
-import java.awt.event.KeyAdapter;
-import java.awt.event.KeyEvent;
-import java.awt.event.MouseEvent;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-import java.util.function.Consumer;
-import javax.swing.JFrame;
-import javax.swing.event.MouseInputAdapter;
-import me.hammerle.code.Script;
-
-public class GraphicFrame extends JFrame
-{
-    private final Script parent;
-    public final GraphicPanel graphics;
-    
-    public GraphicFrame(int width, int height, Script sc)
-    {
-        parent = sc;
-        graphics = new GraphicPanel();
-        
-        super.setSize(width, height + 22);
-        super.setResizable(false);
-        super.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
-        super.setVisible(true);
-        super.add(graphics);
-        
-        super.addWindowListener(new WindowAdapter() 
-        {
-            @Override
-            public void windowClosing(WindowEvent evt) 
-            {
-                generalEvent("window-closing", (sc) -> {});
-            }
-        });
-        
-        super.addKeyListener(new KeyAdapter()
-        {
-            @Override
-            public void keyPressed(KeyEvent e) 
-            {
-                keyEvent(e, "pressed");
-            } 
-            @Override
-            public void keyTyped(KeyEvent e) 
-            {
-                keyEvent(e, "typed");
-            }
-            @Override
-            public void keyReleased(KeyEvent e) 
-            {
-                keyEvent(e, "released");
-            }
-        });
-        
-        graphics.addMouseListener(new MouseInputAdapter() 
-        {
-            @Override
-            public void mousePressed(MouseEvent e) 
-            {
-                mouseEvent(e, "pressed");
-            }          
-        });
-    }
-    
-    private void generalEvent(String name, Consumer<Script> f)
-    {
-        if(parent.isLoadedEvent(name))
-        {
-            parent.setVar("event", name);
-            f.accept(parent);
-            parent.runCode(); 
-        }
-    }
-    
-    private void keyEvent(KeyEvent e, String name)
-    {
-        generalEvent("key-" + name, sc -> 
-        {
-            sc.setVar("keycode", e.getKeyCode());
-            sc.setVar("keychar", e.getKeyChar());
-        });
-    }
-    
-    private void mouseEvent(MouseEvent e, String name)
-    {      
-        generalEvent("mouse-" + name, sc -> 
-        {
-            parent.setVar("button", e.getButton());
-            parent.setVar("count", e.getClickCount());
-            parent.setVar("x", e.getX());
-            parent.setVar("y", e.getY());
-        });
-    }
-}

+ 0 - 46
src/me/hammerle/graphics/GraphicPanel.java

@@ -1,46 +0,0 @@
-package me.hammerle.graphics;
-
-import java.awt.Color;
-import java.awt.Graphics;
-import java.util.TreeMap;
-import javax.swing.JPanel;
-
-public class GraphicPanel extends JPanel
-{
-    private final TreeMap<Integer, Graphic> objects;
-    
-    public GraphicPanel()
-    {
-        this.objects = new TreeMap<>();
-        super.setBackground(Color.black);
-    }
-    
-    public synchronized Graphic getGraphic(int id)
-    {
-        return objects.get(id);
-    }
-    
-    public synchronized void removeGraphic(int id)
-    {
-        objects.remove(id);
-    }
-    
-    public synchronized void addGraphic(int id, Graphic g)
-    {
-        objects.put(id, g);
-    }
-
-    @Override
-    public synchronized void paint(Graphics g) 
-    {
-        super.paint(g);
-        objects.values().forEach(go -> 
-        {
-            if(go.hasColor())
-            {
-                g.setColor(((Colorable) go).getColor());
-            }
-            go.paint(g);
-        });
-    }   
-}

+ 0 - 63
src/me/hammerle/graphics/Image.java

@@ -1,63 +0,0 @@
-package me.hammerle.graphics;
-
-import java.awt.Graphics;
-import java.awt.image.BufferedImage;
-
-public class Image extends Line implements Graphic
-{
-    private int x;
-    private int y;
-    private BufferedImage image;
-    private final GraphicPanel panel;
-    
-    public Image(GraphicPanel panel, BufferedImage image, int x, int y, int x1, int y1, int x2, int y2)
-    {
-        super(null, x1, y1, x2, y2);
-        this.image = image;
-        this.x = x;
-        this.y = y;
-        this.panel = panel;
-    }
-    
-    public Image(GraphicPanel panel, BufferedImage image, int x, int y)
-    {
-        this(panel, image, x, y, 0, 0, image.getWidth(), image.getHeight());
-    }
-    
-    public void setX(int x)
-    {
-        this.x = x;
-    }
-    
-    public void setY(int y)
-    {
-        this.y = y;
-    }
-
-    public int getX()
-    {
-        return x;
-    }
-
-    public int getY()
-    {
-        return y;
-    }
-    
-    public void setImage(BufferedImage image)
-    {
-        this.image = image;
-    }
-    
-    @Override
-    public void paint(Graphics g) 
-    {
-        g.drawImage(image.getSubimage(x1, y1, x2 - x1, y2 - y1), x, y, panel);
-    }
-
-    @Override
-    public boolean hasColor() 
-    {
-        return false;
-    }
-}

+ 0 - 82
src/me/hammerle/graphics/Line.java

@@ -1,82 +0,0 @@
-package me.hammerle.graphics;
-
-import java.awt.Color;
-import java.awt.Graphics;
-
-public class Line extends Colorable implements Graphic
-{
-    protected int x1;
-    protected int y1;
-    protected int x2;
-    protected int y2;
-    
-    public Line(Color c, int x1, int y1, int x2, int y2) 
-    {
-        super(c);
-        this.x1 = x1;
-        this.y1 = y1;
-        this.x2 = x2;
-        this.y2 = y2;
-    }   
-    
-    public void setFirstX(int x) 
-    {
-        x1 = x;
-    }
-    
-    public void setFirstY(int y)    
-    {
-        y1 = y;
-    }
-    
-    public void setSecondX(int x)    
-    {
-        x2 = x;
-    }
-    
-    public void setSecondY(int y)    
-    {
-        y2 = y;
-    }
-    
-    public int getFirstX()    
-    {
-        return x1;
-    }
-    
-    public int getFirstY()    
-    {
-        return y1;
-    }
-    
-    public int getSecondX()    
-    {
-        return x2;
-    }
-    
-    public int getSecondY()    
-    {
-        return y2;
-    }
-
-    @Override
-    public void paint(Graphics g) 
-    {
-        g.drawLine(x1, y1, x2, y2);
-    }
-
-    @Override
-    public boolean hasColor() 
-    {
-        return true;
-    }
-
-    @Override
-    public void translate(int x, int y) 
-    {
-        x1 += x;
-        x2 += x;
-        y1 += y;
-        y2 += y;
-    }
-}

+ 0 - 25
src/me/hammerle/graphics/Oval.java

@@ -1,25 +0,0 @@
-package me.hammerle.graphics;
-
-import java.awt.Color;
-import java.awt.Graphics;
-
-public class Oval extends Line
-{
-    public Oval(Color c, int x1, int y1, int x2, int y2) 
-    {
-        super(c, x1, y1, x2, y2);
-    }  
-    
-    @Override
-    public void paint(Graphics g) 
-    {
-        if(isFilled())
-        {
-            g.fillOval(x1, y1, x2 - x1 - 1, y2 - y1 - 1);
-        }
-        else
-        {
-            g.drawOval(x1, y1, x2 - x1 - 1, y2 - y1 - 1);
-        }
-    }
-}

+ 0 - 39
src/me/hammerle/graphics/Point.java

@@ -1,39 +0,0 @@
-package me.hammerle.graphics;
-
-import java.awt.Color;
-
-public class Point extends Line
-{
-    public Point(Color c, int x, int y) 
-    {
-        super(c, x, y, x, y);
-    }
-    
-    @Override
-    public void setFirstX(int x) 
-    {
-        x1 = x;
-        x2 = x;
-    }
-    
-    @Override
-    public void setFirstY(int y)    
-    {
-        y1 = y;
-        y2 = y;
-    }
-    
-    @Override
-    public void setSecondX(int x)    
-    {
-        x2 = x;
-        x2 = x;
-    }
-    
-    @Override
-    public void setSecondY(int y)    
-    {
-        y2 = y;
-        y2 = y;
-    }
-}

+ 0 - 25
src/me/hammerle/graphics/Rectangle.java

@@ -1,25 +0,0 @@
-package me.hammerle.graphics;
-
-import java.awt.Color;
-import java.awt.Graphics;
-
-public class Rectangle extends Line
-{
-    public Rectangle(Color c, int x1, int y1, int x2, int y2) 
-    {
-        super(c, x1, y1, x2, y2);
-    }  
-    
-    @Override
-    public void paint(Graphics g) 
-    {
-        if(isFilled())
-        {
-            g.fillRect(x1, y1, x2 - x1, y2 - y1);
-        }
-        else
-        {
-            g.drawRect(x1, y1, x2 - x1, y2 - y1);
-        }
-    }
-}

+ 0 - 20
src/me/hammerle/scheduler/SnuviScheduler.java

@@ -1,20 +0,0 @@
-package me.hammerle.scheduler;
-
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-
-public class SnuviScheduler 
-{
-    public static void doScheduledTask(Runnable r)
-    {
-        r.run();
-    }
-    
-    public static void doScheduledTask(Runnable r, int delay)
-    {
-        ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();  
-        executor.schedule(r, delay, TimeUnit.MILLISECONDS);
-        executor.shutdown();
-    }
-}

+ 34 - 20
src/me/hammerle/snuviscript/SnuviScript.java

@@ -1,32 +1,46 @@
 package me.hammerle.snuviscript;
 
-import me.hammerle.code.CodeParser;
-import me.hammerle.console.Console;
-import me.hammerle.code.ScriptControl;
-import me.hammerle.code.ScriptUtils;
-import me.hammerle.exceptions.FileException;
+import me.hammerle.code.Script;
+import me.hammerle.code.SnuviParser;
+import me.hammerle.exceptions.SnuviException;
+import me.hammerle.code.ISnuviScheduler;
 
 public class SnuviScript 
 {
-    public static Console console;
-    
     public static void main(String[] args) 
     {
-        CodeParser.initCodeParser();
-        console = new Console();
-        
-        try
+        SnuviParser parser = new SnuviParser((SnuviException ex) -> 
         {
-            ScriptControl.startScriptFromFile("start"); 
-        }
-        catch(FileException ex)
+            System.out.println("Exception " + ex);
+            System.out.println(ex.getOriginalException());
+            System.out.println(ex.getCode());
+            System.out.println(ex.getLine());
+            System.out.println(ex.getScriptName());
+        }, new ISnuviScheduler() 
         {
-            ScriptUtils.printDebug("You haven't configured a start file yet.");
-        }
+            @Override
+            public void scheduleTask(Runnable r) 
+            {
+                System.out.println("Schedule");
+            }
+
+            @Override
+            public void scheduleTask(Runnable r, long delay) 
+            {
+                System.out.println("Schedule");
+            }
+        });
+        parser.registerConsumer("debug", (o, sc) -> System.out.println(o[0]));
         
-        /*for(String s : GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames())
-        {
-            System.out.println(s);
-        }*/
+        parser.startScript(Script.class, "test", 
+                "wusi = 5;\n" +
+                "@test;\n" +
+                "while(wusi < 10)\n" +
+                "{\n" +
+                "    wusi += 1;\n" +
+                "    debug(wusi);\n" +
+                "}\n" + 
+                "if( wusi > 100) { term();}" +
+                "debug(wusi); wusi += 5; goto(\"test\");", true);
     }   
 }

+ 0 - 6
todo.txt

@@ -1,6 +0,0 @@
-To-Do-List für SnuviScript:
-
-Hierfür am Besten beim einlesen gotoline einbauen:
-continue, break
-
-Kommentare mit // und /* + */, zu Beginn der Code-Generierung entfernen