Skip to content

Commit 715fac7

Browse files
authored
Merge pull request #1914 from idodeclare/feature/clojure_tests
Feature/clojure tests
2 parents 6dad1c3 + baf28a7 commit 715fac7

File tree

14 files changed

+1137
-45
lines changed

14 files changed

+1137
-45
lines changed

LICENSE-eclipse.txt

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
Clojure is licensed by the Eclipse Public License, below.
2+
3+
Eclipse Public License, Version 1.0 (EPL-1.0) (plain text) THE ACCOMPANYING
4+
PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE
5+
("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM
6+
CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
7+
8+
1. DEFINITIONS
9+
10+
"Contribution" means:
11+
12+
a) in the case of the initial Contributor, the initial code and
13+
documentation distributed under this Agreement, and b) in the case of each
14+
subsequent Contributor: i) changes to the Program, and ii) additions to the
15+
Program; where such changes and/or additions to the Program originate from
16+
and are distributed by that particular Contributor. A Contribution
17+
'originates' from a Contributor if it was added to the Program by such
18+
Contributor itself or anyone acting on such Contributor's behalf.
19+
Contributions do not include additions to the Program which: (i) are
20+
separate modules of software distributed in conjunction with the Program
21+
under their own license agreement, and (ii) are not derivative works of the
22+
Program. "Contributor" means any person or entity that distributes the
23+
Program.
24+
25+
"Licensed Patents " mean patent claims licensable by a Contributor which are
26+
necessarily infringed by the use or sale of its Contribution alone or when
27+
combined with the Program.
28+
29+
"Program" means the Contributions distributed in accordance with this
30+
Agreement.
31+
32+
"Recipient" means anyone who receives the Program under this Agreement,
33+
including all Contributors.
34+
35+
2. GRANT OF RIGHTS
36+
37+
a) Subject to the terms of this Agreement, each Contributor hereby grants
38+
Recipient a non-exclusive, worldwide, royalty-free copyright license to
39+
reproduce, prepare derivative works of, publicly display, publicly perform,
40+
distribute and sublicense the Contribution of such Contributor, if any, and
41+
such derivative works, in source code and object code form. b) Subject to
42+
the terms of this Agreement, each Contributor hereby grants Recipient a
43+
non-exclusive, worldwide, royalty-free patent license under Licensed Patents
44+
to make, use, sell, offer to sell, import and otherwise transfer the
45+
Contribution of such Contributor, if any, in source code and object code
46+
form. This patent license shall apply to the combination of the Contribution
47+
and the Program if, at the time the Contribution is added by the
48+
Contributor, such addition of the Contribution causes such combination to be
49+
covered by the Licensed Patents. The patent license shall not apply to any
50+
other combinations which include the Contribution. No hardware per se is
51+
licensed hereunder. c) Recipient understands that although each Contributor
52+
grants the licenses to its Contributions set forth herein, no assurances are
53+
provided by any Contributor that the Program does not infringe the patent or
54+
other intellectual property rights of any other entity. Each Contributor
55+
disclaims any liability to Recipient for claims brought by any other entity
56+
based on infringement of intellectual property rights or otherwise. As a
57+
condition to exercising the rights and licenses granted hereunder, each
58+
Recipient hereby assumes sole responsibility to secure any other
59+
intellectual property rights needed, if any. For example, if a third party
60+
patent license is required to allow Recipient to distribute the Program, it
61+
is Recipient's responsibility to acquire that license before distributing
62+
the Program. d) Each Contributor represents that to its knowledge it has
63+
sufficient copyright rights in its Contribution, if any, to grant the
64+
copyright license set forth in this Agreement.
65+
66+
3. REQUIREMENTS
67+
68+
A Contributor may choose to distribute the Program in object code form under
69+
its own license agreement, provided that:
70+
71+
a) it complies with the terms and conditions of this Agreement; and b) its
72+
license agreement: i) effectively disclaims on behalf of all Contributors
73+
all warranties and conditions, express and implied, including warranties or
74+
conditions of title and non-infringement, and implied warranties or
75+
conditions of merchantability and fitness for a particular purpose; ii)
76+
effectively excludes on behalf of all Contributors all liability for
77+
damages, including direct, indirect, special, incidental and consequential
78+
damages, such as lost profits; iii) states that any provisions which differ
79+
from this Agreement are offered by that Contributor alone and not by any
80+
other party; and iv) states that source code for the Program is available
81+
from such Contributor, and informs licensees how to obtain it in a
82+
reasonable manner on or through a medium customarily used for software
83+
exchange. When the Program is made available in source code form:
84+
85+
a) it must be made available under this Agreement; and b) a copy of this
86+
Agreement must be included with each copy of the Program. Contributors may
87+
not remove or alter any copyright notices contained within the Program. Each
88+
Contributor must identify itself as the originator of its Contribution, if
89+
any, in a manner that reasonably allows subsequent Recipients to identify
90+
the originator of the Contribution.
91+
92+
4. COMMERCIAL DISTRIBUTION
93+
94+
Commercial distributors of software may accept certain responsibilities with
95+
respect to end users, business partners and the like. While this license is
96+
intended to facilitate the commercial use of the Program, the Contributor
97+
who includes the Program in a commercial product offering should do so in a
98+
manner which does not create potential liability for other Contributors.
99+
Therefore, if a Contributor includes the Program in a commercial product
100+
offering, such Contributor ("Commercial Contributor") hereby agrees to
101+
defend and indemnify every other Contributor ("Indemnified Contributor")
102+
against any losses, damages and costs (collectively "Losses") arising from
103+
claims, lawsuits and other legal actions brought by a third party against
104+
the Indemnified Contributor to the extent caused by the acts or omissions of
105+
such Commercial Contributor in connection with its distribution of the
106+
Program in a commercial product offering. The obligations in this section do
107+
not apply to any claims or Losses relating to any actual or alleged
108+
intellectual property infringement. In order to qualify, an Indemnified
109+
Contributor must: a) promptly notify the Commercial Contributor in writing
110+
of such claim, and b) allow the Commercial Contributor to control, and
111+
cooperate with the Commercial Contributor in, the defense and any related
112+
settlement negotiations. The Indemnified Contributor may participate in any
113+
such claim at its own expense.
114+
115+
For example, a Contributor might include the Program in a commercial product
116+
offering, Product X. That Contributor is then a Commercial Contributor. If
117+
that Commercial Contributor then makes performance claims, or offers
118+
warranties related to Product X, those performance claims and warranties are
119+
such Commercial Contributor's responsibility alone. Under this section, the
120+
Commercial Contributor would have to defend claims against the other
121+
Contributors related to those performance claims and warranties, and if a
122+
court requires any other Contributor to pay any damages as a result, the
123+
Commercial Contributor must pay those damages.
124+
125+
5. NO WARRANTY
126+
127+
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON
128+
AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER
129+
EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR
130+
CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A
131+
PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the
132+
appropriateness of using and distributing the Program and assumes all risks
133+
associated with its exercise of rights under this Agreement , including but
134+
not limited to the risks and costs of program errors, compliance with
135+
applicable laws, damage to or loss of data, programs or equipment, and
136+
unavailability or interruption of operations.
137+
138+
6. DISCLAIMER OF LIABILITY
139+
140+
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY
141+
CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL,
142+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION
143+
LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
144+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
145+
ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
146+
EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY
147+
OF SUCH DAMAGES.
148+
149+
7. GENERAL
150+
151+
If any provision of this Agreement is invalid or unenforceable under
152+
applicable law, it shall not affect the validity or enforceability of the
153+
remainder of the terms of this Agreement, and without further action by the
154+
parties hereto, such provision shall be reformed to the minimum extent
155+
necessary to make such provision valid and enforceable.
156+
157+
If Recipient institutes patent litigation against any entity (including a
158+
cross-claim or counterclaim in a lawsuit) alleging that the Program itself
159+
(excluding combinations of the Program with other software or hardware)
160+
infringes such Recipient's patent(s), then such Recipient's rights granted
161+
under Section 2(b) shall terminate as of the date such litigation is filed.
162+
163+
All Recipient's rights under this Agreement shall terminate if it fails to
164+
comply with any of the material terms or conditions of this Agreement and
165+
does not cure such failure in a reasonable period of time after becoming
166+
aware of such noncompliance. If all Recipient's rights under this Agreement
167+
terminate, Recipient agrees to cease use and distribution of the Program as
168+
soon as reasonably practicable. However, Recipient's obligations under this
169+
Agreement and any licenses granted by Recipient relating to the Program
170+
shall continue and survive.
171+
172+
Everyone is permitted to copy and distribute copies of this Agreement, but
173+
in order to avoid inconsistency the Agreement is copyrighted and may only be
174+
modified in the following manner. The Agreement Steward reserves the right
175+
to publish new versions (including revisions) of this Agreement from time to
176+
time. No one other than the Agreement Steward has the right to modify this
177+
Agreement. The Eclipse Foundation is the initial Agreement Steward. The
178+
Eclipse Foundation may assign the responsibility to serve as the Agreement
179+
Steward to a suitable separate entity. Each new version of the Agreement
180+
will be given a distinguishing version number. The Program (including
181+
Contributions) may always be distributed subject to the version of the
182+
Agreement under which it was received. In addition, after a new version of
183+
the Agreement is published, Contributor may elect to distribute the Program
184+
(including its Contributions) under the new version. Except as expressly
185+
stated in Sections 2(a) and 2(b) above, Recipient receives no rights or
186+
licenses to the intellectual property of any Contributor under this
187+
Agreement, whether expressly, by implication, estoppel or otherwise. All
188+
rights in the Program not expressly granted under this Agreement are
189+
reserved.
190+
191+
This Agreement is governed by the laws of the State of New York and the
192+
intellectual property laws of the United States of America. No party to this
193+
Agreement will bring a legal action under this Agreement more than one year
194+
after the cause of action arose. Each party waives its rights to a jury
195+
trial in any resulting litigation.

opengrok-indexer/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
9595
<exclude>*.java</exclude>
9696
</excludes>
9797
</testResource>
98+
<testResource>
99+
<targetPath>org/opensolaris/opengrok/analysis/clojure/</targetPath>
100+
<directory>../test/org/opensolaris/opengrok/analysis/clojure/</directory>
101+
<excludes>
102+
<exclude>*.java</exclude>
103+
</excludes>
104+
</testResource>
98105
<testResource>
99106
<targetPath>org/opensolaris/opengrok/analysis/document/</targetPath>
100107
<directory>../test/org/opensolaris/opengrok/analysis/document/</directory>

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,16 @@ private void initialize() throws IOException {
149149
command.add("--regex-golang=/var[[:space:]]+([a-zA-Z_][a-zA-Z0-9_]+)/\\1/v,var/");
150150
command.add("--regex-golang=/type[[:space:]]+([a-zA-Z_][a-zA-Z0-9_]+)/\\1/t,type/");
151151
}
152+
152153
//temporarily use our defs until ctags will fix https://github.com/universal-ctags/ctags/issues/988
153154
command.add("--langdef=clojure"); // clojure support (patterns are from https://gist.github.com/kul/8704283)
154155
command.add("--langmap=clojure:+.clj");
156+
if (!env.isUniversalCtags()) {
157+
command.add("--regex-clojure=/\\([[:space:]]*defn[[:space:]]+([-[:alnum:]*+!_:\\/.?]+)/\\1/f,function/");
158+
command.add("--regex-clojure=/\\([[:space:]]*ns[[:space:]]+([-[:alnum:]*+!_:\\/.?]+)/\\1/n,namespace/");
159+
}
155160
command.add("--regex-clojure=/\\([[:space:]]*create-ns[[:space:]]+([-[:alnum:]*+!_:\\/.?]+)/\\1/n,namespace/");
156161
command.add("--regex-clojure=/\\([[:space:]]*def[[:space:]]+([-[:alnum:]*+!_:\\/.?]+)/\\1/d,definition/");
157-
command.add("--regex-clojure=/\\([[:space:]]*defn[[:space:]]+([-[:alnum:]*+!_:\\/.?]+)/\\1/f,function/");
158162
command.add("--regex-clojure=/\\([[:space:]]*defn-[[:space:]]+([-[:alnum:]*+!_:\\/.?]+)/\\1/p,private function/");
159163
command.add("--regex-clojure=/\\([[:space:]]*defmacro[[:space:]]+([-[:alnum:]*+!_:\\/.?]+)/\\1/m,macro/");
160164
command.add("--regex-clojure=/\\([[:space:]]*definline[[:space:]]+([-[:alnum:]*+!_:\\/.?]+)/\\1/i,inline/");
@@ -163,7 +167,6 @@ private void initialize() throws IOException {
163167
command.add("--regex-clojure=/\\([[:space:]]*defonce[[:space:]]+([-[:alnum:]*+!_:\\/.?]+)/\\1/c,definition (once)/");
164168
command.add("--regex-clojure=/\\([[:space:]]*defstruct[[:space:]]+([-[:alnum:]*+!_:\\/.?]+)/\\1/s,struct/");
165169
command.add("--regex-clojure=/\\([[:space:]]*intern[[:space:]]+([-[:alnum:]*+!_:\\/.?]+)/\\1/v,intern/");
166-
command.add("--regex-clojure=/\\([[:space:]]*ns[[:space:]]+([-[:alnum:]*+!_:\\/.?]+)/\\1/n,namespace/");
167170

168171
command.add("--langdef=kotlin");
169172
command.add("--langmap=kotlin:+.kt");
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
23+
*/
24+
25+
Identifier = {Symbol}
26+
27+
Number = ({NumberLong} | {NumberDecimal} | {NumberSci} | {NumberHex} |
28+
{NumberBinary} | {NumberCrazy} | {NumberRatio})
29+
NumberLong = [\-\+]?[0-9]+
30+
NumberDecimal = [\-\+]?[0-9]*\.[0-9]+
31+
NumberSci = ({NumberLong} | {NumberDecimal}) ([eE][+-]?[0-9]+)?
32+
NumberHex = 0[Xx][0-9A-Fa-f]+
33+
NumberBinary = 2[Rr][01]+
34+
NumberCrazy = 36[Rr][0-9A-Za-z]+
35+
NumberRatio = {NumberLong}"/"{NumberLong}
36+
37+
/*
38+
* Symbols
39+
*
40+
* Symbols begin with a non-numeric character and can contain alphanumeric
41+
* characters and *, +, !, -, _, ', and ? (other characters may be allowed
42+
* eventually).
43+
*
44+
* N.b. under "Macro Characters", the Quote (') macro is defined -- and that
45+
* section implies that Symbols cannot begin with \'
46+
*/
47+
Symbol = ({SymbolNormal} | {SymbolSlashed} | {SymbolDotted} | {SymbolColon})
48+
SymbolNormal = {SymCharLead} {SymCharAny}*
49+
SymCharSpecial = [\*\+\!\-_\'\?]
50+
SymCharLead = ([A-Za-z] | [[\*\+\!\-_\'\?]--\']) // i.e. [{SymCharSpecial}--\']
51+
SymCharAlphanum = [A-Za-z0-9]
52+
SymCharAny = ({SymCharAlphanum} | {SymCharSpecial})
53+
/*
54+
* '/' has special meaning, it can be used once in the middle of a symbol to
55+
* separate the namespace from the name, e.g. my-namespace/foo. '/' by itself
56+
* names the division function.
57+
*/
58+
SymbolSlashed = {SymbolNormal} "/" {SymCharAny}+
59+
/*
60+
* '.' has special meaning - it can be used one or more times in the middle of
61+
* a symbol to designate a fully-qualified class name, e.g. java.util.BitSet,
62+
* or in namespace names. Symbols beginning or ending with '.' are reserved by
63+
* Clojure. Symbols containing / or . are said to be 'qualified'.
64+
*/
65+
SymbolDotted = {SymbolNormal} ("." {SymCharAny}+)+
66+
/*
67+
* Symbols beginning or ending with ':' are reserved by Clojure. A symbol can
68+
* contain one or more non-repeating ':'s.
69+
*/
70+
SymbolColon = (":" {SymCharAny}+ ":"? | {SymCharAny}+ ":")

src/org/opensolaris/opengrok/analysis/clojure/ClojureSymbolTokenizer.lex

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

2929
package org.opensolaris.opengrok.analysis.clojure;
30+
3031
import java.io.IOException;
31-
import java.io.Reader;
3232
import org.opensolaris.opengrok.analysis.JFlexTokenizer;
33-
3433
%%
3534
%public
3635
%class ClojureSymbolTokenizer
@@ -45,41 +44,54 @@ super(in);
4544

4645
%{
4746
private int nestedComment;
48-
%}
4947

50-
Identifier = [\-\+\*\!\@\$\%\&\/\?\.\,\:\{\}\=a-zA-Z0-9_\<\>]+
48+
@Override
49+
public void reset() throws IOException {
50+
super.reset();
51+
nestedComment = 0;
52+
}
53+
%}
5154

5255
%state STRING COMMENT SCOMMENT
5356

57+
%include Common.lexh
58+
%include Clojure.lexh
5459
%%
5560

5661
<YYINITIAL> {
57-
{Identifier} {String id = yytext();
58-
if (!Consts.kwd.contains(id.toLowerCase())) {
62+
{Identifier} {
63+
String id = yytext();
64+
if (!Consts.kwd.contains(id)) {
5965
setAttribs(id, yychar, yychar + yylength());
60-
return yystate(); }
66+
return yystate();
6167
}
68+
}
69+
70+
{Number} {}
71+
6272
\" { yybegin(STRING); }
6373
";" { yybegin(SCOMMENT); }
6474
}
6575

6676
<STRING> {
6777
\" { yybegin(YYINITIAL); }
68-
\\\\ | \\\" {}
78+
\\[\"\\] {}
6979
}
7080

7181
<YYINITIAL, COMMENT> {
72-
"#|" { yybegin(COMMENT); ++nestedComment; }
82+
"#|" { if (nestedComment++ == 0) { yybegin(COMMENT); } }
7383
}
7484

7585
<COMMENT> {
7686
"|#" { if (--nestedComment == 0) { yybegin(YYINITIAL); } }
7787
}
7888

7989
<SCOMMENT> {
80-
\n { yybegin(YYINITIAL);}
90+
{EOL} { yybegin(YYINITIAL);}
8191
}
8292

8393
<YYINITIAL, STRING, COMMENT, SCOMMENT> {
94+
{WhiteSpace} {}
95+
8496
[^] {}
8597
}

0 commit comments

Comments
 (0)