Skip to content

Commit 59849ba

Browse files
committed
Add CSharpSymbolTokenizerTest, and fix number bug
1 parent ac3a642 commit 59849ba

File tree

7 files changed

+338
-15
lines changed

7 files changed

+338
-15
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
23+
*/
24+
25+
CsharpEOL = {EOL}|\u2028|\u2029|\u000B|\u000C|\u0085
26+
27+
Identifier = [a-zA-Z_] [a-zA-Z0-9_]*
28+
29+
Number = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[0-9]+)(([eE][+-]?[0-9]+)?[ufdlUFDL]*)?

src/org/opensolaris/opengrok/analysis/csharp/CSharpSymbolTokenizer.lex

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,23 @@ super(in);
4242
%int
4343
%include CommonTokenizer.lexh
4444
%char
45-
Identifier = [a-zA-Z_] [a-zA-Z0-9_]*
4645

4746
%state STRING COMMENT SCOMMENT QSTRING VSTRING
4847

48+
%include CSharp.lexh
4949
%%
5050

5151
<YYINITIAL> {
52-
{Identifier} {String id = yytext();
52+
{Identifier} {
53+
String id = yytext();
5354
if(!Consts.kwd.contains(id)){
5455
setAttribs(id, yychar, yychar + yylength());
55-
return yystate(); }
56-
}
56+
return yystate();
57+
}
58+
}
59+
60+
{Number} {}
61+
5762
\" { yybegin(STRING); }
5863
\' { yybegin(QSTRING); }
5964
"/*" { yybegin(COMMENT); }

src/org/opensolaris/opengrok/analysis/csharp/CSharpXref.lex

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,14 @@ import org.opensolaris.opengrok.web.Util;
5050
protected void setLineNumber(int x) { yyline = x; }
5151
%}
5252

53-
CsharpEOL = {EOL}|\u2028|\u2029|\u000B|\u000C|\u0085
54-
Identifier = [a-zA-Z_] [a-zA-Z0-9_]+
55-
5653
File = [a-zA-Z]{FNameChar}* "." ([chts]|"cs")
5754

58-
Number = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[0-9]+)(([eE][+-]?[0-9]+)?[ufdlUFDL]*)?
59-
60-
//ClassName = ({Identifier} ".")* {Identifier}
61-
//ParamName = {Identifier} | "<" {Identifier} ">"
62-
6355
%state STRING COMMENT SCOMMENT QSTRING VSTRING
6456

6557
%include Common.lexh
6658
%include CommonURI.lexh
6759
%include CommonPath.lexh
60+
%include CSharp.lexh
6861
%%
6962
<YYINITIAL>{
7063
\{ { incScope(); writeUnicodeChar(yycharat(0)); }
@@ -73,7 +66,13 @@ Number = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[0-9]+)(([eE][+-]?[0-9]+)?[ufdlUFDL]*
7366

7467
{Identifier} {
7568
String id = yytext();
76-
writeSymbol(id, Consts.kwd, yyline);
69+
// N.b. for historical reasons, CSharpXref does not link identifiers of
70+
// length=1.
71+
if (id.length() > 1) {
72+
writeSymbol(id, Consts.kwd, yyline);
73+
} else {
74+
out.write(id);
75+
}
7776
}
7877

7978
"<" ({File} | {FPath}) ">" {
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) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
23+
*/
24+
25+
package org.opensolaris.opengrok.analysis.csharp;
26+
27+
import java.io.BufferedReader;
28+
import java.io.InputStream;
29+
import java.io.InputStreamReader;
30+
import java.util.ArrayList;
31+
import java.util.List;
32+
import static org.junit.Assert.assertNotNull;
33+
import org.junit.Test;
34+
import static org.opensolaris.opengrok.util.CustomAssertions.assertSymbolStream;
35+
36+
/**
37+
* Tests the {@link CSharpSymbolTokenizer} class.
38+
*/
39+
public class CSharpSymbolTokenizerTest {
40+
41+
/**
42+
* Test sample.cs v. samplesymbols.txt
43+
* @throws java.lang.Exception thrown on error
44+
*/
45+
@Test
46+
public void testCSharpSymbolStream() throws Exception {
47+
InputStream csres = getClass().getClassLoader().getResourceAsStream(
48+
"org/opensolaris/opengrok/analysis/csharp/sample.cs");
49+
assertNotNull("despite sample.cs as resource,", csres);
50+
InputStream symres = getClass().getClassLoader().getResourceAsStream(
51+
"org/opensolaris/opengrok/analysis/csharp/samplesymbols.txt");
52+
assertNotNull("despite samplesymbols.txt as resource,", symres);
53+
54+
List<String> expectedSymbols = new ArrayList<>();
55+
try (BufferedReader wdsr = new BufferedReader(new InputStreamReader(
56+
symres, "UTF-8"))) {
57+
String line;
58+
while ((line = wdsr.readLine()) != null) {
59+
int hasho = line.indexOf('#');
60+
if (hasho != -1) line = line.substring(0, hasho);
61+
expectedSymbols.add(line.trim());
62+
}
63+
}
64+
65+
assertSymbolStream(CSharpSymbolTokenizer.class, csres,
66+
expectedSymbols);
67+
}
68+
}

test/org/opensolaris/opengrok/analysis/csharp/sample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ internal enum DataFormat
7474
///
7575
/// </summary>
7676

77-
XML = 1,
77+
XML = 0xFF,
7878

7979
/// <summary>
8080
///

test/org/opensolaris/opengrok/analysis/csharp/sample_xref.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
<a class="l" name="74" href="#74">74</a><span class='fold-space'>&nbsp;</span> <span class="c">///</span>
8383
<a class="l" name="75" href="#75">75</a><span class='fold-space'>&nbsp;</span> <span class="c">/// &lt;/summary&gt;</span>
8484
<a class="l" name="76" href="#76">76</a><span class='fold-space'>&nbsp;</span>
85-
<a class="l" name="77" href="#77">77</a><span class='fold-space'>&nbsp;</span> <a class="xer" name="XML"/><a href="/source/s?refs=XML" class="xer intelliWindow-symbol" data-definition-place="def">XML</a> = <span class="n">1</span>,
85+
<a class="l" name="77" href="#77">77</a><span class='fold-space'>&nbsp;</span> <a class="xer" name="XML"/><a href="/source/s?refs=XML" class="xer intelliWindow-symbol" data-definition-place="def">XML</a> = <span class="n">0xFF</span>,
8686
<a class="l" name="78" href="#78">78</a><span class='fold-space'>&nbsp;</span>
8787
<a class="l" name="79" href="#79">79</a><span class='fold-space'>&nbsp;</span> <span class="c">/// &lt;summary&gt;</span>
8888
<a class="hl" name="80" href="#80">80</a><span class='fold-space'>&nbsp;</span> <span class="c">///</span>

0 commit comments

Comments
 (0)