diff --git a/builtin/next.npl b/builtin/next.npl index e9c06de..2ac9237 100644 --- a/builtin/next.npl +++ b/builtin/next.npl @@ -300,40 +300,39 @@ false {{- end}} {{- end}} +{{/* next/node:snake.case.name: Generates a snake_case name for a node */}} {{- define "next/node:snake.case.name"}} -{{- with .Annotations.next.snake_case}} - {{- .}} +{{- with .Annotations.next.tokens}} + {{- . | split " " | join "_" | lower}} {{- else}} {{- $.Name | snakeCase}} {{- end}} {{- end}} -{{- define "next/node:pascal.case.name"}} -{{- with .Annotations.next.pascal_case}} - {{- .}} -{{- else with .Annotations.next.snake_case}} - {{- . | snakeCase | split "_" | map capitalize | join ""}} +{{/* next/node:kebab.case.name: Generates a kebab-case name for a node */}} +{{- define "next/node:kebab.case.name"}} +{{- with .Annotations.next.tokens}} + {{- . | split " " | join "-" | lower}} {{- else}} - {{- $.Name | pascalCase}} + {{- $.Name | kebabCase}} {{- end}} {{- end}} +{{/* next/node:camel.case.name: Generates a camelCase name for a node */}} {{- define "next/node:camel.case.name"}} -{{- with .Annotations.next.camel_case}} - {{- .}} -{{- else with .Annotations.next.snake_case}} - {{- . | snakeCase | split "_" | map capitalize | join "" | uncapitalize}} +{{- with .Annotations.next.tokens}} + {{- $tokens := . | split " "}} + {{- index $tokens 0 | lower}}{{slice $tokens 1 | map capitalize | join ""}} {{- else}} {{- $.Name | camelCase}} {{- end}} {{- end}} -{{- define "next/node:kebab.case.name"}} -{{- with .Annotations.next.kebab_case}} - {{- .}} -{{- else with .Annotations.next.snake_case}} - {{- . | snakeCase | replace "_" "-"}} +{{/* next/node:pascal.case.name: Generates a PascalCase name for a node */}} +{{- define "next/node:pascal.case.name"}} +{{- with .Annotations.next.tokens}} + {{- . | split " " | map capitalize | join ""}} {{- else}} - {{- $.Name | kebabCase}} + {{- $.Name | pascalCase}} {{- end}} {{- end}} \ No newline at end of file diff --git a/src/compile/comment.go b/src/compile/comment.go index ed28563..89ef77d 100644 --- a/src/compile/comment.go +++ b/src/compile/comment.go @@ -211,14 +211,25 @@ func formatComments(list []string, appendNewline bool, indent string, beginAndEn if len(begins) > 1 { lines = append(begins[1:], lines...) } + + trimmedIndent := strings.TrimRight(indent, " \t") if end == "" { for i, line := range lines { - lines[i] = indent + begin + line + line = begin + line + if line == "" { + lines[i] = trimmedIndent + } else { + lines[i] = indent + line + } } } else { lines = append([]string{begin + lines[0]}, lines[1:]...) for i := 1; i < len(lines); i++ { - lines[i] = indent + lines[i] + if lines[i] == "" { + lines[i] = trimmedIndent + } else { + lines[i] = indent + lines[i] + } } lines = append(lines, end) } diff --git a/src/grammar/grammar.go b/src/grammar/grammar.go index 5ee8e0c..1b9f0c0 100644 --- a/src/grammar/grammar.go +++ b/src/grammar/grammar.go @@ -1460,6 +1460,10 @@ func next(node string, parameters ...Options[AnnotationParameter]) Options[Annot }) } +func base_next(node string, parameters ...Options[AnnotationParameter]) Options[Annotation] { + return next(node, append(parameters, available(), deprecated(), tokens())...) +} + func deprecated() Options[AnnotationParameter] { return opt(AnnotationParameter{ Name: "deprecated", @@ -1484,39 +1488,10 @@ func default_() Options[AnnotationParameter] { }) } -func withCases(a Options[Annotation]) Options[Annotation] { - a.value.Parameters = append(a.value.Parameters, snake_case(), camel_case(), pascal_case(), kebab_case()) - return a -} - -func snake_case() Options[AnnotationParameter] { - return opt(AnnotationParameter{ - Name: "snake_case", - Description: "Sets the snake_case name for the declaration.", - Types: types(String), - }) -} - -func camel_case() Options[AnnotationParameter] { - return opt(AnnotationParameter{ - Name: "camel_case", - Description: "Sets the camelCase name for the declaration.", - Types: types(String), - }) -} - -func pascal_case() Options[AnnotationParameter] { - return opt(AnnotationParameter{ - Name: "pascal_case", - Description: "Sets the PascalCase name for the declaration.", - Types: types(String), - }) -} - -func kebab_case() Options[AnnotationParameter] { +func tokens() Options[AnnotationParameter] { return opt(AnnotationParameter{ - Name: "kebab_case", - Description: "Sets the kebab-case name for the declaration.", + Name: "tokens", + Description: "Sets the space separated tokens for the declaration.", Types: types(String), }) } @@ -1553,7 +1528,7 @@ func type_() Options[AnnotationParameter] { }) } -func LANG_package() Options[AnnotationParameter] { +func lang_package() Options[AnnotationParameter] { return opt(AnnotationParameter{ Name: ".+_package", Description: "Sets the package name for target languages.", @@ -1568,7 +1543,7 @@ func LANG_package() Options[AnnotationParameter] { }) } -func LANG_imports() Options[AnnotationParameter] { +func lang_imports() Options[AnnotationParameter] { return opt(AnnotationParameter{ Name: ".+_imports", Description: "Sets the import declarations for target languages.", @@ -1576,7 +1551,7 @@ func LANG_imports() Options[AnnotationParameter] { }) } -func LANG_alias() Options[AnnotationParameter] { +func lang_alias() Options[AnnotationParameter] { return opt(AnnotationParameter{ Name: ".+_alias", Description: "Sets the alias name for target languages.", @@ -1591,31 +1566,31 @@ func appendTo[S ~[]T, T any](s *S, x ...T) { var Builtin = Grammar{ builtin: true, Package: Package{ - Annotations: Annotations{withCases(next("package", available(), deprecated(), LANG_package(), LANG_imports()))}, + Annotations: Annotations{base_next("package", lang_package(), lang_imports())}, }, Const: Const{ - Annotations: Annotations{withCases(next("const", available(), deprecated()))}, + Annotations: Annotations{base_next("const")}, Types: validConstTypes, }, Enum: Enum{ - Annotations: Annotations{next("enum", available(), deprecated(), type_())}, + Annotations: Annotations{base_next("enum", type_())}, Member: EnumMember{ - Annotations: Annotations{withCases(next("enum.member", available(), deprecated()))}, + Annotations: Annotations{base_next("enum.member")}, Types: validEnumMemberTypes, }, }, Struct: Struct{ - Annotations: Annotations{next("struct", available(), deprecated(), LANG_alias())}, + Annotations: Annotations{base_next("struct", lang_alias())}, Field: StructField{ - Annotations: Annotations{withCases(next("struct.field", available(), deprecated(), optional(), default_(), LANG_alias()))}, + Annotations: Annotations{base_next("struct.field", optional(), default_(), lang_alias())}, }, }, Interface: Interface{ - Annotations: Annotations{next("interface", available(), deprecated(), LANG_alias())}, + Annotations: Annotations{base_next("interface", lang_alias())}, Method: InterfaceMethod{ - Annotations: Annotations{withCases(next("interface.method", available(), deprecated(), mut(), error_()))}, + Annotations: Annotations{base_next("interface.method", mut(), error_())}, Parameter: InterfaceMethodParameter{ - Annotations: Annotations{withCases(next("interface.method.parameter", mut(), LANG_alias()))}, + Annotations: Annotations{next("interface.method.parameter", deprecated(), tokens(), mut(), lang_alias())}, }, }, }, diff --git a/website/example/gen/c/a/a.next.h b/website/example/gen/c/a/a.next.h index 10e3a3d..e35590b 100644 --- a/website/example/gen/c/a/a.next.h +++ b/website/example/gen/c/a/a.next.h @@ -173,8 +173,8 @@ typedef enum DEMO_A_IotatestEnum { * Struct types */ typedef struct DEMO_A_Point2D { - double x; - double y; + double x; /* x-coordinate */ + double y; /* y-coordinate */ } DEMO_A_Point2D; typedef struct DEMO_A_Point3D { diff --git a/website/example/gen/c/demo/demo.next.h b/website/example/gen/c/demo/demo.next.h index e0aa1e2..7c2231d 100644 --- a/website/example/gen/c/demo/demo.next.h +++ b/website/example/gen/c/demo/demo.next.h @@ -77,6 +77,14 @@ typedef struct DEMO_User { int32_t matrix[3][2]; char* email; DEMO_Color favorite_color; + /** + * @next(tokens) applies to the node name: + * - For snake_case: "last_login_ip" + * - For camelCase: "lastLoginIP" + * - For PascalCase: "LastLoginIP" + * - For kebab-case: "last-login-ip" + */ + char* last_login_ip; void* extra; } DEMO_User; @@ -154,11 +162,11 @@ struct DEMO_Reader { * @next(error) applies to the method: * - For Go: The method may return an error * - For C++/Java: The method throws an exception - * + * * @next(mut) applies to the method: * - For C++: The method is non-const * - For other languages: This annotation may not have a direct effect - * + * * @next(mut) applies to the parameter buffer: * - For C++: The parameter is non-const, allowing modification * - For other languages: This annotation may not have a direct effect, @@ -176,7 +184,7 @@ typedef struct DEMO_HTTPClient DEMO_HTTPClient; struct DEMO_HTTPClient { void* context; char* (*request)(DEMO_HTTPClient* self, char* url, char* method, char* body); - char* (*request_2)(DEMO_HTTPClient* self, char* url, char* method, char* body); + char* (*request2)(DEMO_HTTPClient* self, char* url, char* method, char* body); }; /** @@ -186,8 +194,8 @@ static inline char* DEMO_HTTPClient_request(DEMO_HTTPClient* self, char* url, ch return self->request(self, url, method, body); } -static inline char* DEMO_HTTPClient_request_2(DEMO_HTTPClient* self, char* url, char* method, char* body) { - return self->request_2(self, url, method, body); +static inline char* DEMO_HTTPClient_request2(DEMO_HTTPClient* self, char* url, char* method, char* body) { + return self->request2(self, url, method, body); } #endif /* DEMO_DEMO_H */ diff --git a/website/example/gen/cpp/a.h b/website/example/gen/cpp/a.h index f97ac8f..f5a1024 100644 --- a/website/example/gen/cpp/a.h +++ b/website/example/gen/cpp/a.h @@ -149,8 +149,8 @@ enum class IotatestEnum : int32_t { // Struct types class Point2D { public: - double x = {0.0}; - double y = {0.0}; + double x = {0.0}; // x-coordinate + double y = {0.0}; // y-coordinate public: Point2D() = default; diff --git a/website/example/gen/cpp/demo.h b/website/example/gen/cpp/demo.h index edb4e19..41f7826 100644 --- a/website/example/gen/cpp/demo.h +++ b/website/example/gen/cpp/demo.h @@ -88,6 +88,12 @@ class User { std::array, 3> matrix; std::string email = {""}; Color favorite_color = {Color(0)}; + // @next(tokens) applies to the node name: + // - For snake_case: "last_login_ip" + // - For camelCase: "lastLoginIP" + // - For PascalCase: "LastLoginIP" + // - For kebab-case: "last-login-ip" + std::string last_login_ip = {""}; std::any extra; public: @@ -157,11 +163,11 @@ class Reader { // @next(error) applies to the method: // - For Go: The method may return an error // - For C++/Java: The method throws an exception - // + // // @next(mut) applies to the method: // - For C++: The method is non-const // - For other languages: This annotation may not have a direct effect - // + // // @next(mut) applies to the parameter buffer: // - For C++: The parameter is non-const, allowing modification // - For other languages: This annotation may not have a direct effect, @@ -175,7 +181,7 @@ class HTTPClient { virtual ~HTTPClient() = default; // Available for all languages virtual std::string request(const std::string& url, const std::string& method, const std::string& body) const = 0; - virtual std::string request_2(const std::string& url, const std::string& method, const std::string& body) const = 0; + virtual std::string request2(const std::string& url, const std::string& method, const std::string& body) const = 0; // Available for C++ virtual std::string post(const std::string& url, const std::string& body) const = 0; }; diff --git a/website/example/gen/csharp/a/a.next.cs b/website/example/gen/csharp/a/a.next.cs index 30cfd9b..01c81d0 100644 --- a/website/example/gen/csharp/a/a.next.cs +++ b/website/example/gen/csharp/a/a.next.cs @@ -129,8 +129,8 @@ public enum IotatestEnum // Struct types public class Point2D { - public double x { get; set; } - public double y { get; set; } + public double x { get; set; } // x-coordinate + public double y { get; set; } // y-coordinate } public class Point3D diff --git a/website/example/gen/csharp/demo/demo.next.cs b/website/example/gen/csharp/demo/demo.next.cs index 3e7e468..859a8e1 100644 --- a/website/example/gen/csharp/demo/demo.next.cs +++ b/website/example/gen/csharp/demo/demo.next.cs @@ -47,6 +47,12 @@ public class User public int[][] matrix { get; set; } public string email { get; set; } public Color favoriteColor { get; set; } + // @next(tokens) applies to the node name: + // - For snake_case: "last_login_ip" + // - For camelCase: "lastLoginIP" + // - For PascalCase: "LastLoginIP" + // - For kebab-case: "last-login-ip" + public string lastLoginIP { get; set; } public object extra { get; set; } } @@ -95,11 +101,11 @@ public interface Reader // @next(error) applies to the method: // - For Go: The method may return an error // - For C++/Java: The method throws an exception - // + // // @next(mut) applies to the method: // - For C++: The method is non-const // - For other languages: This annotation may not have a direct effect - // + // // @next(mut) applies to the parameter buffer: // - For C++: The parameter is non-const, allowing modification // - For other languages: This annotation may not have a direct effect, diff --git a/website/example/gen/go/a/a.next.go b/website/example/gen/go/a/a.next.go index aed6282..feaf39b 100644 --- a/website/example/gen/go/a/a.next.go +++ b/website/example/gen/go/a/a.next.go @@ -48,90 +48,90 @@ const Complex5 = 31 type Color int32 const ( - ColorRed = 1 - ColorGreen = 2 - ColorBlue = 4 - ColorAlpha = 8 - ColorYellow = 3 - ColorCyan = 6 - ColorMagenta = 5 - ColorWhite = 7 + ColorRed Color = 1 + ColorGreen Color = 2 + ColorBlue Color = 4 + ColorAlpha Color = 8 + ColorYellow Color = 3 + ColorCyan Color = 6 + ColorMagenta Color = 5 + ColorWhite Color = 7 ) // Enum with complex iota usage type FilePermission int32 const ( - FilePermissionNone = 0 - FilePermissionExecute = 1 - FilePermissionWrite = 2 - FilePermissionRead = 4 - FilePermissionUserRead = 4 - FilePermissionUserWrite = 32 - FilePermissionUserExecute = 256 - FilePermissionGroupRead = 2048 - FilePermissionGroupWrite = 16384 - FilePermissionGroupExecute = 131072 - FilePermissionOthersRead = 1048576 - FilePermissionOthersWrite = 8388608 - FilePermissionOthersExecute = 67108864 + FilePermissionNone FilePermission = 0 + FilePermissionExecute FilePermission = 1 + FilePermissionWrite FilePermission = 2 + FilePermissionRead FilePermission = 4 + FilePermissionUserRead FilePermission = 4 + FilePermissionUserWrite FilePermission = 32 + FilePermissionUserExecute FilePermission = 256 + FilePermissionGroupRead FilePermission = 2048 + FilePermissionGroupWrite FilePermission = 16384 + FilePermissionGroupExecute FilePermission = 131072 + FilePermissionOthersRead FilePermission = 1048576 + FilePermissionOthersWrite FilePermission = 8388608 + FilePermissionOthersExecute FilePermission = 67108864 // 4|32|256|2048|16384|131072|1048576|8388608|67108864 // 4 + 32 + 256 + 2048 + 16384 + 131072 + 1048576 + 8388608 + 67108864 - FilePermissionAll = 76695844 + FilePermissionAll FilePermission = 76695844 ) type Day int32 const ( - DayMonday = 1 - DayTuesday = 2 - DayWednesday = 4 - DayThursday = 8 - DayFriday = 16 - DaySaturday = 32 - DaySunday = 64 - DayWeekday = 31 - DayWeekend = 96 + DayMonday Day = 1 + DayTuesday Day = 2 + DayWednesday Day = 4 + DayThursday Day = 8 + DayFriday Day = 16 + DaySaturday Day = 32 + DaySunday Day = 64 + DayWeekday Day = 31 + DayWeekend Day = 96 ) type Month int32 const ( - MonthJanuary = 1 - MonthFebruary = 2 - MonthMarch = 4 - MonthApril = 8 - MonthMay = 16 - MonthJune = 32 - MonthJuly = 64 - MonthAugust = 128 - MonthSeptember = 256 - MonthOctober = 512 - MonthNovember = 1024 - MonthDecember = 2048 - MonthQ1 = 7 - MonthQ2 = 56 - MonthQ3 = 448 - MonthQ4 = 3584 + MonthJanuary Month = 1 + MonthFebruary Month = 2 + MonthMarch Month = 4 + MonthApril Month = 8 + MonthMay Month = 16 + MonthJune Month = 32 + MonthJuly Month = 64 + MonthAugust Month = 128 + MonthSeptember Month = 256 + MonthOctober Month = 512 + MonthNovember Month = 1024 + MonthDecember Month = 2048 + MonthQ1 Month = 7 + MonthQ2 Month = 56 + MonthQ3 Month = 448 + MonthQ4 Month = 3584 ) // Test cases for iota type IotatestEnum int32 const ( - IotatestEnumA = 0 // 0 - IotatestEnumB = 1 // 1 - IotatestEnumC = 0 // 0 - IotatestEnumD = 2 // 2 - IotatestEnumE = 0 // 0 - IotatestEnumF = 1 // 1 - IotatestEnumG = 0 // 0 + IotatestEnumA IotatestEnum = 0 // 0 + IotatestEnumB IotatestEnum = 1 // 1 + IotatestEnumC IotatestEnum = 0 // 0 + IotatestEnumD IotatestEnum = 2 // 2 + IotatestEnumE IotatestEnum = 0 // 0 + IotatestEnumF IotatestEnum = 1 // 1 + IotatestEnumG IotatestEnum = 0 // 0 ) // Struct types type Point2D struct { - X float64 - Y float64 + X float64 // x-coordinate + Y float64 // y-coordinate } type Point3D struct { diff --git a/website/example/gen/go/b/b.next.go b/website/example/gen/go/b/b.next.go index 26a81eb..2bdbcbf 100644 --- a/website/example/gen/go/b/b.next.go +++ b/website/example/gen/go/b/b.next.go @@ -9,13 +9,13 @@ var _ = (*a.Color)(nil) type TestEnum int32 const ( - TestEnumA = 1 - TestEnumB = 5 - TestEnumC = 5 - TestEnumD = 10 - TestEnumE = 20 - TestEnumF = 1 - TestEnumG = 2 + TestEnumA TestEnum = 1 + TestEnumB TestEnum = 5 + TestEnumC TestEnum = 5 + TestEnumD TestEnum = 10 + TestEnumE TestEnum = 20 + TestEnumF TestEnum = 1 + TestEnumG TestEnum = 2 ) type TestStruct struct { diff --git a/website/example/gen/go/c/c.next.go b/website/example/gen/go/c/c.next.go index 7b7c3f4..15b5bd1 100644 --- a/website/example/gen/go/c/c.next.go +++ b/website/example/gen/go/c/c.next.go @@ -16,23 +16,23 @@ const D = true type Color int32 const ( - ColorRed = 0 - ColorGreen = 1 - ColorBlue = 2 + ColorRed Color = 0 + ColorGreen Color = 1 + ColorBlue Color = 2 ) type LoginType int32 const ( - LoginTypeUsername = 1 - LoginTypeEmail = 2 + LoginTypeUsername LoginType = 1 + LoginTypeEmail LoginType = 2 ) type UserType int32 const ( - UserTypeAdmin = 1 - UserTypeUser = 2 + UserTypeAdmin UserType = 1 + UserTypeUser UserType = 2 ) type User struct { diff --git a/website/example/gen/go/demo/demo.next.go b/website/example/gen/go/demo/demo.next.go index 4476848..8d34a25 100644 --- a/website/example/gen/go/demo/demo.next.go +++ b/website/example/gen/go/demo/demo.next.go @@ -17,34 +17,34 @@ const Timeout = 3000.0 // Float constant expression type Color int8 const ( - ColorRed = 1 - ColorGreen = 2 - ColorBlue = 4 - ColorYellow = 8 + ColorRed Color = 1 + ColorGreen Color = 2 + ColorBlue Color = 4 + ColorYellow Color = 8 ) // MathConstants represents mathematical constants type MathConstants float64 const ( - MathConstantsPi = 3.14159265358979323846 - MathConstantsE = 2.71828182845904523536 + MathConstantsPi MathConstants = 3.14159265358979323846 + MathConstantsE MathConstants = 2.71828182845904523536 ) // OperatingSystem represents different operating systems type OperatingSystem string const ( - OperatingSystemWindows = "windows" - OperatingSystemLinux = "linux" - OperatingSystemMacOS = "macos" - OperatingSystemAndroid = "android" - OperatingSystemIOS = "ios" + OperatingSystemWindows OperatingSystem = "windows" + OperatingSystemLinux OperatingSystem = "linux" + OperatingSystemMacOS OperatingSystem = "macos" + OperatingSystemAndroid OperatingSystem = "android" + OperatingSystemIOS OperatingSystem = "ios" ) // User represents a user in the system type User struct { - Id int64 + ID int64 Username string Tags []string Scores map[string]int @@ -52,6 +52,12 @@ type User struct { Matrix [3][2]int Email string FavoriteColor Color + // @next(tokens) applies to the node name: + // - For snake_case: "last_login_ip" + // - For camelCase: "lastLoginIP" + // - For PascalCase: "LastLoginIP" + // - For kebab-case: "last-login-ip" + LastLoginIP string Extra any } @@ -95,11 +101,11 @@ type Reader interface { // @next(error) applies to the method: // - For Go: The method may return an error // - For C++/Java: The method throws an exception - // + // // @next(mut) applies to the method: // - For C++: The method is non-const // - For other languages: This annotation may not have a direct effect - // + // // @next(mut) applies to the parameter buffer: // - For C++: The parameter is non-const, allowing modification // - For other languages: This annotation may not have a direct effect, @@ -107,6 +113,14 @@ type Reader interface { Read(buffer []byte) (int, error) } +// HTTPServer provides HTTP server functionality. +// +// @next(available="go|java") indicates that the interface is available for Go and Java. +// @next(tokens="HTTP Server") applies to the interface name. +// - For snake_case: "http_server" +// - For camelCase: "httpServer" +// - For PascalCase: "HTTPServer" +// - For kebab-case: "http-server" type HTTPServer interface { // @next(error) indicates that the method may return an error: // - For Go: The method returns (LoginResponse, error) diff --git a/website/example/gen/java/com/example/a/Point2D.java b/website/example/gen/java/com/example/a/Point2D.java index eaa1d7d..6470405 100644 --- a/website/example/gen/java/com/example/a/Point2D.java +++ b/website/example/gen/java/com/example/a/Point2D.java @@ -10,7 +10,7 @@ * Struct types */ public class Point2D { - private double x; + private double x; // x-coordinate public double getX() { return x; @@ -20,7 +20,7 @@ public void setX(double x) { this.x = x; } - private double y; + private double y; // y-coordinate public double getY() { return y; diff --git a/website/example/gen/java/com/example/demo/HTTPServer.java b/website/example/gen/java/com/example/demo/HTTPServer.java index dd02a00..6010b27 100644 --- a/website/example/gen/java/com/example/demo/HTTPServer.java +++ b/website/example/gen/java/com/example/demo/HTTPServer.java @@ -6,6 +6,16 @@ import java.util.Map; import java.util.Arrays; +/** + * HTTPServer provides HTTP server functionality. + * + * @next(available="go|java") indicates that the interface is available for Go and Java. + * @next(tokens="HTTP Server") applies to the interface name. + * - For snake_case: "http_server" + * - For camelCase: "httpServer" + * - For PascalCase: "HTTPServer" + * - For kebab-case: "http-server" + */ public interface HTTPServer { /** * @next(error) indicates that the method may return an error: diff --git a/website/example/gen/java/com/example/demo/Reader.java b/website/example/gen/java/com/example/demo/Reader.java index b7d0e0d..d382544 100644 --- a/website/example/gen/java/com/example/demo/Reader.java +++ b/website/example/gen/java/com/example/demo/Reader.java @@ -14,11 +14,11 @@ public interface Reader { * @next(error) applies to the method: * - For Go: The method may return an error * - For C++/Java: The method throws an exception - * + * * @next(mut) applies to the method: * - For C++: The method is non-const * - For other languages: This annotation may not have a direct effect - * + * * @next(mut) applies to the parameter buffer: * - For C++: The parameter is non-const, allowing modification * - For other languages: This annotation may not have a direct effect, diff --git a/website/example/gen/java/com/example/demo/User.java b/website/example/gen/java/com/example/demo/User.java index 702a539..507240d 100644 --- a/website/example/gen/java/com/example/demo/User.java +++ b/website/example/gen/java/com/example/demo/User.java @@ -90,6 +90,23 @@ public void setFavoriteColor(Color favoriteColor) { this.favoriteColor = favoriteColor; } + /** + * @next(tokens) applies to the node name: + * - For snake_case: "last_login_ip" + * - For camelCase: "lastLoginIP" + * - For PascalCase: "LastLoginIP" + * - For kebab-case: "last-login-ip" + */ + private String lastLoginIP; + + public String getLastLoginIP() { + return lastLoginIP; + } + + public void setLastLoginIP(String lastLoginIP) { + this.lastLoginIP = lastLoginIP; + } + private Object extra; public Object getExtra() { diff --git a/website/example/gen/js/a.js b/website/example/gen/js/a.js index 9854327..f8b90b6 100644 --- a/website/example/gen/js/a.js +++ b/website/example/gen/js/a.js @@ -142,9 +142,9 @@ export const IotatestEnum = Object.freeze({ export class Point2D { constructor() { /** @type { Number } */ - this.x = 0; + this.x = 0; // x-coordinate /** @type { Number } */ - this.y = 0; + this.y = 0; // y-coordinate } } diff --git a/website/example/gen/js/demo.js b/website/example/gen/js/demo.js index 8f2845c..7590bb9 100644 --- a/website/example/gen/js/demo.js +++ b/website/example/gen/js/demo.js @@ -55,6 +55,15 @@ export class User { this.email = ""; /** @type { 'number' } */ this.favoriteColor = Color[Object.keys(Color)[0]]; + /** + * @next(tokens) applies to the node name: + * - For snake_case: "last_login_ip" + * - For camelCase: "lastLoginIP" + * - For PascalCase: "LastLoginIP" + * - For kebab-case: "last-login-ip" + * @type { String } + */ + this.lastLoginIP = ""; /** @type { 'Object' } */ this.extra = null; } @@ -147,11 +156,11 @@ export class Reader { * @next(error) applies to the method: * - For Go: The method may return an error * - For C++/Java: The method throws an exception - * + * * @next(mut) applies to the method: * - For C++: The method is non-const * - For other languages: This annotation may not have a direct effect - * + * * @next(mut) applies to the parameter buffer: * - For C++: The parameter is non-const, allowing modification * - For other languages: This annotation may not have a direct effect, diff --git a/website/example/gen/lua/a.lua b/website/example/gen/lua/a.lua index 306e9c5..bbd7f5e 100644 --- a/website/example/gen/lua/a.lua +++ b/website/example/gen/lua/a.lua @@ -132,8 +132,8 @@ Point2D.__index = Point2D function Point2D:new() local obj = { - x = 0, - y = 0 + x = 0, -- x-coordinate + y = 0 -- y-coordinate } setmetatable(obj, self) return obj diff --git a/website/example/gen/lua/demo.lua b/website/example/gen/lua/demo.lua index ed78f01..4154724 100644 --- a/website/example/gen/lua/demo.lua +++ b/website/example/gen/lua/demo.lua @@ -50,6 +50,12 @@ function User:new() matrix = {}, email = "", favoriteColor = nil, + -- @next(tokens) applies to the node name: + -- - For snake_case: "last_login_ip" + -- - For camelCase: "lastLoginIP" + -- - For PascalCase: "LastLoginIP" + -- - For kebab-case: "last-login-ip" + lastLoginIP = "", extra = nil } setmetatable(obj, self) @@ -148,11 +154,11 @@ Reader.__index = Reader -- @next(error) applies to the method: -- - For Go: The method may return an error -- - For C++/Java: The method throws an exception --- +-- -- @next(mut) applies to the method: -- - For C++: The method is non-const -- - For other languages: This annotation may not have a direct effect --- +-- -- @next(mut) applies to the parameter buffer: -- - For C++: The parameter is non-const, allowing modification -- - For other languages: This annotation may not have a direct effect, diff --git a/website/example/gen/php/a.php b/website/example/gen/php/a.php index 74bd4e2..e44e53e 100644 --- a/website/example/gen/php/a.php +++ b/website/example/gen/php/a.php @@ -147,8 +147,8 @@ enum IotatestEnum : int */ class Point2D { - public float $x; - public float $y; + public float $x; // x-coordinate + public float $y; // y-coordinate public function __construct() { diff --git a/website/example/gen/php/demo.php b/website/example/gen/php/demo.php index e192ca5..99007e9 100644 --- a/website/example/gen/php/demo.php +++ b/website/example/gen/php/demo.php @@ -42,6 +42,14 @@ class User public array $matrix; public string $email; public Color $favoriteColor; + /** + * @next(tokens) applies to the node name: + * - For snake_case: "last_login_ip" + * - For camelCase: "lastLoginIP" + * - For PascalCase: "LastLoginIP" + * - For kebab-case: "last-login-ip" + */ + public string $lastLoginIP; public mixed $extra; public function __construct() @@ -54,6 +62,7 @@ public function __construct() $this->matrix = []; $this->email = ""; $this->favoriteColor = Color::RED; + $this->lastLoginIP = ""; $this->extra = null; } } @@ -161,11 +170,11 @@ interface Reader * @next(error) applies to the method: * - For Go: The method may return an error * - For C++/Java: The method throws an exception - * + * * @next(mut) applies to the method: * - For C++: The method is non-const * - For other languages: This annotation may not have a direct effect - * + * * @next(mut) applies to the parameter buffer: * - For C++: The parameter is non-const, allowing modification * - For other languages: This annotation may not have a direct effect, diff --git a/website/example/gen/protobuf/a.proto b/website/example/gen/protobuf/a.proto index 968e2c6..d24c3f6 100644 --- a/website/example/gen/protobuf/a.proto +++ b/website/example/gen/protobuf/a.proto @@ -88,8 +88,8 @@ enum IotatestEnum { // Struct types message Point2D { - double x = 1; - double y = 2; + double x = 1; // x-coordinate + double y = 2; // y-coordinate } message Point3D { diff --git a/website/example/gen/protobuf/demo.proto b/website/example/gen/protobuf/demo.proto index 0b9b323..e09321c 100644 --- a/website/example/gen/protobuf/demo.proto +++ b/website/example/gen/protobuf/demo.proto @@ -32,7 +32,13 @@ message User { repeated int32 matrix = 6; string email = 7 [deprecated = true]; Color favoriteColor = 8 [deprecated = true]; - google.protobuf.Any extra = 9; + // @next(tokens) applies to the node name: + // - For snake_case: "last_login_ip" + // - For camelCase: "lastLoginIP" + // - For PascalCase: "LastLoginIP" + // - For kebab-case: "last-login-ip" + string lastLoginIP = 9; + google.protobuf.Any extra = 10; } // uint128 represents a 128-bit unsigned integer. diff --git a/website/example/gen/python/a.py b/website/example/gen/python/a.py index 09f064f..3937177 100644 --- a/website/example/gen/python/a.py +++ b/website/example/gen/python/a.py @@ -139,8 +139,8 @@ class IotatestEnum: """ class Point2D: def __init__(self): - self.x = 0 - self.y = 0 + self.x = 0 # x-coordinate + self.y = 0 # y-coordinate class Point3D: def __init__(self): diff --git a/website/example/gen/python/demo.py b/website/example/gen/python/demo.py index af836a7..7a601a0 100644 --- a/website/example/gen/python/demo.py +++ b/website/example/gen/python/demo.py @@ -47,6 +47,14 @@ def __init__(self): self.matrix = [[0 for _ in range(2)] for _ in range(3)] self.email = "" self.favorite_color = Color(0) + """ + @next(tokens) applies to the node name: + - For snake_case: "last_login_ip" + - For camelCase: "lastLoginIP" + - For PascalCase: "LastLoginIP" + - For kebab-case: "last-login-ip" + """ + self.last_login_ip = "" self.extra = None """ @@ -158,5 +166,5 @@ def request(self, url: str, method: str, body: str) -> str: str """ @abstractmethod - def request_2(self, url: str, method: str, body: str) -> str: + def request2(self, url: str, method: str, body: str) -> str: pass diff --git a/website/example/gen/rust/src/a/a.rs b/website/example/gen/rust/src/a/a.rs index 59c55d3..dc2a7e8 100644 --- a/website/example/gen/rust/src/a/a.rs +++ b/website/example/gen/rust/src/a/a.rs @@ -217,8 +217,8 @@ impl IotatestEnum { /// Struct types pub struct Point2D { - pub x: f64, - pub y: f64, + pub x: f64 // x-coordinate, + pub y: f64 // y-coordinate, } pub struct Point3D { diff --git a/website/example/gen/rust/src/demo/demo.rs b/website/example/gen/rust/src/demo/demo.rs index 1883bb3..86e5865 100644 --- a/website/example/gen/rust/src/demo/demo.rs +++ b/website/example/gen/rust/src/demo/demo.rs @@ -78,6 +78,12 @@ pub struct User { pub matrix: [[i32; 2]; 3], pub email: String, pub favorite_color: Color, + /// @next(tokens) applies to the node name: + /// - For snake_case: "last_login_ip" + /// - For camelCase: "lastLoginIP" + /// - For PascalCase: "LastLoginIP" + /// - For kebab-case: "last-login-ip" + pub last_login_ip: String, pub extra: Box, } @@ -121,11 +127,11 @@ pub trait Reader { /// @next(error) applies to the method: /// - For Go: The method may return an error /// - For C++/Java: The method throws an exception - /// + /// /// @next(mut) applies to the method: /// - For C++: The method is non-const /// - For other languages: This annotation may not have a direct effect - /// + /// /// @next(mut) applies to the parameter buffer: /// - For C++: The parameter is non-const, allowing modification /// - For other languages: This annotation may not have a direct effect, @@ -137,5 +143,5 @@ pub trait Reader { pub trait HTTPClient { /// Available for all languages fn request(&self, url: String, method: String, body: String) -> String; - fn request_2(&self, url: String, method: String, body: String) -> String; + fn request2(&self, url: String, method: String, body: String) -> String; } diff --git a/website/example/gen/ts/a.ts b/website/example/gen/ts/a.ts index 9d2c613..5792589 100644 --- a/website/example/gen/ts/a.ts +++ b/website/example/gen/ts/a.ts @@ -140,8 +140,8 @@ export enum IotatestEnum { * Struct types */ export class Point2D { - x: number = 0; - y: number = 0; + x: number = 0; // x-coordinate + y: number = 0; // y-coordinate } export class Point3D { diff --git a/website/example/gen/ts/demo.ts b/website/example/gen/ts/demo.ts index 8005d62..05677ff 100644 --- a/website/example/gen/ts/demo.ts +++ b/website/example/gen/ts/demo.ts @@ -46,6 +46,14 @@ export class User { matrix: Array> = []; email: string = ""; favoriteColor: Color = 0 as Color; + /** + * @next(tokens) applies to the node name: + * - For snake_case: "last_login_ip" + * - For camelCase: "lastLoginIP" + * - For PascalCase: "LastLoginIP" + * - For kebab-case: "last-login-ip" + */ + lastLoginIP: string = ""; extra: any = null; } @@ -113,11 +121,11 @@ export interface Reader { * @next(error) applies to the method: * - For Go: The method may return an error * - For C++/Java: The method throws an exception - * + * * @next(mut) applies to the method: * - For C++: The method is non-const * - For other languages: This annotation may not have a direct effect - * + * * @next(mut) applies to the parameter buffer: * - For C++: The parameter is non-const, allowing modification * - For other languages: This annotation may not have a direct effect, diff --git a/website/example/next/a.next b/website/example/next/a.next index a4a4bb7..51b3e19 100644 --- a/website/example/next/a.next +++ b/website/example/next/a.next @@ -10,7 +10,7 @@ package a; // XX constant // XX value 2 -@next(snake_case="xx", pascal_case="XX") +@next(tokens="XX") const XX = 1; // XX value // Constants diff --git a/website/example/next/demo.next b/website/example/next/demo.next index 1d12ebc..cddba19 100644 --- a/website/example/next/demo.next +++ b/website/example/next/demo.next @@ -40,6 +40,7 @@ enum MathConstants { // User represents a user in the system struct User { + @next(tokens="ID") int64 id; string username; vector tags; @@ -49,6 +50,14 @@ struct User { @next(deprecated) string email; @next(deprecated="favoriteColor is deprecated, use tags instead") Color favoriteColor; + + // @next(tokens) applies to the node name: + // - For snake_case: "last_login_ip" + // - For camelCase: "lastLoginIP" + // - For PascalCase: "LastLoginIP" + // - For kebab-case: "last-login-ip" + @next(tokens="Last Login IP") + string lastLoginIP; any extra; } @@ -156,7 +165,15 @@ interface Reader { ) interface HTTPHandler {} -@next(available="go|java") +// HTTPServer provides HTTP server functionality. +// +// @next(available="go|java") indicates that the interface is available for Go and Java. +// @next(tokens="HTTP Server") applies to the interface name. +// - For snake_case: "http_server" +// - For camelCase: "httpServer" +// - For PascalCase: "HTTPServer" +// - For kebab-case: "http-server" +@next(available="go|java", tokens="HTTP Server") interface HTTPServer { // @next(error) indicates that the method may return an error: // - For Go: The method returns (LoginResponse, error) @@ -166,9 +183,12 @@ interface HTTPServer { } // HTTPClient provides HTTP request functionality +@next(tokens="HTTP Client") interface HTTPClient { // Available for all languages request(string url, string method, string body) string; + + @next(tokens="Request2") request2(string url, string method, string body) string; // Available for Go and Java