|
18 | 18 | */
|
19 | 19 |
|
20 | 20 | /*
|
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. |
22 | 22 | */
|
23 | 23 |
|
24 | 24 | package org.opensolaris.opengrok.analysis.posh;
|
@@ -54,17 +54,32 @@ import java.util.regex.Matcher;
|
54 | 54 | protected void setLineNumber(int x) { yyline = x; }
|
55 | 55 |
|
56 | 56 | 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); |
64 | 66 | }
|
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); |
66 | 81 | }
|
67 |
| -*/ |
| 82 | + |
68 | 83 | private void pushstate(int state, String style) throws IOException {
|
69 | 84 | if (!styleStack.empty()) {
|
70 | 85 | out.write("</span>");
|
@@ -98,12 +113,14 @@ import java.util.regex.Matcher;
|
98 | 113 | EOL = \r|\n|\r\n
|
99 | 114 | WhiteSpace = [ \t\f]
|
100 | 115 | Identifier = [a-zA-Z_] [a-zA-Z0-9_-]*
|
101 |
| -SimpleVariable = [\$] [a-zA-Z0-9_:-]* |
| 116 | +SimpleVariable = [\$] [a-zA-Z_] [a-zA-Z0-9_:-]* |
102 | 117 | ComplexVariable = [\$] "{" [^}]+ "}"
|
103 | 118 | Operator = "-" [a-zA-Z]+
|
104 | 119 | Label = {WhiteSpace}* ":" {Identifier}
|
105 | 120 | Break = "break" {WhiteSpace}+ {Identifier}
|
106 | 121 | Continue = "continue" {WhiteSpace}+ {Identifier}
|
| 122 | +DataType = "[" [a-zA-Z_] [\[\]a-zA-Z0-9_.-]* "]" |
| 123 | + |
107 | 124 |
|
108 | 125 | /* The following should be matched by the 'Number' pattern below.
|
109 | 126 | * '\$ [0-9]+' :
|
@@ -140,7 +157,7 @@ Number = {RegExGroup} | (0[xX][0-9a-fA-F]+[lL]?|(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE
|
140 | 157 | URIChar = [\?\+\%\&\:\/\.\@\_\;\=\$\,\-\!\~\*\\]
|
141 | 158 | FNameChar = [a-zA-Z0-9_\-\.]
|
142 | 159 | File = {FNameChar}+ "." ([a-zA-Z0-9]+)
|
143 |
| -Path = "/"? [a-zA-Z]{FNameChar}* ("/" [a-zA-Z]{FNameChar}*)+[a-zA-Z0-9] |
| 160 | +Path = "/"? {FNameChar}+ ("/" {FNameChar}+)+ |
144 | 161 |
|
145 | 162 | /*
|
146 | 163 | * States:
|
@@ -200,9 +217,34 @@ Path = "/"? [a-zA-Z]{FNameChar}* ("/" [a-zA-Z]{FNameChar}*)+[a-zA-Z0-9]
|
200 | 217 | out.write(label);
|
201 | 218 | out.write("</a>");
|
202 | 219 | }
|
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(); |
206 | 248 | }
|
207 | 249 | {Identifier} | {Operator} {
|
208 | 250 | String id = yytext();
|
@@ -258,14 +300,16 @@ Path = "/"? [a-zA-Z]{FNameChar}* ("/" [a-zA-Z]{FNameChar}*)+[a-zA-Z0-9]
|
258 | 300 | }
|
259 | 301 |
|
260 | 302 | <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 | + |
264 | 306 | \` ({SimpleVariable} | {ComplexVariable}) { out.write(yytext()); }
|
265 | 307 |
|
266 |
| - {SimpleVariable} | {ComplexVariable} { |
267 |
| - String id = yytext(); |
268 |
| - writeSymbol(id, Consts.poshkwd, yyline, false, true); |
| 308 | + {ComplexVariable} { |
| 309 | + emitComplexVariable(); |
| 310 | + } |
| 311 | + {SimpleVariable} { |
| 312 | + emitSimpleVariable(); |
269 | 313 | }
|
270 | 314 | ^ \"\@ { out.write(yytext()); popstate(); }
|
271 | 315 | [^\r\n] { out.write(yytext()); }
|
|
0 commit comments