Skip to content

Commit a0d03d1

Browse files
committed
Fix dangling Clojure span by subclassing JFlexXrefSimple
Also: - Make ClojureXref case-sensitive -- no patterns were affected. Fix not to lower-case for kwd check in ClojureSymbolTokenizer. - Escape all HTML special characters in ClojureXref. - Use Common.xref in ClojureSymbolTokenizer.
1 parent fb66240 commit a0d03d1

File tree

4 files changed

+83
-69
lines changed

4 files changed

+83
-69
lines changed

src/org/opensolaris/opengrok/analysis/clojure/ClojureSymbolTokenizer.lex

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ super(in);
4949

5050
%state STRING COMMENT SCOMMENT
5151

52+
%include Common.lexh
5253
%include Clojure.lexh
5354
%%
5455

5556
<YYINITIAL> {
5657
{Identifier} {
5758
String id = yytext();
58-
if (!Consts.kwd.contains(id.toLowerCase())) {
59+
if (!Consts.kwd.contains(id)) {
5960
setAttribs(id, yychar, yychar + yylength());
6061
return yystate();
6162
}
@@ -69,21 +70,23 @@ super(in);
6970

7071
<STRING> {
7172
\" { yybegin(YYINITIAL); }
72-
\\\\ | \\\" {}
73+
\\[\"\\] {}
7374
}
7475

7576
<YYINITIAL, COMMENT> {
76-
"#|" { yybegin(COMMENT); ++nestedComment; }
77+
"#|" { if (nestedComment++ == 0) { yybegin(COMMENT); } }
7778
}
7879

7980
<COMMENT> {
8081
"|#" { if (--nestedComment == 0) { yybegin(YYINITIAL); } }
8182
}
8283

8384
<SCOMMENT> {
84-
\n { yybegin(YYINITIAL);}
85+
{EOL} { yybegin(YYINITIAL);}
8586
}
8687

8788
<YYINITIAL, STRING, COMMENT, SCOMMENT> {
89+
{WhiteSpace} {}
90+
8891
[^] {}
8992
}

src/org/opensolaris/opengrok/analysis/clojure/ClojureXref.lex

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

2929
package org.opensolaris.opengrok.analysis.clojure;
30-
import org.opensolaris.opengrok.analysis.JFlexXref;
30+
import org.opensolaris.opengrok.analysis.JFlexXrefSimple;
3131
import java.io.IOException;
3232
import java.io.Writer;
3333
import java.io.Reader;
34+
import org.opensolaris.opengrok.web.HtmlConsts;
3435
import org.opensolaris.opengrok.web.Util;
3536
%%
3637
%public
3738
%class ClojureXref
38-
%extends JFlexXref
39+
%extends JFlexXrefSimple
3940
%unicode
40-
%ignorecase
4141
%int
4242
%include CommonXref.lexh
4343
%{
@@ -72,48 +72,59 @@ File = [a-zA-Z] {FNameChar}+ "." ([a-zA-Z]+)
7272
writeSymbol(id, Consts.kwd, yyline);
7373
}
7474

75-
{Number} { out.write("<span class=\"n\">");
76-
out.write(yytext());
77-
out.write("</span>"); }
75+
{Number} {
76+
disjointSpan(HtmlConsts.NUMBER_CLASS);
77+
out.write(yytext());
78+
disjointSpan(null);
79+
}
7880

79-
\" { yybegin(STRING);out.write("<span class=\"s\">\"");}
80-
";" { yybegin(SCOMMENT);out.write("<span class=\"c\">;");}
81+
\" {
82+
pushSpan(STRING, HtmlConsts.STRING_CLASS);
83+
out.write(htmlize(yytext()));
84+
}
85+
";" {
86+
pushSpan(SCOMMENT, HtmlConsts.COMMENT_CLASS);
87+
out.write(yytext());
88+
}
8189
}
8290

8391
<STRING> {
84-
\" {WhiteSpace} \" { out.write(yytext()); }
85-
\" { yybegin(YYINITIAL); out.write("\"</span>"); }
86-
\\\\ { out.write("\\\\"); }
87-
\\\" { out.write("\\\""); }
92+
\" {WhiteSpace} \" |
93+
\\[\"\\] { out.write(htmlize(yytext())); }
94+
\" {
95+
out.write(htmlize(yytext()));
96+
yypop();
97+
}
8898
}
8999

90100
<YYINITIAL, COMMENT> {
91-
"#|" { yybegin(COMMENT);
92-
if (nestedComment++ == 0) { out.write("<span class=\"c\">"); }
93-
out.write("#|");
94-
}
101+
"#|" {
102+
if (nestedComment++ == 0) {
103+
pushSpan(COMMENT, HtmlConsts.COMMENT_CLASS);
104+
}
105+
out.write(yytext());
95106
}
107+
}
96108

97109
<COMMENT> {
98-
"|#" { out.write("|#");
99-
if (--nestedComment == 0) {
100-
yybegin(YYINITIAL);
101-
out.write("</span>");
102-
}
103-
}
110+
"|#" {
111+
out.write(yytext());
112+
if (--nestedComment == 0) {
113+
yypop();
114+
}
115+
}
104116
}
105117

106118
<SCOMMENT> {
107119
{WhspChar}*{EOL} {
108-
yybegin(YYINITIAL); out.write("</span>");
120+
yypop();
109121
startNewLine();
110122
}
111123
}
112124

113125
<YYINITIAL, STRING, COMMENT, SCOMMENT> {
114-
"&" {out.write( "&amp;");}
115-
"<" {out.write( "&lt;");}
116-
">" {out.write( "&gt;");}
126+
[&<>\'\"] { out.write(htmlize(yytext())); }
127+
117128
{WhspChar}*{EOL} { startNewLine(); }
118129
{WhiteSpace} { out.write(yytext()); }
119130
[!-~] { out.write(yycharat(0)); }

0 commit comments

Comments
 (0)