* Disable the warning caused by jflex code
[scilab.git] / scilab / modules / scinotes / src / java / jflex / function.jflex
1 //CHECKSTYLE:OFF
2
3 package org.scilab.modules.scinotes;
4
5 import java.io.IOException;
6 import java.util.List;
7 import java.util.ArrayList;
8 import javax.swing.text.Element;
9
10 @javax.annotation.Generated("JFlex")
11 @SuppressWarnings("fallthrough")
12 %%
13
14 %public
15 %class FunctionScanner
16 %final
17 %unicode
18 %char
19 %type int
20
21 %switch
22
23 %{
24     List<String> returnValues;
25     List<String> argsValues;
26     String functionName;
27     int end;
28
29     private ScilabDocument doc;
30     private String id;
31
32     public FunctionScanner(ScilabDocument doc) {
33         this.doc = doc;
34         returnValues = new ArrayList();
35         argsValues = new ArrayList();
36     }
37
38     public String getFunctionName() {
39         return functionName;
40     }
41
42     public List<String> getReturnValues() {
43         return returnValues;
44     }
45
46     public List<String> getArgsValues() {
47         return argsValues;
48     }
49
50     public int getLineType(int p0, int p1) {
51         try {
52             returnValues = new ArrayList();
53             argsValues = new ArrayList();
54             end = p1;
55             yyreset(new ScilabDocumentReader(doc, p0, p1));
56             yybegin(BROKEN);
57             int broken = yylex();
58
59             yyreset(new ScilabDocumentReader(doc, p0, p1));
60             while (true) {
61                 int ret = yylex();
62                 if (ret != ScilabDocument.ScilabLeafElement.BROKEN) {
63                    return ret | broken;
64                 }
65                 Element elem = doc.getDefaultRootElement();
66                 int start = end + 1;
67                 elem = elem.getElement(elem.getElementIndex(end + 1));
68                 end = elem.getEndOffset();
69                 yyreset(new ScilabDocumentReader(doc, elem.getStartOffset(), end));
70                 yybegin(ARGS);
71             }
72         } catch (IOException e) {
73             return ScilabDocument.ScilabLeafElement.NOTHING;
74         }
75     }
76
77     public FunctionInfo getFunctionInfo() {
78         return new FunctionInfo(functionName, returnValues, argsValues);
79     }
80
81     public class FunctionInfo {
82         public String functionName;
83         public List<String> returnValues;
84         public List<String> argsValues;
85
86         public FunctionInfo(String name, List ret, List args) {
87             this.functionName = name;
88             this.returnValues = ret;
89             this.argsValues = args;
90         }
91     }
92 %}
93
94 %eofval{
95   return ScilabDocument.ScilabLeafElement.NOTHING;
96 %eofval}
97
98 /* main character classes */
99 white = [ \t]+
100 eol = \n
101
102 comments = {white}*("//".*)?{eol}
103 break = ".."(".")*{comments}
104
105 brokenline = ([^\.]* | ([^\.]*"."[^\.]+)+){break}
106
107 id = [a-zA-Z%_#!$?][a-zA-Z0-9_#!$?]*
108 spec = [^a-zA-Z0-9_#!$?]?
109
110 equal = {white}* "=" {white}*
111
112 rpar = ")"{comments}
113
114 fun = {white}* "function" {white}
115 funb = {white}* "function["
116 endfun = {white}* "endfunction" {spec}
117
118 %x FUNCTION, TYPEID, FUNNAME, RETS, ARGS, BROKEN
119
120 %%
121
122 <YYINITIAL> {
123   {funb}                         {
124                                    yybegin(RETS);
125                                  }
126
127   {fun}                          {
128                                    yybegin(FUNCTION);
129                                  }
130
131   {endfun}                       {
132                                    return ScilabDocument.ScilabLeafElement.ENDFUN;
133                                  }
134
135   .                              |
136   {eol}                          {
137                                    return ScilabDocument.ScilabLeafElement.NOTHING;
138                                  }
139 }
140
141 <BROKEN> {
142   {brokenline}                   {
143                                    return ScilabDocument.ScilabLeafElement.BROKEN;
144                                  }
145
146   .                              |
147   {eol}                          {
148                                    return 0;
149                                  }
150 }
151
152 <FUNCTION> {
153   "["                            {
154                                    yybegin(RETS);
155                                  }
156
157   {id}                           {
158                                    id = yytext();
159                                    yybegin(TYPEID);
160                                  }
161
162   .                              |
163   {eol}                          {
164                                    return ScilabDocument.ScilabLeafElement.NOTHING;
165                                  }
166 }
167
168 <TYPEID> {
169   {equal}                        {
170                                    returnValues.add(id);
171                                    yybegin(FUNNAME);
172                                  }
173
174   "("                            {
175                                    functionName = id;
176                                    yybegin(ARGS);
177                                  }
178
179   {white}                        { }
180
181   {comments}                     {
182                                    functionName = id;
183                                    return ScilabDocument.ScilabLeafElement.FUN;
184                                  }
185
186   .                              {
187                                    return ScilabDocument.ScilabLeafElement.NOTHING;
188                                  }
189 }
190
191 <FUNNAME> {
192   {id}                           {
193                                    functionName = yytext();
194                                  }
195
196   [ \t]*"("                      {
197                                    yybegin(ARGS);
198                                  }
199
200   {comments}                     {
201                                    return ScilabDocument.ScilabLeafElement.FUN;
202                                  }
203
204   .                              {
205                                    return ScilabDocument.ScilabLeafElement.NOTHING;
206                                  }
207 }
208
209 <RETS> {
210   {id}                           {
211                                    returnValues.add(yytext());
212                                  }
213
214   ","                            |
215   {white}                        { }
216
217   "]"{equal}                     {
218                                    yybegin(FUNNAME);
219                                  }
220
221   .                              |
222   {eol}                          {
223                                    return ScilabDocument.ScilabLeafElement.NOTHING;
224                                  }
225 }
226
227 <ARGS> {
228   {id}                           {
229                                    argsValues.add(yytext());
230                                  }
231
232   ","                            |
233   {white}                        { }
234
235   {break}                        {
236                                    return ScilabDocument.ScilabLeafElement.BROKEN;
237                                  }
238
239   {rpar}                         {
240                                    return ScilabDocument.ScilabLeafElement.FUN;
241                                  }
242
243   .                              |
244   {eol}                          {
245                                    return ScilabDocument.ScilabLeafElement.NOTHING;
246                                  }
247 }