Skip to content

Commit f14f432

Browse files
committed
Fix FortranXref and FortranSymbolTokenizer
- Use disjointSpan() exclusively in the former. - Add missing escape pattern to latter's QSTRING handler. Also: - Escape all HTML special characters in FortranXref. - Make FortranSymbolTokenizer explicitly %ignorecase (no patterns or lookups affected). - Use Common.xref in FortranSymbolTokenizer.
1 parent 1182423 commit f14f432

File tree

3 files changed

+41
-25
lines changed

3 files changed

+41
-25
lines changed

src/org/opensolaris/opengrok/analysis/fortran/FortranSymbolTokenizer.lex

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import org.opensolaris.opengrok.analysis.JFlexTokenizer;
3232
%class FortranSymbolTokenizer
3333
%extends JFlexTokenizer
3434
%unicode
35+
%ignorecase
3536
%init{
3637
super(in);
3738
%init}
@@ -42,8 +43,10 @@ super(in);
4243
Identifier = [a-zA-Z_] [a-zA-Z0-9_]*
4344
Label = [0-9]+
4445

46+
// (OK to exclude LSTRING state used in FortranXref.)
4547
%state STRING COMMENT SCOMMENT QSTRING
4648

49+
%include Common.lexh
4750
%%
4851

4952
<YYINITIAL> {
@@ -61,10 +64,11 @@ Label = [0-9]+
6164

6265
<STRING> {
6366
\" { yybegin(YYINITIAL); }
64-
\\\\ | \\\" {}
67+
\\[\"\\] {}
6568
}
6669

6770
<QSTRING> {
71+
\\[\'\\] {}
6872
\' { yybegin(YYINITIAL); }
6973
}
7074

@@ -73,7 +77,8 @@ Label = [0-9]+
7377
}
7478

7579
<SCOMMENT> {
76-
\n { yybegin(YYINITIAL);}
80+
{WhiteSpace} {}
81+
{EOL} { yybegin(YYINITIAL);}
7782
}
7883

7984
<YYINITIAL, STRING, COMMENT, SCOMMENT, QSTRING> {

src/org/opensolaris/opengrok/analysis/fortran/FortranXref.lex

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ Number = ([0-9]+\.[0-9]+|[0-9][0-9]*|"0x" [0-9a-fA-F]+ )([udl]+)?
6161
%include CommonPath.lexh
6262
%%
6363
<YYINITIAL>{
64-
^{Label} { out.write("<span class=\"n\">"); out.write(yytext()); out.write("</span>"); }
64+
^{Label} {
65+
disjointSpan(HtmlConsts.NUMBER_CLASS);
66+
out.write(yytext());
67+
disjointSpan(null);
68+
}
6569
^[^ \t\f\r\n]+ {
6670
pushSpan(LCOMMENT, HtmlConsts.COMMENT_CLASS);
6771
out.write(htmlize(yytext()));
@@ -85,7 +89,11 @@ Number = ([0-9]+\.[0-9]+|[0-9][0-9]*|"0x" [0-9a-fA-F]+ )([udl]+)?
8589
/*{Hier}
8690
{ out.write(Util.breadcrumbPath(urlPrefix+"defs=",yytext(),'.'));}
8791
*/
88-
{Number} { out.write("<span class=\"n\">"); out.write(yytext()); out.write("</span>"); }
92+
{Number} {
93+
disjointSpan(HtmlConsts.NUMBER_CLASS);
94+
out.write(yytext());
95+
disjointSpan(null);
96+
}
8997

9098
\" {
9199
pushSpan(STRING, HtmlConsts.STRING_CLASS);
@@ -102,21 +110,28 @@ Number = ([0-9]+\.[0-9]+|[0-9][0-9]*|"0x" [0-9a-fA-F]+ )([udl]+)?
102110
}
103111

104112
<STRING> {
105-
\" {WhiteSpace} \" { out.write(yytext());}
106-
\" { out.write('"'); yypop(); }
107-
\\\\ { out.write("\\\\"); }
108-
\\\" { out.write("\\\""); }
113+
\" {WhiteSpace} \" { out.write(htmlize(yytext()));}
114+
\" {
115+
out.write(htmlize(yytext()));
116+
yypop();
117+
}
118+
\\[\"\\] { out.write(htmlize(yytext())); }
109119
}
110120

111121
<QSTRING> {
112-
"\\\\" { out.write("\\\\"); }
113-
"\\'" { out.write("\\\'"); }
114-
\' {WhiteSpace} \' { out.write(yytext()); }
115-
\' { out.write('\''); yypop(); }
122+
\\[\'\\] { out.write(htmlize(yytext())); }
123+
\' {WhiteSpace} \' { out.write(htmlize(yytext())); }
124+
\' {
125+
out.write(htmlize(yytext()));
126+
yypop();
127+
}
116128
}
117129

118130
<COMMENT> {
119-
"*/" { out.write("*/"); yypop(); }
131+
"*/" {
132+
out.write(yytext());
133+
yypop();
134+
}
120135
}
121136

122137
<SCOMMENT> {
@@ -125,9 +140,7 @@ Number = ([0-9]+\.[0-9]+|[0-9][0-9]*|"0x" [0-9a-fA-F]+ )([udl]+)?
125140
}
126141

127142
<LCOMMENT> {
128-
"&" {out.write( "&amp;");}
129-
"<" {out.write( "&lt;");}
130-
">" {out.write( "&gt;");}
143+
[&<>\'\"] { out.write(htmlize(yytext())); }
131144
{WhspChar}*{EOL} { yypop();
132145
startNewLine();}
133146
{WhiteSpace} { out.write(yytext()); }
@@ -137,9 +150,7 @@ Number = ([0-9]+\.[0-9]+|[0-9][0-9]*|"0x" [0-9a-fA-F]+ )([udl]+)?
137150

138151

139152
<YYINITIAL, STRING, COMMENT, SCOMMENT, QSTRING> {
140-
"&" {out.write( "&amp;");}
141-
"<" {out.write( "&lt;");}
142-
">" {out.write( "&gt;");}
153+
[&<>\'\"] { out.write(htmlize(yytext())); }
143154
{WhspChar}*{EOL} { startNewLine(); }
144155
{WhiteSpace} { out.write(yytext()); }
145156
[!-~] { out.write(yycharat(0)); }

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<a class="l" name="37" href="#37">37</a><span class="c">* intellectual property rights.</span>
4646
<a class="l" name="38" href="#38">38</a><span class="c">*</span>
4747
<a class="l" name="39" href="#39">39</a><span class="c">* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS</span>
48-
<a class="hl" name="40" href="#40">40</a><span class="c">* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT</span>
48+
<a class="hl" name="40" href="#40">40</a><span class="c">* &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT</span>
4949
<a class="l" name="41" href="#41">41</a><span class="c">* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR</span>
5050
<a class="l" name="42" href="#42">42</a><span class="c">* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT</span>
5151
<a class="l" name="43" href="#43">43</a><span class="c">* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,</span>
@@ -65,11 +65,11 @@
6565
<a class="l" name="57" href="#57">57</a><span class="c">*</span>
6666
<a class="l" name="58" href="#58">58</a><span class="c">*&gt; \htmlonly</span>
6767
<a class="l" name="59" href="#59">59</a><span class="c">*&gt; Download DGESV + dependencies</span>
68-
<a class="hl" name="60" href="#60">60</a><span class="c">*&gt; &lt;a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&amp;filename=/lapack/lapack_routine/dgesv.f"&gt;</span>
68+
<a class="hl" name="60" href="#60">60</a><span class="c">*&gt; &lt;a href=&quot;http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&amp;filename=/lapack/lapack_routine/dgesv.f&quot;&gt;</span>
6969
<a class="l" name="61" href="#61">61</a><span class="c">*&gt; [TGZ]&lt;/a&gt;</span>
70-
<a class="l" name="62" href="#62">62</a><span class="c">*&gt; &lt;a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&amp;filename=/lapack/lapack_routine/dgesv.f"&gt;</span>
70+
<a class="l" name="62" href="#62">62</a><span class="c">*&gt; &lt;a href=&quot;http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&amp;filename=/lapack/lapack_routine/dgesv.f&quot;&gt;</span>
7171
<a class="l" name="63" href="#63">63</a><span class="c">*&gt; [ZIP]&lt;/a&gt;</span>
72-
<a class="l" name="64" href="#64">64</a><span class="c">*&gt; &lt;a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&amp;filename=/lapack/lapack_routine/dgesv.f"&gt;</span>
72+
<a class="l" name="64" href="#64">64</a><span class="c">*&gt; &lt;a href=&quot;http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&amp;filename=/lapack/lapack_routine/dgesv.f&quot;&gt;</span>
7373
<a class="l" name="65" href="#65">65</a><span class="c">*&gt; [TXT]&lt;/a&gt;</span>
7474
<a class="l" name="66" href="#66">66</a><span class="c">*&gt; \endhtmlonly</span>
7575
<a class="l" name="67" href="#67">67</a><span class="c">*</span>
@@ -216,7 +216,7 @@
216216
<a class="l" name="208" href="#208">208</a> <a href="/source/s?defs=INFO" class="intelliWindow-symbol" data-definition-place="undefined-in-file">INFO</a> = -<span class="n">7</span>
217217
<a class="l" name="209" href="#209">209</a> <b>END</b> <b>IF</b>
218218
<a class="hl" name="210" href="#210">210</a> <b>IF</b>( <a href="/source/s?defs=INFO" class="intelliWindow-symbol" data-definition-place="undefined-in-file">INFO</a>.<b>NE</b>.<span class="n">0</span> ) <b>THEN</b>
219-
<a class="l" name="211" href="#211">211</a> <b>CALL</b> <a href="/source/s?defs=XERBLA" class="intelliWindow-symbol" data-definition-place="undefined-in-file">XERBLA</a>( <span class="s">&apos;DGESV '</span>, -<a href="/source/s?defs=INFO" class="intelliWindow-symbol" data-definition-place="undefined-in-file">INFO</a> )
219+
<a class="l" name="211" href="#211">211</a> <b>CALL</b> <a href="/source/s?defs=XERBLA" class="intelliWindow-symbol" data-definition-place="undefined-in-file">XERBLA</a>( <span class="s">&apos;DGESV &apos;</span>, -<a href="/source/s?defs=INFO" class="intelliWindow-symbol" data-definition-place="undefined-in-file">INFO</a> )
220220
<a class="l" name="212" href="#212">212</a> <b>RETURN</b>
221221
<a class="l" name="213" href="#213">213</a> <b>END</b> <b>IF</b>
222222
<a class="l" name="214" href="#214">214</a><span class="c">*</span>
@@ -227,7 +227,7 @@
227227
<a class="l" name="219" href="#219">219</a><span class="c">*</span>
228228
<a class="hl" name="220" href="#220">220</a><span class="c">* Solve the system A*X = B, overwriting B with X.</span>
229229
<a class="l" name="221" href="#221">221</a><span class="c">*</span>
230-
<a class="l" name="222" href="#222">222</a> <b>CALL</b> <a href="/source/s?defs=DGETRS" class="intelliWindow-symbol" data-definition-place="undefined-in-file">DGETRS</a>( <span class="s">&apos;No transpose'</span>, N, <a href="/source/s?defs=NRHS" class="intelliWindow-symbol" data-definition-place="undefined-in-file">NRHS</a>, A, <a href="/source/s?defs=LDA" class="intelliWindow-symbol" data-definition-place="undefined-in-file">LDA</a>, <a href="/source/s?defs=IPIV" class="intelliWindow-symbol" data-definition-place="undefined-in-file">IPIV</a>, B, <a href="/source/s?defs=LDB" class="intelliWindow-symbol" data-definition-place="undefined-in-file">LDB</a>,
230+
<a class="l" name="222" href="#222">222</a> <b>CALL</b> <a href="/source/s?defs=DGETRS" class="intelliWindow-symbol" data-definition-place="undefined-in-file">DGETRS</a>( <span class="s">&apos;No transpose&apos;</span>, N, <a href="/source/s?defs=NRHS" class="intelliWindow-symbol" data-definition-place="undefined-in-file">NRHS</a>, A, <a href="/source/s?defs=LDA" class="intelliWindow-symbol" data-definition-place="undefined-in-file">LDA</a>, <a href="/source/s?defs=IPIV" class="intelliWindow-symbol" data-definition-place="undefined-in-file">IPIV</a>, B, <a href="/source/s?defs=LDB" class="intelliWindow-symbol" data-definition-place="undefined-in-file">LDB</a>,
231231
<a class="l" name="223" href="#223">223</a> $ <a href="/source/s?defs=INFO" class="intelliWindow-symbol" data-definition-place="undefined-in-file">INFO</a> )
232232
<a class="l" name="224" href="#224">224</a> <b>END</b> <b>IF</b>
233233
<a class="l" name="225" href="#225">225</a> <b>RETURN</b>

0 commit comments

Comments
 (0)