3 package org.scilab.modules.scinotes;
5 import java.io.IOException;
6 import javax.swing.text.Element;
8 @javax.annotation.Generated("JFlex")
9 @SuppressWarnings("fallthrough")
13 %class MatchingBlockScanner
23 private ScilabDocument doc;
25 private boolean transp = false;
26 private ScilabLexer scilabLexer;
31 public MatchingBlockScanner(ScilabDocument doc) {
33 this.elem = doc.getDefaultRootElement();
34 this.scilabLexer = doc.createLexer();
37 public MatchingPositions getNextBlock(int pos, boolean lr) {
43 end = doc.getEndPosition().getOffset();
44 yyreset(new ScilabDocumentReader(doc, start, end));
49 yyreset(new ScilabDocumentReader(doc, true, start, end));
58 } while (zzMarkedPos != 0 && s != 0);
59 } catch (IOException e) {
64 return new MatchingPositions(pos, pos, pos + yychar, pos + yychar + (transp?(yylength()-1):yylength()));
66 return new MatchingPositions(pos, pos, pos - yychar - yylength(), pos - yychar);
73 public MatchingPositions getMatchingBlock(int pos, boolean lr) {
79 end = doc.getEndPosition().getOffset();
80 yyreset(new ScilabDocumentReader(doc, start, end));
86 p1 = pos + yylength();
91 yyreset(new ScilabDocumentReader(doc, true, start, end));
96 p1 = pos - yylength();
106 } while (zzMarkedPos != 0 && s != 0);
107 } catch (IOException e) {
112 return new MatchingPositions(pos, p1, pos + yychar, pos + yychar + (transp?(yylength()-1):yylength()));
114 return new MatchingPositions(p1, pos, pos - yychar - yylength(), pos - yychar);
121 public final class MatchingPositions {
127 private MatchingPositions(int x1, int x2, int y1, int y2) {
140 /* main character classes */
143 comment = "//".*{eol}
145 tnemmoc = {eol}([^\r\n]*"//")+
147 spec = [a-zA-Z0-9_#!$?]
149 id = [a-zA-Z%_#!?][a-zA-Z0-9_#!$?]*
151 string = (([^\'\"\r\n]*)|([\'\"]{2}))*
152 qstring = (\"|\'){string}(\"|\')
153 gnirtsq = \"{string}(\"|\')
154 transp = ({spec} | ")" | "]" | "}") "'"
156 openK = ("if" | "for" | "while" | "select" | "try" | "function")
157 openKx = {openK}{spec}+
159 elseif = "elseif" | "else"
161 openS = "(" | "[" | "{"
162 closeK = ("end" | "endfunction")
163 closeKx = {closeK}{spec}+
164 xcloseK = ({spec} | "%" ){closeK}
165 closeS = ")" | "]" | "}"
167 esolcK = ("fi" | "rof" | "elihw" | "tceles" | "yrt" | "noitcnuf")
168 esolcKx = {spec}{esolcK}
169 xesolcK = {esolcK}{spec}
170 nepoK = ("dne" | "noitcnufdne")
171 nepoKx = {spec}{nepoK}
173 %x LR, RL, OPENCLOSE, CLOSEOPEN, PSNART, SPEC
179 char c = yycharat(yylength() - 2);
180 if (c == ')' || c == ']' || c == '}') {
237 if (scilabLexer.getKeyword(start - yychar, false) == ScilabLexerConstants.STRING) {
238 savePos = start - yychar - scilabLexer.beginString - scilabLexer.start;
249 if (--savePos == 0) {