Skip to content

Commit 0ed261b

Browse files
committed
Fix #2907 : Add support for TypeScript
1 parent feb551f commit 0ed261b

File tree

18 files changed

+1684
-10
lines changed

18 files changed

+1684
-10
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/AnalyzerGuru.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
import org.opengrok.indexer.analysis.sql.SQLAnalyzerFactory;
101101
import org.opengrok.indexer.analysis.swift.SwiftAnalyzerFactory;
102102
import org.opengrok.indexer.analysis.tcl.TclAnalyzerFactory;
103+
import org.opengrok.indexer.analysis.typescript.TypeScriptAnalyzerFactory;
103104
import org.opengrok.indexer.analysis.uue.UuencodeAnalyzerFactory;
104105
import org.opengrok.indexer.analysis.vb.VBAnalyzerFactory;
105106
import org.opengrok.indexer.analysis.verilog.VerilogAnalyzerFactory;
@@ -294,7 +295,8 @@ public class AnalyzerGuru {
294295
new AdaAnalyzerFactory(),
295296
new RubyAnalyzerFactory(),
296297
new EiffelAnalyzerFactory(),
297-
new VerilogAnalyzerFactory()
298+
new VerilogAnalyzerFactory(),
299+
new TypeScriptAnalyzerFactory()
298300
};
299301

300302
for (AnalyzerFactory analyzer : analyzers) {
@@ -328,15 +330,15 @@ public class AnalyzerGuru {
328330
* {@link FileAnalyzerFactory} subclasses are revised to target more or
329331
* different files.
330332
* @return a value whose lower 32-bits are a static value
331-
* 20190211_00
333+
* 20191006_00
332334
* for the current implementation and whose higher-32 bits are non-zero if
333335
* {@link #addExtension(java.lang.String, AnalyzerFactory)}
334336
* or
335337
* {@link #addPrefix(java.lang.String, AnalyzerFactory)}
336338
* has been called.
337339
*/
338340
public static long getVersionNo() {
339-
final int ver32 = 20190211_00; // Edit comment above too!
341+
final int ver32 = 20191006_00; // Edit comment above too!
340342
long ver = ver32;
341343
if (customizationHashCode != 0) {
342344
ver |= (long) customizationHashCode << 32;

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/Ctags.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@ private void initialize() throws IOException {
160160
command.add("--langmap=sql:+.pkb"); // # 1763
161161
command.add("--langmap=sql:+.pck"); // # 1763
162162

163-
command.add("--langmap=javascript:+.ts");
164-
165163
//Ideally all below should be in ctags, or in outside config file,
166164
//we might run out of command line SOON
167165
//Also note, that below ctags definitions HAVE to be in POSIX

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/javascript/JavaScriptAnalyzerFactory.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
22+
* Portions Copyright (c) 2017, 2019, Chris Fraire <[email protected]>.
2323
*/
2424

2525
package org.opengrok.indexer.analysis.javascript;
@@ -31,10 +31,7 @@ public class JavaScriptAnalyzerFactory extends FileAnalyzerFactory {
3131

3232
private static final String name = "JavaScript";
3333

34-
private static final String[] SUFFIXES = {
35-
"JS",
36-
"TS"
37-
};
34+
private static final String[] SUFFIXES = {"JS"};
3835

3936
public JavaScriptAnalyzerFactory() {
4037
super(null, null, SUFFIXES, null, null, "text/plain", AbstractAnalyzer.Genre.PLAIN, name);
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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, 2018, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2019, Chris Fraire <[email protected]>.
23+
*/
24+
25+
package org.opengrok.indexer.analysis.typescript;
26+
27+
import java.util.Collections;
28+
import java.util.HashSet;
29+
import java.util.Set;
30+
31+
/**
32+
* Represents a container for TypeScript Version 1.8 (January 2016) plus
33+
* ECMAScript (June 2019) keywords.
34+
*/
35+
public class Consts {
36+
37+
private static final Set<String> kwd = new HashSet<>();
38+
static final Set<String> KEYWORDS = Collections.unmodifiableSet(kwd);
39+
40+
static {
41+
// literals
42+
kwd.add("true");
43+
kwd.add("false");
44+
kwd.add("null");
45+
46+
// builtins
47+
kwd.add("Array");
48+
kwd.add("BigInt"); // TypeScript 3.2
49+
kwd.add("Boolean");
50+
kwd.add("Date");
51+
kwd.add("Function");
52+
kwd.add("Infinity"); // ECMA version?
53+
kwd.add("Math");
54+
kwd.add("Number");
55+
kwd.add("Object");
56+
kwd.add("RegExp");
57+
kwd.add("String");
58+
59+
// ECMAScript keywords
60+
kwd.add("await"); // ECMA-262, 10th edition, June 2019
61+
kwd.add("break");
62+
kwd.add("case");
63+
kwd.add("catch");
64+
kwd.add("class");
65+
kwd.add("const");
66+
kwd.add("continue");
67+
kwd.add("debugger");
68+
kwd.add("default");
69+
kwd.add("delete");
70+
kwd.add("do");
71+
kwd.add("else");
72+
kwd.add("export");
73+
kwd.add("extends");
74+
kwd.add("finally");
75+
kwd.add("for");
76+
kwd.add("function");
77+
kwd.add("if");
78+
kwd.add("in");
79+
kwd.add("instanceof");
80+
kwd.add("import");
81+
kwd.add("new");
82+
kwd.add("return");
83+
kwd.add("super");
84+
kwd.add("switch");
85+
kwd.add("this");
86+
kwd.add("throw");
87+
kwd.add("try");
88+
kwd.add("typeof");
89+
kwd.add("var");
90+
kwd.add("void");
91+
kwd.add("while");
92+
kwd.add("with");
93+
kwd.add("yield");
94+
95+
// future reserved
96+
kwd.add("enum");
97+
98+
// strict future reserved
99+
kwd.add("implements");
100+
kwd.add("interface");
101+
kwd.add("let");
102+
kwd.add("package");
103+
kwd.add("private");
104+
kwd.add("protected");
105+
kwd.add("public");
106+
kwd.add("static");
107+
108+
// TypeScript, Version Unknown
109+
kwd.add("any");
110+
// "await" also in ECMA-262.
111+
kwd.add("boolean");
112+
kwd.add("number");
113+
kwd.add("string");
114+
kwd.add("symbol");
115+
kwd.add("abstract");
116+
kwd.add("as");
117+
kwd.add("async");
118+
kwd.add("constructor");
119+
kwd.add("declare");
120+
kwd.add("from");
121+
kwd.add("get");
122+
kwd.add("is");
123+
kwd.add("module");
124+
kwd.add("namespace");
125+
kwd.add("of");
126+
kwd.add("require");
127+
kwd.add("set");
128+
kwd.add("Symbol"); // symbol constructor is Symbol()
129+
kwd.add("type");
130+
kwd.add("undefined");
131+
// TypeScript, Version 2.0
132+
kwd.add("never");
133+
// TypeScript, Version 2.1
134+
kwd.add("keyof");
135+
// TypeScript, Version 2.2
136+
kwd.add("object");
137+
// TypeScript, Version 3.0
138+
kwd.add("unknown");
139+
// TypeScript, Version 3.2
140+
kwd.add("bigint");
141+
}
142+
143+
private Consts() {
144+
}
145+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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, 2019, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2017-2019, Chris Fraire <[email protected]>.
23+
*/
24+
package org.opengrok.indexer.analysis.typescript;
25+
26+
import org.opengrok.indexer.analysis.AbstractAnalyzer;
27+
import org.opengrok.indexer.analysis.AnalyzerFactory;
28+
import org.opengrok.indexer.analysis.JFlexTokenizer;
29+
import org.opengrok.indexer.analysis.JFlexXref;
30+
import org.opengrok.indexer.analysis.plain.AbstractSourceCodeAnalyzer;
31+
32+
import java.io.Reader;
33+
34+
/**
35+
* Represents an analyzer for the TypeScript language.
36+
*/
37+
public class TypeScriptAnalyzer extends AbstractSourceCodeAnalyzer {
38+
39+
/**
40+
* Creates a new instance of {@link TypeScriptAnalyzer}.
41+
* @param factory defined instance for the analyzer
42+
*/
43+
TypeScriptAnalyzer(AnalyzerFactory factory) {
44+
super(factory, new JFlexTokenizer(new TypeScriptSymbolTokenizer(
45+
AbstractAnalyzer.DUMMY_READER)));
46+
}
47+
48+
/**
49+
* Gets a version number to be used to tag processed documents so that
50+
* re-analysis can be re-done later if a stored version number is different
51+
* from the current implementation.
52+
* @return 20191006_00
53+
*/
54+
@Override
55+
protected int getSpecializedVersionNo() {
56+
return 20191006_00; // Edit comment above too!
57+
}
58+
59+
/**
60+
* Creates a wrapped {@link TypeScriptXref} instance.
61+
* @param reader the data to produce xref for
62+
* @return a defined instance
63+
*/
64+
@Override
65+
protected JFlexXref newXref(Reader reader) {
66+
return new JFlexXref(new TypeScriptXref(reader));
67+
}
68+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2017, 2019, Chris Fraire <[email protected]>.
23+
*/
24+
25+
package org.opengrok.indexer.analysis.typescript;
26+
27+
import org.opengrok.indexer.analysis.AbstractAnalyzer;
28+
import org.opengrok.indexer.analysis.FileAnalyzerFactory;
29+
30+
public class TypeScriptAnalyzerFactory extends FileAnalyzerFactory {
31+
32+
private static final String name = "TypeScript";
33+
34+
private static final String[] SUFFIXES = {"TS"};
35+
36+
public TypeScriptAnalyzerFactory() {
37+
super(null, null, SUFFIXES, null, null, "text/plain", AbstractAnalyzer.Genre.PLAIN, name);
38+
}
39+
40+
@Override
41+
protected AbstractAnalyzer newAnalyzer() {
42+
return new TypeScriptAnalyzer(this);
43+
}
44+
}

0 commit comments

Comments
 (0)