Skip to content

Commit a18d47e

Browse files
ajaykLubos Kosco
authored andcommitted
add scala support (just for xrefs, defs and refs are not in there)
1 parent 42b6083 commit a18d47e

File tree

10 files changed

+624
-0
lines changed

10 files changed

+624
-0
lines changed

build.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
183183
<jflex file="${src.dir}/org/opensolaris/opengrok/analysis/lisp/LispXref.lex" destdir="${src.generatedsrc.dir}"/>
184184
<jflex file="${src.dir}/org/opensolaris/opengrok/analysis/tcl/TclSymbolTokenizer.lex" destdir="${src.generatedsrc.dir}"/>
185185
<jflex file="${src.dir}/org/opensolaris/opengrok/analysis/tcl/TclXref.lex" destdir="${src.generatedsrc.dir}"/>
186+
<jflex file="${src.dir}/org/opensolaris/opengrok/analysis/scala/ScalaSymbolTokenizer.lex" destdir="${src.generatedsrc.dir}"/>
187+
<jflex file="${src.dir}/org/opensolaris/opengrok/analysis/scala/ScalaXref.lex" destdir="${src.generatedsrc.dir}"/>
186188
<jflex file="${src.dir}/org/opensolaris/opengrok/analysis/plain/PlainFullTokenizer.lex" destdir="${src.generatedsrc.dir}"/>
187189
<jflex file="${src.dir}/org/opensolaris/opengrok/analysis/plain/PlainSymbolTokenizer.lex" destdir="${src.generatedsrc.dir}"/>
188190
<jflex file="${src.dir}/org/opensolaris/opengrok/analysis/plain/PlainXref.lex" destdir="${src.generatedsrc.dir}"/>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import org.opensolaris.opengrok.analysis.plain.PlainAnalyzerFactory;
6262
import org.opensolaris.opengrok.analysis.plain.XMLAnalyzerFactory;
6363
import org.opensolaris.opengrok.analysis.python.PythonAnalyzerFactory;
64+
import org.opensolaris.opengrok.analysis.scala.ScalaAnalyzerFactory;
6465
import org.opensolaris.opengrok.analysis.sh.ShAnalyzerFactory;
6566
import org.opensolaris.opengrok.analysis.sql.PLSQLAnalyzerFactory;
6667
import org.opensolaris.opengrok.analysis.sql.SQLAnalyzerFactory;
@@ -149,6 +150,7 @@ public class AnalyzerGuru {
149150
new PhpAnalyzerFactory(),
150151
new LispAnalyzerFactory(),
151152
new TclAnalyzerFactory(),
153+
new ScalaAnalyzerFactory(),
152154
new SQLAnalyzerFactory(),
153155
new PLSQLAnalyzerFactory(),
154156
new FortranAnalyzerFactory()
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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) 2010, Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
package org.opensolaris.opengrok.analysis.scala;
24+
25+
import java.util.HashSet;
26+
import java.util.Set;
27+
28+
/**
29+
* Holds static hash set containing the Scala keywords
30+
*/
31+
public class Consts{
32+
public static final Set<String> kwd = new HashSet<String>() ;
33+
static {
34+
//Note that keywords with 1 letter will be ignored since we need at least 2 chars per identifier
35+
kwd.add("abstract");
36+
kwd.add("case");
37+
kwd.add("catch");
38+
kwd.add("class");
39+
kwd.add("def");
40+
kwd.add("do");
41+
kwd.add("else");
42+
kwd.add("extends");
43+
kwd.add("false");
44+
kwd.add("final");
45+
kwd.add("finally");
46+
kwd.add("for");
47+
kwd.add("forSome");
48+
kwd.add("if");
49+
kwd.add("implicit");
50+
kwd.add("import");
51+
kwd.add("lazy");
52+
kwd.add("match");
53+
kwd.add("new");
54+
kwd.add("null");
55+
kwd.add("object");
56+
kwd.add("override");
57+
kwd.add("package");
58+
kwd.add("private");
59+
kwd.add("return");
60+
kwd.add("sealed");
61+
kwd.add("super");
62+
kwd.add("this");
63+
kwd.add("throw");
64+
kwd.add("trait");
65+
kwd.add("try");
66+
kwd.add("true");
67+
kwd.add("type");
68+
kwd.add("val");
69+
kwd.add("var");
70+
kwd.add("while");
71+
kwd.add("with");
72+
kwd.add("yield");
73+
}
74+
75+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
package org.opensolaris.opengrok.analysis.scala;
24+
25+
import java.io.IOException;
26+
import java.io.Reader;
27+
import java.io.Writer;
28+
import org.opensolaris.opengrok.analysis.Definitions;
29+
import org.opensolaris.opengrok.analysis.FileAnalyzerFactory;
30+
import org.opensolaris.opengrok.analysis.JFlexTokenizer;
31+
import org.opensolaris.opengrok.analysis.JFlexXref;
32+
import org.opensolaris.opengrok.analysis.plain.AbstractSourceCodeAnalyzer;
33+
import org.opensolaris.opengrok.configuration.Project;
34+
import org.opensolaris.opengrok.history.Annotation;
35+
36+
/**
37+
*
38+
* @author Ajay K
39+
*/
40+
public class ScalaAnalyzer extends AbstractSourceCodeAnalyzer {
41+
42+
/**
43+
* Creates a new instance of ScalaAnalyzer
44+
*/
45+
protected ScalaAnalyzer(FileAnalyzerFactory factory) {
46+
super(factory);
47+
}
48+
49+
@Override
50+
protected JFlexTokenizer newSymbolTokenizer(Reader reader) {
51+
return new ScalaSymbolTokenizer(reader);
52+
}
53+
54+
@Override
55+
protected JFlexXref newXref(Reader reader) {
56+
return new ScalaXref(reader);
57+
}
58+
59+
static void writeXref(Reader in, Writer out, Definitions defs, Annotation annotation, Project project) throws IOException {
60+
ScalaXref xref = new ScalaXref(in);
61+
AbstractSourceCodeAnalyzer.writeXref(xref, in, out, defs, annotation, project);
62+
}
63+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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) 2010, Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
24+
package org.opensolaris.opengrok.analysis.scala;
25+
26+
import java.io.IOException;
27+
import java.io.Reader;
28+
import java.io.Writer;
29+
import org.opensolaris.opengrok.analysis.Definitions;
30+
import org.opensolaris.opengrok.analysis.FileAnalyzer;
31+
import org.opensolaris.opengrok.analysis.FileAnalyzer.Genre;
32+
import org.opensolaris.opengrok.analysis.FileAnalyzerFactory;
33+
import org.opensolaris.opengrok.configuration.Project;
34+
import org.opensolaris.opengrok.history.Annotation;
35+
36+
/**
37+
*
38+
* @author Ajay K
39+
*/
40+
41+
public class ScalaAnalyzerFactory extends FileAnalyzerFactory {
42+
43+
private static final String[] SUFFIXES = {
44+
"SCALA"
45+
};
46+
private static final String[] MAGICS = {
47+
"/"
48+
};
49+
50+
public ScalaAnalyzerFactory() {
51+
super(null, SUFFIXES, MAGICS, null, "text/plain", Genre.PLAIN);
52+
}
53+
54+
@Override
55+
protected FileAnalyzer newAnalyzer() {
56+
return new ScalaAnalyzer(this);
57+
}
58+
59+
@Override
60+
public void writeXref(Reader in, Writer out, Definitions defs, Annotation annotation, Project project)
61+
throws IOException {
62+
ScalaAnalyzer.writeXref(in, out, defs, annotation, project);
63+
}
64+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
24+
/*
25+
* Gets Java symbols - ignores comments, strings, keywords
26+
*/
27+
28+
package org.opensolaris.opengrok.analysis.scala;
29+
import org.opensolaris.opengrok.analysis.JFlexTokenizer;
30+
31+
%%
32+
%public
33+
%class ScalaSymbolTokenizer
34+
%extends JFlexTokenizer
35+
%init{
36+
super(in);
37+
%init}
38+
%unicode
39+
%type boolean
40+
%eofval{
41+
this.finalOffset = zzEndRead;
42+
return false;
43+
%eofval}
44+
%char
45+
46+
Identifier = [a-zA-Z_] [a-zA-Z0-9_]*
47+
48+
%state STRING COMMENT SCOMMENT QSTRING
49+
50+
%%
51+
52+
<YYINITIAL> {
53+
{Identifier} {String id = yytext();
54+
if(!Consts.kwd.contains(id)){
55+
setAttribs(id, yychar, yychar + yylength());
56+
return true; }
57+
}
58+
\" { yybegin(STRING); }
59+
\' { yybegin(QSTRING); }
60+
"/*" { yybegin(COMMENT); }
61+
"//" { yybegin(SCOMMENT); }
62+
}
63+
64+
<STRING> {
65+
\" { yybegin(YYINITIAL); }
66+
\\\\ | \\\" {}
67+
}
68+
69+
<QSTRING> {
70+
\' { yybegin(YYINITIAL); }
71+
}
72+
73+
<COMMENT> {
74+
"*/" { yybegin(YYINITIAL);}
75+
}
76+
77+
<SCOMMENT> {
78+
\n { yybegin(YYINITIAL);}
79+
}
80+
81+
<YYINITIAL, STRING, COMMENT, SCOMMENT, QSTRING> {
82+
<<EOF>> { this.finalOffset = zzEndRead; return false;}
83+
.|\n {}
84+
}

0 commit comments

Comments
 (0)