3 package org.scilab.modules.scinotes;
5 import java.util.Arrays;
6 import java.util.HashSet;
7 import java.util.Iterator;
8 import java.util.ArrayList;
11 import java.io.IOException;
12 import javax.swing.text.BadLocationException;
13 import javax.swing.text.Element;
15 import org.scilab.modules.commons.ScilabCommonsUtils;
17 @javax.annotation.Generated("JFlex")
18 @SuppressWarnings("fallthrough")
24 %extends ScilabLexerConstants
35 public int beginString;
36 public static Set<String> commands = new HashSet<String>();
37 public static Set<String> macros = new HashSet<String>();
38 public static Set<String> variables = new HashSet<String>();
39 public Set<String> infile;
41 private ScilabDocument doc;
42 private boolean transposable;
44 private boolean breakstring;
46 public ScilabLexer(ScilabDocument doc) {
50 public ScilabLexer(ScilabDocument doc, boolean update) {
52 this.elem = doc.getDefaultRootElement();
53 this.infile = doc.getFunctionsInDoc();
59 public static void update() {
60 if (ScilabCommonsUtils.isScilabThread()) {
61 String[] vars = ScilabKeywords.GetVariablesName();
62 String[] funs = ScilabKeywords.GetFunctionsName();
63 String[] macs = ScilabKeywords.GetMacrosName();
68 variables.addAll(Arrays.asList(vars));
71 commands.addAll(Arrays.asList(funs));
74 macros.addAll(Arrays.asList(macs));
79 public void setRange(int p0, int p1) {
84 yyreset(new ScilabDocumentReader(doc, p0, p1));
85 int currentLine = elem.getElementIndex(start);
86 if (currentLine != 0 && ((ScilabDocument.ScilabLeafElement) elem.getElement(currentLine - 1)).isBrokenString()) {
95 public int scan() throws IOException {
97 if (start + yychar + yylength() == end - 1) {
98 ((ScilabDocument.ScilabLeafElement) elem.getElement(elem.getElementIndex(start))).setBrokenString(breakstring);
104 public int getKeyword(int pos, boolean strict) {
105 Element line = elem.getElement(elem.getElementIndex(pos));
106 int end = line.getEndOffset();
108 start = line.getStartOffset();
113 yyreset(new ScilabDocumentReader(doc, start, end));
118 while (startL < pos && (s != startL || yystate() == BREAKSTRING)) {
121 startL = start + yychar + yylength();
125 } catch (IOException e) {
126 return ScilabLexerConstants.DEFAULT;
130 public static ScilabTokens getScilabTokens(String str) {
131 ScilabDocument doc = new ScilabDocument(false);
133 doc.insertString(0, str, null);
134 } catch (BadLocationException e) { }
135 return getScilabTokens(doc);
138 public static ScilabTokens getScilabTokens(ScilabDocument doc) {
139 ScilabLexer lexer = new ScilabLexer(doc);
140 lexer.yyreset(new ScilabDocumentReader(doc, 0, doc.getLength()));
141 ScilabTokens tokens = new ScilabTokens();
144 while (tok != ScilabLexerConstants.EOF) {
146 tokens.add(tok, lexer.yychar + lexer.yylength());
148 } catch (IOException e) { }
153 public static class ScilabTokens {
154 private List<Integer> tokenType = new ArrayList<Integer>();
155 private List<Integer> tokenPos = new ArrayList<Integer>();
159 void add(final int type, final int pos) {
164 public final List<Integer> getTokenType() {
168 public final List<Integer> getTokenPos() {
174 /* main character classes */
177 open = "[" | "(" | "{"
178 close = "]" | ")" | "}"
186 cstes = "%t" | "%T" | "%f" | "%F" | "%e" | "%pi" | "%inf" | "%i" | "%z" | "%s" | "%nan" | "%eps" | "SCI" | "WSCI" | "SCIHOME" | "TMPDIR"
188 operator = ".'" | ".*" | "./" | ".\\" | ".^" | ".**" | "+" | "-" | "/" | "\\" | "*" | "^" | "**" | "==" | "~=" | "<>" | "<" | ">" | "<=" | ">=" | ".*." | "./." | ".\\." | "/." | "=" | "&" | "|" | "@" | "@=" | "~"
190 functionKwds = "function" | "endfunction"
192 structureKwds = "then" | "do" | "catch" | "case"
194 elseif = "elseif" | "else"
196 openCloseStructureKwds = "if" | "for" | "while" | "try" | "select" | "end"
198 controlKwds = "abort" | "break" | "quit" | "return" | "resume" | "pause" | "continue" | "exit"
200 authors = "Calixte Denizet" | "Calixte DENIZET" | "Sylvestre Ledru" | "Sylvestre LEDRU" | "Antoine Elias" | "Antoine ELIAS" | "Bruno Jofret" | "Bruno JOFRET" | "Claude Gomez" | "Claude GOMEZ" | "Clement David" | "Clement DAVID" | "Manuel Juliachs" | "Manuel JULIACHS" | "Sheldon Cooper" | "Leonard Hofstadter" | "Serge Steer" | "Serge STEER" | "Vincent Couvert" | "Vincent COUVERT" | "Adeline Carnis" | "Adeline CARNIS" | "Charlotte Hecquet" | "Charlotte HECQUET" | "Paul Bignier" | "Paul BIGNIER" | "Alexandre Herisse" | "Alexandre HERISSE" | "Simon Marchetto" | "Simon MARCHETTO" | "Vladislav Trubkin" | "Vladislav TRUBKIN" | "Cedric Delamarre" | "Cedric DELAMARRE" | "Inria" | "INRIA" | "DIGITEO" | "Digiteo" | "Scilab Enterprises" | "ENPC"
202 error = "Scilab Entreprises" | "Scilab Entreprise" | "Scilab Enterprise"
203 todo = ("TODO" | "todo" | "Todo")[ \t:]+[^\n]*
206 breakinstring = {break}[ \t]*({comment} | {eol})
208 special = "$" | ":" | {break}
210 string = (([^ \t\'\"\r\n\.]*)|([\'\"]{2}))+
212 id = ([a-zA-Z%_#!?][a-zA-Z0-9_#!$?]*)|("$"[a-zA-Z0-9_#!$?]+)
214 badid = ([0-9$][a-zA-Z0-9_#!$?]+)
215 whitabs = (" "+"\t" | "\t"+" ")[ \t]*
216 badop = [+-]([\*\/\\\^] | "."[\*\+\-\/\\\^]) | ":=" | "->" | " !=" | "&&" | "||" | ([*+-/\\\^]"=")
220 url = ("http://"|"https://"|"ftp://"|"dav://"|"davs://"|"sftp://"|"ftps://"|"smb:///"|"file://")[^ \t\f\n\r\'\"]+
221 mailaddr = [ \t]*[a-zA-Z0-9_\.\-]+"@"([a-zA-Z0-9\-]+".")+[a-zA-Z]{2,5}[ \t]*
222 mail = ("<" {mailaddr} ">") | ("mailto:" {mailaddr})
224 latex = "$$"(([^$]*|"\\$")+)"$$"
225 latexinstring = (\"|\')"$"(([^$\'\"]*|"\\$"|([\'\"]{2}))+)"$"(\"|\')
228 exp = [dDeE][+-]?{digit}*
229 number = ({digit}+"."?{digit}*{exp}?)|("."{digit}+{exp}?)
231 %x QSTRING, COMMENT, FIELD, COMMANDS, COMMANDSWHITE, BREAKSTRING
237 transposable = false;
243 transposable = false;
244 return ScilabLexerConstants.OPERATOR;
248 transposable = false;
249 return ScilabLexerConstants.FKEYWORD;
252 {openCloseStructureKwds} {
253 transposable = false;
254 return ScilabLexerConstants.OSKEYWORD;
258 transposable = false;
259 return ScilabLexerConstants.SKEYWORD;
263 transposable = false;
264 return ScilabLexerConstants.ELSEIF;
268 transposable = false;
269 return ScilabLexerConstants.CKEYWORD;
274 return ScilabLexerConstants.CONSTANTES;
279 String str = yytext();
280 if (commands.contains(str)) {
282 return ScilabLexerConstants.COMMANDS;
283 } else if (macros.contains(str)) {
285 return ScilabLexerConstants.MACROS;
286 } else if (infile.contains(str)) {
288 return ScilabLexerConstants.MACROINFILE;
290 List<String>[] arr = doc.getInOutArgs(start + yychar);
291 if (arr != null && (arr[0].contains(str) || arr[1].contains(str))) {
292 return ScilabLexerConstants.INPUTOUTPUTARGS;
293 } else if (variables.contains(str)) {
294 return ScilabLexerConstants.VARIABLES;
297 return ScilabLexerConstants.ID;
302 return ScilabLexerConstants.NUMBER;
306 transposable = false;
307 return ScilabLexerConstants.SPECIAL;
311 transposable = false;
313 return ScilabLexerConstants.OPERATOR;
317 return ScilabLexerConstants.LATEXINSTRING;
322 return ScilabLexerConstants.TRANSP;
324 beginString = zzStartRead;
326 return ScilabLexerConstants.STRING;
331 transposable = false;
332 return ScilabLexerConstants.OPENCLOSE;
337 return ScilabLexerConstants.OPENCLOSE;
341 transposable = false;
342 beginString = zzStartRead;
344 return ScilabLexerConstants.STRING;
350 return ScilabLexerConstants.ERROR;
354 transposable = false;
355 return ScilabLexerConstants.WHITE;
359 transposable = false;
360 return ScilabLexerConstants.TAB;
365 transposable = false;
366 return ScilabLexerConstants.DEFAULT;
372 yypushback(yylength());
377 yybegin(COMMANDSWHITE);
378 return ScilabLexerConstants.WHITE;
382 yybegin(COMMANDSWHITE);
383 return ScilabLexerConstants.TAB;
396 transposable = false;
401 ([^ \t,;/]*) | ("/"[^ /]*) {
402 return ScilabLexerConstants.STRING;
406 return ScilabLexerConstants.WHITE;
410 return ScilabLexerConstants.TAB;
423 return ScilabLexerConstants.FIELD;
435 yypushback(yylength());
436 yybegin(BREAKSTRING);
437 transposable = false;
438 return ScilabLexerConstants.STRING;
442 return ScilabLexerConstants.WHITE_STRING;
446 return ScilabLexerConstants.TAB_STRING;
451 return ScilabLexerConstants.STRING;
455 transposable = false;
457 return ScilabLexerConstants.STRING;
462 return ScilabLexerConstants.DEFAULT;
468 return ScilabLexerConstants.TODO;
472 return ScilabLexerConstants.ERROR;
477 return ScilabLexerConstants.AUTHORS;
481 return ScilabLexerConstants.URL;
485 return ScilabLexerConstants.MAIL;
489 return ScilabLexerConstants.LATEX;
493 return ScilabLexerConstants.WHITE_COMMENT;
497 return ScilabLexerConstants.TAB_COMMENT;
501 return ScilabLexerConstants.COMMENT;
506 return ScilabLexerConstants.DEFAULT;
513 return ScilabLexerConstants.SPECIAL;
517 return ScilabLexerConstants.WHITE;
521 return ScilabLexerConstants.TAB;
525 transposable = false;
532 return ScilabLexerConstants.DEFAULT;
537 return ScilabLexerConstants.EOF;