Skip to content

Commit 914f50c

Browse files
authored
Merge pull request #3531 from kumarstack55/develop
PowerShell: parse a colon following the class name
2 parents 83c1a09 + 433c933 commit 914f50c

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
MyException input.ps1 /^class MyException : Exception {$/;" c
2+
Derived input.ps1 /^class Derived : Base {$/;" c
3+
Derived2 input.ps1 /^class Derived2: Base {$/;" c
24
Foo input.ps1 /^class Foo {$/;" c
35
GetBar input.ps1 /^function GetBar {$/;" f
46
GetBaz input.ps1 /^function GetBaz() {$/;" f signature:()

Units/parser-powershell.r/class-powershell.d/input.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ class MyException : Exception {
44
}
55
}
66

7+
class Derived : Base {
8+
}
9+
10+
class Derived2: Base {
11+
}
12+
713
class Foo {
814
$Property1
915
$Property2 = 20

parsers/powershell.c

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,12 @@ static void addToScope (tokenInfo *const token, const vString *const extra)
218218

219219
static bool isIdentChar (const int c)
220220
{
221-
return (isalnum (c) || c == ':' || c == '_' || c == '-' || c >= 0x80);
221+
return (isalnum (c) || c == '_' || c == '-' || c >= 0x80);
222+
}
223+
224+
static bool isScopeIdentifierChar (const int c)
225+
{
226+
return (isIdentChar (c) || c == ':');
222227
}
223228

224229
static void parseString (vString *const string, const int delimiter)
@@ -228,20 +233,40 @@ static void parseString (vString *const string, const int delimiter)
228233
int c = getcFromInputFile ();
229234

230235
if (c == '\\' && (c = getcFromInputFile ()) != EOF)
231-
vStringPut (string, (char) c);
236+
vStringPut (string, c);
232237
else if (c == EOF || c == delimiter)
233238
break;
234239
else
235-
vStringPut (string, (char) c);
240+
vStringPut (string, c);
236241
}
237242
}
238243

244+
/* parse a identifier that may contain scopes, such as function names and
245+
* variable names.
246+
*
247+
* VariableName
248+
* FunctionName
249+
* local:VariableName
250+
* private:FunctionName
251+
*/
252+
static void parseScopeIdentifier (vString *const string, const int firstChar)
253+
{
254+
int c = firstChar;
255+
do
256+
{
257+
vStringPut (string, c);
258+
c = getcFromInputFile ();
259+
} while (isScopeIdentifierChar (c));
260+
ungetcToInputFile (c);
261+
}
262+
263+
/* parse a identifier that do not contain scope, such as class names. */
239264
static void parseIdentifier (vString *const string, const int firstChar)
240265
{
241266
int c = firstChar;
242267
do
243268
{
244-
vStringPut (string, (char) c);
269+
vStringPut (string, c);
245270
c = getcFromInputFile ();
246271
} while (isIdentChar (c));
247272
ungetcToInputFile (c);
@@ -365,14 +390,14 @@ static void readToken (tokenInfo *const token)
365390
case '$': /* variable start */
366391
{
367392
int d = getcFromInputFile ();
368-
if (! isIdentChar (d))
393+
if (! isScopeIdentifierChar (d))
369394
{
370395
ungetcToInputFile (d);
371396
token->type = TOKEN_UNDEFINED;
372397
}
373398
else
374399
{
375-
parseIdentifier (token->string, d);
400+
parseScopeIdentifier (token->string, d);
376401
token->type = TOKEN_VARIABLE;
377402
}
378403
break;
@@ -383,7 +408,11 @@ static void readToken (tokenInfo *const token)
383408
token->type = TOKEN_UNDEFINED;
384409
else
385410
{
386-
parseIdentifier (token->string, c);
411+
if (token->keyword == KEYWORD_function ||
412+
token->keyword == KEYWORD_filter)
413+
parseScopeIdentifier (token->string, c);
414+
else
415+
parseIdentifier (token->string, c);
387416
token->keyword = lookupCaseKeyword (
388417
vStringValue (token->string), getInputLanguage ());
389418
if (token->keyword == KEYWORD_NONE)
@@ -536,6 +565,7 @@ static bool parseFunction (tokenInfo *const token, int kind)
536565
/* parse a class
537566
*
538567
* class MyClass {}
568+
* class Derived : Base {}
539569
*/
540570
static bool parseClass (tokenInfo *const token)
541571
{

0 commit comments

Comments
 (0)