package org.scilab.modules.scinotes;
+import java.io.IOException;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
-import java.util.Iterator;
-import java.util.ArrayList;
import java.util.List;
import java.util.Set;
-import java.io.IOException;
import javax.swing.text.BadLocationException;
import javax.swing.text.Element;
-
import org.scilab.modules.commons.ScilabCommonsUtils;
@javax.annotation.Generated("JFlex")
-@SuppressWarnings("fallthrough")
%%
%unicode
%char
%type int
-%switch
+%pack
%{
public int start;
private boolean transposable;
private Element elem;
private boolean breakstring;
+ private boolean breakcomment;
+ private MatchingBlockScanner matchBlock;
+
+ static {
+ // For SciNotes colors in preferences
+ commands.add("cos");
+ macros.add("sind");
+ }
public ScilabLexer(ScilabDocument doc) {
- this(doc, true);
+ this(doc, new MatchingBlockScanner(doc), true);
}
public ScilabLexer(ScilabDocument doc, boolean update) {
+ this(doc, new MatchingBlockScanner(doc), update);
+ }
+
+ public ScilabLexer(ScilabDocument doc, MatchingBlockScanner matchBlock, boolean update) {
this.doc = doc;
this.elem = doc.getDefaultRootElement();
this.infile = doc.getFunctionsInDoc();
- if (update) {
- update();
- }
- }
+ this.matchBlock = matchBlock;
+ if (update) {
+ update();
+ }
+ }
public static void update() {
- if (ScilabCommonsUtils.isScilabThread()) {
- String[] vars = ScilabKeywords.GetVariablesName();
- String[] funs = ScilabKeywords.GetFunctionsName();
- String[] macs = ScilabKeywords.GetMacrosName();
- variables.clear();
- commands.clear();
- macros.clear();
- if (vars != null) {
- variables.addAll(Arrays.asList(vars));
- }
- if (funs != null) {
- commands.addAll(Arrays.asList(funs));
- }
- if (macs != null) {
- macros.addAll(Arrays.asList(macs));
- }
- }
+ if (ScilabCommonsUtils.isScilabThread()) {
+ String[] vars = ScilabKeywords.GetVariablesName();
+ String[] funs = ScilabKeywords.GetFunctionsName();
+ String[] macs = ScilabKeywords.GetMacrosName();
+ variables.clear();
+ commands.clear();
+ macros.clear();
+ if (vars != null) {
+ variables.addAll(Arrays.asList(vars));
+ }
+ if (funs != null) {
+ commands.addAll(Arrays.asList(funs));
+ }
+ if (macs != null) {
+ macros.addAll(Arrays.asList(macs));
+ }
+ }
}
public void setRange(int p0, int p1) {
breakstring = false;
yyreset(new ScilabDocumentReader(doc, p0, p1));
int currentLine = elem.getElementIndex(start);
- if (currentLine != 0 && ((ScilabDocument.ScilabLeafElement) elem.getElement(currentLine - 1)).isBrokenString()) {
- yybegin(QSTRING);
+ if (currentLine != 0) {
+ ScilabDocument.ScilabLeafElement e = (ScilabDocument.ScilabLeafElement) elem.getElement(currentLine - 1);
+ if (e.isBrokenString()) {
+ yybegin(QSTRING);
+ } else if (e.isBlockComment()) {
+ yybegin(BLOCKCOMMENT);
+ }
}
}
public int yychar() {
- return yychar;
+ return (int) yychar;
}
public int scan() throws IOException {
int ret = yylex();
- if (start + yychar + yylength() == end - 1) {
+ int lastPos = start + yychar() + yylength();
+ if (lastPos == end - 1) {
((ScilabDocument.ScilabLeafElement) elem.getElement(elem.getElementIndex(start))).setBrokenString(breakstring);
breakstring = false;
+ } else if (lastPos == end) {
+ ((ScilabDocument.ScilabLeafElement) elem.getElement(elem.getElementIndex(start))).setBlockComment(yystate() == BLOCKCOMMENT);
}
return ret;
}
+ public boolean isLineFinishedByBlockComment(int start, int end) {
+ this.start = start;
+ this.end = end;
+ try {
+ yyreset(new ScilabDocumentReader(doc, start, end));
+ int tok = 0;
+ while (tok != ScilabLexerConstants.EOF) {
+ tok = yylex();
+ }
+ } catch (Exception e) { }
+
+ return yystate() == BLOCKCOMMENT;
+ }
+
public int getKeyword(int pos, boolean strict) {
+ // Pre condition
+ if (elem == null) {
+ return ScilabLexerConstants.DEFAULT;
+ }
+
Element line = elem.getElement(elem.getElementIndex(pos));
int end = line.getEndOffset();
int tok = -1;
while (startL < pos && (s != startL || yystate() == BREAKSTRING)) {
s = startL;
tok = yylex();
- startL = start + yychar + yylength();
+ startL = start + yychar() + yylength();
}
return tok;
}
public static ScilabTokens getScilabTokens(String str) {
- ScilabDocument doc = new ScilabDocument(false);
- try {
- doc.insertString(0, str, null);
+ ScilabDocument doc = new ScilabDocument(false);
+ try {
+ doc.insertString(0, str, null);
} catch (BadLocationException e) { }
- return getScilabTokens(doc);
+ return getScilabTokens(doc);
}
public static ScilabTokens getScilabTokens(ScilabDocument doc) {
- ScilabLexer lexer = new ScilabLexer(doc);
- lexer.yyreset(new ScilabDocumentReader(doc, 0, doc.getLength()));
- ScilabTokens tokens = new ScilabTokens();
- int tok = -1;
- try {
- while (tok != ScilabLexerConstants.EOF) {
+ ScilabLexer lexer = new ScilabLexer(doc);
+ lexer.yyreset(new ScilabDocumentReader(doc, 0, doc.getLength()));
+ ScilabTokens tokens = new ScilabTokens();
+ int tok = -1;
+ try {
+ while (tok != ScilabLexerConstants.EOF) {
tok = lexer.yylex();
- tokens.add(tok, lexer.yychar + lexer.yylength());
- }
- } catch (IOException e) { }
+ tokens.add(tok, lexer.yychar() + lexer.yylength());
+ }
+ } catch (IOException e) { }
- return tokens;
+ return tokens;
}
public static class ScilabTokens {
private List<Integer> tokenType = new ArrayList<Integer>();
private List<Integer> tokenPos = new ArrayList<Integer>();
- ScilabTokens() { }
+ ScilabTokens() { }
- void add(final int type, final int pos) {
- tokenType.add(type);
- tokenPos.add(pos);
- }
+ void add(final int type, final int pos) {
+ tokenType.add(type);
+ tokenPos.add(pos);
+ }
- public final List<Integer> getTokenType() {
- return tokenType;
- }
+ public final List<Integer> getTokenType() {
+ return tokenType;
+ }
- public final List<Integer> getTokenPos() {
- return tokenPos;
- }
+ public final List<Integer> getTokenPos() {
+ return tokenPos;
+ }
}
%}
close = "]" | ")" | "}"
comment = "//"
+startcomment = ("/" "*"+)
+endcomment = ("*"+) "/"
quote = "'"
cstes = "%t" | "%T" | "%f" | "%F" | "%e" | "%pi" | "%inf" | "%i" | "%z" | "%s" | "%nan" | "%eps" | "SCI" | "WSCI" | "SCIHOME" | "TMPDIR"
-operator = ".'" | ".*" | "./" | ".\\" | ".^" | ".**" | "+" | "-" | "/" | "\\" | "*" | "^" | "**" | "==" | "~=" | "<>" | "<" | ">" | "<=" | ">=" | ".*." | "./." | ".\\." | "/." | "=" | "&" | "|" | "@" | "@=" | "~"
+operator = ".'" | ".*" | "./" | ".\\" | ".^" | ".**" | "+" | "-" | "/" | "\\" | "*" | "^" | "**" | "==" | "~=" | "<>" | "<" | ">" | "<=" | ">=" | ".*." | "./." | ".\\." | "/." | "=" | "&" | "|" | "@" | "@=" | "~" | "&&" | "||"
functionKwds = "function" | "endfunction"
-structureKwds = "then" | "do" | "catch" | "case"
+structureKwds = "then" | "do" | "catch" | "case" | "otherwise"
elseif = "elseif" | "else"
-openCloseStructureKwds = "if" | "for" | "while" | "try" | "select" | "end"
+openCloseStructureKwds = "if" | "for" | "while" | "try" | "select" | "switch"
+
+end = "end"
controlKwds = "abort" | "break" | "quit" | "return" | "resume" | "pause" | "continue" | "exit"
-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" | "Nicolas Kahhali" | "Nicolas KAHHALI" | "Inria" | "INRIA" | "DIGITEO" | "Digiteo" | "Scilab Enterprises" | "ENPC"
+authors = "Michael Baudin" | "Michael BAUDIN" | "Paul Bignier" | "Paul BIGNIER" | "Adeline CARNIS" | "Adeline CARNIS" | "Yann Collette" | "Yann COLLETTE" | "Allan Cornet" | "Allan CORNET" | "Vincent Couvert" | "Vincent COUVERT" | "Clement David" | "Clement DAVID" | "Calixte Denizet" | "Calixte DENIZET" | "Cedric Delamarre" | "Cedric DELAMARRE" | "Antoine Elias" | "Antoine ELIAS" | "Simon Gareste" | "Simon GARESTE" | "Claude Gomez" | "Claude GOMEZ" | "Samuel Gougeon" | "Samuel GOUGEON" | "Bernard Hugueney" | "Bernard HUGUENEY" | "Bruno Jofret" | "Bruno JOFRET" | "Manuel Juliachs" | "Manuel JULIACHS" | "Sylvestre Koumar" | "Sylvestre KOUMAR" | "Pierre Lando" | "Pierre LANDO" | "Sylvestre Ledru" | "Sylvestre LEDRU" | "Vincent Lejeune" | "Vincent LEJEUNE" | "Vincent Liard" | "Vincent LIARD" | "Zhour Madini-Zouine" | "Zhour MADINI-ZOUINE" | "Pierre Marechal" | "Pierre MARECHAL" | "Stephane Mottelet" | "Stephane MOTTELET" | "Jerome Picard" | "Jerome PICARD" | "Allan Simon" | "Allan SIMON" | "Serge Steer" | "Serge STEER" | "Inria" | "INRIA" | "DIGITEO" | "Digiteo" | "ENPC" | "ESI Group"
+
-error = "Scilab Entreprises" | "Scilab Entreprise" | "Scilab Enterprise"
todo = ("TODO" | "todo" | "Todo")[ \t:]+[^\n]*
break = ".."(".")*
-breakinstring = {break}[ \t]*({comment} | {eol})
+breakinstring = {break}[ \t]*{comment}?
special = "$" | ":" | {break}
badid = ([0-9$][a-zA-Z0-9_#!$?]+)
whitabs = (" "+"\t" | "\t"+" ")[ \t]*
-badop = [+-]([\*\/\\\^] | "."[\*\+\-\/\\\^]) | ":=" | "->" | " !=" | "&&" | "||" | ([*+-/\\\^]"=")
+badop = [+-]([\*\/\\\^] | "."[\*\+\-\/\\\^]) | ":=" | "->" | " !=" | ("&&" "&"+) | ("||" "|"+) | ([*+-/\\\^]"=")
dot = "."
-url = "http://"[^ \t\f\n\r\'\"]+
+url = ("http://"|"https://"|"ftp://"|"sftp://"|"ftps://"|"smb:///"|"file://")[^ \t\f\n\r\'\"]+
mail = "<"[ \t]*[a-zA-Z0-9_\.\-]+"@"([a-zA-Z0-9\-]+".")+[a-zA-Z]{2,5}[ \t]*">"
latex = "$"(([^$]*|"\\$")+)"$"
exp = [dDeE][+-]?{digit}*
number = ({digit}+"."?{digit}*{exp}?)|("."{digit}+{exp}?)
-%x QSTRING, COMMENT, FIELD, COMMANDS, COMMANDSWHITE, BREAKSTRING
+%x QSTRING, COMMENT, BLOCKCOMMENT, FIELD, COMMANDS, COMMANDSWHITE, BREAKSTRING
%%
yybegin(COMMENT);
}
+ {startcomment} {
+ transposable = false;
+ yypushback(2);
+ yybegin(BLOCKCOMMENT);
+ }
+
{operator} {
transposable = false;
return ScilabLexerConstants.OPERATOR;
return ScilabLexerConstants.OSKEYWORD;
}
+ {end} {
+ transposable = false;
+ if (matchBlock != null) {
+ 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 ScilabLexerConstants.FKEYWORD;
+ }
+ } catch (BadLocationException e) { }
+ }
+ }
+ return ScilabLexerConstants.OSKEYWORD;
+ }
+
{structureKwds} {
transposable = false;
return ScilabLexerConstants.SKEYWORD;
yybegin(COMMANDS);
return ScilabLexerConstants.MACROINFILE;
} else {
- List<String>[] arr = doc.getInOutArgs(start + yychar);
+ List<String>[] arr = doc.getInOutArgs(start + yychar());
if (arr != null && (arr[0].contains(str) || arr[1].contains(str))) {
return ScilabLexerConstants.INPUTOUTPUTARGS;
} else if (variables.contains(str)) {
}
{latexinstring} {
- return ScilabLexerConstants.LATEXINSTRING;
+ return ScilabLexerConstants.LATEX;
}
{quote} {
}
" " {
- transposable = false;
return ScilabLexerConstants.WHITE;
}
"\t" {
- transposable = false;
return ScilabLexerConstants.TAB;
}
"\t" {
return ScilabLexerConstants.TAB;
}
-
- . |
- {eol} {
+ .
+ {
yypushback(1);
yybegin(YYINITIAL);
}
+
+ {eol} { }
}
<FIELD> {
return ScilabLexerConstants.FIELD;
}
- . |
- {eol} {
+ . {
yypushback(1);
yybegin(YYINITIAL);
}
+
+ {eol} { }
}
<QSTRING> {
}
}
-<COMMENT> {
- {todo} {
- return ScilabLexerConstants.TODO;
- }
+<BLOCKCOMMENT> {
+ {authors} {
+ return ScilabLexerConstants.AUTHORS;
+ }
+
+ {todo} {
+ return ScilabLexerConstants.TODO;
+ }
+
+ {url} {
+ return ScilabLexerConstants.URL;
+ }
+
+ {mail} {
+ return ScilabLexerConstants.MAIL;
+ }
+
+ {latex} {
+ return ScilabLexerConstants.LATEX;
+ }
+
+ " " {
+ return ScilabLexerConstants.WHITE_COMMENT;
+ }
- {error} {
- return ScilabLexerConstants.ERROR;
- }
+ "\t" {
+ return ScilabLexerConstants.TAB_COMMENT;
+ }
+ {endcomment} {
+ yybegin(YYINITIAL);
+ return ScilabLexerConstants.COMMENT;
+ }
+
+ . |
+ {eol} {
+ return ScilabLexerConstants.COMMENT;
+ }
+}
+<COMMENT> {
{authors} {
return ScilabLexerConstants.AUTHORS;
}
+ {todo} {
+ return ScilabLexerConstants.TODO;
+ }
+
{url} {
return ScilabLexerConstants.URL;
}
return ScilabLexerConstants.TAB_COMMENT;
}
- . {
+ . |
+ {eol} {
return ScilabLexerConstants.COMMENT;
}
-
- {eol} {
- yybegin(YYINITIAL);
- return ScilabLexerConstants.DEFAULT;
- }
}
<BREAKSTRING> {