Skip to content

Commit 18901b1

Browse files
committed
Merge pull request #910 from trondn/erlang
Add Erlang analyzer
2 parents 92eb0ac + 901a436 commit 18901b1

File tree

7 files changed

+407
-1
lines changed

7 files changed

+407
-1
lines changed

build.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
181181
<run-jflex file="${src.dir}/org/opensolaris/opengrok/analysis/c/CXref.lex"/>
182182
<run-jflex file="${src.dir}/org/opensolaris/opengrok/analysis/c/CxxSymbolTokenizer.lex"/>
183183
<run-jflex file="${src.dir}/org/opensolaris/opengrok/analysis/c/CxxXref.lex"/>
184-
<run-jflex file="${src.dir}/org/opensolaris/opengrok/analysis/c/CScopeParser.lex"/>
184+
<run-jflex file="${src.dir}/org/opensolaris/opengrok/analysis/c/CScopeParser.lex"/>
185+
<run-jflex file="${src.dir}/org/opensolaris/opengrok/analysis/erlang/ErlangSymbolTokenizer.lex"/>
186+
<run-jflex file="${src.dir}/org/opensolaris/opengrok/analysis/erlang/ErlangXref.lex"/>
185187
<run-jflex file="${src.dir}/org/opensolaris/opengrok/analysis/fortran/FortranSymbolTokenizer.lex"/>
186188
<run-jflex file="${src.dir}/org/opensolaris/opengrok/analysis/fortran/FortranXref.lex"/>
187189
<run-jflex file="${src.dir}/org/opensolaris/opengrok/analysis/java/JavaSymbolTokenizer.lex"/>

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

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.opensolaris.opengrok.analysis.data.IgnorantAnalyzerFactory;
5252
import org.opensolaris.opengrok.analysis.data.ImageAnalyzerFactory;
5353
import org.opensolaris.opengrok.analysis.document.TroffAnalyzerFactory;
54+
import org.opensolaris.opengrok.analysis.erlang.ErlangAnalyzerFactory;
5455
import org.opensolaris.opengrok.analysis.executables.ELFAnalyzerFactory;
5556
import org.opensolaris.opengrok.analysis.executables.JarAnalyzerFactory;
5657
import org.opensolaris.opengrok.analysis.executables.JavaClassAnalyzerFactory;
@@ -145,6 +146,7 @@ public class AnalyzerGuru {
145146
new CSharpAnalyzerFactory(),
146147
new VBAnalyzerFactory(),
147148
new CxxAnalyzerFactory(),
149+
new ErlangAnalyzerFactory(),
148150
new ShAnalyzerFactory(),
149151
PlainAnalyzerFactory.DEFAULT_INSTANCE,
150152
new UuencodeAnalyzerFactory(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
package org.opensolaris.opengrok.analysis.erlang;
21+
22+
import java.util.HashSet;
23+
import java.util.Set;
24+
25+
/**
26+
* Holds static hash set containing the Erlang keywords
27+
*/
28+
public class Consts{
29+
public static final Set<String> kwd = new HashSet<String>() ;
30+
static {
31+
kwd.add("after");
32+
kwd.add("begin");
33+
kwd.add("case");
34+
kwd.add("try");
35+
kwd.add("cond");
36+
kwd.add("catch");
37+
kwd.add("andalso");
38+
kwd.add("orelse");
39+
kwd.add("end");
40+
kwd.add("fun");
41+
kwd.add("if");
42+
kwd.add("let");
43+
kwd.add("of");
44+
kwd.add("query");
45+
kwd.add("receive");
46+
kwd.add("when");
47+
kwd.add("bnot");
48+
kwd.add("not");
49+
kwd.add("div");
50+
kwd.add("rem");
51+
kwd.add("band");
52+
kwd.add("and");
53+
kwd.add("bor");
54+
kwd.add("bxor");
55+
kwd.add("bsl");
56+
kwd.add("bsr");
57+
kwd.add("or");
58+
kwd.add("xor");
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
package org.opensolaris.opengrok.analysis.erlang;
20+
21+
import java.io.IOException;
22+
import java.io.Reader;
23+
import java.io.Writer;
24+
import org.opensolaris.opengrok.analysis.Definitions;
25+
import org.opensolaris.opengrok.analysis.FileAnalyzerFactory;
26+
import org.opensolaris.opengrok.analysis.JFlexTokenizer;
27+
import org.opensolaris.opengrok.analysis.JFlexXref;
28+
import org.opensolaris.opengrok.analysis.plain.AbstractSourceCodeAnalyzer;
29+
import org.opensolaris.opengrok.configuration.Project;
30+
import org.opensolaris.opengrok.history.Annotation;
31+
32+
public class ErlangAnalyzer extends AbstractSourceCodeAnalyzer {
33+
34+
/**
35+
* Creates a new instance of ErlangAnalyzer
36+
*/
37+
protected ErlangAnalyzer(FileAnalyzerFactory factory) {
38+
super(factory);
39+
}
40+
41+
// @Override
42+
// protected JFlexScopeParser newScopeParser(Reader reader) {
43+
// return new ErlangScopeParser(reader);
44+
// }
45+
46+
@Override
47+
protected JFlexTokenizer newSymbolTokenizer(Reader reader) {
48+
return new ErlangSymbolTokenizer(reader);
49+
}
50+
51+
@Override
52+
protected JFlexXref newXref(Reader reader) {
53+
return new ErlangXref(reader);
54+
}
55+
56+
static void writeXref(Reader in, Writer out, Definitions defs, Annotation annotation, Project project) throws IOException {
57+
ErlangXref xref = new ErlangXref(in);
58+
AbstractSourceCodeAnalyzer.writeXref(xref, in, out, defs, annotation, project);
59+
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
package org.opensolaris.opengrok.analysis.erlang;
20+
21+
import java.io.IOException;
22+
import java.io.Reader;
23+
import java.io.Writer;
24+
import org.opensolaris.opengrok.analysis.Definitions;
25+
import org.opensolaris.opengrok.analysis.FileAnalyzer;
26+
import org.opensolaris.opengrok.analysis.FileAnalyzer.Genre;
27+
import org.opensolaris.opengrok.analysis.FileAnalyzerFactory;
28+
import org.opensolaris.opengrok.configuration.Project;
29+
import org.opensolaris.opengrok.history.Annotation;
30+
31+
public class ErlangAnalyzerFactory extends FileAnalyzerFactory {
32+
33+
private static final String[] SUFFIXES = {
34+
"ERL", "HRL", "ESCRIPT"
35+
};
36+
private static final String[] MAGICS = {
37+
"#!/usr/bin/env escript"
38+
};
39+
40+
public ErlangAnalyzerFactory() {
41+
super(null, null, SUFFIXES, MAGICS, null, "text/plain", Genre.PLAIN);
42+
}
43+
44+
@Override
45+
protected FileAnalyzer newAnalyzer() {
46+
return new ErlangAnalyzer(this);
47+
}
48+
49+
@Override
50+
public void writeXref(Reader in, Writer out, Definitions defs, Annotation annotation, Project project)
51+
throws IOException {
52+
ErlangAnalyzer.writeXref(in, out, defs, annotation, project);
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
* Gets Erlang symbols - ignores comments, strings, keywords
22+
*/
23+
24+
package org.opensolaris.opengrok.analysis.erlang;
25+
import java.io.IOException;
26+
import java.io.Reader;
27+
import org.opensolaris.opengrok.analysis.JFlexTokenizer;
28+
29+
%%
30+
%public
31+
%class ErlangSymbolTokenizer
32+
%extends JFlexTokenizer
33+
%unicode
34+
%type boolean
35+
%eofval{
36+
return false;
37+
%eofval}
38+
%char
39+
40+
Identifier = [A-Z_] [a-zA-Z0-9_@]*
41+
42+
%state STRING COMMENT QATOM
43+
44+
%%
45+
46+
<YYINITIAL> {
47+
{Identifier} {String id = yytext();
48+
if(!Consts.kwd.contains(id)){
49+
setAttribs(id, yychar, yychar + yylength());
50+
return true; }
51+
}
52+
\" { yybegin(STRING); }
53+
\' { yybegin(QATOM); }
54+
"%" { yybegin(COMMENT); }
55+
}
56+
57+
<STRING> {
58+
\" { yybegin(YYINITIAL); }
59+
\\\\ | \\\" {}
60+
}
61+
62+
<QATOM> {
63+
\' { yybegin(YYINITIAL); }
64+
\\\\ | \\\' {}
65+
}
66+
67+
<COMMENT> {
68+
\n { yybegin(YYINITIAL);}
69+
}
70+
71+
<YYINITIAL, STRING, QATOM, COMMENT> {
72+
<<EOF>> { return false;}
73+
[^] {}
74+
}

0 commit comments

Comments
 (0)