Skip to content

Commit 8ce7336

Browse files
committed
Fix dangling Golang span by subclassing JFlexXrefSimple
Also: - Make GolangXref case-sensitive, revising {File} to match any case. - Escape all HTML special characters in GolangXref. - Do not writeUnicodeChar() normal printable characters. - Use Common.xref in GolangSymbolTokenizer.
1 parent 60e6c60 commit 8ce7336

File tree

4 files changed

+171
-142
lines changed

4 files changed

+171
-142
lines changed

src/org/opensolaris/opengrok/analysis/golang/GolangSymbolTokenizer.lex

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ super(in);
4747

4848
%state STRING COMMENT SCOMMENT QSTRING
4949

50+
%include Common.lexh
5051
%include Golang.lexh
5152
%%
5253

@@ -66,22 +67,24 @@ super(in);
6667
}
6768

6869
<STRING> {
69-
\" { yybegin(YYINITIAL); }
70-
\\\\ | \\\" {}
70+
\\[\"\\] {}
71+
\" { yybegin(YYINITIAL); }
7172
}
7273

7374
<QSTRING> {
74-
\' { yybegin(YYINITIAL); }
75+
\\[\'\\] {}
76+
\' { yybegin(YYINITIAL); }
7577
}
7678

7779
<COMMENT> {
7880
"*/" { yybegin(YYINITIAL); }
7981
}
8082

8183
<SCOMMENT> {
82-
\n { yybegin(YYINITIAL); }
84+
{EOL} { yybegin(YYINITIAL); }
8385
}
8486

8587
<YYINITIAL, STRING, COMMENT, SCOMMENT, QSTRING> {
88+
{WhiteSpace} {}
8689
[^] {}
8790
}

src/org/opensolaris/opengrok/analysis/golang/GolangXref.lex

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

2929
package org.opensolaris.opengrok.analysis.golang;
30-
import org.opensolaris.opengrok.analysis.JFlexXref;
30+
import org.opensolaris.opengrok.analysis.JFlexXrefSimple;
31+
import org.opensolaris.opengrok.web.HtmlConsts;
3132
import org.opensolaris.opengrok.web.Util;
3233

3334
/**
@@ -37,9 +38,8 @@ import org.opensolaris.opengrok.web.Util;
3738
%%
3839
%public
3940
%class GolangXref
40-
%extends JFlexXref
41+
%extends JFlexXrefSimple
4142
%unicode
42-
%ignorecase
4343
%int
4444
%include CommonXref.lexh
4545
%{
@@ -50,7 +50,8 @@ import org.opensolaris.opengrok.web.Util;
5050
protected void setLineNumber(int x) { yyline = x; }
5151
%}
5252

53-
File = [a-zA-Z]{FNameChar}* "." ("go"|"txt"|"htm"|"html"|"diff"|"patch")
53+
File = [a-zA-Z]{FNameChar}* "." ([Gg][Oo] | [Tt][Xx][Tt] | [Hh][Tt][Mm][Ll]? |
54+
[Dd][Ii][Ff][Ff] | [Pp][Aa][Tt][Cc][Hh])
5455

5556
%state STRING COMMENT SCOMMENT QSTRING
5657

@@ -64,11 +65,27 @@ File = [a-zA-Z]{FNameChar}* "." ("go"|"txt"|"htm"|"html"|"diff"|"patch")
6465
String id = yytext();
6566
writeSymbol(id, Consts.kwd, yyline);
6667
}
67-
{Number} { out.write("<span class=\"n\">"); out.write(yytext()); out.write("</span>"); }
68-
\" { yybegin(STRING); out.write("<span class=\"s\">\""); }
69-
\' { yybegin(QSTRING); out.write("<span class=\"s\">\'"); }
70-
"/*" { yybegin(COMMENT); out.write("<span class=\"c\">/*"); }
71-
"//" { yybegin(SCOMMENT); out.write("<span class=\"c\">//"); }
68+
{Number} {
69+
disjointSpan(HtmlConsts.NUMBER_CLASS);
70+
out.write(yytext());
71+
disjointSpan(null);
72+
}
73+
\" {
74+
pushSpan(STRING, HtmlConsts.STRING_CLASS);
75+
out.write(htmlize(yytext()));
76+
}
77+
\' {
78+
pushSpan(QSTRING, HtmlConsts.STRING_CLASS);
79+
out.write(htmlize(yytext()));
80+
}
81+
"/*" {
82+
pushSpan(COMMENT, HtmlConsts.COMMENT_CLASS);
83+
out.write(yytext());
84+
}
85+
"//" {
86+
pushSpan(SCOMMENT, HtmlConsts.COMMENT_CLASS);
87+
out.write(yytext());
88+
}
7289
}
7390

7491
"<" ({File}|{FPath}) ">" {
@@ -85,33 +102,42 @@ File = [a-zA-Z]{FNameChar}* "." ("go"|"txt"|"htm"|"html"|"diff"|"patch")
85102
}
86103

87104
<STRING> {
88-
\" {WhiteSpace} \" { out.write(yytext()); }
89-
\" { yybegin(YYINITIAL); out.write("\"</span>"); }
90-
\\\\ { out.write("\\\\"); }
91-
\\\" { out.write("\\\""); }
105+
\\[\"\\] |
106+
\" {WhiteSpace} \" { out.write(htmlize(yytext())); }
107+
\" {
108+
out.write(htmlize(yytext()));
109+
yypop();
110+
}
92111
}
93112

94113
<QSTRING> {
95-
"\\\\" { out.write("\\\\"); }
96-
"\\'" { out.write("\\\'"); }
97-
\' {WhiteSpace} \' { out.write(yytext()); }
98-
\' { yybegin(YYINITIAL); out.write("'</span>"); }
114+
\\[\'\\] |
115+
\' {WhiteSpace} \' { out.write(htmlize(yytext())); }
116+
\' {
117+
out.write(htmlize(yytext()));
118+
yypop();
119+
}
99120
}
100121

101122
<COMMENT> {
102-
"*/" { yybegin(YYINITIAL); out.write("*/</span>"); }
123+
"*/" {
124+
out.write(yytext());
125+
yypop();
126+
}
103127
}
104128

105129
<SCOMMENT> {
106-
{WhspChar}*{EOL} { yybegin(YYINITIAL); out.write("</span>"); startNewLine(); }
130+
{WhspChar}*{EOL} {
131+
yypop();
132+
startNewLine();
133+
}
107134
}
108135

109136
<YYINITIAL, STRING, COMMENT, SCOMMENT, QSTRING> {
110-
"&" { out.write( "&amp;"); }
111-
"<" { out.write( "&lt;"); }
112-
">" { out.write( "&gt;"); }
137+
[&<>\'\"] { out.write(htmlize(yytext())); }
113138
{WhspChar}*{EOL} { startNewLine(); }
114139
{WhiteSpace} { out.write(yytext()); }
140+
[!-~] { out.write(yycharat(0)); }
115141
[^\n] { writeUnicodeChar(yycharat(0)); }
116142
}
117143

0 commit comments

Comments
 (0)