Skip to content

Commit 23eb76c

Browse files
authored
Merge pull request #1894 from idodeclare/feature/fortran_tests
Feature/fortran tests
2 parents 8f3d658 + c263451 commit 23eb76c

21 files changed

+1248
-186
lines changed

opengrok-indexer/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
102102
<exclude>*.java</exclude>
103103
</excludes>
104104
</testResource>
105+
<testResource>
106+
<targetPath>org/opensolaris/opengrok/analysis/fortran/</targetPath>
107+
<directory>../test/org/opensolaris/opengrok/analysis/fortran/</directory>
108+
<excludes>
109+
<exclude>*.java</exclude>
110+
</excludes>
111+
</testResource>
105112
<testResource>
106113
<targetPath>org/opensolaris/opengrok/analysis/perl/</targetPath>
107114
<directory>../test/org/opensolaris/opengrok/analysis/perl/</directory>

src/org/opensolaris/opengrok/analysis/JFlexXref.java

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.Set;
3636
import java.util.SortedSet;
3737
import java.util.TreeSet;
38+
import java.util.regex.Pattern;
3839
import org.opensolaris.opengrok.analysis.Definitions.Tag;
3940
import org.opensolaris.opengrok.analysis.Scopes.Scope;
4041
import org.opensolaris.opengrok.configuration.Project;
@@ -217,8 +218,8 @@ protected void appendProject() throws IOException {
217218
}
218219

219220
/**
220-
* Calls {@link #appendLink(java.lang.String, boolean)} with false to
221-
* disable {@code doPushback} handling.
221+
* Calls {@link #appendLink(java.lang.String, boolean)} with {@code url}
222+
* and false.
222223
* @param url the URL to append
223224
* @throws IOException if an error occurs while appending
224225
*/
@@ -227,30 +228,64 @@ protected void appendLink(String url) throws IOException {
227228
}
228229

229230
/**
230-
* Appends the {@code url} to the active {@link Writer}. If
231-
* {@code doPushback} is true, then any characters counted by
232-
* {@link StringUtils#countURIEndingPushback(java.lang.String)} are
233-
* handled by {@link #yypushback(int)} with {@code url} only partially
234-
* written.
235-
* <p>If the count is equal to the length of {@code url}, then it is
236-
* simply written, and nothing is pushed back.
231+
* Calls
232+
* {@link #appendLink(java.lang.String, boolean, java.util.regex.Pattern)}
233+
* with {@code url}, {@code doEndingPushback}, and null.
237234
* @param url the URL to append
238-
* @param doPushback a value indicating whether to test the {@code url}
239-
* with {@link StringUtils#countURIEndingPushback(java.lang.String)}.
235+
* @param doEndingPushback a value indicating whether to test the
236+
* {@code url} with
237+
* {@link StringUtils#countURIEndingPushback(java.lang.String)}
240238
* @throws IOException if an error occurs while appending
241239
*/
242-
protected void appendLink(String url, boolean doPushback)
240+
protected void appendLink(String url, boolean doEndingPushback)
243241
throws IOException {
244242

245-
if (doPushback) {
246-
int n = StringUtils.countURIEndingPushback(url);
247-
// Push back if positive, but not if equal to the current length,
248-
// or else the pushback might cause a neverending loop.
249-
if (n > 0 && n < url.length()) {
250-
yypushback(n);
251-
url = url.substring(0, url.length() - n);
243+
appendLink(url, doEndingPushback, null);
244+
}
245+
246+
/**
247+
* Appends the {@code url} to the active {@link Writer}.
248+
* <p>If {@code doEndingPushback} is true, then
249+
* {@link StringUtils#countURIEndingPushback(java.lang.String)} is enlisted
250+
* for use with {@link #yypushback(int)} -- i.e., {@code url} is only
251+
* partially written.
252+
* <p>If {@code collateralCapture} is not null, then its match in
253+
* {@code url} will alternatively mark the start of a count for pushback --
254+
* i.e., everything at and beyond the first {@code collateralCapture} match
255+
* will be considered not to belong to the URI.
256+
* <p>If the pushback count is equal to the length of {@code url}, then it
257+
* is simply written -- and nothing is pushed back -- in order to avoid a
258+
* never-ending {@code yylex()} loop.
259+
* @param url the URL to append
260+
* @param doEndingPushback a value indicating whether to test the
261+
* {@code url} with
262+
* {@link StringUtils#countURIEndingPushback(java.lang.String)}
263+
* @param collateralCapture optional pattern to indicate characters which
264+
* may have been captured as valid URI characters but in a particular
265+
* context should mark the start of a pushback
266+
* @throws IOException if an error occurs while appending
267+
*/
268+
protected void appendLink(String url, boolean doEndingPushback,
269+
Pattern collateralCapture)
270+
throws IOException {
271+
272+
int n = 0;
273+
if (doEndingPushback) {
274+
n = StringUtils.countURIEndingPushback(url);
275+
}
276+
if (collateralCapture != null) {
277+
int o = StringUtils.patindexOf(url, collateralCapture);
278+
if (o > 0) {
279+
int ccn = url.length() - o;
280+
if (ccn > n) n = ccn;
252281
}
253282
}
283+
// Push back if positive, but not if equal to the current length.
284+
if (n > 0 && n < url.length()) {
285+
yypushback(n);
286+
url = url.substring(0, url.length() - n);
287+
}
288+
254289
out.write("<a href=\"");
255290
out.write(Util.formQuoteEscape(url));
256291
out.write("\">");
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
23+
*/
24+
25+
Identifier = [a-zA-Z_] [a-zA-Z0-9_]*
26+
Label = [0-9]+
27+
28+
Number = ([0-9]+\.[0-9]+|[0-9][0-9]* | [0][xX] [0-9a-fA-F]+ )([uUdDlL]+)?

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,26 @@
2323
*/
2424

2525
package org.opensolaris.opengrok.analysis.fortran;
26-
import java.io.IOException;
27-
import java.io.Reader;
28-
import org.opensolaris.opengrok.analysis.JFlexTokenizer;
2926

27+
import org.opensolaris.opengrok.analysis.JFlexTokenizer;
3028
%%
3129
%public
3230
%class FortranSymbolTokenizer
3331
%extends JFlexTokenizer
3432
%unicode
33+
%ignorecase
3534
%init{
3635
super(in);
3736
%init}
3837
%int
3938
%include CommonTokenizer.lexh
4039
%char
4140

42-
Identifier = [a-zA-Z_] [a-zA-Z0-9_]*
43-
Label = [0-9]+
44-
45-
%state STRING COMMENT SCOMMENT QSTRING
41+
// (OK to exclude LCOMMENT state used in FortranXref.)
42+
%state STRING SCOMMENT QSTRING
4643

44+
%include Common.lexh
45+
%include Fortran.lexh
4746
%%
4847

4948
<YYINITIAL> {
@@ -54,28 +53,29 @@ Label = [0-9]+
5453
setAttribs(id, yychar, yychar + yylength());
5554
return yystate(); }
5655
}
56+
57+
{Number} {}
58+
5759
\" { yybegin(STRING); }
5860
\' { yybegin(QSTRING); }
5961
\! { yybegin(SCOMMENT); }
6062
}
6163

6264
<STRING> {
65+
\"\" {}
6366
\" { yybegin(YYINITIAL); }
64-
\\\\ | \\\" {}
6567
}
6668

6769
<QSTRING> {
70+
\'\' {}
6871
\' { yybegin(YYINITIAL); }
6972
}
7073

71-
<COMMENT> {
72-
"*/" { yybegin(YYINITIAL);}
73-
}
74-
7574
<SCOMMENT> {
76-
\n { yybegin(YYINITIAL);}
75+
{WhiteSpace} {}
76+
{EOL} { yybegin(YYINITIAL);}
7777
}
7878

79-
<YYINITIAL, STRING, COMMENT, SCOMMENT, QSTRING> {
79+
<YYINITIAL, STRING, SCOMMENT, QSTRING> {
8080
[^] {}
8181
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2017, Chris Fraire <[email protected]>.
22+
*/
23+
24+
package org.opensolaris.opengrok.analysis.fortran;
25+
26+
import java.util.regex.Pattern;
27+
28+
/**
29+
* Represents a container for Fortran-related utility methods.
30+
*/
31+
public class FortranUtils {
32+
33+
/**
34+
* Matches an apostrophe that is not¹ part of a Fortran apostrophe escape
35+
* sequence:
36+
* <pre>
37+
* {@code
38+
* \'((?<=^.(?!\'))|(?<=[^\'].(?!\'))|(?<=^(\'\'){1,3}.(?!\'))|(?<=[^\'](\'\'){1,3}.(?!\')))
39+
* }
40+
* </pre>
41+
* (Edit above and paste below [in NetBeans] for easy String escaping.)
42+
* <p>
43+
* ¹Correctness in a long sequence of apostrophes is limited because Java
44+
* look-behind is not variable length but instead must have a definite
45+
* upper bound in the regex definition.
46+
*/
47+
public static final Pattern CHARLITERAL_APOS_DELIMITER =
48+
Pattern.compile("\\'((?<=^.(?!\\'))|(?<=[^\\'].(?!\\'))|(?<=^(\\'\\'){1,3}.(?!\\'))|(?<=[^\\'](\\'\\'){1,3}.(?!\\')))");
49+
50+
private FortranUtils() {
51+
}
52+
}

0 commit comments

Comments
 (0)