Skip to content

Commit 14bce55

Browse files
committed
swift first stab, small kotlin fixes
1 parent 2c32bb2 commit 14bce55

File tree

11 files changed

+605
-1
lines changed

11 files changed

+605
-1
lines changed

build.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,20 +262,25 @@ Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
262262
<run-jflex dir="${gen.analysis.dir}/scala" name="ScalaXref"/>
263263
<!-- Kotlin tokenizer is below and has disabled buffer -->
264264
<run-jflex dir="${gen.analysis.dir}/kotlin" name="KotlinXref"/>
265+
<!-- Swift tokenizer is below and has disabled buffer -->
266+
<run-jflex dir="${gen.analysis.dir}/swift" name="SwiftXref"/>
265267

266268
<!-- just those 4 below will not increase buffer size beyond lucene token limits -->
267269
<run-jflex-and-disable-buffer-expansion dir="${gen.analysis.dir}/plain" name="PlainFullTokenizer"/>
268270
<run-jflex-and-disable-buffer-expansion dir="${gen.analysis.dir}/plain" name="PlainSymbolTokenizer"/>
269271
<run-jflex-and-disable-buffer-expansion dir="${gen.analysis.dir}/javascript" name="JavaScriptSymbolTokenizer"/>
270272
<run-jflex-and-disable-buffer-expansion dir="${gen.analysis.dir}/java" name="JavaSymbolTokenizer"/>
271273
<run-jflex-and-disable-buffer-expansion dir="${gen.analysis.dir}/kotlin" name="KotlinSymbolTokenizer"/>
274+
<run-jflex-and-disable-buffer-expansion dir="${gen.analysis.dir}/swift" name="SwiftSymbolTokenizer"/>
272275

273276
<!-- old analysers that will produce tokens > 32766 chars, since they have the buffer increase code in -->
274277
<!--
275278
<run-jflex dir="${gen.analysis.dir}/plain" name="PlainFullTokenizer"/>
276279
<run-jflex dir="${gen.analysis.dir}/plain" name="PlainSymbolTokenizer"/>
277280
<run-jflex dir="${gen.analysis.dir}/javascript" name="JavaScriptSymbolTokenizer"/>
278281
<run-jflex dir="${gen.analysis.dir}/java" name="JavaSymbolTokenizer"/>
282+
<run-jflex dir="${gen.analysis.dir}/kotlin" name="KotlinSymbolTokenizer"/>
283+
<run-jflex dir="${gen.analysis.dir}/swift" name="SwiftSymbolTokenizer"/>
279284
-->
280285

281286
<run-jflex dir="${gen.analysis.dir}/plain" name="PlainXref"/>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
import org.opensolaris.opengrok.analysis.sh.ShAnalyzerFactory;
8484
import org.opensolaris.opengrok.analysis.sql.PLSQLAnalyzerFactory;
8585
import org.opensolaris.opengrok.analysis.sql.SQLAnalyzerFactory;
86+
import org.opensolaris.opengrok.analysis.swift.SwiftAnalyzerFactory;
8687
import org.opensolaris.opengrok.analysis.tcl.TclAnalyzerFactory;
8788
import org.opensolaris.opengrok.analysis.uue.UuencodeAnalyzerFactory;
8889
import org.opensolaris.opengrok.analysis.vb.VBAnalyzerFactory;
@@ -180,6 +181,7 @@ public class AnalyzerGuru {
180181
new JavaAnalyzerFactory(),
181182
new JavaScriptAnalyzerFactory(),
182183
new KotlinAnalyzerFactory(),
184+
new SwiftAnalyzerFactory(),
183185
new PythonAnalyzerFactory(),
184186
new RustAnalyzerFactory(),
185187
new PerlAnalyzerFactory(),

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,17 @@ private void initialize() throws IOException {
179179
command.add("--regex-kotlin=/^[[:space:]]*((abstract|final|sealed|implicit|lazy|private[^ ]*|protected)[[:space:]]*)*var[[:space:]]+([[:alnum:]_:]+)/\\3/v,variables/");
180180
command.add("--regex-kotlin=/^[[:space:]]*package[[:space:]]+([[:alnum:]_.:]+)/\\1/p,packages/");
181181
command.add("--regex-kotlin=/^[[:space:]]*import[[:space:]]+([[:alnum:]_.:]+)/\\1/I,imports/");
182+
183+
command.add("--langdef=swift");
184+
command.add("--langmap=swift:+.swift");
185+
command.add("--regex-swift=/enum[[:space:]]+([^\\{\\}]+).*$/\\1/n,enum,enums/");
186+
command.add("--regex-swift=/typealias[[:space:]]+([^:=]+).*$/\\1/t,typealias,typealiases/");
187+
command.add("--regex-swift=/protocol[[:space:]]+([^:\\{]+).*$/\\1/p,protocol,protocols/");
188+
command.add("--regex-swift=/struct[[:space:]]+([^:\\{]+).*$/\\1/s,struct,structs/");
189+
command.add("--regex-swift=/class[[:space:]]+([^:\\{]+).*$/\\1/c,class,classes/");
190+
command.add("--regex-swift=/func[[:space:]]+([^\\(\\)]+)\\([^\\(\\)]*\\)/\\1/f,function,functions/");
191+
command.add("--regex-swift=/(var|let)[[:space:]]+([^:=]+).*$/\\2/v,variable,variables/");
192+
command.add("--regex-swift=/^[[:space:]]*extension[[:space:]]+([^:\\{]+).*$/\\1/e,extension,extensions/");
182193

183194
command.add("--langdef=pascal");
184195
command.add("--langmap=pascal:+.pas");

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ public class Consts {
6868
kwd.add("is");
6969
kwd.add("lateinit");
7070
kwd.add("noinline");
71+
kwd.add("null");
7172
kwd.add("nullobject");
73+
kwd.add("object");
7274
kwd.add("open");
7375
kwd.add("operator");
7476
kwd.add("out");
@@ -81,12 +83,14 @@ public class Consts {
8183
kwd.add("return");
8284
kwd.add("sealed");
8385
kwd.add("set");
84-
kwd.add("super");
86+
kwd.add("super");
8587
kwd.add("tailrec");
8688
kwd.add("this");
8789
kwd.add("throw");
8890
kwd.add("true");
8991
kwd.add("try");
92+
kwd.add("typealias");
93+
kwd.add("typeof");
9094
kwd.add("val");
9195
kwd.add("var");
9296
kwd.add("vararg");

src/org/opensolaris/opengrok/analysis/kotlin/KotlinSymbolTokenizer.lex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Identifier = [:jletter:] [:jletterdigit:]*
5353

5454
%%
5555

56+
/* TODO : support identifiers escaped by ` `*/
5657
<YYINITIAL> {
5758
{Identifier} {String id = yytext();
5859
if(!Consts.kwd.contains(id)){
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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, Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
package org.opensolaris.opengrok.analysis.swift;
24+
25+
import java.util.HashSet;
26+
import java.util.Set;
27+
28+
/**
29+
* Holds static hash set containing the Swift keywords
30+
*/
31+
public class Consts {
32+
33+
public static final Set<String> kwd = new HashSet<String>();
34+
35+
static {
36+
kwd.add("associatedtype");
37+
kwd.add("class");
38+
kwd.add("deinit");
39+
kwd.add("enum");
40+
kwd.add("extension");
41+
kwd.add("fileprivate");
42+
kwd.add("func");
43+
kwd.add("import");
44+
kwd.add("init");
45+
kwd.add("inout");
46+
kwd.add("internal");
47+
kwd.add("let");
48+
kwd.add("open");
49+
kwd.add("operator");
50+
kwd.add("private");
51+
kwd.add("protocol");
52+
kwd.add("public");
53+
kwd.add("static");
54+
kwd.add("struct");
55+
kwd.add("subscript");
56+
kwd.add("typealias");
57+
kwd.add("var");
58+
kwd.add("break");
59+
kwd.add("case");
60+
kwd.add("continue");
61+
kwd.add("default");
62+
kwd.add("defer");
63+
kwd.add("do");
64+
kwd.add("else");
65+
kwd.add("fallthrough");
66+
kwd.add("for");
67+
kwd.add("guard");
68+
kwd.add("if");
69+
kwd.add("in");
70+
kwd.add("repeat");
71+
kwd.add("return");
72+
kwd.add("switch");
73+
kwd.add("where");
74+
kwd.add("while");
75+
kwd.add("as");
76+
kwd.add("Any");
77+
kwd.add("catch");
78+
kwd.add("false");
79+
kwd.add("is");
80+
kwd.add("nil");
81+
kwd.add("rethrows");
82+
kwd.add("super");
83+
kwd.add("self");
84+
kwd.add("Self");
85+
kwd.add("throw");
86+
kwd.add("throws");
87+
kwd.add("true");
88+
kwd.add("try");
89+
kwd.add("#available");
90+
kwd.add("#colorLiteral");
91+
kwd.add("#column");
92+
kwd.add("#else");
93+
kwd.add("#elseif");
94+
kwd.add("#endif");
95+
kwd.add("#file");
96+
kwd.add("#fileLiteral");
97+
kwd.add("#function");
98+
kwd.add("#if");
99+
kwd.add("#imageLiteral");
100+
kwd.add("#line");
101+
kwd.add("#selector");
102+
kwd.add("#sourceLocation");
103+
//TODO below might be context sensitive ones, should we still detect them?
104+
kwd.add("associativity");
105+
kwd.add("convenience");
106+
kwd.add("dynamic");
107+
kwd.add("didSet");
108+
kwd.add("final");
109+
kwd.add("get");
110+
kwd.add("infix");
111+
kwd.add("indirect");
112+
kwd.add("lazy");
113+
kwd.add("left");
114+
kwd.add("mutating");
115+
kwd.add("none");
116+
kwd.add("nonmutating");
117+
kwd.add("optional");
118+
kwd.add("override");
119+
kwd.add("postfix");
120+
kwd.add("precedence");
121+
kwd.add("prefix");
122+
kwd.add("Protocol");
123+
kwd.add("required");
124+
kwd.add("right");
125+
kwd.add("set");
126+
kwd.add("Type");
127+
kwd.add("unowned");
128+
kwd.add("weak");
129+
kwd.add("willSet");
130+
}
131+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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, Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
package org.opensolaris.opengrok.analysis.swift;
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.FileAnalyzer;
30+
import org.opensolaris.opengrok.analysis.FileAnalyzerFactory;
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 Lubos Kosco
39+
*/
40+
public class SwiftAnalyzer extends AbstractSourceCodeAnalyzer {
41+
42+
/**
43+
* Creates a new instance of KotlinAnalyzer
44+
* @param factory name
45+
*/
46+
protected SwiftAnalyzer(FileAnalyzerFactory factory) {
47+
super(factory);
48+
SymbolTokenizer=new SwiftSymbolTokenizer(FileAnalyzer.dummyReader);
49+
}
50+
51+
@Override
52+
protected JFlexXref newXref(Reader reader) {
53+
return new SwiftXref(reader);
54+
}
55+
56+
@Override
57+
protected boolean supportsScopes() {
58+
return true;
59+
}
60+
61+
static void writeXref(Reader in, Writer out, Definitions defs, Annotation annotation, Project project) throws IOException {
62+
SwiftXref xref = new SwiftXref(in);
63+
AbstractSourceCodeAnalyzer.writeXref(xref, in, out, defs, annotation, project);
64+
}
65+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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, Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
24+
package org.opensolaris.opengrok.analysis.swift;
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+
public class SwiftAnalyzerFactory extends FileAnalyzerFactory {
37+
38+
private static final String name = "Swift";
39+
40+
private static final String[] SUFFIXES = {
41+
"SWIFT",
42+
};
43+
44+
public SwiftAnalyzerFactory() {
45+
super(null, null, SUFFIXES, null, null, "text/plain", Genre.PLAIN, name);
46+
}
47+
48+
@Override
49+
protected FileAnalyzer newAnalyzer() {
50+
return new SwiftAnalyzer(this);
51+
}
52+
53+
@Override
54+
public void writeXref(Reader in, Writer out, Definitions defs, Annotation annotation, Project project)
55+
throws IOException {
56+
SwiftAnalyzer.writeXref(in, out, defs, annotation, project);
57+
}
58+
}

0 commit comments

Comments
 (0)