Update jflex to 1.8.2
[scilab.git] / scilab / modules / scinotes / src / java / jflex / function.jflex
index ed0490a..46b1668 100644 (file)
@@ -5,10 +5,10 @@ package org.scilab.modules.scinotes;
 import java.io.IOException;
 import java.util.List;
 import java.util.ArrayList;
+import javax.swing.text.BadLocationException;
 import javax.swing.text.Element;
 
 @javax.annotation.Generated("JFlex")
-@SuppressWarnings("fallthrough")
 %%
 
 %public
@@ -18,21 +18,26 @@ import javax.swing.text.Element;
 %char
 %type int
 
-%switch
-
 %{
     List<String> returnValues;
     List<String> argsValues;
     String functionName;
     int end;
+    int start;
 
     private ScilabDocument doc;
     private String id;
+    private MatchingBlockScanner matchBlock;
 
     public FunctionScanner(ScilabDocument doc) {
         this.doc = doc;
         returnValues = new ArrayList();
         argsValues = new ArrayList();
+       this.matchBlock = new MatchingBlockScanner(doc);
+    }
+
+    public int yychar() {
+        return (int) yychar;
     }
 
     public String getFunctionName() {
@@ -51,6 +56,7 @@ import javax.swing.text.Element;
         try {
             returnValues = new ArrayList();
             argsValues = new ArrayList();
+           start = p0;
             end = p1;
             yyreset(new ScilabDocumentReader(doc, p0, p1));
             yybegin(BROKEN);
@@ -63,7 +69,6 @@ import javax.swing.text.Element;
                    return ret | broken;
                 }
                 Element elem = doc.getDefaultRootElement();
-                int start = end + 1;
                 elem = elem.getElement(elem.getElementIndex(end + 1));
                 end = elem.getEndOffset();
                 yyreset(new ScilabDocumentReader(doc, elem.getStartOffset(), end));
@@ -99,21 +104,22 @@ import javax.swing.text.Element;
 white = [ \t]+
 eol = \n
 
-comments = ("//".*)?{eol}
-break = ".."(".")*{white}*{comments}
+comments = {white}*("//".*)?{eol}
+break = ".."(".")*{comments}
 
 brokenline = ([^\.]* | ([^\.]*"."[^\.]+)+){break}
 
 id = [a-zA-Z%_#!$?][a-zA-Z0-9_#!$?]*
-spec = [^a-zA-Z0-9_#!$?]
+spec = [^a-zA-Z0-9_#!$?]?
 
 equal = {white}* "=" {white}*
 
-rpar = ")"[,; \t]*{comments}
+rpar = ")"{comments}
 
 fun = {white}* "function" {white}
 funb = {white}* "function["
 endfun = {white}* "endfunction" {spec}
+end = "end"
 
 %x FUNCTION, TYPEID, FUNNAME, RETS, ARGS, BROKEN
 
@@ -129,7 +135,19 @@ endfun = {white}* "endfunction" {spec}
                                  }
 
   {endfun}                       {
-                                   return ScilabDocument.ScilabLeafElement.ENDFUN;
+                                  return ScilabDocument.ScilabLeafElement.ENDFUN;
+                                }
+
+  {end}                                 {
+                                  MatchingBlockScanner.MatchingPositions pos = matchBlock.getMatchingBlock(start + yychar() + yylength(), false);
+                                  if (pos != null) {
+                                     try {
+                                        String match = doc.getText(pos.secondB, pos.secondE - pos.secondB);
+                                        if (match.equals("function")) {
+                                           return ScilabDocument.ScilabLeafElement.ENDFUN;
+                                        }
+                                     } catch (BadLocationException e) { }
+                                  }
                                  }
 
   .                              |