Skip to content

Conversation

@iaalm
Copy link
Contributor

@iaalm iaalm commented Nov 11, 2025

Test passed with make units LANGUAGES=TypeSpec

@masatake
Copy link
Member

Thank you.

Could you change the commit log header to "TypeSpec: add enumerator support" ?

Test passed with make units LANGUAGES=TypeSpec

Our CI/CD platforms reported failures.
On my local PC, simple-typespec.d failed, too.

I read your code. Your code calls setScope on a token object. However, the caller and the callee share the token object. As a result, setting the scope affects the caller side.
You must save/restore the scope in the callee.
Diff is much better than my English.

diff --git a/parsers/typespec.c b/parsers/typespec.c
index 75ae13059..b0e16e3a5 100644
--- a/parsers/typespec.c
+++ b/parsers/typespec.c
@@ -139,9 +139,12 @@ static void copyToken (tokenInfo *const dest, const tokenInfo *const src)
    vStringCopy (dest->string, src->string);
 }
 
-static void setScope (tokenInfo *const token, int scope)
+static int setScope (tokenInfo *const token, int scope)
 {
+   int originalScope = token->scope;
+
    token->scope = scope;
+   return originalScope;
 }
 
 static bool isIdentChar (const int c)
@@ -402,12 +405,12 @@ static void parseEnum(tokenInfo *const token)
        if (token->type == TOKEN_OPEN_CURLY)
        {
            /* Parse enum body */
+           int originalScope = setScope (token, enumIndex);
            while (token->type != TOKEN_CLOSE_CURLY && token->type != TOKEN_EOF)
            {
                if (token->type == TOKEN_IDENTIFIER)
                {
                    /* Create tag for enumerator */
-                   setScope (token, enumIndex);
                    makeTypeSpecTag(token, K_ENUMERATOR);
                    readToken(token);
@@ -431,6 +434,7 @@ static void parseEnum(tokenInfo *const token)
                else
                    readToken(token);
            }
+           setScope(token, originalScope);
        }
    }
 }

Your new code:

+                   /* Skip value assignment if any */
+                   if (token->type == TOKEN_EQUAL_SIGN)
+                   {
+                       readToken(token);
+                       /* Skip the value */
+                       while (token->type != TOKEN_COMMA && 
+                              token->type != TOKEN_CLOSE_CURLY && 
+                              token->type != TOKEN_EOF)
+                       {
+                           readToken(token);
+                       }
+                   }

These lines are not tested at all.
You can extend parser-typespec.r/simple-typespec.d. Or you can add parser-typespec.r/enumerator.d.

Please, delete trailing white spaces.

image (Don't you use EditorConfig on your editor?)

Your commit is based on an old commit.

ommit 286a85d9b779b7c3edb5a8944298c2a157ce1fbe (HEAD -> tsp-improve)
Author: iaalm <[email protected]>
Date:   Tue May 27 18:57:43 2025 +0800

    Add enumerator support for TypeSpec

commit aafc6538c05670d4c38d13b69f5c8f80b1c7ba6f
Merge: 7dbc4db57 846da8d9e
Author: Masatake YAMATO <[email protected]>
Date:   Tue May 27 18:43:07 2025 +0900

    Merge pull request #4243 from iaalm/tsp
    
    TypeSpec: new parser

Could you rebase your branch on the latest master branch?

Adding a kind to a parser changes the CLI of ctags.
I had asked contributors to write the addition to the man page of their parser, like:
https://docs.ctags.io/en/latest/man/ctags-lang-scheme.7.html#versions

After reconsidering, adding man pages solely for versioning is not a good idea.
A self-descriptive way is better. Now ctags itself shows version information.

[yamato@dev64]~/var/ctags-github% ./ctags --list-kinds-full=Scheme
#LETTER NAME     ENABLED REFONLY NROLES MASTER VER DESCRIPTION
Y       unknown  yes     no      0      NONE     1 unknown type of definitions
f       function yes     no      0      NONE     0 functions
s       set      yes     no      0      NONE     0 sets
[yamato@dev64]~/var/ctags-github% ./ctags --version=Scheme        
parser/Scheme: 1.1

This output tells users that the Scheme parser is version 1 (current 1.1). The kind set has been updated once in an upper compatible way (age 1.1). The function kind and the set kind were added in the parser version 0. The unknown kind was added in the parser version 1.

In this PR, you will add a kind. So I would like you to consider the versioning.

diff --git a/parsers/typespec.c b/parsers/typespec.c
index 75ae13059..d3507f8f5 100644
--- a/parsers/typespec.c
+++ b/parsers/typespec.c
@@ -45,7 +45,8 @@ static kindDefinition TypeSpecKinds[COUNT_KIND] = {
 	{ true, 'u', "union",		"unions" },
 	{ true, 'a', "alias",		"aliases" },
 	{ true, 'p', "property",	"properties" },
-	{ true, 'e', "enumerator",	"enumerators (values inside an enumeration)" }
+	{ true, 'e', "enumerator",	"enumerators (values inside an enumeration)",
+	  .version = 1 },
 };
 
 typedef enum eTokenType {
@@ -416,8 +417,8 @@ static void parseEnum(tokenInfo *const token)
 					{
 						readToken(token);
 						/* Skip the value */
-						while (token->type != TOKEN_COMMA && 
-							   token->type != TOKEN_CLOSE_CURLY && 
+						while (token->type != TOKEN_COMMA &&
+							   token->type != TOKEN_CLOSE_CURLY &&
 							   token->type != TOKEN_EOF)
 						{
 							readToken(token);
@@ -709,5 +710,9 @@ extern parserDefinition* TypeSpecParser (void)
 	def->keywordCount = ARRAY_SIZE (TypeSpecKeywordTable);
 	def->defaultScopeSeparator = SCOPE_SEPARATOR;
 	def->useCork = CORK_QUEUE;
+
+	def->versionCurrent = 1;
+	def->versionAge = 1;
+
 	return def;
 }

{ true, 'a', "alias", "aliases" },
{ true, 'p', "property", "properties" }
{ true, 'p', "property", "properties" },
{ true, 'e', "enumerator", "enumerators (values inside an enumeration)" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put "," at the end of the new entry for "e".
When adding a new entry next time, you can make the diff output smaller:)

@iaalm
Copy link
Contributor Author

iaalm commented Nov 11, 2025

thanks, working on the fix

@codecov
Copy link

codecov bot commented Nov 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.87%. Comparing base (d48558f) to head (027af24).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4339   +/-   ##
=======================================
  Coverage   85.87%   85.87%           
=======================================
  Files         252      252           
  Lines       62597    62618   +21     
=======================================
+ Hits        53755    53776   +21     
  Misses       8842     8842           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@masatake masatake merged commit d34fff1 into universal-ctags:master Nov 14, 2025
95 of 96 checks passed
@masatake
Copy link
Member

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants