ast.proto 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. syntax = "proto3";
  2. package python.ast;
  3. option go_package = "github.com/kyleconroy/sqlc/internal/python/ast";
  4. message Node {
  5. oneof node {
  6. ClassDef class_def = 1 [json_name="ClassDef"];
  7. Import import = 2 [json_name="Import"];
  8. ImportFrom import_from = 3 [json_name="ImportFrom"];
  9. Module module = 4 [json_name="Module"];
  10. Alias alias = 5 [json_name="Alias"];
  11. AnnAssign ann_assign = 6 [json_name="AnnAssign"];
  12. Name name = 7 [json_name="Name"];
  13. Subscript subscript = 8 [json_name="Subscript"];
  14. Attribute attribute = 9 [json_name="Attribute"];
  15. Constant constant = 10 [json_name="Constant"];
  16. Assign assign = 11 [json_name="Assign"];
  17. Comment comment = 12 [json_name="Comment"];
  18. Expr expr = 13 [json_name="Expr"];
  19. Call call = 14 [json_name="Call"];
  20. FunctionDef function_def = 15 [json_name="FunctionDef"];
  21. Arg arg = 16 [json_name="Arg"];
  22. Arguments arguments = 17 [json_name="Arguments"];
  23. AsyncFunctionDef async_function_def = 18 [json_name="AsyncFunctionDef"];
  24. Pass pass = 19 [json_name="Pass"];
  25. Dict dict = 20 [json_name="Dict"];
  26. If if = 21 [json_name="If"];
  27. Compare compare = 22 [json_name="Compare"];
  28. Return return = 23 [json_name="Return"];
  29. Is is = 24 [json_name="Is"];
  30. Keyword keyword = 25 [json_name="Keyword"];
  31. Yield yield = 26 [json_name="Yield"];
  32. For for = 27 [json_name="For"];
  33. Await await = 28 [json_name="Await"];
  34. AsyncFor async_for = 29 [json_name="AsyncFor"];
  35. ImportGroup import_group = 30 [json_name="ImportGroup"];
  36. }
  37. }
  38. message Alias
  39. {
  40. string name = 1 [json_name="name"];
  41. }
  42. message Await
  43. {
  44. Node value = 1 [json_name="value"];
  45. }
  46. message Attribute
  47. {
  48. Node value = 1 [json_name="value"];
  49. string attr = 2 [json_name="attr"];
  50. }
  51. message AnnAssign
  52. {
  53. Name target = 1 [json_name="target"];
  54. Node annotation = 2 [json_name="annotation"];
  55. int32 simple = 3 [json_name="simple"];
  56. string Comment = 4 [json_name="comment"];
  57. }
  58. message Arg
  59. {
  60. string arg = 1 [json_name="arg"];
  61. Node annotation = 2 [json_name="annotation"];
  62. }
  63. message Arguments
  64. {
  65. repeated Arg args = 1 [json_name="args"];
  66. repeated Arg kw_only_args = 2 [json_name="kwonlyargs"];
  67. }
  68. message AsyncFor
  69. {
  70. Node target = 1 [json_name="target"];
  71. Node iter = 2 [json_name="iter"];
  72. repeated Node body = 3 [json_name="body"];
  73. }
  74. message AsyncFunctionDef
  75. {
  76. string name = 1 [json_name="name"];
  77. Arguments Args = 2 [json_name="args"];
  78. repeated Node body = 3 [json_name="body"];
  79. Node returns = 4 [json_name="returns"];
  80. }
  81. message Assign
  82. {
  83. repeated Node targets = 1 [json_name="targets"];
  84. Node value = 2 [json_name="value"];
  85. string Comment = 3 [json_name="comment"];
  86. }
  87. message Call
  88. {
  89. Node func = 1 [json_name="func"];
  90. repeated Node args = 2 [json_name="args"];
  91. repeated Keyword keywords = 3 [json_name="keywords"];
  92. }
  93. message ClassDef
  94. {
  95. string name = 1 [json_name="name"];
  96. repeated Node bases = 2 [json_name="bases"];
  97. repeated Node keywords = 3 [json_name="keywords"];
  98. repeated Node body = 4 [json_name="body"];
  99. repeated Node decorator_list = 5 [json_name="decorator_list"];
  100. }
  101. // The Python ast module does not parse comments. It's not clear if this is the
  102. // best way to support them in the AST
  103. message Comment
  104. {
  105. string text = 1 [json_name="text"];
  106. }
  107. message Compare
  108. {
  109. Node left = 1 [json_name="left"];
  110. repeated Node ops = 2 [json_name="ops"];
  111. repeated Node comparators = 3 [json_name="comparators"];
  112. }
  113. message Constant
  114. {
  115. oneof value {
  116. string str = 1 [json_name="string"];
  117. int32 int = 2 [json_name="int"];
  118. bool none = 3 [json_name="none"];
  119. }
  120. }
  121. message Dict
  122. {
  123. repeated Node keys = 1 [json_name="keys"];
  124. repeated Node values = 2 [json_name="values"];
  125. }
  126. message Expr
  127. {
  128. Node value = 1 [json_name="value"];
  129. }
  130. message For
  131. {
  132. Node target = 1 [json_name="target"];
  133. Node iter = 2 [json_name="iter"];
  134. repeated Node body = 3 [json_name="body"];
  135. }
  136. message FunctionDef
  137. {
  138. string name = 1 [json_name="name"];
  139. Arguments Args = 2 [json_name="args"];
  140. repeated Node body = 3 [json_name="body"];
  141. Node returns = 4 [json_name="returns"];
  142. }
  143. message If
  144. {
  145. Node test = 1 [json_name="test"];
  146. repeated Node body = 2 [json_name="body"];
  147. repeated Node or_else = 3 [json_name="orelse"];
  148. }
  149. message Import
  150. {
  151. repeated Node names = 1 [json_name="names"];
  152. }
  153. message ImportFrom
  154. {
  155. string module = 1 [json_name="module"];
  156. repeated Node names = 2 [json_name="names"];
  157. int32 level = 3 [json_name="level"];
  158. }
  159. // Imports are always put at the top of the file, just after any module
  160. // comments and docstrings, and before module globals and constants.
  161. //
  162. // Imports should be grouped in the following order:
  163. //
  164. // Standard library imports.
  165. // Related third party imports.
  166. // Local application/library specific imports.
  167. //
  168. // You should put a blank line between each group of imports.
  169. //
  170. // https://www.python.org/dev/peps/pep-0008/#imports
  171. message ImportGroup
  172. {
  173. repeated Node imports = 1 [json_name="imports"];
  174. }
  175. message Is
  176. {
  177. }
  178. message Keyword
  179. {
  180. string arg = 1 [json_name="arg"];
  181. Node value = 2 [json_name="value"];
  182. }
  183. message Module
  184. {
  185. repeated Node body = 1 [json_name="body"];
  186. }
  187. message Name
  188. {
  189. string id = 1 [json_name="id"];
  190. }
  191. message Pass
  192. {
  193. }
  194. message Return
  195. {
  196. Node value = 1 [json_name="value"];
  197. }
  198. message Subscript
  199. {
  200. Name value = 1 [json_name="value"];
  201. Node slice = 2 [json_name="slice"];
  202. }
  203. message Yield
  204. {
  205. Node value = 1 [json_name="value"];
  206. }