Skip to content

Commit 4c99a20

Browse files
authored
Merge pull request #1901 from idodeclare/feature/sh_tests
Feature/sh tests
2 parents ed9e7cf + 82e9390 commit 4c99a20

22 files changed

+1258
-167
lines changed

opengrok-indexer/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
144144
<exclude>*.java</exclude>
145145
</excludes>
146146
</testResource>
147+
<testResource>
148+
<targetPath>org/opensolaris/opengrok/analysis/sh/</targetPath>
149+
<directory>../test/org/opensolaris/opengrok/analysis/sh/</directory>
150+
<excludes>
151+
<exclude>*.java</exclude>
152+
</excludes>
153+
</testResource>
147154
</testResources>
148155

149156
<plugins>

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,15 @@ public void disjointSpan(String className) throws IOException {
420420
disjointSpanClassName = className;
421421
}
422422

423+
/**
424+
* Gets the argument from the last call to
425+
* {@link #disjointSpan(java.lang.String)}.
426+
* @return a defined value or null
427+
*/
428+
public String getDisjointSpanClassName() {
429+
return disjointSpanClassName;
430+
}
431+
423432
/**
424433
* Write xref to the specified {@code Writer}.
425434
*

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
/*
2121
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2222
* Use is subject to license terms.
23+
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
2324
*/
2425

2526
package org.opensolaris.opengrok.analysis.sh;
@@ -144,5 +145,6 @@ public class Consts{
144145
shkwd.add( "void" );
145146
shkwd.add( "unsigned" );
146147
shkwd.add( "nameref" );
148+
shkwd.add( "in" );
147149
}
148150
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
23+
*/
24+
25+
Identifier = [a-zA-Z_] [a-zA-Z0-9_]*
26+
27+
Number = \$? [0-9]+\.[0-9]+| [0-9][0-9]* | [0][xX] [0-9a-fA-F]+
28+
29+
/*
30+
* Rather than enumerate letters, just treat all hyphen- or plus- with a
31+
* single-char as a unary op. "req_lookahead" because an assertion is needed
32+
* that it is followed by non-word or end-of-line.
33+
*/
34+
Unary_op_req_lookahead = [\-\+]{Unary_op_char}
35+
Unary_op_char = [A-Za-z]
36+
37+
Binary_op = [\-]("ef"|"nt"|"ot"|"eq"|"ge"|"gt"|"le"|"lt"|"ne"){WhspChar}

src/org/opensolaris/opengrok/analysis/sh/ShSymbolTokenizer.lex

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
*/
2424

2525
package org.opensolaris.opengrok.analysis.sh;
26-
import java.io.IOException;
27-
import java.io.Reader;
26+
2827
import org.opensolaris.opengrok.analysis.JFlexTokenizer;
2928
%%
3029
%public
@@ -38,48 +37,65 @@ super(in);
3837
%include CommonTokenizer.lexh
3938
%char
4039

41-
Identifier = [a-zA-Z_] [a-zA-Z0-9_]*
42-
4340
%state STRING COMMENT SCOMMENT QSTRING
4441

42+
%include Common.lexh
43+
%include Sh.lexh
4544
%%
4645

4746
<YYINITIAL> {
48-
{Identifier} {String id = yytext();
47+
{Identifier} {
48+
String id = yytext();
4949
if(!Consts.shkwd.contains(id)){
5050
setAttribs(id, yychar, yychar + yylength());
5151
return yystate(); }
5252
}
53+
{Number} {}
5354
\" { yybegin(STRING); }
5455
\' { yybegin(QSTRING); }
5556
"#" { yybegin(SCOMMENT); }
57+
58+
{Unary_op_req_lookahead} / \W {
59+
// noop
60+
}
61+
{Unary_op_req_lookahead} $ {
62+
// noop
63+
}
64+
{WhiteSpace} {Unary_op_char} / ")" {
65+
// noop
66+
}
67+
{Binary_op} {
68+
// noop
69+
}
5670
}
5771

5872
<STRING> {
59-
"$" {Identifier} {
73+
"$" {Identifier} {
6074
setAttribs(yytext().substring(1), yychar + 1, yychar + yylength());
6175
return yystate();
62-
}
76+
}
6377

64-
"${" {Identifier} "}" {
78+
"${" {Identifier} "}" {
6579
int startOffset = 2; // trim away the "${" prefix
6680
int endOffset = yylength() - 1; // trim away the "}" suffix
6781
setAttribs(yytext().substring(startOffset, endOffset),
6882
yychar + startOffset,
6983
yychar + endOffset);
7084
return yystate();
71-
}
85+
}
7286

7387
\" { yybegin(YYINITIAL); }
74-
\\\\ | \\\" {}
88+
\\[\"\$\`\\] {}
7589
}
7690

7791
<QSTRING> {
92+
\\[\'] {}
7893
\' { yybegin(YYINITIAL); }
7994
}
8095

8196
<SCOMMENT> {
82-
\n { yybegin(YYINITIAL);}
97+
{WhiteSpace} {}
98+
{EOL} { yybegin(YYINITIAL);}
8399
}
84100

85101
<YYINITIAL, STRING, SCOMMENT, QSTRING> {

0 commit comments

Comments
 (0)