Skip to content

Commit 07aff55

Browse files
authored
Merge pull request #2957 from idodeclare/feature/typescript
Feature/typescript
2 parents 81c77aa + d26116b commit 07aff55

31 files changed

+1910
-272
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: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
22+
* Portions Copyright (c) 2017-2019, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.analysis;
2525

@@ -137,9 +137,6 @@ private void initialize() throws IOException {
137137
command.add(binary);
138138
command.add("--c-kinds=+l");
139139

140-
command.add("--langmap=clojure:+.cljs");
141-
command.add("--langmap=clojure:+.cljx");
142-
143140
// Workaround for bug #14924: Don't get local variables in Java
144141
// code since that creates many false positives.
145142
// CtagsTest : bug14924 "too many methods" guards for this
@@ -163,8 +160,6 @@ private void initialize() throws IOException {
163160
command.add("--langmap=sql:+.pkb"); // # 1763
164161
command.add("--langmap=sql:+.pck"); // # 1763
165162

166-
command.add("--langmap=javascript:+.ts");
167-
168163
//Ideally all below should be in ctags, or in outside config file,
169164
//we might run out of command line SOON
170165
//Also note, that below ctags definitions HAVE to be in POSIX
@@ -319,6 +314,8 @@ private void addKotlinSupport(List<String> command) {
319314
private void addClojureSupport(List<String> command) {
320315
command.add("--langdef=clojure"); // clojure support (patterns are from https://gist.github.com/kul/8704283)
321316
command.add("--langmap=clojure:+.clj");
317+
command.add("--langmap=clojure:+.cljs");
318+
command.add("--langmap=clojure:+.cljx");
322319

323320
command.add("--regex-clojure=/\\([[:space:]]*create-ns[[:space:]]+([-[:alnum:]*+!_:\\/.?]+)/\\1/n,namespace/");
324321
command.add("--regex-clojure=/\\([[:space:]]*def[[:space:]]+([-[:alnum:]*+!_:\\/.?]+)/\\1/d,definition/");

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

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,26 @@
1919

2020
/*
2121
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2019, Chris Fraire <[email protected]>.
2223
*/
2324

2425
package org.opengrok.indexer.analysis.javascript;
2526

27+
import java.util.Collections;
2628
import java.util.HashSet;
2729
import java.util.Set;
2830

2931
/**
30-
* Holds static hash set containing the JavaScript keywords.
31-
*
32-
* ECMA-262 5.1 Edition June 2011
32+
* Holds JavaScript keywords from ECMA-262 10th Edition, June 2019.
3333
*/
34-
//TODO update to latest ecmascript ... (for angular support)
3534
public class Consts {
3635

37-
public static final Set<String> kwd = new HashSet<>();
36+
private static final Set<String> kwd = new HashSet<>();
37+
38+
public static final Set<String> KEYWORDS = Collections.unmodifiableSet(kwd);
39+
3840
static {
39-
//constants
41+
// literals
4042
kwd.add("true");
4143
kwd.add("false");
4244
kwd.add("null");
@@ -45,29 +47,37 @@ public class Consts {
4547
kwd.add("Boolean");
4648
kwd.add("Date");
4749
kwd.add("Function");
50+
kwd.add("Infinity"); // ECMA-262, 10th edition, June 2019
4851
kwd.add("Math");
4952
kwd.add("Number");
5053
kwd.add("Object");
5154
kwd.add("RegExp");
5255
kwd.add("String");
5356
//keywords
57+
kwd.add("await"); // ECMA-262, 10th edition, June 2019
5458
kwd.add("break");
5559
kwd.add("case");
5660
kwd.add("catch");
61+
kwd.add("class");
62+
kwd.add("const");
5763
kwd.add("continue");
5864
kwd.add("debugger");
5965
kwd.add("default");
6066
kwd.add("delete");
6167
kwd.add("do");
6268
kwd.add("else");
69+
kwd.add("export");
70+
kwd.add("extends");
6371
kwd.add("finally");
6472
kwd.add("for");
6573
kwd.add("function");
6674
kwd.add("if");
6775
kwd.add("in");
6876
kwd.add("instanceof");
77+
kwd.add("import");
6978
kwd.add("new");
7079
kwd.add("return");
80+
kwd.add("super");
7181
kwd.add("switch");
7282
kwd.add("this");
7383
kwd.add("throw");
@@ -77,14 +87,9 @@ public class Consts {
7787
kwd.add("void");
7888
kwd.add("while");
7989
kwd.add("with");
90+
kwd.add("yield");
8091
//future reserved
81-
kwd.add("class");
82-
kwd.add("const");
8392
kwd.add("enum");
84-
kwd.add("export");
85-
kwd.add("extends");
86-
kwd.add("import");
87-
kwd.add("super");
8893
//strict future reserved
8994
kwd.add("implements");
9095
kwd.add("interface");
@@ -94,10 +99,8 @@ public class Consts {
9499
kwd.add("protected");
95100
kwd.add("public");
96101
kwd.add("static");
97-
kwd.add("yield");
98102
}
99103

100-
private Consts() {
104+
protected Consts() {
101105
}
102-
103106
}

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

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

2020
/*
2121
* Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
22+
* Portions Copyright (c) 2017-2019, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.analysis.javascript;
2525

@@ -50,11 +50,11 @@ protected JavaScriptAnalyzer(AnalyzerFactory factory) {
5050
* Gets a version number to be used to tag processed documents so that
5151
* re-analysis can be re-done later if a stored version number is different
5252
* from the current implementation.
53-
* @return 20190217_00
53+
* @return 20191006_00
5454
*/
5555
@Override
5656
protected int getSpecializedVersionNo() {
57-
return 20190217_00; // Edit comment above too!
57+
return 20191006_00; // Edit comment above too!
5858
}
5959

6060
/**

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: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
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, 2019, Chris Fraire <[email protected]>.
22+
*/
23+
24+
package org.opengrok.indexer.analysis.javascript;
25+
26+
import org.opengrok.indexer.analysis.JFlexJointLexer;
27+
import org.opengrok.indexer.analysis.JFlexSymbolMatcher;
28+
import org.opengrok.indexer.analysis.Resettable;
29+
import org.opengrok.indexer.web.HtmlConsts;
30+
31+
import java.io.IOException;
32+
import java.util.Stack;
33+
34+
/**
35+
* Represents an abstract base class for JavaScript lexers.
36+
*/
37+
@SuppressWarnings("Duplicates")
38+
public abstract class JavaScriptLexer extends JFlexSymbolMatcher
39+
implements JFlexJointLexer, Resettable {
40+
41+
private ECMAScriptLexerData data;
42+
43+
/**
44+
* Represents the stack of data if substitution is nested.
45+
*/
46+
private Stack<ECMAScriptLexerData> dataStack;
47+
48+
public JavaScriptLexer() {
49+
data = new ECMAScriptLexerData();
50+
// dataStack is null to begin.
51+
}
52+
53+
/**
54+
* Resets the instance to an initial state.
55+
*/
56+
@Override
57+
public void reset() {
58+
super.reset();
59+
data = new ECMAScriptLexerData();
60+
if (dataStack != null) {
61+
dataStack.clear();
62+
}
63+
}
64+
65+
/**
66+
* Calls {@link #phLOC()} if the yystate is not COMMENT or SCOMMENT.
67+
*/
68+
public void chkLOC() {
69+
if (yystate() != COMMENT() && yystate() != SCOMMENT()) {
70+
phLOC();
71+
}
72+
}
73+
74+
/**
75+
* Resets the substitution brace counter to 1.
76+
*/
77+
protected void substitutionOp() {
78+
data.nEndBrace = 1;
79+
}
80+
81+
/**
82+
* Determine if template substitution should end based on the first
83+
* character of {@code capture}, and also recognizing tokens that increase
84+
* the nesting level alternatively.
85+
* <p>
86+
* Calling this method has side effects to possibly modify
87+
* {@code nEndBrace}.
88+
* @return {@code true} if the substitution state does not end
89+
*/
90+
protected boolean notInTemplateOrSubstitutionDoesNotEnd(String capture) throws IOException {
91+
if (data.nEndBrace <= 0) {
92+
return true;
93+
}
94+
if (capture.startsWith("}")) {
95+
if (--data.nEndBrace <= 0) {
96+
int nRemaining = capture.length() - 1;
97+
String opener = capture.substring(0, 1);
98+
popData();
99+
yypop();
100+
disjointSpan(HtmlConsts.STRING_CLASS);
101+
offer(opener);
102+
if (nRemaining > 0) {
103+
yypushback(nRemaining);
104+
}
105+
return false;
106+
}
107+
}
108+
if (capture.startsWith("{")) {
109+
++data.nEndBrace;
110+
}
111+
return true;
112+
}
113+
114+
protected void pushData() {
115+
if (dataStack == null) {
116+
dataStack = new Stack<>();
117+
}
118+
dataStack.push(data);
119+
data = new ECMAScriptLexerData();
120+
}
121+
122+
private void popData() {
123+
data = dataStack.pop();
124+
}
125+
126+
/**
127+
* Subclasses must override to get the constant value created by JFlex to
128+
* represent COMMENT.
129+
*/
130+
protected abstract int COMMENT();
131+
132+
/**
133+
* Subclasses must override to get the constant value created by JFlex to
134+
* represent SCOMMENT.
135+
*/
136+
protected abstract int SCOMMENT();
137+
138+
private static class ECMAScriptLexerData {
139+
/**
140+
* When interpolating inside `` with ${, the number of remaining '}'
141+
* characters is stored. It starts at 1, and any nesting increases the
142+
* value.
143+
*/
144+
int nEndBrace;
145+
}
146+
}

0 commit comments

Comments
 (0)