Skip to content

Commit 775b4ad

Browse files
authored
Merge pull request #1915 from idodeclare/feature/erlang_tests
Feature/erlang tests
2 parents 715fac7 + 0ef1317 commit 775b4ad

File tree

14 files changed

+638
-82
lines changed

14 files changed

+638
-82
lines changed

opengrok-indexer/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
109109
<exclude>*.java</exclude>
110110
</excludes>
111111
</testResource>
112+
<testResource>
113+
<targetPath>org/opensolaris/opengrok/analysis/erlang/</targetPath>
114+
<directory>../test/org/opensolaris/opengrok/analysis/erlang/</directory>
115+
<excludes>
116+
<exclude>*.java</exclude>
117+
</excludes>
118+
</testResource>
112119
<testResource>
113120
<targetPath>org/opensolaris/opengrok/analysis/fortran/</targetPath>
114121
<directory>../test/org/opensolaris/opengrok/analysis/fortran/</directory>

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

Lines changed: 47 additions & 28 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.erlang;
@@ -31,34 +32,52 @@
3132
*/
3233
public class Consts{
3334
public static final Set<String> kwd = new HashSet<String>() ;
35+
public static final Set<String> modules_kwd = new HashSet<String>() ;
3436
static {
35-
kwd.add("after");
36-
kwd.add("begin");
37-
kwd.add("case");
38-
kwd.add("try");
39-
kwd.add("cond");
40-
kwd.add("catch");
41-
kwd.add("andalso");
42-
kwd.add("orelse");
43-
kwd.add("end");
44-
kwd.add("fun");
45-
kwd.add("if");
46-
kwd.add("let");
47-
kwd.add("of");
48-
kwd.add("query");
49-
kwd.add("receive");
50-
kwd.add("when");
51-
kwd.add("bnot");
52-
kwd.add("not");
53-
kwd.add("div");
54-
kwd.add("rem");
55-
kwd.add("band");
56-
kwd.add("and");
57-
kwd.add("bor");
58-
kwd.add("bxor");
59-
kwd.add("bsl");
60-
kwd.add("bsr");
61-
kwd.add("or");
62-
kwd.add("xor");
37+
kwd.add("after"); // Ref. 9.1 "1.5 Reserved Words"
38+
kwd.add("and"); // Ref. 9.1 "1.5 Reserved Words"
39+
kwd.add("andalso"); // Ref. 9.1 "1.5 Reserved Words"
40+
kwd.add("band"); // Ref. 9.1 "1.5 Reserved Words"
41+
kwd.add("begin"); // Ref. 9.1 "1.5 Reserved Words"
42+
kwd.add("bnot"); // Ref. 9.1 "1.5 Reserved Words"
43+
kwd.add("bor"); // Ref. 9.1 "1.5 Reserved Words"
44+
kwd.add("bsl"); // Ref. 9.1 "1.5 Reserved Words"
45+
kwd.add("bsr"); // Ref. 9.1 "1.5 Reserved Words"
46+
kwd.add("bxor"); // Ref. 9.1 "1.5 Reserved Words"
47+
kwd.add("case"); // Ref. 9.1 "1.5 Reserved Words"
48+
kwd.add("catch"); // Ref. 9.1 "1.5 Reserved Words"
49+
kwd.add("cond"); // Ref. 9.1 "1.5 Reserved Words"
50+
kwd.add("div"); // Ref. 9.1 "1.5 Reserved Words"
51+
kwd.add("end"); // Ref. 9.1 "1.5 Reserved Words"
52+
kwd.add("fun"); // Ref. 9.1 "1.5 Reserved Words"
53+
kwd.add("if"); // Ref. 9.1 "1.5 Reserved Words"
54+
kwd.add("let"); // Ref. 9.1 "1.5 Reserved Words"
55+
kwd.add("not"); // Ref. 9.1 "1.5 Reserved Words"
56+
kwd.add("of"); // Ref. 9.1 "1.5 Reserved Words"
57+
kwd.add("or"); // Ref. 9.1 "1.5 Reserved Words"
58+
kwd.add("orelse"); // Ref. 9.1 "1.5 Reserved Words"
59+
kwd.add("receive"); // Ref. 9.1 "1.5 Reserved Words"
60+
kwd.add("rem"); // Ref. 9.1 "1.5 Reserved Words"
61+
kwd.add("try"); // Ref. 9.1 "1.5 Reserved Words"
62+
kwd.add("when"); // Ref. 9.1 "1.5 Reserved Words"
63+
kwd.add("xor"); // Ref. 9.1 "1.5 Reserved Words"
64+
65+
kwd.add("query"); // pre-existing here of unknown provenance
66+
67+
modules_kwd.add("behavior"); // Ref. 9.1 "5.2 Module Attributes"
68+
modules_kwd.add("behaviour"); // Ref. 9.1 "5.2 Module Attributes"
69+
modules_kwd.add("callback"); // Ref. 9.1 "5.2 Module Attributes"
70+
modules_kwd.add("compile"); // Ref. 9.1 "5.2 Module Attributes"
71+
modules_kwd.add("define"); // Ref. 9.1 "5.2 Module Attributes"
72+
modules_kwd.add("export"); // Ref. 9.1 "5.2 Module Attributes"
73+
modules_kwd.add("file"); // Ref. 9.1 "5.2 Module Attributes"
74+
modules_kwd.add("import"); // Ref. 9.1 "5.2 Module Attributes"
75+
modules_kwd.add("include"); // Ref. 9.1 "5.2 Module Attributes"
76+
modules_kwd.add("module"); // Ref. 9.1 "5.2 Module Attributes"
77+
modules_kwd.add("on_load"); // Ref. 9.1 "5.2 Module Attributes"
78+
modules_kwd.add("record"); // Ref. 9.1 "5.2 Module Attributes"
79+
modules_kwd.add("spec"); // Ref. 9.1 "5.2 Module Attributes"
80+
modules_kwd.add("type"); // Ref. 9.1 "5.2 Module Attributes"
81+
modules_kwd.add("vsn"); // Ref. 9.1 "5.2 Module Attributes"
6382
}
6483
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 = [a-zA-Z_] [a-zA-Z0-9_@]*
26+
ErlInt = ([12][0-9]|3[0-6]|[1-9])#[0-9]+
27+
Number = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[0-9]+)(([eE][+-]?[0-9]+)?[loxbLOXBjJ]*)?
28+
29+
ErlangWhspChar = ({WhspChar} | [\u{B}])
30+
ErlangWhiteSpace = {ErlangWhspChar}+ | {WhiteSpace}

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

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

2929
package org.opensolaris.opengrok.analysis.erlang;
30-
import java.io.IOException;
31-
import java.io.Reader;
32-
import org.opensolaris.opengrok.analysis.JFlexTokenizer;
3330

31+
import org.opensolaris.opengrok.analysis.JFlexTokenizer;
3432
%%
3533
%public
3634
%class ErlangSymbolTokenizer
@@ -43,37 +41,59 @@ super(in);
4341
%include CommonTokenizer.lexh
4442
%char
4543

46-
Identifier = [A-Z_] [a-zA-Z0-9_@]*
47-
4844
%state STRING COMMENT QATOM
4945

46+
%include Common.lexh
47+
%include Erlang.lexh
5048
%%
5149

5250
<YYINITIAL> {
53-
{Identifier} {String id = yytext();
54-
if(!Consts.kwd.contains(id)){
51+
52+
"?" {Identifier} { // Macros
53+
}
54+
55+
{Identifier} {
56+
String id = yytext();
57+
if (!id.equals("_") && !Consts.kwd.contains(id)) {
5558
setAttribs(id, yychar, yychar + yylength());
56-
return yystate(); }
57-
}
59+
return yystate();
60+
}
61+
}
62+
63+
^"-" {Identifier} {
64+
String capture = yytext();
65+
String punc = capture.substring(0, 1);
66+
String id = capture.substring(1);
67+
if (!Consts.modules_kwd.contains(id)) {
68+
setAttribs(id, yychar + 1, yychar + yylength());
69+
return yystate();
70+
}
71+
}
72+
73+
{ErlInt} {}
74+
{Number} {}
75+
5876
\" { yybegin(STRING); }
5977
\' { yybegin(QATOM); }
6078
"%" { yybegin(COMMENT); }
6179
}
6280

6381
<STRING> {
82+
\\[\"\\] {}
6483
\" { yybegin(YYINITIAL); }
65-
\\\\ | \\\" {}
6684
}
6785

6886
<QATOM> {
87+
\\[\'\\] {}
6988
\' { yybegin(YYINITIAL); }
70-
\\\\ | \\\' {}
7189
}
7290

7391
<COMMENT> {
74-
\n { yybegin(YYINITIAL);}
92+
{EOL} { yybegin(YYINITIAL);}
7593
}
7694

7795
<YYINITIAL, STRING, QATOM, COMMENT> {
96+
{ErlangWhiteSpace} {}
97+
7898
[^] {}
7999
}

0 commit comments

Comments
 (0)