Skip to content

Commit

Permalink
Merge pull request #3998 from b4n/powershell-enum-labels
Browse files Browse the repository at this point in the history
powershell: Parse enum labels
  • Loading branch information
b4n committed May 15, 2024
2 parents b1509ff + 2686322 commit 8904e85
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Units/parser-powershell.r/enum-powershell.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
EnumName1 input.ps1 /^enum EnumName1 {$/;" g
Label11 input.ps1 /^ Label11$/;" e enum:EnumName1
Label12 input.ps1 /^ Label12 = 10$/;" e enum:EnumName1
EnumName2 input.ps1 /^enum EnumName2 {$/;" g
Label21 input.ps1 /^ Label21$/;" e enum:EnumName2
Label22 input.ps1 /^ Label22 = 20$/;" e enum:EnumName2
EnumName3 input.ps1 /^Enum EnumName3 {$/;" g
Label31 input.ps1 /^ Label31$/;" e enum:EnumName3
Label32 input.ps1 /^ Label32 = 30$/;" e enum:EnumName3
EnumName4 input.ps1 /^[Flags()] enum EnumName4 {$/;" g
Label41 input.ps1 /^ Label41$/;" e enum:EnumName4
Label42 input.ps1 /^ Label42 = 40$/;" e enum:EnumName4
1 change: 1 addition & 0 deletions docs/man-pages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Man pages
ctags-lang-ldscript(7) <man/ctags-lang-ldscript.7.rst>
ctags-lang-lex(7) <man/ctags-lang-lex.7.rst>
ctags-lang-markdown(7) <man/ctags-lang-markdown.7.rst>
ctags-lang-powershell(7) <man/ctags-lang-powershell.7.rst>
ctags-lang-python(7) <man/ctags-lang-python.7.rst>
ctags-lang-r(7) <man/ctags-lang-r.7.rst>
ctags-lang-rmarkdown(7) <man/ctags-lang-rmarkdown.7.rst>
Expand Down
34 changes: 34 additions & 0 deletions docs/man/ctags-lang-powershell.7.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.. _ctags-lang-powershell(7):

==============================================================
ctags-lang-powershell
==============================================================

Random notes about tagging PowerShell source code with Universal Ctags

:Version: 6.1.0
:Manual group: Universal Ctags
:Manual section: 7

SYNOPSIS
--------
| **ctags** ... --languages=+PowerShell ...
| **ctags** ... --language-force=PowerShell ...
| **ctags** ... --map-powershell=+.ps1 ...
| **ctags** ... --map-powershell=+.psm1 ...
DESCRIPTION
-----------
This man page gathers random notes about tagging PowerShell source code.

VERSIONS
--------

Change since "0.0"
~~~~~~~~~~~~~~~~~~

* New kind ``enumlabel``

SEE ALSO
--------
:ref:`ctags(1) <ctags(1)>`
1 change: 1 addition & 0 deletions man/GNUmakefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ GEN_IN_MAN_FILES = \
ctags-lang-ldscript.7 \
ctags-lang-lex.7 \
ctags-lang-markdown.7 \
ctags-lang-powershell.7 \
ctags-lang-python.7 \
ctags-lang-r.7 \
ctags-lang-rmarkdown.7 \
Expand Down
34 changes: 34 additions & 0 deletions man/ctags-lang-powershell.7.rst.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.. _ctags-lang-powershell(7):

==============================================================
ctags-lang-powershell
==============================================================
-----------------------------------------------------------------------
Random notes about tagging PowerShell source code with Universal Ctags
-----------------------------------------------------------------------
:Version: @VERSION@
:Manual group: Universal Ctags
:Manual section: 7

SYNOPSIS
--------
| **@CTAGS_NAME_EXECUTABLE@** ... --languages=+PowerShell ...
| **@CTAGS_NAME_EXECUTABLE@** ... --language-force=PowerShell ...
| **@CTAGS_NAME_EXECUTABLE@** ... --map-powershell=+.ps1 ...
| **@CTAGS_NAME_EXECUTABLE@** ... --map-powershell=+.psm1 ...

DESCRIPTION
-----------
This man page gathers random notes about tagging PowerShell source code.

VERSIONS
--------

Change since "0.0"
~~~~~~~~~~~~~~~~~~

* New kind ``enumlabel``

SEE ALSO
--------
ctags(1)
35 changes: 35 additions & 0 deletions parsers/powershell.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ typedef enum {
K_CLASS,
K_FILTER,
K_ENUM,
K_ENUMLABEL,
COUNT_KIND
} powerShellKind;

Expand All @@ -51,6 +52,7 @@ static kindDefinition PowerShellKinds[COUNT_KIND] = {
{ true, 'c', "class", "classes" },
{ true, 'i', "filter", "filter" },
{ true, 'g', "enum", "enum names" },
{ true, 'e', "enumlabel", "enum labels" },
};


Expand Down Expand Up @@ -648,6 +650,30 @@ static bool parseEnum (tokenInfo *const token)
return readNext;
}

/* parses declarations of the form
* <label> [= <int-value>]
* that is, contents of an enum
*/
static bool parseEnumLabel (tokenInfo *const token)
{
bool readNext = true;

if (token->parentKind != K_ENUM)
return false;

if (token->type != TOKEN_IDENTIFIER)
return false;

makeSimplePowerShellTag (token, K_ENUMLABEL, ACCESS_UNDEFINED);
readToken (token);
if (token->type != TOKEN_EQUAL_SIGN)
readNext = false;
else /* skip int-value */
readToken (token);

return readNext;
}

/* parses declarations of the form
* $var = VALUE
*/
Expand Down Expand Up @@ -735,6 +761,11 @@ static void enterScope (tokenInfo *const parentToken,
readNext = parseVariable (token);
break;

case TOKEN_IDENTIFIER:
if (parentKind == K_ENUM)
readNext = parseEnumLabel (token);
break;

default: break;
}

Expand Down Expand Up @@ -770,5 +801,9 @@ extern parserDefinition* PowerShellParser (void)
def->parser = findPowerShellTags;
def->keywordTable = PowerShellKeywordTable;
def->keywordCount = ARRAY_SIZE (PowerShellKeywordTable);

def->versionCurrent = 1;
def->versionAge = 1;

return def;
}

0 comments on commit 8904e85

Please sign in to comment.