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 getMatchingBlock(int pos, boolean lr) {
43 end = doc.getEndPosition().getOffset();
44 yyreset(new ScilabDocumentReader(doc, start, end));
50 p1 = pos + yylength();
55 yyreset(new ScilabDocumentReader(doc, true, start, end));
60 p1 = pos - yylength();
70 } while (zzMarkedPos != 0 && s != 0);
71 } catch (IOException e) {
76 return new MatchingPositions(pos, p1, pos + yychar, pos + yychar + (transp?(yylength()-1):yylength()));
78 return new MatchingPositions(p1, pos, pos - yychar - yylength(), pos - yychar);
85 public final class MatchingPositions {
91 private MatchingPositions(int x1, int x2, int y1, int y2) {
104 /* main character classes */
107 comment = "//".*{eol}
109 tnemmoc = {eol}([^\r\n]*"//")+
111 spec = [a-zA-Z0-9_#!$?]
113 id = [a-zA-Z%_#!?][a-zA-Z0-9_#!$?]*
115 string = (([^\'\"\r\n]*)|([\'\"]{2}))*
116 qstring = (\"|\'){string}(\"|\')
117 gnirtsq = \"{string}(\"|\')
118 transp = ({spec} | ")" | "]" | "}") "'"
120 openK = ("if" | "for" | "while" | "select" | "try" | "function")
121 openKx = {openK}{spec}+
123 elseif = "elseif" | "else"
125 openS = "(" | "[" | "{"
126 closeK = ("end" | "endfunction")
127 closeKx = {closeK}{spec}+
128 xcloseK = ({spec} | "%" ){closeK}
129 closeS = ")" | "]" | "}"
131 esolcK = ("fi" | "rof" | "elihw" | "tceles" | "yrt" | "noitcnuf")
132 esolcKx = {spec}{esolcK}
133 xesolcK = {esolcK}{spec}
134 nepoK = ("dne" | "noitcnufdne")
135 nepoKx = {spec}{nepoK}
137 %x LR, RL, OPENCLOSE, CLOSEOPEN, PSNART, SPEC
143 char c = yycharat(yylength() - 2);
144 if (c == ')' || c == ']' || c == '}') {
201 if (scilabLexer.getKeyword(start - yychar, false) == ScilabLexerConstants.STRING) {
202 savePos = start - yychar - scilabLexer.beginString - scilabLexer.start;
213 if (--savePos == 0) {