Skip to content

TypeSpec: new parser #4243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

TypeSpec: new parser #4243

wants to merge 1 commit into from

Conversation

iaalm
Copy link
Contributor

@iaalm iaalm commented May 8, 2025

Add parser for TypeSpec

Test passed with make units LANGUAGES=TypeSpec

Copy link

codecov bot commented May 8, 2025

Codecov Report

Attention: Patch coverage is 87.84195% with 40 lines in your changes missing coverage. Please review.

Project coverage is 85.86%. Comparing base (fc82393) to head (a9dfcf7).
Report is 27 commits behind head on master.

Files with missing lines Patch % Lines
parsers/typespec.c 87.84% 40 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4243      +/-   ##
==========================================
- Coverage   85.89%   85.86%   -0.04%     
==========================================
  Files         243      245       +2     
  Lines       62847    63315     +468     
==========================================
+ Hits        53985    54368     +383     
- Misses       8862     8947      +85     

☔ 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.

@iaalm iaalm changed the title TypeSpec: add parser TypeSpec: new parser May 8, 2025
@masatake masatake self-assigned this May 8, 2025
Copy link
Member

@masatake masatake left a comment

Choose a reason for hiding this comment

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

Well written. Thank you.
Could you add the name of the new parser to docs/news/HEAD.rst?

I think we can simplify the code with "cork API",
See https://docs.ctags.io/en/latest/internal.html#cork-api

I will show you how to apply the CORK API to your parser in the next comment.

c = next;
next = getcFromInputFile ();
}

Copy link
Member

Choose a reason for hiding this comment

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

Remove the tab char at the beginning of line.

@masatake
Copy link
Member

masatake commented May 8, 2025

Let's use CORK API.
See the latest two commits at https://github.com/masatake/ctags/commits/tsp-20250509/ .

@masatake masatake added this to the 6.2 milestone May 8, 2025
namespace Name.Space;

@doc("API Versions")
enum Versions {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we fill the scope: field of Versions with Name.Space?
(This comment applies to the other extractions.)

  • No, TypeSpec is not such a language,
  • Yes, "I'm interested in implementing it in this pull request", or
  • Yes, but someone will fix it in the future.

If you're interested in implementing it in this pull request, talk to me. I have some hints.
Of course, "Yes, but someone ..." is acceptable.


Let's call the above three items NYY-choice.

@doc("API Versions")
enum Versions {
@doc("May 01, 2024 Preview API Version")
v2024_05_01_preview: "2024-05-01-preview",
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we extract v2024_05_01_preview ?

NYY-choice.

import "./common.tsp";

using TypeSpec;
using TypeSpec.Rest;
Copy link
Member

Choose a reason for hiding this comment

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

I'm interested in extracting imported items and usinged items.
I will work on them after merging this pull request.

#3906
#2428

ModelB<ModelA[]>
>;

interface InterfaceA extends InterfaceB {
Copy link
Member

Choose a reason for hiding this comment

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

We can fill inherits: field of interfaceA: with InterfaceB.
NYY-choice.

Filling such a field makes your work applicable to broader use cases.

Here is an example of C++.

$ cat /tmp/foo.cc 
class A: B {
	int x;
};
$ ./ctags -o - /tmp/foo.cc
A	/tmp/foo.cc	/^class A: B {$/;"	c	file:
x	/tmp/foo.cc	/^	int x;$/;"	m	class:A	typeref:typename:int	file:
$ ./ctags --fields=+i -o - /tmp/foo.cc
A	/tmp/foo.cc	/^class A: B {$/;"	c	file:	inherits:B
x	/tmp/foo.cc	/^	int x;$/;"	m	class:A	typeref:typename:int	file:
$ ./ctags --fields=+i -o foo.tags /tmp/foo.cc
$ ~/bin/querytags --tag-file foo.tags class-hierarchy  A
  A
   B

{ true, 'u', "union", "unions" },
{ true, 'a', "alias", "aliases" },
{ true, 'p', "property", "properties" }
};
Copy link
Member

Choose a reason for hiding this comment

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

My reviewing log: These are good. They align with the kinds of TypeScript.

dest->filePosition = src->filePosition;
dest->type = src->type;
vStringCopy (dest->string, src->string);
if (copyScope)
Copy link
Member

Choose a reason for hiding this comment

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

It seems that no caller passes true as copyScope. So you can remove the branch related to copyScope. Another choice is to keep dest->scope = src->scope; without the condition.

TParamB,
TParamC extends ModelX = {},
TError = Error
> = ModelB<TParamA, TParamB, TParamC, TError>;
Copy link
Member

Choose a reason for hiding this comment

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

Let's increase the testing coverage, though. We don't have a target percentage.

E.g., the code skipping

 // comment

is not tested at all.

Copy link
Member

Choose a reason for hiding this comment

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

String literal including \ is not converted.

}
else if (token->type == TOKEN_OPEN_CURLY)
{
enterScope(token, namespaceIndex);
Copy link
Member

Choose a reason for hiding this comment

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

This branch should be tested.

{
/* Skip expression after "is" */
do {
readToken(token);
Copy link
Member

Choose a reason for hiding this comment

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

This branch is not tested.

Comment on lines +302 to +308
parseIdentifier (token->string, c);
token->keyword = lookupCaseKeyword (
vStringValue (token->string), getInputLanguage ());
if (token->keyword == KEYWORD_NONE)
token->type = TOKEN_IDENTIFIER;
else
token->type = TOKEN_KEYWORD;
Copy link
Member

Choose a reason for hiding this comment

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

The indentation looks strange.

@masatake
Copy link
Member

Thank you for updating.

Could you add the name of the new parser to docs/news/HEAD.rst?

@masatake masatake modified the milestones: 6.2, 6.3 May 20, 2025
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