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

Merged
merged 1 commit into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Units/parser-typespec.r/simple-typespec.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--sort=no
13 changes: 13 additions & 0 deletions Units/parser-typespec.r/simple-typespec.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Name.Space input.tsp /^namespace Name.Space;$/;" n
Inner input.tsp /^namespace Inner {$/;" n namespace:Name.Space
Versions input.tsp /^ enum Versions {$/;" g namespace:Name.Space.Inner
OpA input.tsp /^ op OpA<T extends TypeSpec.Reflection.Model> is OpB<$/;" o namespace:Name.Space.Inner
InterfaceA input.tsp /^ interface InterfaceA extends InterfaceB {$/;" i namespace:Name.Space.Inner
opA input.tsp /^ opA is OpA<{$/;" p interface:Name.Space.Inner.InterfaceA
opB input.tsp /^ opB is OpB<$/;" p interface:Name.Space.Inner.InterfaceA
UnionA input.tsp /^ union UnionA {$/;" u namespace:Name.Space.Inner
ModelA input.tsp /^model ModelA {$/;" m namespace:Name.Space
contentA input.tsp /^ contentA: ModelB;$/;" p model:Name.Space.ModelA
contentB input.tsp /^ contentB?: boolean;$/;" p model:Name.Space.ModelA
ModelB input.tsp /^model ModelB extends ModelA {$/;" m namespace:Name.Space
AliasA input.tsp /^alias AliasA<$/;" a namespace:Name.Space
92 changes: 92 additions & 0 deletions Units/parser-typespec.r/simple-typespec.d/input.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import "@typespec/http";
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


@armProviderNamespace
@service(#{ title: "Name.Space" })
@versioned(Versions)
@armCommonTypesVersion(CommonTypes.Versions.v3)
namespace Name.Space;

namespace Inner {
@doc("API Versions")
@added(a())
enum Versions {
@doc("May 01, 2024 Preview API Version")
v2024_05_01_preview: "2024-05-01-preview",
}

@summary("Example operation summary for demonstration purposes.")
@doc("""
Example
multi-line
documentation.
""")
@returnsDoc("Example return documentation")
@post
op OpA<T extends TypeSpec.Reflection.Model> is OpB<
T & ModelA,
ModelB<ModelA[]>
>;

// single line comment
interface InterfaceA extends InterfaceB {
opA is OpA<{
@doc("The format of the HTTP payload.")
@header
contentType: "application/json";

@clientName("uri", "c\\sharp")
@doc("Example URL parameter.")
opB: url;
}>;

/**
* Example operation description
*/
opB is OpB<
ModelA,
{
...ModelB
}
>;
}

@doc("Example union type description.")
union UnionA {
string,

@doc("Example option A description with some technical details that would be typical for this kind of documentation.")
"unionA",

@doc("Example option B description with additional technical context that would be common in API documentation.")
"unionB",
}
}

@doc("Example model description.")
model ModelA {
@doc("Example property description.")
contentA: ModelB;

@removed(Versions.v1_2)
@doc("Example boolean property with typical documentation about its purpose and default behavior.")
contentB?: boolean;

...ModelX;
}

@doc("Example model description.")
model ModelB extends ModelA {
...ModelX;
}


alias AliasA<
TParamA extends ModelX,
TParamB,
TParamC extends ModelX = {},
TError = Error
> = ModelB<TParamA, TParamB, TParamC, TError>;
1 change: 1 addition & 0 deletions docs/news/HEAD.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ New parsers
* PythonEntryPoints *subparser*
* Scdoc *optlib*
* JNI *subparser*
* TypeSpec *parser*

.. note:: We added a TOML as a new parser in this version. However,
after adding it, we learned its implementation didn't work
Expand Down
1 change: 1 addition & 0 deletions main/parsers_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
TTCNParser, \
Txt2tagsParser, \
TypeScriptParser, \
TypeSpecParser, \
VParser, \
VeraParser, \
VerilogParser, \
Expand Down
Loading
Loading