Skip to content

Commit 4efb8c4

Browse files
committed
Attempt number 3 to get past build break
1 parent d277c45 commit 4efb8c4

File tree

6 files changed

+81
-35
lines changed

6 files changed

+81
-35
lines changed

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -241,19 +241,18 @@ private void initialize() throws IOException {
241241
// PowerShell
242242
command.add("--langdef=Posh");
243243
command.add("--langmap=Posh:+.ps1,Posh:+.psm1");
244-
command.add("--kinddef-Posh=f,function,functions");
245244
command.add("--_fielddef-Posh=signature,signatures");
246245
command.add("--fields-Posh=+{signature}");
247246

248247
// escaped variable markers
249-
command.add("--regex-Posh=/`(\\$[[:alnum:]_]+([:.][[:alnum:]_]+)*)/\\1//{exclusive}");
250-
command.add("--regex-Posh=/`(\\$\\{[^}]+\\})/\\1//{exclusive}");
251-
command.add("--regex-Posh=/#.*(\\$[[:alnum:]_]+([:.][[:alnum:]_]+)*)/\\1//{exclusive}");
252-
command.add("--regex-Posh=/#.*(\\$\\{[^}]+\\})/\\1//{exclusive}");
253-
254-
command.add("--regex-Posh=/(\\$\\{[^}]+\\})/\\1/v,variable/");
255-
command.add("--regex-Posh=/(\\$[[:alnum:]_]+([:.][[:alnum:]_]+)*)/\\1/v,variable/");
256-
command.add("--regex-Posh=/^[[:space:]]*(function|filter)[[:space:]]+([^({[:space:]]+)[[:space:]]*(\\(([^)]+)\\))?/\\2/f/{icase}{exclusive}{_field=signature:(\\4)}");
248+
command.add("--regex-Posh=/`\\$([[:alnum:]_]+([:.][[:alnum:]_]+)*)/\\1//{exclusive}");
249+
command.add("--regex-Posh=/`\\$(\\{[^}]+\\})/\\1//{exclusive}");
250+
command.add("--regex-Posh=/#.*\\$([[:alnum:]_]+([:.][[:alnum:]_]+)*)/\\1//{exclusive}");
251+
command.add("--regex-Posh=/#.*\\$(\\{[^}]+\\})/\\1//{exclusive}");
252+
253+
command.add("--regex-Posh=/\\$(\\{[^}]+\\})/\\1/v,variable/");
254+
command.add("--regex-Posh=/\\$([[:alnum:]_]+([:.][[:alnum:]_]+)*)/\\1/v,variable/");
255+
command.add("--regex-Posh=/^[[:space:]]*(function|filter)[[:space:]]+([^({[:space:]]+)[[:space:]]*(\\(([^)]+)\\))?/\\2/f,function,functions/{icase}{exclusive}{_field=signature:(\\4)}");
257256
command.add("--regex-Posh=/^[[:space:]]*(:[^[:space:]]+)/\\1/l,label/");
258257

259258
//PLEASE add new languages ONLY with POSIX syntax (see above wiki link)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright 2005, 2017 Sun Microsystems, Inc. All rights reserved.
21+
* Copyright 2017 Sun Microsystems, Inc. All rights reserved.
2222
* Use is subject to license terms.
2323
*/
2424

src/org/opensolaris/opengrok/analysis/posh/PoshAnalyzer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opensolaris.opengrok.analysis.posh;
2424

src/org/opensolaris/opengrok/analysis/posh/PoshAnalyzerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opensolaris.opengrok.analysis.posh;
2424

src/org/opensolaris/opengrok/analysis/posh/PoshSymbolTokenizer.lex

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

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

2424
package org.opensolaris.opengrok.analysis.posh;
@@ -42,9 +42,10 @@ return false;
4242
EOL = \r|\n|\r\n
4343
WhiteSpace = [ \t\f]
4444
Identifier = [a-zA-Z_] [a-zA-Z0-9_-]*
45-
SimpleVariable = [\$] [a-zA-Z0-9_:-]*
45+
SimpleVariable = [\$] [a-zA-Z_] [a-zA-Z0-9_:-]*
4646
ComplexVariable = [\$] "{" [^}]+ "}"
4747
Label = {WhiteSpace}* ":" {Identifier}
48+
DataType = "[" [a-zA-Z_] [\[\]a-zA-Z0-9_.-]* "]"
4849

4950
%state STRING COMMENT SCOMMENT QSTRING HERESTRING HEREQSTRING
5051

@@ -64,6 +65,8 @@ Label = {WhiteSpace}* ":" {Identifier}
6465
return true;
6566
}
6667
}
68+
{DataType} { return true; }
69+
6770
\" { yybegin(STRING); }
6871
\' { yybegin(QSTRING); }
6972
\@\" { yybegin(HERESTRING); }

src/org/opensolaris/opengrok/analysis/posh/PoshXref.lex

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

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

2424
package org.opensolaris.opengrok.analysis.posh;
@@ -54,17 +54,32 @@ import java.util.regex.Matcher;
5454
protected void setLineNumber(int x) { yyline = x; }
5555

5656
private Pattern GoToLabel = Pattern.compile("(break|continue)(\\s+)(\\w+)");
57-
/*
58-
private int countOf(char thisChar, String text) {
59-
int count = 0;
60-
for(int i = 0; i < text.length(); i++) {
61-
if(text.charAt(i) == thisChar) {
62-
count+=1;
63-
}
57+
58+
private String getVariableName(String text) {
59+
String name = text;
60+
// Extract variable name from ${name} (complex variable)
61+
if (text.startsWith("${")) {
62+
name = text.substring(2,text.length()-1);
63+
} else {
64+
// Assuming extracting name from $name (simple variable)
65+
name = text.substring(1);
6466
}
65-
return count;
67+
return name;
68+
}
69+
70+
private void emitComplexVariable() throws IOException {
71+
String id = getVariableName(yytext());
72+
out.write("${");
73+
writeSymbol(id, Consts.poshkwd, yyline, false, true);
74+
out.write("}");
75+
}
76+
77+
private void emitSimpleVariable() throws IOException {
78+
String id = getVariableName(yytext());
79+
out.write("$");
80+
writeSymbol(id, Consts.poshkwd, yyline, false, true);
6681
}
67-
*/
82+
6883
private void pushstate(int state, String style) throws IOException {
6984
if (!styleStack.empty()) {
7085
out.write("</span>");
@@ -98,12 +113,14 @@ import java.util.regex.Matcher;
98113
EOL = \r|\n|\r\n
99114
WhiteSpace = [ \t\f]
100115
Identifier = [a-zA-Z_] [a-zA-Z0-9_-]*
101-
SimpleVariable = [\$] [a-zA-Z0-9_:-]*
116+
SimpleVariable = [\$] [a-zA-Z_] [a-zA-Z0-9_:-]*
102117
ComplexVariable = [\$] "{" [^}]+ "}"
103118
Operator = "-" [a-zA-Z]+
104119
Label = {WhiteSpace}* ":" {Identifier}
105120
Break = "break" {WhiteSpace}+ {Identifier}
106121
Continue = "continue" {WhiteSpace}+ {Identifier}
122+
DataType = "[" [a-zA-Z_] [\[\]a-zA-Z0-9_.-]* "]"
123+
107124

108125
/* The following should be matched by the 'Number' pattern below.
109126
* '\$ [0-9]+' :
@@ -140,7 +157,7 @@ Number = {RegExGroup} | (0[xX][0-9a-fA-F]+[lL]?|(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE
140157
URIChar = [\?\+\%\&\:\/\.\@\_\;\=\$\,\-\!\~\*\\]
141158
FNameChar = [a-zA-Z0-9_\-\.]
142159
File = {FNameChar}+ "." ([a-zA-Z0-9]+)
143-
Path = "/"? [a-zA-Z]{FNameChar}* ("/" [a-zA-Z]{FNameChar}*)+[a-zA-Z0-9]
160+
Path = "/"? {FNameChar}+ ("/" {FNameChar}+)+
144161

145162
/*
146163
* States:
@@ -200,9 +217,34 @@ Path = "/"? [a-zA-Z]{FNameChar}* ("/" [a-zA-Z]{FNameChar}*)+[a-zA-Z0-9]
200217
out.write(label);
201218
out.write("</a>");
202219
}
203-
{SimpleVariable} | {ComplexVariable} {
204-
String id = yytext();
205-
writeSymbol(id, Consts.poshkwd, yyline, false, true);
220+
{DataType} {
221+
String dataType = yytext();
222+
223+
// strip off outer '[' and ']' and massage letter size
224+
String id = dataType.substring(1, dataType.length()-1).toLowerCase();
225+
226+
// Check for array data type indicator ([]) and strip off
227+
int pos = id.indexOf("[]");
228+
if (pos != -1) {
229+
id = id.substring(0,pos);
230+
}
231+
// Dynamically add data type to constant
232+
// list so they do not turn into links.
233+
if (!Consts.poshkwd.contains(id)) {
234+
Consts.poshkwd.add(id);
235+
}
236+
out.write("[");
237+
writeSymbol(id, Consts.poshkwd, yyline, false, false);
238+
if (pos != -1) {
239+
out.write("[]");
240+
}
241+
out.write("]");
242+
}
243+
{ComplexVariable} {
244+
emitComplexVariable();
245+
}
246+
{SimpleVariable} {
247+
emitSimpleVariable();
206248
}
207249
{Identifier} | {Operator} {
208250
String id = yytext();
@@ -258,14 +300,16 @@ Path = "/"? [a-zA-Z]{FNameChar}* ("/" [a-zA-Z]{FNameChar}*)+[a-zA-Z0-9]
258300
}
259301

260302
<HERESTRING> {
261-
/* Match escaped dollar sign of variable
262-
* (eg. `$var) so it does not turn into web-link.
263-
*/
303+
// Match escaped dollar sign of variable
304+
// (eg. `$var) so it does not turn into web-link.
305+
264306
\` ({SimpleVariable} | {ComplexVariable}) { out.write(yytext()); }
265307

266-
{SimpleVariable} | {ComplexVariable} {
267-
String id = yytext();
268-
writeSymbol(id, Consts.poshkwd, yyline, false, true);
308+
{ComplexVariable} {
309+
emitComplexVariable();
310+
}
311+
{SimpleVariable} {
312+
emitSimpleVariable();
269313
}
270314
^ \"\@ { out.write(yytext()); popstate(); }
271315
[^\r\n] { out.write(yytext()); }

0 commit comments

Comments
 (0)