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
34 public int beginString;
35 public static Set<String> commands = new HashSet<String>();
36 public static Set<String> macros = new HashSet<String>();
37 public static Set<String> variables = new HashSet<String>();
38 public Set<String> infile;
40 private ScilabDocument doc;
41 private boolean transposable;
43 private boolean breakstring;
45 public ScilabLexer(ScilabDocument doc) {
47 this.elem = doc.getDefaultRootElement();
48 this.infile = doc.getFunctionsInDoc();
52 public static void update() {
53 if (ScilabCommonsUtils.isScilabThread()) {
54 String[] vars = ScilabKeywords.GetVariablesName();
55 String[] funs = ScilabKeywords.GetFunctionsName();
56 String[] macs = ScilabKeywords.GetMacrosName();
61 variables.addAll(Arrays.asList(vars));
64 commands.addAll(Arrays.asList(funs));
67 macros.addAll(Arrays.asList(macs));
72 public void setRange(int p0, int p1) {
77 yyreset(new ScilabDocumentReader(doc, p0, p1));
78 int currentLine = elem.getElementIndex(start);
79 if (currentLine != 0 && ((ScilabDocument.ScilabLeafElement) elem.getElement(currentLine - 1)).isBrokenString()) {
88 public int scan() throws IOException {
90 if (start + yychar + yylength() == end - 1) {
91 ((ScilabDocument.ScilabLeafElement) elem.getElement(elem.getElementIndex(start))).setBrokenString(breakstring);
97 public int getKeyword(int pos, boolean strict) {
98 Element line = elem.getElement(elem.getElementIndex(pos));
99 int end = line.getEndOffset();
101 start = line.getStartOffset();
106 yyreset(new ScilabDocumentReader(doc, start, end));
111 while (startL < pos && (s != startL || yystate() == BREAKSTRING)) {
114 startL = start + yychar + yylength();
118 } catch (IOException e) {
119 return ScilabLexerConstants.DEFAULT;
123 public static ScilabTokens getScilabTokens(String str) {
124 ScilabDocument doc = new ScilabDocument(false);
126 doc.insertString(0, str, null);
127 } catch (BadLocationException e) { }
128 return getScilabTokens(doc);
131 public static ScilabTokens getScilabTokens(ScilabDocument doc) {
132 ScilabLexer lexer = new ScilabLexer(doc);
133 lexer.yyreset(new ScilabDocumentReader(doc, 0, doc.getLength()));
134 ScilabTokens tokens = new ScilabTokens();
137 while (tok != ScilabLexerConstants.EOF) {
139 tokens.add(tok, lexer.yychar + lexer.yylength());
141 } catch (IOException e) { }
146 public static class ScilabTokens {
147 private List<Integer> tokenType = new ArrayList<Integer>();
148 private List<Integer> tokenPos = new ArrayList<Integer>();
152 void add(final int type, final int pos) {
157 public final List<Integer> getTokenType() {
161 public final List<Integer> getTokenPos() {
167 /* main character classes */
170 open = "[" | "(" | "{"
171 close = "]" | ")" | "}"
179 cstes = "%t" | "%T" | "%f" | "%F" | "%e" | "%pi" | "%inf" | "%i" | "%z" | "%s" | "%nan" | "%eps" | "SCI" | "WSCI" | "SCIHOME" | "TMPDIR"
181 operator = ".'" | ".*" | "./" | ".\\" | ".^" | ".**" | "+" | "-" | "/" | "\\" | "*" | "^" | "**" | "==" | "~=" | "<>" | "<" | ">" | "<=" | ">=" | ".*." | "./." | ".\\." | "/." | "=" | "&" | "|" | "@" | "@=" | "~"
183 functionKwds = "function" | "endfunction"
185 structureKwds = "then" | "do" | "catch" | "case"
187 elseif = "elseif" | "else"
189 openCloseStructureKwds = "if" | "for" | "while" | "try" | "select" | "end"
191 controlKwds = "abort" | "break" | "quit" | "return" | "resume" | "pause" | "continue" | "exit"
193 authors = "Calixte Denizet" | "Calixte DENIZET" | "Sylvestre Ledru" | "Sylvestre LEDRU" | "Yann Collette" | "Yann COLLETTE" | "Allan Cornet" | "Allan CORNET" | "Antoine Elias" | "Antoine ELIAS" | "Bruno Jofret" | "Bruno JOFRET" | "Claude Gomez" | "Claude GOMEZ" | "Clement David" | "Clement DAVID" | "Manuel Juliachs" | "Manuel JULIACHS" | "Michael Baudin" | "Michael BAUDIN" | "Pierre Lando" | "Pierre LANDO" | "Pierre Marechal" | "Pierre MARECHAL" | "Sheldon Cooper" | "Leonard Hofstadter" | "Serge Steer" | "Serge STEER" | "Vincent Couvert" | "Vincent COUVERT" | "Vincent Liard" | "Vincent LIARD" | "Adeline Carnis" | "Adeline CARNIS" | "Simon Gareste" | "Simon GARESTE" | "Cedric Delamarre" | "Cedric DELAMARRE" | "Inria" | "INRIA" | "DIGITEO" | "Digiteo" | "Scilab Enterprises" | "ENPC"
195 error = "Scilab Entreprises" | "Scilab Entreprise" | "Scilab Enterprise"
198 breakinstring = {break}[ \t]*({comment} | {eol})
200 special = "$" | ":" | {break}
202 string = (([^ \t\'\"\r\n\.]*)|([\'\"]{2}))+
204 id = ([a-zA-Z%_#!?][a-zA-Z0-9_#!$?]*)|("$"[a-zA-Z0-9_#!$?]+)
206 badid = ([0-9$][a-zA-Z0-9_#!$?]+)
207 whitabs = (" "+"\t" | "\t"+" ")[ \t]*
208 badop = [+-]([\*\/\\\^] | "."[\*\+\-\/\\\^]) | ":=" | "->" | " !=" | "&&" | "||" | ([*+-/\\\^]"=")
212 url = "http://"[^ \t\f\n\r\'\"]+
213 mail = "<"[ \t]*[a-zA-Z0-9_\.\-]+"@"([a-zA-Z0-9\-]+".")+[a-zA-Z]{2,5}[ \t]*">"
215 latex = "$"(([^$]*|"\\$")+)"$"
216 latexinstring = (\"|\')"$"(([^$\'\"]*|"\\$"|([\'\"]{2}))+)"$"(\"|\')
219 exp = [dDeE][+-]?{digit}*
220 number = ({digit}+"."?{digit}*{exp}?)|("."{digit}+{exp}?)
222 %x QSTRING, COMMENT, FIELD, COMMANDS, COMMANDSWHITE, BREAKSTRING
228 transposable = false;
234 transposable = false;
235 return ScilabLexerConstants.OPERATOR;
239 transposable = false;
240 return ScilabLexerConstants.FKEYWORD;
243 {openCloseStructureKwds} {
244 transposable = false;
245 return ScilabLexerConstants.OSKEYWORD;
249 transposable = false;
250 return ScilabLexerConstants.SKEYWORD;
254 transposable = false;
255 return ScilabLexerConstants.ELSEIF;
259 transposable = false;
260 return ScilabLexerConstants.CKEYWORD;
265 return ScilabLexerConstants.CONSTANTES;
270 String str = yytext();
271 if (commands.contains(str)) {
273 return ScilabLexerConstants.COMMANDS;
274 } else if (macros.contains(str)) {
276 return ScilabLexerConstants.MACROS;
277 } else if (infile.contains(str)) {
279 return ScilabLexerConstants.MACROINFILE;
281 List<String>[] arr = doc.getInOutArgs(start + yychar);
282 if (arr != null && (arr[0].contains(str) || arr[1].contains(str))) {
283 return ScilabLexerConstants.INPUTOUTPUTARGS;
284 } else if (variables.contains(str)) {
285 return ScilabLexerConstants.VARIABLES;
288 return ScilabLexerConstants.ID;
293 return ScilabLexerConstants.NUMBER;
297 transposable = false;
298 return ScilabLexerConstants.SPECIAL;
302 transposable = false;
304 return ScilabLexerConstants.OPERATOR;
308 return ScilabLexerConstants.LATEXINSTRING;
313 return ScilabLexerConstants.TRANSP;
315 beginString = zzStartRead;
317 return ScilabLexerConstants.STRING;
322 transposable = false;
323 return ScilabLexerConstants.OPENCLOSE;
328 return ScilabLexerConstants.OPENCLOSE;
332 transposable = false;
333 beginString = zzStartRead;
335 return ScilabLexerConstants.STRING;
341 return ScilabLexerConstants.ERROR;
345 transposable = false;
346 return ScilabLexerConstants.WHITE;
350 transposable = false;
351 return ScilabLexerConstants.TAB;
356 transposable = false;
357 return ScilabLexerConstants.DEFAULT;
363 yypushback(yylength());
368 yybegin(COMMANDSWHITE);
369 return ScilabLexerConstants.WHITE;
373 yybegin(COMMANDSWHITE);
374 return ScilabLexerConstants.TAB;
387 transposable = false;
392 ([^ \t,;/]*) | ("/"[^ /]*) {
393 return ScilabLexerConstants.STRING;
397 return ScilabLexerConstants.WHITE;
401 return ScilabLexerConstants.TAB;
414 return ScilabLexerConstants.FIELD;
426 yypushback(yylength());
427 yybegin(BREAKSTRING);
428 transposable = false;
429 return ScilabLexerConstants.STRING;
433 return ScilabLexerConstants.WHITE_STRING;
437 return ScilabLexerConstants.TAB_STRING;
442 return ScilabLexerConstants.STRING;
446 transposable = false;
448 return ScilabLexerConstants.STRING;
453 return ScilabLexerConstants.DEFAULT;
459 return ScilabLexerConstants.ERROR;
464 return ScilabLexerConstants.AUTHORS;
468 return ScilabLexerConstants.URL;
472 return ScilabLexerConstants.MAIL;
476 return ScilabLexerConstants.LATEX;
480 return ScilabLexerConstants.WHITE_COMMENT;
484 return ScilabLexerConstants.TAB_COMMENT;
488 return ScilabLexerConstants.COMMENT;
493 return ScilabLexerConstants.DEFAULT;
500 return ScilabLexerConstants.SPECIAL;
504 return ScilabLexerConstants.WHITE;
508 return ScilabLexerConstants.TAB;
512 transposable = false;
519 return ScilabLexerConstants.DEFAULT;
524 return ScilabLexerConstants.EOF;