Skip to content

Commit 2b0f4fd

Browse files
committed
Fix dangling Erlang span by subclassing JFlexXrefSimple
Also: - Make ErlangXref case-sensitive, revising {File} to match any case. - Escape all HTML special characters in ErlangXref. - Use Common.xref in ErlangSymbolTokenizer.
1 parent b825a55 commit 2b0f4fd

File tree

5 files changed

+55
-29
lines changed

5 files changed

+55
-29
lines changed

src/org/opensolaris/opengrok/analysis/erlang/ErlangSymbolTokenizer.lex

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ super(in);
4545

4646
%state STRING COMMENT QATOM
4747

48+
%include Common.lexh
4849
%include Erlang.lexh
4950
%%
5051

@@ -80,19 +81,21 @@ super(in);
8081
}
8182

8283
<STRING> {
84+
\\[\"\\] {}
8385
\" { yybegin(YYINITIAL); }
84-
\\\\ | \\\" {}
8586
}
8687

8788
<QATOM> {
89+
\\[\'\\] {}
8890
\' { yybegin(YYINITIAL); }
89-
\\\\ | \\\' {}
9091
}
9192

9293
<COMMENT> {
93-
\n { yybegin(YYINITIAL);}
94+
{EOL} { yybegin(YYINITIAL);}
9495
}
9596

9697
<YYINITIAL, STRING, QATOM, COMMENT> {
98+
{ErlangWhiteSpace} {}
99+
97100
[^] {}
98101
}

src/org/opensolaris/opengrok/analysis/erlang/ErlangXref.lex

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

2929
package org.opensolaris.opengrok.analysis.erlang;
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
%%
3738
%public
3839
%class ErlangXref
39-
%extends JFlexXref
40+
%extends JFlexXrefSimple
4041
%unicode
41-
%ignorecase
4242
%int
4343
%include CommonXref.lexh
4444
%{
@@ -51,7 +51,9 @@ import org.opensolaris.opengrok.web.Util;
5151

5252
IncludeDirective = (include|include_lib)
5353

54-
File = [a-zA-Z]{FNameChar}* "." ("erl"|"hrl"|"app"|"asn"|"yrl"|"asn1"|"xml"|"html")
54+
File = [a-zA-Z]{FNameChar}* "." ([Ee][Rr][Ll] | [Hh][Rr][Ll] | [Aa][Pp][Pp] |
55+
[Aa][Ss][Nn] | [Yy][Rr][Ll] | [Aa][Ss][Nn][1] | [Xx][Mm][Ll] |
56+
[Hh][Tt][Mm][Ll]?)
5557

5658
%state STRING COMMENT QATOM
5759

@@ -63,7 +65,9 @@ File = [a-zA-Z]{FNameChar}* "." ("erl"|"hrl"|"app"|"asn"|"yrl"|"asn1"|"xml"|"htm
6365
<YYINITIAL>{
6466

6567
"?" {Identifier} { // Macros
66-
out.write("<span class=\"xm\">"); out.write(yytext()); out.write("</span>");
68+
disjointSpan(HtmlConsts.MACRO_CLASS);
69+
out.write(yytext());
70+
disjointSpan(null);
6771
}
6872

6973
{Identifier} {
@@ -98,41 +102,59 @@ File = [a-zA-Z]{FNameChar}* "." ("erl"|"hrl"|"app"|"asn"|"yrl"|"asn1"|"xml"|"htm
98102
writeSymbol(id, Consts.modules_kwd, yyline);
99103
}
100104

101-
{ErlInt} { out.write("<span class=\"n\">"); out.write(yytext()); out.write("</span>"); }
102-
{Number} { out.write("<span class=\"n\">"); out.write(yytext()); out.write("</span>"); }
105+
{ErlInt} |
106+
{Number} {
107+
disjointSpan(HtmlConsts.NUMBER_CLASS);
108+
out.write(yytext());
109+
disjointSpan(null);
110+
}
111+
112+
\" {
113+
pushSpan(STRING, HtmlConsts.STRING_CLASS);
114+
out.write(htmlize(yytext()));
115+
}
103116

104-
\" { yybegin(STRING);out.write("<span class=\"s\">\"");}
105-
\' { yybegin(QATOM);out.write("<span class=\"s\">\'");}
106-
"%" { yybegin(COMMENT);out.write("<span class=\"c\">%");}
117+
\' {
118+
pushSpan(QATOM, HtmlConsts.STRING_CLASS);
119+
out.write(htmlize(yytext()));
120+
}
121+
122+
"%" {
123+
pushSpan(COMMENT, HtmlConsts.COMMENT_CLASS);
124+
out.write(yytext());
125+
}
107126
}
108127

109128
<STRING> {
110-
\" { yybegin(YYINITIAL); out.write("\"</span>"); }
111-
\\\\ { out.write("\\\\"); }
112-
\\\" { out.write("\\\""); }
129+
\\[\"\\] { out.write(htmlize(yytext())); }
130+
\" {
131+
out.write(htmlize(yytext()));
132+
yypop();
133+
}
113134
}
114135

115136
<QATOM> {
116-
\' { yybegin(YYINITIAL); out.write("\'</span>"); }
117-
\\\\ { out.write("\\\\"); }
118-
\\\' { out.write("\\\'"); }
137+
\\[\'\\] { out.write(htmlize(yytext())); }
138+
\' {
139+
out.write(htmlize(yytext()));
140+
yypop();
141+
}
119142
}
120143

121144
<COMMENT> {
122145
{ErlangWhspChar}*{EOL} {
123-
yybegin(YYINITIAL); out.write("</span>");
146+
yypop();
124147
startNewLine();
125148
}
126149
}
127150

128151
<YYINITIAL, STRING, COMMENT, QATOM> {
129-
"&" {out.write( "&amp;");}
130-
"<" {out.write( "&lt;");}
131-
">" {out.write( "&gt;");}
152+
[&<>\'\"] { out.write(htmlize(yytext())); }
132153
{ErlangWhspChar}*{EOL} { startNewLine(); }
133154
{ErlangWhiteSpace} { out.write(yytext()); }
134155
[!-~] { out.write(yycharat(0)); }
135-
. { writeUnicodeChar(yycharat(0)); }
156+
157+
[^] { writeUnicodeChar(yycharat(0)); }
136158
}
137159

138160
<STRING, COMMENT, STRING, QATOM> {

src/org/opensolaris/opengrok/web/HtmlConsts.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class HtmlConsts {
3939
public static final String AUTHOR_CLASS = "a";
4040
public static final String COMMENT_CLASS = "c";
4141
public static final String DELETED_CLASS = "d";
42+
public static final String MACRO_CLASS = "xm";
4243
public static final String NUMBER_CLASS = "n";
4344
public static final String STRING_CLASS = "s";
4445

test/org/opensolaris/opengrok/analysis/erlang/sample_xref.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<a class="l" name="4" href="#4">4</a><span class="c">%% purpose with or without fee is hereby granted, provided that the above</span>
1313
<a class="l" name="5" href="#5">5</a><span class="c">%% copyright notice and this permission notice appear in all copies.</span>
1414
<a class="l" name="6" href="#6">6</a><span class="c">%%</span>
15-
<a class="l" name="7" href="#7">7</a><span class="c">%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES</span>
15+
<a class="l" name="7" href="#7">7</a><span class="c">%% THE SOFTWARE IS PROVIDED &quot;AS IS&quot; AND THE AUTHOR DISCLAIMS ALL WARRANTIES</span>
1616
<a class="l" name="8" href="#8">8</a><span class="c">%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF</span>
1717
<a class="l" name="9" href="#9">9</a><span class="c">%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR</span>
1818
<a class="hl" name="10" href="#10">10</a><span class="c">%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES</span>
@@ -44,10 +44,10 @@
4444
<a class="l" name="36" href="#36">36</a> <a href="/source/s?defs=Transport" class="intelliWindow-symbol" data-definition-place="undefined-in-file">Transport</a>:<a href="/source/s?defs=close" class="intelliWindow-symbol" data-definition-place="undefined-in-file">close</a>(<a href="/source/s?defs=CSocket" class="intelliWindow-symbol" data-definition-place="undefined-in-file">CSocket</a>)
4545
<a class="l" name="37" href="#37">37</a> <b>end</b>;
4646
<a class="l" name="38" href="#38">38</a> <span class="c">%% Reduce the accept rate if we run out of file descriptors.</span>
47-
<a class="l" name="39" href="#39">39</a> <span class="c">%% We can't accept anymore anyway, so we might as well wait</span>
47+
<a class="l" name="39" href="#39">39</a> <span class="c">%% We can&apos;t accept anymore anyway, so we might as well wait</span>
4848
<a class="hl" name="40" href="#40">40</a> <span class="c">%% a little for the situation to resolve itself.</span>
4949
<a class="l" name="41" href="#41">41</a> {<a href="/source/s?defs=error" class="intelliWindow-symbol" data-definition-place="undefined-in-file">error</a>, <a href="/source/s?defs=emfile" class="intelliWindow-symbol" data-definition-place="undefined-in-file">emfile</a>} -&gt;
50-
<a class="l" name="42" href="#42">42</a> <a href="/source/s?defs=error_logger" class="intelliWindow-symbol" data-definition-place="undefined-in-file">error_logger</a>:<a href="/source/s?defs=warning_msg" class="intelliWindow-symbol" data-definition-place="undefined-in-file">warning_msg</a>(<span class="s">"Ranch acceptor reducing accept rate: out of file descriptors~n"</span>),
50+
<a class="l" name="42" href="#42">42</a> <a href="/source/s?defs=error_logger" class="intelliWindow-symbol" data-definition-place="undefined-in-file">error_logger</a>:<a href="/source/s?defs=warning_msg" class="intelliWindow-symbol" data-definition-place="undefined-in-file">warning_msg</a>(<span class="s">&quot;Ranch acceptor reducing accept rate: out of file descriptors~n&quot;</span>),
5151
<a class="l" name="43" href="#43">43</a> <b>receive</b> <b>after</b> <span class="n">0xFF</span> -&gt; <a href="/source/s?defs=ok" class="intelliWindow-symbol" data-definition-place="undefined-in-file">ok</a> <b>end</b>;
5252
<a class="l" name="44" href="#44">44</a> <span class="c">%% We want to crash if the listening socket got closed.</span>
5353
<a class="l" name="45" href="#45">45</a> {<a href="/source/s?defs=error" class="intelliWindow-symbol" data-definition-place="undefined-in-file">error</a>, <a href="/source/s?defs=Reason" class="intelliWindow-symbol" data-definition-place="undefined-in-file">Reason</a>} <b>when</b> <a href="/source/s?defs=Reason" class="intelliWindow-symbol" data-definition-place="undefined-in-file">Reason</a> =/= <a href="/source/s?defs=closed" class="intelliWindow-symbol" data-definition-place="undefined-in-file">closed</a> -&gt;
@@ -59,7 +59,7 @@
5959
<a class="l" name="51" href="#51">51</a><a class="xf" name="flush"/><a href="/source/s?refs=flush" class="xf intelliWindow-symbol" data-definition-place="def">flush</a>() -&gt;
6060
<a class="l" name="52" href="#52">52</a> <b>receive</b> <a href="/source/s?defs=Msg" class="intelliWindow-symbol" data-definition-place="undefined-in-file">Msg</a> -&gt;
6161
<a class="l" name="53" href="#53">53</a> <a href="/source/s?defs=error_logger" class="intelliWindow-symbol" data-definition-place="undefined-in-file">error_logger</a>:<a href="/source/s?defs=error_msg" class="intelliWindow-symbol" data-definition-place="undefined-in-file">error_msg</a>(
62-
<a class="l" name="54" href="#54">54</a> <span class="s">"Ranch acceptor received unexpected message: ~p~n"</span>,
62+
<a class="l" name="54" href="#54">54</a> <span class="s">&quot;Ranch acceptor received unexpected message: ~p~n&quot;</span>,
6363
<a class="l" name="55" href="#55">55</a> [<a href="/source/s?defs=Msg" class="intelliWindow-symbol" data-definition-place="undefined-in-file">Msg</a>]),
6464
<a class="l" name="56" href="#56">56</a> <a class="d intelliWindow-symbol" href="#flush" data-definition-place="defined-in-file">flush</a>()
6565
<a class="l" name="57" href="#57">57</a> <b>after</b> <span class="n">0</span> -&gt;

test/org/opensolaris/opengrok/analysis/erlang/truncated_xref.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
class="xref">
66
<head>
77
<title>sampleFile - OpenGrok cross reference for /sampleFile</title></head><body>
8-
<a class="l" name="1" href="#1">1</a> <span class="s">"Oops this is trun</span></body>
8+
<a class="l" name="1" href="#1">1</a> <span class="s">&quot;Oops this is trun</span></body>
99
</html>

0 commit comments

Comments
 (0)