Skip to content

Commit d92b4a3

Browse files
committed
Fix dangling Tcl span by subclassing JFlexXrefSimple
Also: - Make TclXref case-sensitive (no affected patterns). - Escape all HTML special characters in TclXref. - Use Common.xref in TclSymbolTokenizer.
1 parent eb72744 commit d92b4a3

File tree

4 files changed

+150
-121
lines changed

4 files changed

+150
-121
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
23+
*/
24+
25+
Identifier = [\:\=a-zA-Z0-9_]+
26+
27+
Number = ([0-9]+\.[0-9]+|[0-9][0-9]*|"#" [boxBOX] [0-9a-fA-F]+)

src/org/opensolaris/opengrok/analysis/tcl/TclSymbolTokenizer.lex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@
2727
*/
2828

2929
package org.opensolaris.opengrok.analysis.tcl;
30-
import java.io.IOException;
31-
import java.io.Reader;
32-
import org.opensolaris.opengrok.analysis.JFlexTokenizer;
3330

31+
import org.opensolaris.opengrok.analysis.JFlexTokenizer;
3432
%%
3533
%public
3634
%class TclSymbolTokenizer
@@ -43,10 +41,10 @@ super(in);
4341
%include CommonTokenizer.lexh
4442
%char
4543

46-
Identifier = [\:\=a-zA-Z0-9_]+
47-
4844
%state STRING COMMENT SCOMMENT
4945

46+
%include Common.lexh
47+
%include Tcl.lexh
5048
%%
5149

5250
<YYINITIAL> {
@@ -55,21 +53,23 @@ Identifier = [\:\=a-zA-Z0-9_]+
5553
setAttribs(id, yychar, yychar + yylength());
5654
return yystate(); }
5755
}
56+
{Number} {}
5857
\" { yybegin(STRING); }
5958
"#" { yybegin(SCOMMENT); }
6059

6160
\\\" {}
6261
}
6362

6463
<STRING> {
64+
\\[\"\\] {}
6565
\" { yybegin(YYINITIAL); }
66-
\\\\ | \\\" {}
6766
}
6867

6968
<SCOMMENT> {
70-
\n { yybegin(YYINITIAL);}
69+
{EOL} { yybegin(YYINITIAL);}
7170
}
7271

7372
<YYINITIAL, STRING, COMMENT, SCOMMENT> {
73+
{WhiteSpace} |
7474
[^] {}
7575
}

src/org/opensolaris/opengrok/analysis/tcl/TclXref.lex

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,15 @@
2727
*/
2828

2929
package org.opensolaris.opengrok.analysis.tcl;
30-
import org.opensolaris.opengrok.analysis.JFlexXref;
31-
import java.io.IOException;
32-
import java.io.Writer;
33-
import java.io.Reader;
34-
import org.opensolaris.opengrok.web.Util;
3530

31+
import org.opensolaris.opengrok.analysis.JFlexXrefSimple;
32+
import org.opensolaris.opengrok.web.HtmlConsts;
33+
import org.opensolaris.opengrok.web.Util;
3634
%%
3735
%public
3836
%class TclXref
39-
%extends JFlexXref
37+
%extends JFlexXrefSimple
4038
%unicode
41-
%ignorecase
4239
%int
4340
%include CommonXref.lexh
4441
%{
@@ -49,17 +46,14 @@ import org.opensolaris.opengrok.web.Util;
4946
protected void setLineNumber(int x) { yyline = x; }
5047
%}
5148

52-
Identifier = [\:\=a-zA-Z0-9_]+
53-
5449
File = [a-zA-Z] {FNameChar}+ "." ([a-zA-Z]+)
5550

56-
Number = ([0-9]+\.[0-9]+|[0-9][0-9]*|"#" [boxBOX] [0-9a-fA-F]+)
57-
5851
%state STRING COMMENT SCOMMENT
5952

6053
%include Common.lexh
6154
%include CommonURI.lexh
6255
%include CommonPath.lexh
56+
%include Tcl.lexh
6357
%%
6458
<YYINITIAL>{
6559

@@ -68,34 +62,42 @@ Number = ([0-9]+\.[0-9]+|[0-9][0-9]*|"#" [boxBOX] [0-9a-fA-F]+)
6862
writeSymbol(id, Consts.kwd, yyline);
6963
}
7064

71-
{Number} { out.write("<span class=\"n\">");
72-
out.write(yytext());
73-
out.write("</span>"); }
74-
75-
\" { yybegin(STRING);out.write("<span class=\"s\">\"");}
76-
"#" { yybegin(SCOMMENT);out.write("<span class=\"c\">#");}
65+
{Number} {
66+
disjointSpan(HtmlConsts.NUMBER_CLASS);
67+
out.write(yytext());
68+
disjointSpan(null);
69+
}
70+
71+
\" {
72+
pushSpan(STRING, HtmlConsts.STRING_CLASS);
73+
out.write(htmlize(yytext()));
74+
}
75+
"#" {
76+
pushSpan(SCOMMENT, HtmlConsts.COMMENT_CLASS);
77+
out.write(yytext());
78+
}
7779

7880
\\\" { out.write(htmlize(yytext())); }
7981
}
8082

8183
<STRING> {
82-
\" {WhiteSpace} \" { out.write(yytext()); }
83-
\" { yybegin(YYINITIAL); out.write("\"</span>"); }
84-
\\\\ { out.write("\\\\"); }
85-
\\\" { out.write("\\\""); }
84+
\\[\"\\] |
85+
\" {WhiteSpace} \" { out.write(htmlize(yytext())); }
86+
\" {
87+
out.write(htmlize(yytext()));
88+
yypop();
89+
}
8690
}
8791

8892
<SCOMMENT> {
89-
{EOL} {
90-
yybegin(YYINITIAL); out.write("</span>");
93+
{WhspChar}*{EOL} {
94+
yypop();
9195
startNewLine();
9296
}
9397
}
9498

9599
<YYINITIAL, STRING, COMMENT, SCOMMENT> {
96-
"&" {out.write( "&amp;");}
97-
"<" {out.write( "&lt;");}
98-
">" {out.write( "&gt;");}
100+
[&<>\'\"] { out.write(htmlize(yytext())); }
99101
{WhspChar}*{EOL} { startNewLine(); }
100102
{WhiteSpace} { out.write(yytext()); }
101103
[!-~] { out.write(yycharat(0)); }

0 commit comments

Comments
 (0)