Guest User

Syntax tree

a guest
Mar 30th, 2016
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.70 KB | None | 0 0
  1. Source:
  2.  
  3. class TestSwiftFile {
  4. static let file: String = __FILE__
  5. }
  6.  
  7. class TestSwiftFileWithFunction {
  8. func doWork(a: Int, andB b: String) -> [String] {
  9. return []
  10. }
  11. }
  12.  
  13. Output:
  14.  
  15. statements {
  16. statement {
  17. declaration {
  18. class_declaration {
  19. class "class",
  20. class_name {
  21. identifier {
  22. Identifier "TestSwiftFile"
  23. }
  24. },
  25. class_body {
  26. LCURLY "{",
  27. declarations {
  28. declaration {
  29. constant_declaration {
  30. declaration_modifiers {
  31. declaration_modifier {
  32. static "static"
  33. }
  34. },
  35. let "let",
  36. pattern_initializer_list {
  37. pattern_initializer {
  38. pattern {
  39. identifier_pattern {
  40. identifier {
  41. Identifier "file"
  42. }
  43. },
  44. type_annotation {
  45. COLON ":",
  46. type {
  47. type_identifier {
  48. type_name {
  49. identifier {
  50. Identifier "String"
  51. }
  52. }
  53. }
  54. }
  55. }
  56. },
  57. initializer {
  58. assignment_operator {
  59. EQUAL "="
  60. },
  61. expression {
  62. prefix_expression {
  63. postfix_expression {
  64. primary_expression {
  65. literal_expression {
  66. __FILE__ "__FILE__"
  67. }
  68. }
  69. }
  70. }
  71. }
  72. }
  73. }
  74. }
  75. }
  76. }
  77. },
  78. RCURLY "}"
  79. }
  80. }
  81. }
  82. },
  83. statement {
  84. declaration {
  85. class_declaration {
  86. class "class",
  87. class_name {
  88. identifier {
  89. Identifier "TestSwiftFileWithFunction"
  90. }
  91. },
  92. class_body {
  93. LCURLY "{",
  94. declarations {
  95. declaration {
  96. function_declaration {
  97. function_head {
  98. func "func"
  99. },
  100. function_name {
  101. identifier {
  102. Identifier "doWork"
  103. }
  104. },
  105. function_signature {
  106. parameter_clauses {
  107. parameter_clause {
  108. LPAREN "(",
  109. parameter_list {
  110. parameter {
  111. local_parameter_name {
  112. identifier {
  113. Identifier "a"
  114. }
  115. },
  116. type_annotation {
  117. COLON ":",
  118. type {
  119. type_identifier {
  120. type_name {
  121. identifier {
  122. Identifier "Int"
  123. }
  124. }
  125. }
  126. }
  127. }
  128. },
  129. COMMA ",",
  130. parameter {
  131. external_parameter_name {
  132. identifier {
  133. Identifier "andB"
  134. }
  135. },
  136. local_parameter_name {
  137. identifier {
  138. Identifier "b"
  139. }
  140. },
  141. type_annotation {
  142. COLON ":",
  143. type {
  144. type_identifier {
  145. type_name {
  146. identifier {
  147. Identifier "String"
  148. }
  149. }
  150. }
  151. }
  152. }
  153. }
  154. },
  155. RPAREN ")"
  156. }
  157. },
  158. function_result {
  159. arrow_operator {
  160. SUB "-",
  161. GT ">"
  162. },
  163. type {
  164. LBRACK "[",
  165. type {
  166. type_identifier {
  167. type_name {
  168. identifier {
  169. Identifier "String"
  170. }
  171. }
  172. }
  173. },
  174. RBRACK "]"
  175. }
  176. }
  177. },
  178. function_body {
  179. code_block {
  180. LCURLY "{",
  181. statements {
  182. statement {
  183. control_transfer_statement {
  184. return_statement {
  185. return "return",
  186. expression {
  187. prefix_expression {
  188. postfix_expression {
  189. primary_expression {
  190. literal_expression {
  191. array_literal {
  192. LBRACK "[",
  193. RBRACK "]"
  194. }
  195. }
  196. }
  197. }
  198. }
  199. }
  200. }
  201. }
  202. }
  203. },
  204. RCURLY "}"
  205. }
  206. }
  207. }
  208. }
  209. },
  210. RCURLY "}"
  211. }
  212. }
  213. }
  214. }
  215. }
Advertisement
Add Comment
Please, Sign In to add comment