-
Notifications
You must be signed in to change notification settings - Fork 635
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
base: master
Are you sure you want to change the base?
TypeSpec: new parser #4243
Conversation
Codecov ReportAttention: Patch coverage is
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. 🚀 New features to boost your workflow:
|
There was a problem hiding this 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.
parsers/typespec.c
Outdated
c = next; | ||
next = getcFromInputFile (); | ||
} | ||
|
There was a problem hiding this comment.
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.
Let's use CORK API. |
namespace Name.Space; | ||
|
||
@doc("API Versions") | ||
enum Versions { |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ModelB<ModelA[]> | ||
>; | ||
|
||
interface InterfaceA extends InterfaceB { |
There was a problem hiding this comment.
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" } | ||
}; |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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>; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation looks strange.
Thank you for updating. Could you add the name of the new parser to docs/news/HEAD.rst? |
Add parser for TypeSpec
Test passed with
make units LANGUAGES=TypeSpec