Skip to content

Commit 27e4c8d

Browse files
committed
Fix dangling Lua span by subclassing JFlexXrefSimple
Also: - Make LuaXref case-sensitive, revising {File} to match any case. - Escape all HTML special characters in LuaXref. - Use Common.xref in LuaSymbolTokenizer.
1 parent 34de17b commit 27e4c8d

File tree

4 files changed

+99
-66
lines changed

4 files changed

+99
-66
lines changed

src/org/opensolaris/opengrok/analysis/lua/LuaSymbolTokenizer.lex

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

2929
package org.opensolaris.opengrok.analysis.lua;
30+
3031
import org.opensolaris.opengrok.analysis.JFlexTokenizer;
3132

3233
/**
3334
* @author Evan Kinney
3435
*/
35-
3636
%%
3737
%public
3838
%class LuaSymbolTokenizer
@@ -84,7 +84,7 @@ super(in);
8484
}
8585

8686
<COMMENT> {
87-
"--]]" { yybegin(YYINITIAL); }
87+
"]]" { yybegin(YYINITIAL); }
8888
}
8989

9090
<SCOMMENT> {

src/org/opensolaris/opengrok/analysis/lua/LuaXref.lex

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@
2727
*/
2828

2929
package org.opensolaris.opengrok.analysis.lua;
30-
import org.opensolaris.opengrok.analysis.JFlexXref;
30+
31+
import org.opensolaris.opengrok.analysis.JFlexXrefSimple;
32+
import org.opensolaris.opengrok.web.HtmlConsts;
3133
import org.opensolaris.opengrok.web.Util;
3234

3335
/**
3436
* @author Evan Kinney
3537
*/
36-
3738
%%
3839
%public
3940
%class LuaXref
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}* "." ("lua"|"txt"|"htm"|"html"|"diff"|"patch")
53+
File = [a-zA-Z]{FNameChar}* "." ([Ll][Uu][Aa] | [Tt][Xx][Tt] |
54+
[Hh][Tt][Mm][Ll]? | [Dd][Ii][Ff][Ff] | [Pp][Aa][Tt][Cc][Hh])
5455

5556
%state STRING LSTRING COMMENT SCOMMENT QSTRING
5657

@@ -64,12 +65,31 @@ File = [a-zA-Z]{FNameChar}* "." ("lua"|"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(LSTRING); out.write("<span class=\"s\">[["); }
70-
\' { yybegin(QSTRING); out.write("<span class=\"s\">\'"); }
71-
"--[[" { yybegin(COMMENT); out.write("<span class=\"c\">--[["); }
72-
"--" { 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(LSTRING, HtmlConsts.STRING_CLASS);
79+
out.write(yytext());
80+
}
81+
\' {
82+
pushSpan(QSTRING, HtmlConsts.STRING_CLASS);
83+
out.write(htmlize(yytext()));
84+
}
85+
"--[[" {
86+
pushSpan(COMMENT, HtmlConsts.COMMENT_CLASS);
87+
out.write(htmlize(yytext()));
88+
}
89+
"--" {
90+
pushSpan(SCOMMENT, HtmlConsts.COMMENT_CLASS);
91+
out.write(htmlize(yytext()));
92+
}
7393
}
7494

7595
"<" ({File}|{FPath}) ">" {
@@ -87,35 +107,48 @@ File = [a-zA-Z]{FNameChar}* "." ("lua"|"txt"|"htm"|"html"|"diff"|"patch")
87107

88108
<STRING> {
89109
\\[\"\\] |
90-
\" {WhiteSpace} \" { out.write(yytext()); }
91-
\" { yybegin(YYINITIAL); out.write("\"</span>"); }
110+
\" {WhiteSpace} \" { out.write(htmlize(yytext())); }
111+
\" {
112+
out.write(htmlize(yytext()));
113+
yypop();
114+
}
92115
}
93116

94117
<QSTRING> {
95118
\\[\'\\] |
96-
\' {WhiteSpace} \' { out.write(yytext()); }
97-
\' { yybegin(YYINITIAL); out.write("'</span>"); }
119+
\' {WhiteSpace} \' { out.write(htmlize(yytext())); }
120+
\' {
121+
out.write(htmlize(yytext()));
122+
yypop();
123+
}
98124
}
99125

100126
<LSTRING> {
101127
\\[\"\\] |
102-
\" {WhiteSpace} \" { out.write(yytext());}
103-
"]]" { yybegin(YYINITIAL); out.write("]]</span>"); }
128+
\" {WhiteSpace} \" { out.write(htmlize(yytext())); }
129+
"]]" {
130+
out.write(htmlize(yytext()));
131+
yypop();
132+
}
104133
}
105134

106135
<COMMENT> {
107-
"--]]" { yybegin(YYINITIAL); out.write("--]]</span>"); }
136+
"]]" {
137+
out.write(yytext());
138+
yypop();
139+
}
108140
}
109141

110142
<SCOMMENT> {
111-
{WhspChar}*{EOL} { yybegin(YYINITIAL); out.write("</span>"); startNewLine(); }
143+
{WhspChar}*{EOL} {
144+
yypop();
145+
startNewLine();
146+
}
112147
}
113148

114149
<YYINITIAL, STRING, LSTRING, COMMENT, SCOMMENT, QSTRING> {
115-
"&" { out.write( "&amp;"); }
116-
"<" { out.write( "&lt;"); }
117-
">" { out.write( "&gt;"); }
118-
{WhspChar}*{EOL} { startNewLine(); }
150+
[&<>\'\"] { out.write(htmlize(yytext())); }
151+
{WhspChar}*{EOL} { startNewLine(); }
119152
{WhiteSpace} { out.write(yytext()); }
120153
[!-~] { out.write(yytext()); }
121154
[^\n] { writeUnicodeChar(yycharat(0)); }

0 commit comments

Comments
 (0)