Skip to content

Commit 2ace4dd

Browse files
committed
support json analyzer, javascript now recognizes angular ts
1 parent 14bce55 commit 2ace4dd

File tree

11 files changed

+474
-15
lines changed

11 files changed

+474
-15
lines changed

build.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
264264
<run-jflex dir="${gen.analysis.dir}/kotlin" name="KotlinXref"/>
265265
<!-- Swift tokenizer is below and has disabled buffer -->
266266
<run-jflex dir="${gen.analysis.dir}/swift" name="SwiftXref"/>
267+
<!-- Swift tokenizer is below and has disabled buffer -->
268+
<run-jflex dir="${gen.analysis.dir}/json" name="JsonXref"/>
267269

268270
<!-- just those 4 below will not increase buffer size beyond lucene token limits -->
269271
<run-jflex-and-disable-buffer-expansion dir="${gen.analysis.dir}/plain" name="PlainFullTokenizer"/>
@@ -272,6 +274,7 @@ Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
272274
<run-jflex-and-disable-buffer-expansion dir="${gen.analysis.dir}/java" name="JavaSymbolTokenizer"/>
273275
<run-jflex-and-disable-buffer-expansion dir="${gen.analysis.dir}/kotlin" name="KotlinSymbolTokenizer"/>
274276
<run-jflex-and-disable-buffer-expansion dir="${gen.analysis.dir}/swift" name="SwiftSymbolTokenizer"/>
277+
<run-jflex-and-disable-buffer-expansion dir="${gen.analysis.dir}/json" name="JsonSymbolTokenizer"/>
275278

276279
<!-- old analysers that will produce tokens > 32766 chars, since they have the buffer increase code in -->
277280
<!--
@@ -281,6 +284,7 @@ Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
281284
<run-jflex dir="${gen.analysis.dir}/java" name="JavaSymbolTokenizer"/>
282285
<run-jflex dir="${gen.analysis.dir}/kotlin" name="KotlinSymbolTokenizer"/>
283286
<run-jflex dir="${gen.analysis.dir}/swift" name="SwiftSymbolTokenizer"/>
287+
<run-jflex dir="${gen.analysis.dir}/swift" name="JsonSymbolTokenizer"/>
284288
-->
285289

286290
<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
@@ -79,6 +79,7 @@
7979
import org.opensolaris.opengrok.analysis.rust.RustAnalyzerFactory;
8080
import org.opensolaris.opengrok.analysis.scala.ScalaAnalyzerFactory;
8181
import org.opensolaris.opengrok.analysis.clojure.ClojureAnalyzerFactory;
82+
import org.opensolaris.opengrok.analysis.json.JsonAnalyzerFactory;
8283
import org.opensolaris.opengrok.analysis.kotlin.KotlinAnalyzerFactory;
8384
import org.opensolaris.opengrok.analysis.sh.ShAnalyzerFactory;
8485
import org.opensolaris.opengrok.analysis.sql.PLSQLAnalyzerFactory;
@@ -182,6 +183,7 @@ public class AnalyzerGuru {
182183
new JavaScriptAnalyzerFactory(),
183184
new KotlinAnalyzerFactory(),
184185
new SwiftAnalyzerFactory(),
186+
new JsonAnalyzerFactory(),
185187
new PythonAnalyzerFactory(),
186188
new RustAnalyzerFactory(),
187189
new PerlAnalyzerFactory(),

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

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ private void initialize() throws IOException {
112112
command.add("--langmap=sql:+.pld"); // RFE #19208
113113
command.add("--langmap=sql:+.pks"); // RFE #19208 ?
114114

115+
command.add("--langmap=javascript:+.ts");
116+
115117
//Ideally all below should be in ctags, or in outside config file,
116118
//we might run out of command line SOON
117119
//Also note, that below ctags definitions HAVE to be in POSIX
@@ -191,18 +193,23 @@ private void initialize() throws IOException {
191193
command.add("--regex-swift=/(var|let)[[:space:]]+([^:=]+).*$/\\2/v,variable,variables/");
192194
command.add("--regex-swift=/^[[:space:]]*extension[[:space:]]+([^:\\{]+).*$/\\1/e,extension,extensions/");
193195

194-
command.add("--langdef=pascal");
195-
command.add("--langmap=pascal:+.pas");
196-
command.add("--regex-pascal=/([[:alnum:]_]+)[[:space:]]*=[[:space:]]*\\([[:space:]]*[[:alnum:]_][[:space:]]*\\)/\\1/t,Type/");
197-
command.add("--regex-pascal=/([[:alnum:]_]+)[[:space:]]*=[[:space:]]*class[[:space:]]*[^;]*$/\\1/c,Class/");
198-
command.add("--regex-pascal=/([[:alnum:]_]+)[[:space:]]*=[[:space:]]*interface[[:space:]]*[^;]*$/\\1/i,interface/");
199-
command.add("--regex-pascal=/^constructor[[:space:]]+(T[a-zA-Z0-9_]+(<[a-zA-Z0-9_, ]+>)?\\.)([a-zA-Z0-9_<>, ]+)(.*)+/\\1\\3/n,Constructor/");
200-
command.add("--regex-pascal=/^destructor[[:space:]]+(T[a-zA-Z0-9_]+(<[a-zA-Z0-9_, ]+>)?\\.)([a-zA-Z0-9_<>, ]+)(.*)+/\\1\\3/d,Destructor/");
201-
command.add("--regex-pascal=/^(procedure)[[:space:]]+T[a-zA-Z0-9_<>, ]+\\.([a-zA-Z0-9_<>, ]+)(.*)/\\2/p,procedure/");
202-
command.add("--regex-pascal=/^(function)[[:space:]]+T[a-zA-Z0-9_<>, ]+\\.([a-zA-Z0-9_<>, ]+)(.*)/\\2/f,function/");
203-
command.add("--regex-pascal=/^[[:space:]]*property[[:space:]]+([a-zA-Z0-9_<>, ]+)[[:space:]]*\\:(.*)/\\1/o,property/");
204-
command.add("--regex-pascal=/^(uses|interface|implementation)$/\\1/s,Section/");
205-
command.add("--regex-pascal=/^unit[[:space:]]+([a-zA-Z0-9_<>, ]+)[;(]/\\1/u,unit/");
196+
/*
197+
--langdef=scss
198+
--langmap=scss:.scss
199+
--regex-scss=/^[ \t]*([^\t {][^{]{1,100})(\t| )*\{/| \1/d,definition/
200+
201+
// css is supported by universal ctags
202+
--langdef=css
203+
--langmap=css:.css
204+
--langmap=css:+.scss
205+
--langmap=css:+.sass
206+
--langmap=css:+.styl
207+
--langmap=css:+.less
208+
--regex-css=/^[ \t]*(([A-Za-z0-9_-]+[ \t\n,]+)+)\{/\1/t,tag,tags/
209+
--regex-css=/^[ \t]*#([A-Za-z0-9_-]+)/#\1/i,id,ids/
210+
--regex-css=/^[ \t]*\.([A-Za-z0-9_-]+)/.\1/c,class,classes/
211+
212+
*/
206213

207214
command.add("--langdef=rust");
208215
command.add("--langmap=rust:+.rs");
@@ -216,7 +223,20 @@ private void initialize() throws IOException {
216223
command.add("--regex-rust=/^[[:space:]]*(pub[[:space:]]+)?(unsafe[[:space:]]+)?impl([[:space:]\n]*<[^>]*>)?[[:space:]]+(([[:alnum:]_:]+)[[:space:]]*(<[^>]*>)?[[:space:]]+(for)[[:space:]]+)?([[:alnum:]_]+)/\\5 \\7 \\8/I,impls,trait implementations/");
217224
command.add("--regex-rust=/^[[:space:]]*macro_rules![[:space:]]+([[:alnum:]_]+)/\\1/d,macros,macro definitions/");
218225
command.add("--regex-rust=/^[[:space:]]*let[[:space:]]+(mut)?[[:space:]]+([[:alnum:]_]+)/\\2/V,variables/");
219-
226+
227+
command.add("--langdef=pascal");
228+
command.add("--langmap=pascal:+.pas");
229+
command.add("--regex-pascal=/([[:alnum:]_]+)[[:space:]]*=[[:space:]]*\\([[:space:]]*[[:alnum:]_][[:space:]]*\\)/\\1/t,Type/");
230+
command.add("--regex-pascal=/([[:alnum:]_]+)[[:space:]]*=[[:space:]]*class[[:space:]]*[^;]*$/\\1/c,Class/");
231+
command.add("--regex-pascal=/([[:alnum:]_]+)[[:space:]]*=[[:space:]]*interface[[:space:]]*[^;]*$/\\1/i,interface/");
232+
command.add("--regex-pascal=/^constructor[[:space:]]+(T[a-zA-Z0-9_]+(<[a-zA-Z0-9_, ]+>)?\\.)([a-zA-Z0-9_<>, ]+)(.*)+/\\1\\3/n,Constructor/");
233+
command.add("--regex-pascal=/^destructor[[:space:]]+(T[a-zA-Z0-9_]+(<[a-zA-Z0-9_, ]+>)?\\.)([a-zA-Z0-9_<>, ]+)(.*)+/\\1\\3/d,Destructor/");
234+
command.add("--regex-pascal=/^(procedure)[[:space:]]+T[a-zA-Z0-9_<>, ]+\\.([a-zA-Z0-9_<>, ]+)(.*)/\\2/p,procedure/");
235+
command.add("--regex-pascal=/^(function)[[:space:]]+T[a-zA-Z0-9_<>, ]+\\.([a-zA-Z0-9_<>, ]+)(.*)/\\2/f,function/");
236+
command.add("--regex-pascal=/^[[:space:]]*property[[:space:]]+([a-zA-Z0-9_<>, ]+)[[:space:]]*\\:(.*)/\\1/o,property/");
237+
command.add("--regex-pascal=/^(uses|interface|implementation)$/\\1/s,Section/");
238+
command.add("--regex-pascal=/^unit[[:space:]]+([a-zA-Z0-9_<>, ]+)[;(]/\\1/u,unit/");
239+
220240
//PLEASE add new languages ONLY with POSIX syntax (see above wiki link)
221241

222242
/* Add extra command line options for ctags. */

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
* * ECMA-262 5.1 Edition June 2011
3333
*
3434
*/
35+
36+
//TODO update to latest ecmascript ... (for angular support)
3537
public class Consts{
3638
public static final Set<String> kwd = new HashSet<String>() ;
3739
static {

src/org/opensolaris/opengrok/analysis/javascript/JavaScriptAnalyzerFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323

2424
package org.opensolaris.opengrok.analysis.javascript;
@@ -38,7 +38,8 @@ public class JavaScriptAnalyzerFactory extends FileAnalyzerFactory {
3838
private static final String name = "JavaScript";
3939

4040
private static final String[] SUFFIXES = {
41-
"JS"
41+
"JS",
42+
"TS"
4243
};
4344

4445
private static final String[] MAGICS = {
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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.json;
24+
25+
import java.util.HashSet;
26+
import java.util.Set;
27+
28+
/**
29+
* Holds static hash set containing the Json (schema) keywords
30+
*
31+
*/
32+
public class Consts {
33+
34+
public static final Set<String> kwd = new HashSet<String>();
35+
36+
static {
37+
kwd.add("true");
38+
kwd.add("false");
39+
kwd.add("null");
40+
41+
//TODO below applies ONLY for schema - detect this is a schema and use keywords, not otherwise
42+
//json as such has no keywords
43+
44+
/*
45+
kwd.add("title");
46+
kwd.add("description");
47+
kwd.add("default");
48+
kwd.add("enum");
49+
kwd.add("Boolean");
50+
51+
string
52+
pattern
53+
format
54+
date-time email
55+
hostname ipv4
56+
ipv6 uri
57+
integer number
58+
multipleOf minimum, maximum, exclusiveMinimum and exclusiveMaximum
59+
object properties
60+
additionalProperties required
61+
minProperties maxProperties
62+
dependencies
63+
...
64+
array...
65+
boolean...
66+
null...
67+
*/
68+
69+
}
70+
}
Lines changed: 61 additions & 0 deletions
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+
20+
/*
21+
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
package org.opensolaris.opengrok.analysis.json;
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+
*/
41+
public class JsonAnalyzer extends AbstractSourceCodeAnalyzer {
42+
43+
/**
44+
* Creates a new instance of JavaAnalyzer
45+
* @param factory factory for this analyzer
46+
*/
47+
protected JsonAnalyzer(FileAnalyzerFactory factory) {
48+
super(factory);
49+
SymbolTokenizer=new JsonSymbolTokenizer(FileAnalyzer.dummyReader);
50+
}
51+
52+
@Override
53+
protected JFlexXref newXref(Reader reader) {
54+
return new JsonXref(reader);
55+
}
56+
57+
static void writeXref(Reader in, Writer out, Definitions defs, Annotation annotation, Project project) throws IOException {
58+
JsonXref xref = new JsonXref(in);
59+
AbstractSourceCodeAnalyzer.writeXref(xref, in, out, defs, annotation, project);
60+
}
61+
}
Lines changed: 61 additions & 0 deletions
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+
20+
/*
21+
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
24+
package org.opensolaris.opengrok.analysis.json;
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 JsonAnalyzerFactory extends FileAnalyzerFactory {
37+
// TODO add schema support
38+
private static final String name = "Json";
39+
40+
private static final String[] SUFFIXES = {
41+
"JSON"
42+
};
43+
44+
private static final String[] MAGICS = {
45+
};
46+
47+
public JsonAnalyzerFactory() {
48+
super(null, null, SUFFIXES, MAGICS, null, "text/plain", Genre.PLAIN, name);
49+
}
50+
51+
@Override
52+
protected FileAnalyzer newAnalyzer() {
53+
return new JsonAnalyzer(this);
54+
}
55+
56+
@Override
57+
public void writeXref(Reader in, Writer out, Definitions defs, Annotation annotation, Project project)
58+
throws IOException {
59+
JsonAnalyzer.writeXref(in, out, defs, annotation, project);
60+
}
61+
}

0 commit comments

Comments
 (0)