Skip to content

Commit 66dfb31

Browse files
authored
Merge pull request #1939 from idodeclare/feature/haskell_tests
Feature/haskell tests
2 parents bb9873d + 4e33612 commit 66dfb31

File tree

16 files changed

+1833
-63
lines changed

16 files changed

+1833
-63
lines changed

build.xml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,20 +250,24 @@ Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
250250
replace="" flags="s" />
251251
<replaceregexp file="${src.generatedsrc.dir}/@{dir}/@{name}.java"
252252
match="private static final int ZZ_BUFFERSIZE ="
253-
replace="private int ZZ_BUFFERSIZE ="/>
253+
replace="private int ZZ_BUFFERSIZE ="
254+
preserveLastModified="true"/>
254255
<replaceregexp file="${src.generatedsrc.dir}/@{dir}/@{name}.java"
255256
match="int requested = zzBuffer\.length - zzEndRead;"
256-
replace="int requested = zzBuffer.length - zzEndRead - zzFinalHighSurrogate;"/>
257+
replace="int requested = zzBuffer.length - zzEndRead - zzFinalHighSurrogate;"
258+
preserveLastModified="true"/>
257259
<!-- <replaceregexp file="${src.generatedsrc.dir}/@{dir}/@{name}.java"
258260
match="(zzFinalHighSurrogate = 1;)(\r?\n)"
259261
replace="\1\2 if (totalRead == 1) { return true; }\2"/> this only works for jflex 1.6.0 -->
260262
<replaceregexp file="${src.generatedsrc.dir}/@{dir}/@{name}.java"
261263
match="(zzFinalHighSurrogate = 1;)(\r?\n)"
262-
replace="\1\2 if (numRead == 1) { return true; }\2"/>
264+
replace="\1\2 if (numRead == 1) { return true; }\2"
265+
preserveLastModified="true"/>
263266
<!-- also revert 0 character check that got in with 1.6.1 : https://github.com/jflex-de/jflex/blob/master/jflex/examples/zero-reader/README.md -->
264267
<replaceregexp file="${src.generatedsrc.dir}/@{dir}/@{name}.java"
265268
match="[ \t]*/\* not supposed to occur according to specification of java\.io\.Reader \*/\s+if \(numRead == 0.*?\}[ \t]*\r?\n"
266-
replace="" flags="s" />
269+
replace="" flags="s"
270+
preserveLastModified="true"/>
267271
</sequential>
268272
</macrodef>
269273

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

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -270,16 +270,28 @@ protected void appendLink(String url, boolean doEndingPushback,
270270
throws IOException {
271271

272272
int n = 0;
273-
if (doEndingPushback) {
274-
n = StringUtils.countURIEndingPushback(url);
275-
}
276-
int ccn = StringUtils.countPushback(url, collateralCapture);
277-
if (ccn > n) n = ccn;
278-
// Push back if positive, but not if equal to the current length.
279-
if (n > 0 && n < url.length()) {
280-
yypushback(n);
281-
url = url.substring(0, url.length() - n);
282-
}
273+
int subn;
274+
do {
275+
// An ending-pushback could be present before a collateral capture,
276+
// so detect both in a loop (on a shrinking `url') until no more
277+
// shrinking should occur.
278+
279+
subn = 0;
280+
if (doEndingPushback) {
281+
subn = StringUtils.countURIEndingPushback(url);
282+
}
283+
int ccn = StringUtils.countPushback(url, collateralCapture);
284+
if (ccn > subn) subn = ccn;
285+
286+
// Push back if positive, but not if equal to the current length.
287+
if (subn > 0 && subn < url.length()) {
288+
url = url.substring(0, url.length() - subn);
289+
n += subn;
290+
} else {
291+
subn = 0;
292+
}
293+
} while (subn != 0);
294+
if (n > 0) yypushback(n);
283295

284296
out.write("<a href=\"");
285297
out.write(Util.formQuoteEscape(url));

src/org/opensolaris/opengrok/analysis/haskell/Consts.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
2223
*/
2324

2425
package org.opensolaris.opengrok.analysis.haskell;
@@ -57,5 +58,7 @@ public class Consts {
5758
kwd.add("then");
5859
kwd.add("type");
5960
kwd.add("where");
61+
62+
kwd.add("_"); // 2.4 Identifiers and Operators
6063
}
6164
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
22+
* Copyright (c) 2017, Chris Fraire <[email protected]>.
23+
*
24+
* Copyright (c) Simon Peyton Jones.
25+
* Copyright (c) Simon Marlow.
26+
* The authors and publisher intend this Report to belong to the entire Haskell
27+
* community, and grant permission to copy and distribute it for any purpose,
28+
* provided that it is reproduced in its entirety, including this Notice.
29+
* Modified versions of this Report may also be copied and distributed for any
30+
* purpose, provided that the modified version is clearly presented as such,
31+
* and that it does not claim to be a definition of the language Haskell 2010.
32+
*/
33+
34+
Identifier = ({varid} | {conid})
35+
/*
36+
* varid → (small {small | large | digit | ' })⟨reservedid⟩
37+
* ; N.b. "except {reservedid} is excluded from OpenGrok's varid definition
38+
*/
39+
varid = {small} ({small} | {large} | {digit} | [\'])*
40+
/*
41+
* conid → large {small | large | digit | ' }
42+
*/
43+
conid = {large} ({small} | {large} | {digit} | [\'])*
44+
/*
45+
* small → ascSmall | uniSmall | _
46+
* ascSmall → a | b | … | z
47+
* uniSmall → any Unicode lowercase letter
48+
*/
49+
small = [a-z\p{Ll}_]
50+
/*
51+
* large → ascLarge | uniLarge
52+
* ascLarge → A | B | … | Z
53+
* uniLarge → any uppercase or titlecase Unicode letter
54+
*/
55+
large = [A-Z\p{Lu}\p{Lt}]
56+
/*
57+
* digit → ascDigit | uniDigit
58+
* ascDigit → 0 | 1 | … | 9
59+
* uniDigit → any Unicode decimal digit
60+
* octit → 0 | 1 | … | 7
61+
* hexit → digit | A | … | F | a | … | f
62+
*/
63+
digit = [0-9\p{Nd}]
64+
octit = [0-7]
65+
hexit = [0-9\p{Nd}A-Fa-f]
66+
67+
Number = ({integer} | {float})
68+
/*
69+
* decimal → digit{digit}
70+
* octal → octit{octit}
71+
* hexadecimal → hexit{hexit}
72+
*/
73+
decimal = {digit}+
74+
octal = {octit}+
75+
hexadecimal = {hexit}+
76+
/*
77+
*
78+
* integer → decimal
79+
* | 0o octal | 0O octal
80+
* | 0x hexadecimal | 0X hexadecimal
81+
*/
82+
integer = ({decimal} | [0][oO]{octal} | [0][xX]{hexadecimal})
83+
/*
84+
* float → decimal . decimal [exponent]
85+
* | decimal exponent
86+
*/
87+
float = ({decimal} [\.] {decimal} {exponent}? |
88+
{decimal} {exponent})
89+
/*
90+
* exponent → (e | E) [+ | -] decimal
91+
*/
92+
exponent = [eE] [\+\-]? {decimal}
93+
94+
/*
95+
* "For example, '-->' or '|--' do not begin a comment, because both of these
96+
* are legal lexemes;"
97+
*/
98+
NotComments = ("-->" | "|--")

src/org/opensolaris/opengrok/analysis/haskell/HaskellSymbolTokenizer.lex

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

2929
package org.opensolaris.opengrok.analysis.haskell;
30+
31+
import java.io.IOException;
3032
import org.opensolaris.opengrok.analysis.JFlexTokenizer;
3133

3234
/**
3335
* @author Harry Pan
3436
*/
35-
3637
%%
3738
%public
3839
%class HaskellSymbolTokenizer
@@ -44,11 +45,19 @@ super(in);
4445
%int
4546
%include CommonTokenizer.lexh
4647
%char
48+
%{
49+
private int nestedComment;
4750

48-
Identifier = [a-zA-Z_] [a-zA-Z0-9_']*
51+
public void reset() throws IOException {
52+
super.reset();
53+
nestedComment = 0;
54+
}
55+
%}
4956

5057
%state STRING CHAR COMMENT BCOMMENT
5158

59+
%include Common.lexh
60+
%include Haskell.lexh
5261
%%
5362

5463
<YYINITIAL> {
@@ -59,29 +68,44 @@ Identifier = [a-zA-Z_] [a-zA-Z0-9_']*
5968
return yystate();
6069
}
6170
}
71+
{Number} {}
6272
\" { yybegin(STRING); }
6373
\' { yybegin(CHAR); }
6474
"--" { yybegin(COMMENT); }
65-
"{-" { yybegin(BCOMMENT); }
75+
76+
{NotComments} {}
6677
}
6778

6879
<STRING> {
80+
\\[\"\\] {}
6981
\" { yybegin(YYINITIAL); }
70-
\\\" {} // escaped double quote - don't do anything
7182
}
7283

7384
<CHAR> { // we don't need to consider the case where prime is part of an identifier since it is handled above
85+
\\[\'\\] {}
7486
\' { yybegin(YYINITIAL); }
75-
\\\' {} // escaped single quote - don't do anything
7687
}
7788

7889
<COMMENT> {
79-
\n { yybegin(YYINITIAL); }
90+
{EOL} { yybegin(YYINITIAL); }
91+
}
92+
93+
<YYINITIAL, BCOMMENT> {
94+
"{-" {
95+
if (nestedComment++ == 0) {
96+
yybegin(BCOMMENT);
97+
}
98+
}
8099
}
81100

82101
<BCOMMENT> {
83-
"-}" { yybegin(YYINITIAL); }
102+
"-}" {
103+
if (--nestedComment == 0) {
104+
yybegin(YYINITIAL);
105+
}
106+
}
84107
}
85108

86109
// fallback
110+
{WhiteSpace} |
87111
[^] {}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.haskell;
25+
26+
import java.util.regex.Pattern;
27+
28+
/**
29+
* Represents a container for Haskell-related utility methods
30+
*/
31+
public class HaskellUtils {
32+
33+
/**
34+
* Matches either the end of a Haskell nested comment or a superfluous
35+
* right curly bracket (which is not a valid BrowseableURI character)
36+
* captured in order to be able to detect the end of a Haskell nested
37+
* comment:
38+
* <pre>
39+
* {@code # [ignore the following right brace {]
40+
* \-?\}
41+
* }
42+
* </pre>
43+
* (Edit above and paste below [in NetBeans] for easy String escaping.)
44+
*/
45+
public static final Pattern MAYBE_END_NESTED_COMMENT =
46+
Pattern.compile("\\-?\\}");
47+
48+
/** Private to enforce static. */
49+
private HaskellUtils() {
50+
}
51+
}

0 commit comments

Comments
 (0)