-
Notifications
You must be signed in to change notification settings - Fork 613
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Thrift generator for Starlark constants
Summary: Enhance Thrift generator for Starlark adding support for constants. Only a subset of types are supported: - primitive types (string, integers, floating point numbers) - lists - maps - enums Structs (out of scope) and sets (Starlark doesn't support sets) are not supported. Reviewed By: vitaut Differential Revision: D52435866 fbshipit-source-id: c168a8e55de2e01db6bf064c7db6d88e1e76af9d
- Loading branch information
1 parent
0dc2ecc
commit b440477
Showing
8 changed files
with
337 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
thrift/compiler/generate/templates/starlark/consts.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{{#program:constants}}{{! | ||
}}{{#constant:type}}{{! | ||
}}{{#type:starlark_supported?}} | ||
{{constant:name}} = {{! | ||
}}{{#constant:value}}{{! | ||
}}{{> consts/value}}{{! | ||
}}{{/constant:value}} | ||
{{!newline after constant}} | ||
|
||
{{/type:starlark_supported?}}{{! | ||
}}{{/constant:type}}{{! | ||
}}{{/program:constants}} |
54 changes: 54 additions & 0 deletions
54
thrift/compiler/generate/templates/starlark/consts/value.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{{#type:byte?}}{{value:integer_value}}{{/type:byte?}}{{! | ||
}}{{#type:i16?}}{{value:integer_value}}{{/type:i16?}}{{! | ||
}}{{#type:i32?}}{{value:integer_value}}{{/type:i32?}}{{! | ||
}}{{#type:i64?}}{{value:integer_value}}{{/type:i64?}}{{! | ||
}}{{#type:string?}}"{{value:string_value}}"{{/type:string?}}{{! | ||
}}{{#type:bool?}}{{! | ||
}}{{#value:nonzero?}}True{{/value:nonzero?}}{{! | ||
}}{{^value:nonzero?}}False{{/value:nonzero?}}{{! | ||
}}{{/type:bool?}}{{! | ||
}}{{#type:float?}}{{! | ||
}}{{#value:double?}}{{value:double_value}}{{/value:double?}}{{! | ||
}}{{#value:integer?}}{{value:integer_value}}.0{{/value:integer?}}{{! | ||
}}{{/type:float?}}{{! | ||
}}{{#type:double?}}{{! | ||
}}{{#value:double?}}{{value:double_value}}{{/value:double?}}{{! | ||
}}{{#value:integer?}}{{value:integer_value}}.0{{/value:integer?}}{{! | ||
}}{{/type:double?}}{{! | ||
List constants | ||
}}{{#type:list?}}[ | ||
{{#value:list_elements}} | ||
{{#type:list_elem_type}}{{! | ||
}}{{> consts/value}},{{! | ||
}}{{/type:list_elem_type}} | ||
{{/value:list_elements}} | ||
]{{/type:list?}}{{! | ||
Map constants | ||
}}{{#type:map?}}{ | ||
{{#value:map_elements}} | ||
{{#element:key}}{{! | ||
}}{{#type:key_type}}{{! | ||
}}{{> consts/value}}{{! | ||
}}{{/type:key_type}}{{! | ||
}}{{/element:key}}: {{! | ||
}}{{#element:value}}{{! | ||
}}{{#type:value_type}}{{! | ||
}}{{> consts/value}}{{! | ||
}}{{/type:value_type}}{{! | ||
}}{{/element:value}}, | ||
{{/value:map_elements}} | ||
}{{/type:map?}}{{! | ||
Enum constants | ||
}}{{#type:enum?}}{{! | ||
}}{{#type:enum}}{{! | ||
}}{{#value:enum_value?}}{{! | ||
}}{{#value:enum_value}}{{! | ||
Known enum value with a name. | ||
}}{{enum:name}}.{{enum_value:name}}{{! | ||
}}{{/value:enum_value}}{{! | ||
}}{{/value:enum_value?}}{{! | ||
}}{{/type:enum}}{{! | ||
}}{{/type:enum?}} |
2 changes: 2 additions & 0 deletions
2
thrift/compiler/generate/templates/starlark/definitions.star.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{{> enums}} | ||
{{> consts}} |
File renamed without changes.
7 changes: 7 additions & 0 deletions
7
thrift/compiler/test/fixtures/basic-enum/gen-star/module.star
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
206 changes: 206 additions & 0 deletions
206
thrift/compiler/test/fixtures/constants/gen-star/module.star
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.