]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/parser/SCLPostLexer.java
Merge branch 'feature/funcwrite'
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / internal / parsing / parser / SCLPostLexer.java
index 3d3b7b2f512033d90e13119b8edbfa8960cbaafd..9cc1ff27b16a288afb11f138b9d8755a84f642d0 100644 (file)
@@ -37,6 +37,7 @@ public class SCLPostLexer {
         NO_SEMICOLON_BEFORE.add(SCLTerminals.EOF);
         NO_SEMICOLON_BEFORE.add(SCLTerminals.SYMBOL);
         NO_SEMICOLON_BEFORE.add(SCLTerminals.THEN);
+        NO_SEMICOLON_BEFORE.add(SCLTerminals.ELSE);
         NO_SEMICOLON_BEFORE.add(SCLTerminals.IN);
         NO_SEMICOLON_BEFORE.add(SCLTerminals.RBRACE);
         NO_SEMICOLON_BEFORE.add(SCLTerminals.RBRACKET);
@@ -56,6 +57,7 @@ public class SCLPostLexer {
     int lineStart = 0;
     boolean firstTokenOfLine = true;
     private SCLParserOptions options;
+    private boolean isFirstToken = true;
             
     {
         indentations.add(0);
@@ -145,11 +147,18 @@ public class SCLPostLexer {
                         int loc = Locations.endOf(prevToken.location);
                         push(new Token(SCLTerminals.RBRACE, loc, loc, "implicit }"));
                     }
-                    if(indentations.get(indentations.size()-1) == level && symbolId != SCLTerminals.ELSE)
+                    if(indentations.get(indentations.size()-1) == level)
                         push(new Token(SCLTerminals.SEMICOLON, symbolStart, symbolStart, "implicit ;"));
                 }
             }
             firstTokenOfLine = false;
+            if(isFirstToken) {
+                isFirstToken = false;
+                if(symbol.id == SCLTerminals.ID && symbol.text.equals("module") && options != null && options.isModule) {
+                    push(new Token(SCLTerminals.MODULE, symbol.location, symbol.text));
+                    return;
+                }
+            }
         }
         
         switch(symbolId) {
@@ -165,8 +174,8 @@ public class SCLPostLexer {
             return;
         case SCLTerminals.THEN:
             /*for(int tt : indentationTokens.toArray())
-                System.out.print(SCLParser.TERMINAL_NAMES[tt] + " ");
-            System.out.println();*/
+                    System.out.print(SCLParser.TERMINAL_NAMES[tt] + " ");
+                System.out.println();*/
             if(prevTokenId == SCLTerminals.COMMA) {
                 // for list comprehension syntax
                 push(symbol);
@@ -175,7 +184,7 @@ public class SCLPostLexer {
         case SCLTerminals.RBRACE:
         case SCLTerminals.RPAREN:
         case SCLTerminals.RBRACKET:
-        //case SCLTerminals.ELSE:
+        case SCLTerminals.ELSE:
         case SCLTerminals.IN:
             int removedToken = SCLTerminals.EOF;
             while(!indentations.isEmpty()) {
@@ -188,11 +197,15 @@ public class SCLPostLexer {
             }
             if(indentations.isEmpty())
                 throw error(symbolStart, symbolEnd, "No corresponding opening parenthesis for '" + symbol.text + "'.");
-            if(symbolId == SCLTerminals.THEN && removedToken == SCLTerminals.WHEN)
-                curToken = symbol = new Token(SCLTerminals.THEN_AFTER_WHEN, symbol.location, symbol.text);
+            if(symbolId == SCLTerminals.THEN) {
+                if(removedToken == SCLTerminals.WHEN)
+                    curToken = symbol = new Token(SCLTerminals.THEN_AFTER_WHEN, symbol.location, symbol.text);
+                else {
+                    indentations.add(-1);
+                    indentationTokens.add(SCLTerminals.THEN);
+                }
+            }   
             push(symbol);
-            //if(symbolId == SCLTerminals.THEN)
-            //    indentations.add(-1);
             return;
         case SCLTerminals.EOF:
             while(indentations.size() > 1 && indentations.get(indentations.size()-1) >= 0) {