Update jflex to 1.8.2
[scilab.git] / scilab / modules / helptools / src / java / jflex / java.jflex
1 //CHECKSTYLE:OFF
2
3 package org.scilab.modules.helptools.java;
4
5 import java.io.Reader;
6 import java.io.StringReader;
7 import java.io.IOException;
8
9 import org.scilab.modules.helptools.c.AbstractCCodeHandler;
10
11 @javax.annotation.Generated("JFlex"))
12 %%
13
14 %public
15 %class JavaLexer
16 %final
17 %unicode
18 %char
19 %type void
20 %pack
21
22 %{
23
24     private int whitesOnFirstLine;
25     private int saveLexState;
26     private AbstractCCodeHandler handler;
27
28     public JavaLexer() { }
29
30     private String trimEnd(String str) {
31         int end = str.length() - 1;
32         int i = end;
33         for (; i >= 0; i--) {
34            char c = str.charAt(i);
35            if (c != ' ' && c != '\t' && c != '\r' && c != '\n') {
36               break;
37            }
38         }
39         if (i != end) {
40            return str.substring(0, i + 1);
41         }
42
43         return str;
44     }
45
46     public String convert(AbstractCCodeHandler h, String code) {
47         Reader reader = new StringReader(trimEnd(code));
48         String str = convert(h, reader, true);
49         try {
50           reader.close();
51         } catch (IOException e) { }
52
53         return str;
54     }
55
56     public String convert(AbstractCCodeHandler h, Reader code, boolean ret) {
57         if (code == null) {
58            return null;
59         } else {
60            handler = h;
61            whitesOnFirstLine = 0;
62            yyreset(code);
63            yybegin(CLEANFIRST);
64            try {
65                yylex();
66            } catch (IOException e) {
67                return null;
68            }
69            if (ret) {
70                return h.toString();
71            }
72            return "";
73         }
74     }
75 %}
76
77 %x COMMENT, CLEAN, CLEANFIRST
78
79 /* main character classes */
80 eol = \r | \n | \r\n
81 white = [ \t\f]+
82
83 commentBeg = "/" "*"+
84 commentEnd = "*"+ "/"
85 comment = ([^\r\n*/] | "*"+ [^\r\n*/] | [^\r\n*]"/")*
86
87 oneLineComment = "//" [^\r\n]*
88
89 id = [a-zA-Z]([0-9a-zA-Z_])*
90
91 hex = [a-fA-F0-9]
92 is = (l|L)?
93 fs = [fFdD]?
94 digit = [0-9]
95 exp = [Ee] [+-]? {digit}+
96 number = 0 [xX] {hex}+ {is}? | "0"? {digit}+ {is}? | {digit}* "." {digit}+ {exp}? {fs}? | {digit}+ "." {digit}* {exp}? {fs}?
97
98 string = ("\"" ([^\r\n\\\"]* | "\\"[^\r\n])+ "\"") | ("'" "\\"? [^\r\n\t] "'")
99
100 keyword = "break" | "case" | "catch" | "class" | "const" | "continue" | "default" | "do" | "else" | "enum" | "extends" | "false" | "finally" | "for" | "goto" | "if" | "implements" | "import" | "interface" | "native" | "new" | "package" | "return" | "strictfp" | "super" | "switch" | "this" | "throw" | "throws" | "true" | "try" | "while"
101
102 type = [Bb]"oolean" | [Bb]"yte" | "char" | "Character" | "Class" | [Dd]"ouble" | [Ff]"loat" | "int" | "Integer" | [Ll]"ong" | "Object" | [Ss]"hort" | "String" | "StringBuffer" | "StringBuilder" | "Thread" | "void" | "Void"
103
104 exception = "ArithmeticException" | "ArrayIndexOutOfBoundsException" | "ClassCastException" | "ClassNotFoundException" | "CloneNotSupportedException" | "Exception" | "IllegalAccessException" | "IllegalArgumentException" | "IllegalStateException" | "IllegalThreadStateException" | "IndexOutOfBoundsException" | "InstantiationException" | "InterruptedException" | "NegativeArraySizeException" | "NoSuchFieldException" | "NoSuchMethodException" | "NullPointerException" | "NumberFormatException" | "RuntimeException" | "SecurityException" | "StringIndexOutOfBoundsException" | "UnsupportedOperationException"
105
106 modifier = "abstract" | "final" | "private" | "protected" | "public" | "static" | "transient" | "volatile"
107
108 openclose = [(){}\[\]]
109
110 operator = [!%&*+,-./:;<=>?~|\^] | ">>" | "<<" | ">>>"
111
112 %%
113
114 <CLEANFIRST> {
115   {white}*{eol}+                 { }
116
117   {white}                        {
118                                    whitesOnFirstLine = yylength();
119                                    yybegin(YYINITIAL);
120                                  }
121
122   .                              {
123                                    yypushback(1);
124                                    yybegin(YYINITIAL);
125                                  }
126 }
127
128 <CLEAN> {
129   {eol}+                         {
130                                    handler.handleNothing("\n");
131                                  }
132
133   {white}                        {
134                                    int len = yylength() - whitesOnFirstLine;
135                                    if (len > 0) {
136                                       yypushback(len);
137                                    }
138                                    yybegin(saveLexState);
139                                  }
140
141   .                              {
142                                    yypushback(1);
143                                    yybegin(saveLexState);
144                                  }
145 }
146
147 <YYINITIAL> {
148   {oneLineComment}               {
149                                    handler.handleComment(yytext());
150                                  }
151
152   {commentBeg}                   {
153                                    yybegin(COMMENT);
154                                    handler.handleComment(yytext());
155                                  }
156
157   {string}                       {
158                                    handler.handleString(yytext());
159                                  }
160
161   {number}                       {
162                                    handler.handleNumber(yytext());
163                                  }
164
165   {keyword}                      {
166                                    handler.handleKeyword(yytext());
167                                  }
168
169   {type}                         |
170   {exception}                    {
171                                    handler.handleType(yytext());
172                                  }
173
174   {modifier}                     {
175                                    handler.handleModifier(yytext());
176                                  }
177
178   {openclose}                    {
179                                    handler.handleOpenClose(yytext());
180                                  }
181
182   {operator}                     {
183                                    handler.handleOperator(yytext());
184                                  }
185
186   {id}                           {
187                                    handler.handleId(yytext());
188                                  }
189
190   .                              {
191                                    handler.handleDefault(yytext());
192                                  }
193
194   {eol}                          {
195                                    handler.handleNothing("\n");
196                                    saveLexState = YYINITIAL;
197                                    yybegin(CLEAN);
198                                  }
199 }
200
201 <COMMENT> {
202   {commentEnd}                   {
203                                    yybegin(YYINITIAL);
204                                    handler.handleComment(yytext());
205                                  }
206
207   {comment}                      {
208                                    handler.handleComment(yytext());
209                                  }
210
211   "*"{eol}                       {
212                                    handler.handleComment("*");
213                                    handler.handleNothing("\n");
214                                    saveLexState = COMMENT;
215                                    yybegin(CLEAN);
216                                  }
217
218   {eol}                          {
219                                    handler.handleNothing("\n");
220                                    saveLexState = COMMENT;
221                                    yybegin(CLEAN);
222                                  }
223 }
224
225 <<EOF>>                          {
226                                    return;
227                                  }