Skip to content

Commit 8a86b9c

Browse files
authored
Merge pull request #1905 from idodeclare/feature/vb_tests
Feature/vb tests
2 parents 91d0e02 + 5f56799 commit 8a86b9c

File tree

14 files changed

+1930
-216
lines changed

14 files changed

+1930
-216
lines changed

opengrok-indexer/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
158158
<exclude>*.java</exclude>
159159
</excludes>
160160
</testResource>
161+
<testResource>
162+
<targetPath>org/opensolaris/opengrok/analysis/vb/</targetPath>
163+
<directory>../test/org/opensolaris/opengrok/analysis/vb/</directory>
164+
<excludes>
165+
<exclude>*.java</exclude>
166+
</excludes>
167+
</testResource>
161168
</testResources>
162169

163170
<plugins>

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

Lines changed: 168 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,54 +19,193 @@
1919

2020
/*
2121
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
2223
*/
2324
package org.opensolaris.opengrok.analysis.vb;
2425

25-
import java.io.BufferedReader;
26-
import java.io.IOException;
27-
import java.io.InputStreamReader;
2826
import java.util.Collections;
2927
import java.util.HashSet;
30-
import java.util.Locale;
3128
import java.util.Set;
3229

3330
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
3431
public final class Consts {
3532

36-
private static final Set<String> reservedKeywords;
33+
public static final Set<String> reservedKeywords;
34+
public static final Set<String> directives;
3735

3836
static {
39-
HashSet<String> kwds = new HashSet<String>();
40-
try {
41-
42-
populateKeywordSet(kwds, "vbReservedWords.dat");
43-
} catch (IOException ioe) {
44-
throw new RuntimeException(ioe);
45-
}
37+
HashSet<String> kwds = new HashSet<>();
38+
populateKeywordSet(kwds);
4639
reservedKeywords = Collections.unmodifiableSet(kwds);
40+
41+
HashSet<String> hashwords = new HashSet<>();
42+
hashwords.add("#const"); // VB lang-reference/keywords
43+
hashwords.add("#else"); // VB lang-reference/keywords
44+
hashwords.add("#elseif"); // VB lang-reference/keywords
45+
hashwords.add("#end"); // VB lang-reference/keywords
46+
hashwords.add("#if"); // VB lang-reference/keywords
47+
directives = Collections.unmodifiableSet(hashwords);
4748
}
4849

4950
private Consts() {
5051
// Util class, can not be constructed.
5152
}
5253

53-
private static void populateKeywordSet(Set<String> set, String file)
54-
throws IOException {
55-
String line, lline;
56-
try (BufferedReader reader = new BufferedReader(new InputStreamReader(
57-
Consts.class.getResourceAsStream(file), "US-ASCII"))) {
58-
while ((line = reader.readLine()) != null) {
59-
line = line.trim();
60-
lline = line.toLowerCase(Locale.US);
61-
if (line.charAt(0) != '#') {
62-
set.add(line);
63-
set.add(lline);
64-
}
65-
}
66-
}
67-
}
54+
private static void populateKeywordSet(Set<String> kwd) {
55+
kwd.clear();
56+
kwd.add("addhandler"); // Original vb.Consts but now l-case
57+
kwd.add("addressof"); // Original vb.Consts but now l-case
58+
kwd.add("alias"); // Original vb.Consts but now l-case
59+
kwd.add("and"); // Original vb.Consts but now l-case
60+
kwd.add("andalso"); // Original vb.Consts but now l-case
61+
kwd.add("as"); // Original vb.Consts but now l-case
62+
kwd.add("boolean"); // Original vb.Consts but now l-case
63+
kwd.add("byref"); // Original vb.Consts but now l-case
64+
kwd.add("byte"); // Original vb.Consts but now l-case
65+
kwd.add("byval"); // Original vb.Consts but now l-case
66+
kwd.add("call"); // Original vb.Consts but now l-case
67+
kwd.add("case"); // Original vb.Consts but now l-case
68+
kwd.add("catch"); // Original vb.Consts but now l-case
69+
kwd.add("cbool"); // Original vb.Consts but now l-case
70+
kwd.add("cbyte"); // Original vb.Consts but now l-case
71+
kwd.add("cchar"); // Original vb.Consts but now l-case
72+
kwd.add("cdate"); // Original vb.Consts but now l-case
73+
kwd.add("cdec"); // Original vb.Consts but now l-case
74+
kwd.add("cdbl"); // Original vb.Consts but now l-case
75+
kwd.add("char"); // Original vb.Consts but now l-case
76+
kwd.add("cint"); // Original vb.Consts but now l-case
77+
kwd.add("class"); // Original vb.Consts but now l-case
78+
kwd.add("clng"); // Original vb.Consts but now l-case
79+
kwd.add("cobj"); // Original vb.Consts but now l-case
80+
kwd.add("const"); // Original vb.Consts but now l-case
81+
kwd.add("continue"); // Original vb.Consts but now l-case
82+
kwd.add("csbyte"); // Original vb.Consts but now l-case
83+
kwd.add("cshort"); // Original vb.Consts but now l-case
84+
kwd.add("csng"); // Original vb.Consts but now l-case
85+
kwd.add("cstr"); // Original vb.Consts but now l-case
86+
kwd.add("ctype"); // Original vb.Consts but now l-case
87+
kwd.add("cuint"); // Original vb.Consts but now l-case
88+
kwd.add("culng"); // Original vb.Consts but now l-case
89+
kwd.add("cushort"); // Original vb.Consts but now l-case
90+
kwd.add("date"); // Original vb.Consts but now l-case
91+
kwd.add("decimal"); // Original vb.Consts but now l-case
92+
kwd.add("declare"); // Original vb.Consts but now l-case
93+
kwd.add("default"); // Original vb.Consts but now l-case
94+
kwd.add("delegate"); // Original vb.Consts but now l-case
95+
kwd.add("dim"); // Original vb.Consts but now l-case
96+
kwd.add("directcast"); // Original vb.Consts but now l-case
97+
kwd.add("do"); // Original vb.Consts but now l-case
98+
kwd.add("double"); // Original vb.Consts but now l-case
99+
kwd.add("each"); // Original vb.Consts but now l-case
100+
kwd.add("else"); // Original vb.Consts but now l-case
101+
kwd.add("elseif"); // Original vb.Consts but now l-case
102+
kwd.add("end"); // Original vb.Consts but now l-case
103+
kwd.add("endif"); // Original vb.Consts but now l-case
104+
kwd.add("enum"); // Original vb.Consts but now l-case
105+
kwd.add("erase"); // Original vb.Consts but now l-case
106+
kwd.add("error"); // Original vb.Consts but now l-case
107+
kwd.add("event"); // Original vb.Consts but now l-case
108+
kwd.add("exit"); // Original vb.Consts but now l-case
109+
kwd.add("false"); // Original vb.Consts but now l-case
110+
kwd.add("finally"); // Original vb.Consts but now l-case
111+
kwd.add("for"); // Original vb.Consts but now l-case
112+
kwd.add("friend"); // Original vb.Consts but now l-case
113+
kwd.add("function"); // Original vb.Consts but now l-case
114+
kwd.add("get"); // Original vb.Consts but now l-case
115+
kwd.add("gettype"); // Original vb.Consts but now l-case
116+
kwd.add("global"); // Original vb.Consts but now l-case
117+
kwd.add("gosub"); // Original vb.Consts but now l-case
118+
kwd.add("goto"); // Original vb.Consts but now l-case
119+
kwd.add("handles"); // Original vb.Consts but now l-case
120+
kwd.add("if"); // Original vb.Consts but now l-case
121+
kwd.add("implements"); // Original vb.Consts but now l-case
122+
kwd.add("imports"); // Original vb.Consts but now l-case
123+
kwd.add("in"); // Original vb.Consts but now l-case
124+
kwd.add("inherits"); // Original vb.Consts but now l-case
125+
kwd.add("integer"); // Original vb.Consts but now l-case
126+
kwd.add("interface"); // Original vb.Consts but now l-case
127+
kwd.add("is"); // Original vb.Consts but now l-case
128+
kwd.add("isnot"); // Original vb.Consts but now l-case
129+
kwd.add("let"); // Original vb.Consts but now l-case
130+
kwd.add("lib"); // Original vb.Consts but now l-case
131+
kwd.add("like"); // Original vb.Consts but now l-case
132+
kwd.add("long"); // Original vb.Consts but now l-case
133+
kwd.add("loop"); // Original vb.Consts but now l-case
134+
kwd.add("me"); // Original vb.Consts but now l-case
135+
kwd.add("mod"); // Original vb.Consts but now l-case
136+
kwd.add("module"); // Original vb.Consts but now l-case
137+
kwd.add("mustinherit"); // Original vb.Consts but now l-case
138+
kwd.add("mustoverride"); // Original vb.Consts but now l-case
139+
kwd.add("mybase"); // Original vb.Consts but now l-case
140+
kwd.add("myclass"); // Original vb.Consts but now l-case
141+
kwd.add("namespace"); // Original vb.Consts but now l-case
142+
kwd.add("narrowing"); // Original vb.Consts but now l-case
143+
kwd.add("new"); // Original vb.Consts but now l-case
144+
kwd.add("next"); // Original vb.Consts but now l-case
145+
kwd.add("not"); // Original vb.Consts but now l-case
146+
kwd.add("nothing"); // Original vb.Consts but now l-case
147+
kwd.add("notinheritable"); // Original vb.Consts but now l-case
148+
kwd.add("notoverridable"); // Original vb.Consts but now l-case
149+
kwd.add("object"); // Original vb.Consts but now l-case
150+
kwd.add("of"); // Original vb.Consts but now l-case
151+
kwd.add("on"); // Original vb.Consts but now l-case
152+
kwd.add("operator"); // Original vb.Consts but now l-case
153+
kwd.add("option"); // Original vb.Consts but now l-case
154+
kwd.add("optional"); // Original vb.Consts but now l-case
155+
kwd.add("or"); // Original vb.Consts but now l-case
156+
kwd.add("orelse"); // Original vb.Consts but now l-case
157+
kwd.add("overloads"); // Original vb.Consts but now l-case
158+
kwd.add("overridable"); // Original vb.Consts but now l-case
159+
kwd.add("overrides"); // Original vb.Consts but now l-case
160+
kwd.add("paramarray"); // Original vb.Consts but now l-case
161+
kwd.add("partial"); // Original vb.Consts but now l-case
162+
kwd.add("private"); // Original vb.Consts but now l-case
163+
kwd.add("property"); // Original vb.Consts but now l-case
164+
kwd.add("protected"); // Original vb.Consts but now l-case
165+
kwd.add("public"); // Original vb.Consts but now l-case
166+
kwd.add("raiseevent"); // Original vb.Consts but now l-case
167+
kwd.add("readonly"); // Original vb.Consts but now l-case
168+
kwd.add("redim"); // Original vb.Consts but now l-case
169+
kwd.add("rem"); // Original vb.Consts but now l-case
170+
kwd.add("removehandler"); // Original vb.Consts but now l-case
171+
kwd.add("resume"); // Original vb.Consts but now l-case
172+
kwd.add("return"); // Original vb.Consts but now l-case
173+
kwd.add("sbyte"); // Original vb.Consts but now l-case
174+
kwd.add("select"); // Original vb.Consts but now l-case
175+
kwd.add("set"); // Original vb.Consts but now l-case
176+
kwd.add("shadows"); // Original vb.Consts but now l-case
177+
kwd.add("shared"); // Original vb.Consts but now l-case
178+
kwd.add("short"); // Original vb.Consts but now l-case
179+
kwd.add("single"); // Original vb.Consts but now l-case
180+
kwd.add("static"); // Original vb.Consts but now l-case
181+
kwd.add("step"); // Original vb.Consts but now l-case
182+
kwd.add("stop"); // Original vb.Consts but now l-case
183+
kwd.add("string"); // Original vb.Consts but now l-case
184+
kwd.add("structure"); // Original vb.Consts but now l-case
185+
kwd.add("sub"); // Original vb.Consts but now l-case
186+
kwd.add("synclock"); // Original vb.Consts but now l-case
187+
kwd.add("then"); // Original vb.Consts but now l-case
188+
kwd.add("throw"); // Original vb.Consts but now l-case
189+
kwd.add("to"); // Original vb.Consts but now l-case
190+
kwd.add("true"); // Original vb.Consts but now l-case
191+
kwd.add("try"); // Original vb.Consts but now l-case
192+
kwd.add("trycast"); // Original vb.Consts but now l-case
193+
kwd.add("typeof"); // Original vb.Consts but now l-case
194+
kwd.add("variant"); // Original vb.Consts but now l-case
195+
kwd.add("wend"); // Original vb.Consts but now l-case
196+
kwd.add("uinteger"); // Original vb.Consts but now l-case
197+
kwd.add("ulong"); // Original vb.Consts but now l-case
198+
kwd.add("ushort"); // Original vb.Consts but now l-case
199+
kwd.add("using"); // Original vb.Consts but now l-case
200+
kwd.add("when"); // Original vb.Consts but now l-case
201+
kwd.add("while"); // Original vb.Consts but now l-case
202+
kwd.add("widening"); // Original vb.Consts but now l-case
203+
kwd.add("with"); // Original vb.Consts but now l-case
204+
kwd.add("withevents"); // Original vb.Consts but now l-case
205+
kwd.add("writeonly"); // Original vb.Consts but now l-case
206+
kwd.add("xor"); // Original vb.Consts but now l-case
68207

69-
static Set<String> getReservedKeywords() {
70-
return reservedKeywords;
208+
kwd.add("getxmlnamespace"); // VB lang-reference/keywords l-case
209+
kwd.add("out"); // VB lang-reference/keywords l-case
71210
}
72211
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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, 2016, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
23+
*
24+
* ##Legal Notices
25+
* Microsoft and any contributors grant you a license to the Microsoft documentation and other content
26+
* in this repository under the [Creative Commons Attribution 4.0 International Public License](https://creativecommons.org/licenses/by/4.0/legalcode),
27+
* see the [LICENSE](LICENSE) file, and grant you a license to any code in the repository under the [MIT License](https://opensource.org/licenses/MIT), see the
28+
* [LICENSE-CODE](LICENSE-CODE) file.
29+
*
30+
* Microsoft, Windows, Microsoft Azure and/or other Microsoft products and services referenced in the documentation
31+
* may be either trademarks or registered trademarks of Microsoft in the United States and/or other countries.
32+
* The licenses for this project do not grant you rights to use any Microsoft names, logos, or trademarks.
33+
* Microsoft's general trademark guidelines can be found at http://go.microsoft.com/fwlink/?LinkID=254653.
34+
*
35+
* Privacy information can be found at https://privacy.microsoft.com/en-us/
36+
*
37+
* Microsoft and any contributors reserve all others rights, whether under their respective copyrights, patents,
38+
* or trademarks, whether by implication, estoppel or otherwise.
39+
*/
40+
41+
/*
42+
* For historical reasons, VBXref does not link identifiers of length=1
43+
*/
44+
Identifier = ([a-zA-Z] [a-zA-Z0-9_]* | [_] [a-zA-Z0-9_]+)
45+
46+
Number = [\-]? ({Numeric_integer} | {Numeric_fp} | {Hexadecimal} | {Binary} |
47+
{Octal}) {Literal_type_suffix}?
48+
DIGIT = [0-9]
49+
HEXDIG = [0-9A-Fa-f]
50+
BINDIG = [01]
51+
OCTDIG = [0-7]
52+
53+
/*
54+
* "Numeric, no fractional part"
55+
*/
56+
Numeric_integer = {DIGIT} ([_]* {DIGIT})*
57+
/*
58+
* "Numeric, fractional part"
59+
*/
60+
Numeric_fp = {Numeric_integer} "." {Numeric_integer}
61+
/*
62+
* "Hexadecimal (base 16)"
63+
*/
64+
Hexadecimal = [&][Hh] {HEXDIG} ([_]* {HEXDIG})*
65+
/*
66+
* "Binary (base 2)"
67+
*/
68+
Binary = [&][Bb] {BINDIG} ([_]* {BINDIG})*
69+
/*
70+
* "Octal (base 8)"
71+
*/
72+
Octal = [&][Oo] {OCTDIG} ([_]* {OCTDIG})*
73+
74+
/*
75+
* "Literal type character"
76+
*/
77+
Literal_type_suffix = ([Ss] | [Ii] | [Ll] | [Dd] | [Ff] | [Rr] | [Uu][IiLlSs] |
78+
[Cc] | "%" | "&" | "@" | "!" | "#" | "$")

src/org/opensolaris/opengrok/analysis/vb/VBSymbolTokenizer.lex

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,49 +23,53 @@
2323
*/
2424

2525
/*
26-
* Gets Java symbols - ignores comments, strings, keywords
26+
* Gets VB symbols - ignores comments, strings, keywords
2727
*/
2828

2929
package org.opensolaris.opengrok.analysis.vb;
30-
import java.io.IOException;
31-
import java.io.Reader;
32-
import org.opensolaris.opengrok.analysis.JFlexTokenizer;
3330

31+
import org.opensolaris.opengrok.analysis.JFlexTokenizer;
3432
%%
3533
%public
3634
%class VBSymbolTokenizer
3735
%extends JFlexTokenizer
3836
%unicode
37+
%ignorecase
3938
%init{
4039
super(in);
4140
%init}
4241
%int
4342
%include CommonTokenizer.lexh
4443
%char
4544

46-
Identifier = [a-zA-Z_] [a-zA-Z0-9_]*
47-
4845
%state STRING COMMENT
4946

47+
%include Common.lexh
48+
%include VB.lexh
5049
%%
5150

5251
<YYINITIAL> {
53-
{Identifier} {String id = yytext();
54-
if(!Consts.getReservedKeywords().contains(id)){
52+
{Identifier} {
53+
String id = yytext();
54+
if (!Consts.reservedKeywords.contains(id.toLowerCase())) {
5555
setAttribs(id, yychar, yychar + yylength());
5656
return yystate(); }
5757
}
58+
59+
{Number} {}
60+
5861
\" { yybegin(STRING); }
5962
\' { yybegin(COMMENT); }
6063
}
6164

6265
<STRING> {
66+
\"\" {}
6367
\" { yybegin(YYINITIAL); }
64-
\\\\ | \\\" {}
6568
}
6669

6770
<COMMENT> {
68-
\n { yybegin(YYINITIAL);}
71+
{WhiteSpace} {}
72+
{EOL} { yybegin(YYINITIAL);}
6973
}
7074

7175
<YYINITIAL, STRING, COMMENT> {

0 commit comments

Comments
 (0)