tpostexprblocks.nim 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. discard """
  2. nimout: '''
  3. StmtList
  4. Ident "foo010"
  5. Call
  6. Ident "foo020"
  7. Call
  8. Ident "foo030"
  9. Ident "x"
  10. Command
  11. Ident "foo040"
  12. Ident "x"
  13. Call
  14. Ident "foo050"
  15. StmtList
  16. DiscardStmt
  17. Empty
  18. Call
  19. Ident "foo060"
  20. StmtList
  21. DiscardStmt
  22. Empty
  23. Call
  24. Ident "foo070"
  25. StrLit "test"
  26. StmtList
  27. DiscardStmt
  28. Empty
  29. Call
  30. Ident "foo080"
  31. StrLit "test"
  32. StmtList
  33. DiscardStmt
  34. Empty
  35. Command
  36. Ident "foo090"
  37. StrLit "test"
  38. StmtList
  39. DiscardStmt
  40. Empty
  41. Command
  42. Ident "foo100"
  43. Call
  44. StrLit "test"
  45. StmtList
  46. DiscardStmt
  47. Empty
  48. Command
  49. Ident "foo101"
  50. Call
  51. IntLit 10
  52. StmtList
  53. DiscardStmt
  54. Empty
  55. Command
  56. Ident "foo110"
  57. IntLit 1
  58. Par
  59. Infix
  60. Ident "+"
  61. IntLit 2
  62. IntLit 3
  63. StmtList
  64. DiscardStmt
  65. Empty
  66. Command
  67. Ident "foo120"
  68. IntLit 1
  69. Call
  70. Par
  71. Infix
  72. Ident "+"
  73. IntLit 2
  74. IntLit 3
  75. StmtList
  76. DiscardStmt
  77. Empty
  78. Call
  79. Ident "foo130"
  80. Do
  81. Empty
  82. Empty
  83. Empty
  84. FormalParams
  85. Empty
  86. IdentDefs
  87. Ident "x"
  88. Empty
  89. Empty
  90. Empty
  91. Empty
  92. StmtList
  93. DiscardStmt
  94. Empty
  95. Call
  96. Ident "foo140"
  97. Do
  98. Empty
  99. Empty
  100. Empty
  101. FormalParams
  102. Empty
  103. IdentDefs
  104. Ident "x"
  105. Ident "int"
  106. Empty
  107. Empty
  108. Empty
  109. StmtList
  110. DiscardStmt
  111. Empty
  112. Call
  113. Ident "foo150"
  114. Do
  115. Empty
  116. Empty
  117. Empty
  118. FormalParams
  119. Ident "int"
  120. IdentDefs
  121. Ident "x"
  122. Ident "int"
  123. Empty
  124. Empty
  125. Empty
  126. StmtList
  127. DiscardStmt
  128. Empty
  129. Command
  130. Ident "foo160"
  131. Call
  132. Ident "x"
  133. Do
  134. Empty
  135. Empty
  136. Empty
  137. FormalParams
  138. Empty
  139. IdentDefs
  140. Ident "y"
  141. Empty
  142. Empty
  143. Empty
  144. Empty
  145. StmtList
  146. DiscardStmt
  147. Empty
  148. Call
  149. Ident "foo170"
  150. StmtList
  151. DiscardStmt
  152. Empty
  153. Else
  154. StmtList
  155. DiscardStmt
  156. Empty
  157. Call
  158. Ident "foo180"
  159. StmtList
  160. DiscardStmt
  161. Empty
  162. StmtList
  163. DiscardStmt
  164. Empty
  165. Else
  166. StmtList
  167. DiscardStmt
  168. Empty
  169. Command
  170. Ident "foo190"
  171. Call
  172. Ident "x"
  173. Do
  174. Empty
  175. Empty
  176. Empty
  177. FormalParams
  178. Empty
  179. IdentDefs
  180. Ident "y"
  181. Empty
  182. Empty
  183. Empty
  184. Empty
  185. StmtList
  186. DiscardStmt
  187. Empty
  188. Do
  189. Empty
  190. Empty
  191. Empty
  192. FormalParams
  193. Ident "int"
  194. IdentDefs
  195. Ident "z"
  196. Empty
  197. Empty
  198. Empty
  199. Empty
  200. StmtList
  201. DiscardStmt
  202. Empty
  203. Do
  204. Empty
  205. Empty
  206. Empty
  207. FormalParams
  208. Ident "int"
  209. IdentDefs
  210. Ident "w"
  211. Ident "int"
  212. Empty
  213. Empty
  214. Empty
  215. StmtList
  216. DiscardStmt
  217. Empty
  218. StmtList
  219. DiscardStmt
  220. Empty
  221. Else
  222. StmtList
  223. DiscardStmt
  224. Empty
  225. Call
  226. Ident "foo200"
  227. Ident "x"
  228. Call
  229. Ident "bar"
  230. StmtList
  231. DiscardStmt
  232. Empty
  233. Else
  234. StmtList
  235. DiscardStmt
  236. Empty
  237. VarSection
  238. IdentDefs
  239. Ident "a"
  240. Empty
  241. Ident "foo210"
  242. VarSection
  243. IdentDefs
  244. Ident "a"
  245. Empty
  246. Call
  247. Ident "foo220"
  248. VarSection
  249. IdentDefs
  250. Ident "a"
  251. Empty
  252. Call
  253. Ident "foo230"
  254. Ident "x"
  255. VarSection
  256. IdentDefs
  257. Ident "a"
  258. Empty
  259. Command
  260. Ident "foo240"
  261. Ident "x"
  262. VarSection
  263. IdentDefs
  264. Ident "a"
  265. Empty
  266. Call
  267. Ident "foo250"
  268. StmtList
  269. DiscardStmt
  270. Empty
  271. VarSection
  272. IdentDefs
  273. Ident "a"
  274. Empty
  275. Call
  276. Ident "foo260"
  277. StmtList
  278. DiscardStmt
  279. Empty
  280. VarSection
  281. IdentDefs
  282. Ident "a"
  283. Empty
  284. Call
  285. Ident "foo270"
  286. StmtList
  287. DiscardStmt
  288. Empty
  289. Else
  290. StmtList
  291. DiscardStmt
  292. Empty
  293. VarSection
  294. IdentDefs
  295. Ident "a"
  296. Empty
  297. Command
  298. Ident "foo280"
  299. Call
  300. Ident "x"
  301. Do
  302. Empty
  303. Empty
  304. Empty
  305. FormalParams
  306. Empty
  307. IdentDefs
  308. Ident "y"
  309. Empty
  310. Empty
  311. Empty
  312. Empty
  313. StmtList
  314. DiscardStmt
  315. Empty
  316. Else
  317. StmtList
  318. DiscardStmt
  319. Empty
  320. Asgn
  321. Ident "a"
  322. Ident "foo290"
  323. Asgn
  324. Ident "a"
  325. Call
  326. Ident "foo300"
  327. Asgn
  328. Ident "a"
  329. Call
  330. Ident "foo310"
  331. Ident "x"
  332. Asgn
  333. Ident "a"
  334. Command
  335. Ident "foo320"
  336. Ident "x"
  337. Asgn
  338. Ident "a"
  339. Call
  340. Ident "foo330"
  341. StmtList
  342. DiscardStmt
  343. Empty
  344. Asgn
  345. Ident "a"
  346. Call
  347. Ident "foo340"
  348. StmtList
  349. DiscardStmt
  350. Empty
  351. Asgn
  352. Ident "a"
  353. Call
  354. Ident "foo350"
  355. StmtList
  356. DiscardStmt
  357. Empty
  358. Else
  359. StmtList
  360. DiscardStmt
  361. Empty
  362. Asgn
  363. Ident "a"
  364. Command
  365. Ident "foo360"
  366. Call
  367. DotExpr
  368. Ident "x"
  369. Ident "bar"
  370. Do
  371. Empty
  372. Empty
  373. Empty
  374. FormalParams
  375. Empty
  376. IdentDefs
  377. Ident "y"
  378. Empty
  379. Empty
  380. Empty
  381. Empty
  382. StmtList
  383. DiscardStmt
  384. Empty
  385. Else
  386. StmtList
  387. DiscardStmt
  388. Empty
  389. Command
  390. DotExpr
  391. Ident "foo370"
  392. Ident "add"
  393. Call
  394. Ident "quote"
  395. StmtList
  396. DiscardStmt
  397. Empty
  398. Call
  399. DotExpr
  400. Ident "foo380"
  401. Ident "add"
  402. BracketExpr
  403. Call
  404. Ident "quote"
  405. StmtList
  406. DiscardStmt
  407. Empty
  408. IntLit 0
  409. Command
  410. Ident "foo390"
  411. Call
  412. Ident "x"
  413. Do
  414. Empty
  415. Empty
  416. Empty
  417. FormalParams
  418. Empty
  419. IdentDefs
  420. Ident "y"
  421. Empty
  422. Empty
  423. Empty
  424. Empty
  425. StmtList
  426. DiscardStmt
  427. Empty
  428. Do
  429. Empty
  430. Empty
  431. Empty
  432. FormalParams
  433. Ident "int"
  434. IdentDefs
  435. Ident "z"
  436. Empty
  437. Empty
  438. Empty
  439. Empty
  440. StmtList
  441. DiscardStmt
  442. Empty
  443. Do
  444. Empty
  445. Empty
  446. Empty
  447. FormalParams
  448. Ident "int"
  449. IdentDefs
  450. Ident "w"
  451. Ident "int"
  452. Empty
  453. Empty
  454. Empty
  455. StmtList
  456. DiscardStmt
  457. Empty
  458. StmtList
  459. DiscardStmt
  460. Empty
  461. OfBranch
  462. Ident "a"
  463. StmtList
  464. DiscardStmt
  465. Empty
  466. OfBranch
  467. TupleConstr
  468. Ident "a"
  469. Ident "b"
  470. StmtList
  471. DiscardStmt
  472. Empty
  473. ElifBranch
  474. Ident "a"
  475. StmtList
  476. DiscardStmt
  477. Empty
  478. ElifBranch
  479. TupleConstr
  480. Ident "a"
  481. Ident "b"
  482. StmtList
  483. DiscardStmt
  484. Empty
  485. ExceptBranch
  486. Ident "a"
  487. StmtList
  488. DiscardStmt
  489. Empty
  490. ExceptBranch
  491. TupleConstr
  492. Ident "a"
  493. Ident "b"
  494. StmtList
  495. DiscardStmt
  496. Empty
  497. Finally
  498. StmtList
  499. DiscardStmt
  500. Empty
  501. Call
  502. Ident "foo"
  503. Finally
  504. StmtList
  505. DiscardStmt
  506. Empty
  507. '''
  508. """
  509. import macros
  510. dumpTree:
  511. # simple calls
  512. foo010
  513. foo020()
  514. foo030(x)
  515. foo040 x
  516. foo050:
  517. discard
  518. foo060 do:
  519. discard
  520. foo070("test"):
  521. discard
  522. foo080("test") do:
  523. discard
  524. foo090 "test":
  525. discard
  526. foo100 "test" do:
  527. discard
  528. foo101 10 do:
  529. discard
  530. # more complicated calls
  531. foo110 1, (2+3):
  532. discard
  533. foo120 1, (2+3) do:
  534. discard
  535. foo130 do (x):
  536. discard
  537. foo140 do (x: int):
  538. discard
  539. foo150 do (x: int) -> int:
  540. discard
  541. foo160 x do (y):
  542. discard
  543. # extra blocks
  544. foo170:
  545. discard
  546. else:
  547. discard
  548. foo180 do:
  549. discard
  550. do:
  551. discard
  552. else:
  553. discard
  554. foo190 x do (y):
  555. discard
  556. do (z) -> int:
  557. discard
  558. do (w: int) -> int:
  559. discard
  560. do:
  561. discard
  562. else:
  563. discard
  564. # call with blocks as a param
  565. foo200(x, bar do:
  566. discard
  567. else:
  568. discard
  569. )
  570. # introduce a variable
  571. var a = foo210
  572. var a = foo220()
  573. var a = foo230(x)
  574. var a = foo240 x
  575. var a = foo250:
  576. discard
  577. var a = foo260 do:
  578. discard
  579. var a = foo270 do:
  580. discard
  581. else:
  582. discard
  583. var a = foo280 x do (y):
  584. discard
  585. else:
  586. discard
  587. # assignments
  588. a = foo290
  589. a = foo300()
  590. a = foo310(x)
  591. a = foo320 x
  592. a = foo330:
  593. discard
  594. a = foo340 do:
  595. discard
  596. a = foo350 do:
  597. discard
  598. else:
  599. discard
  600. a = foo360 x.bar do (y):
  601. discard
  602. else:
  603. discard
  604. foo370.add quote do:
  605. discard
  606. # some edge cases
  607. foo380.add((quote do:
  608. discard
  609. )[0])
  610. foo390 x do (y):
  611. discard
  612. do (z) -> int:
  613. discard
  614. do (w: int) -> int:
  615. discard
  616. do:
  617. discard
  618. of a:
  619. discard
  620. of (a, b):
  621. discard
  622. elif a:
  623. discard
  624. elif (a, b):
  625. discard
  626. except a:
  627. discard
  628. except (a, b):
  629. discard
  630. finally:
  631. discard
  632. foo:
  633. finally:
  634. discard