ranger-compiler 2.1.69 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (363) hide show
  1. package/CHANGELOG.md +103 -0
  2. package/README.md +991 -96
  3. package/{compiler/Lang.clj → dist/Lang.rgr} +2345 -75
  4. package/dist/README.md +116 -0
  5. package/dist/{bin/api.d.ts → api.d.ts} +430 -154
  6. package/dist/api.js +34345 -0
  7. package/{lib/Ajax.clj → dist/lib/Ajax.rgr} +1 -1
  8. package/{lib/CmdParams.clj → dist/lib/CmdParams.rgr} +72 -72
  9. package/{lib/Crypto.clj → dist/lib/Crypto.rgr} +1 -1
  10. package/{lib/DOMLib.clj → dist/lib/DOMLib.rgr} +2 -2
  11. package/{lib/Engine3D.clj → dist/lib/Engine3D.rgr} +1 -1
  12. package/{lib/ImmutableVector.clj → dist/lib/ImmutableVector.rgr} +364 -364
  13. package/{lib/IndexedDB.clj → dist/lib/IndexedDB.rgr} +1 -1
  14. package/{lib/JSON.clj → dist/lib/JSON.rgr} +105 -2
  15. package/{lib/JinxProcess.clj → dist/lib/JinxProcess.rgr} +3 -3
  16. package/{lib/Storage.clj → dist/lib/Storage.rgr} +1 -1
  17. package/{lib/Timers.clj → dist/lib/Timers.rgr} +176 -170
  18. package/{lib/ViewLib.clj → dist/lib/ViewLib.rgr} +1 -1
  19. package/dist/lib/lib/ACEEditor.rgr +5 -0
  20. package/dist/lib/lib/Ajax.rgr +196 -0
  21. package/dist/lib/lib/CmdParams.rgr +72 -0
  22. package/dist/lib/lib/Crypto.rgr +90 -0
  23. package/dist/lib/lib/DOMLib.rgr +307 -0
  24. package/{examples/3D/Engine3D.clj → dist/lib/lib/Engine3D.rgr} +870 -857
  25. package/dist/lib/lib/ImmutableVector.rgr +364 -0
  26. package/dist/lib/lib/IndexedDB.rgr +32 -0
  27. package/{compiler/JSON.clj → dist/lib/lib/JSON.rgr} +106 -3
  28. package/dist/lib/lib/JinxProcess.rgr +838 -0
  29. package/dist/lib/lib/SQL.rgr +44 -0
  30. package/dist/lib/lib/ServiceLib.rgr +9 -0
  31. package/dist/lib/lib/Storage.rgr +89 -0
  32. package/dist/lib/lib/Time.rgr +75 -0
  33. package/dist/lib/lib/Timers.rgr +176 -0
  34. package/dist/lib/lib/TypedArrays.rgr +14 -0
  35. package/dist/lib/lib/ViewLib.rgr +851 -0
  36. package/dist/lib/lib/WebLib.rgr +47 -0
  37. package/dist/lib/lib/WebServerLib.rgr +137 -0
  38. package/{lib/ranger-dir.clj → dist/lib/lib/ranger-dir.rgr} +1 -1
  39. package/{compiler/stdlib.clj → dist/lib/lib/stdlib.rgr} +42 -19
  40. package/{lib/stdops.clj → dist/lib/lib/stdops.rgr} +1 -1
  41. package/dist/lib/ranger-dir.rgr +175 -0
  42. package/{lib/stdlib.clj → dist/lib/stdlib.rgr} +2 -2
  43. package/dist/lib/stdops.rgr +168 -0
  44. package/dist/package.json +47 -0
  45. package/{bin/output.js → dist/rgrc.js} +15377 -7935
  46. package/dist/stdops.rgr +168 -0
  47. package/package.json +196 -38
  48. package/adventofcode/day1/bin/LambdaSignature1.java +0 -3
  49. package/adventofcode/day1/bin/LambdaSignature2.java +0 -3
  50. package/adventofcode/day1/bin/LambdaSignature3.java +0 -3
  51. package/adventofcode/day1/bin/day1.cpp +0 -124
  52. package/adventofcode/day1/bin/day1.go +0 -75
  53. package/adventofcode/day1/bin/day1.js +0 -45
  54. package/adventofcode/day1/bin/day1.php +0 -46
  55. package/adventofcode/day1/bin/day1.scala +0 -48
  56. package/adventofcode/day1/bin/day1.swift +0 -48
  57. package/adventofcode/day1/bin/day1_part2.cpp +0 -180
  58. package/adventofcode/day1/bin/day1_part2.go +0 -123
  59. package/adventofcode/day1/bin/day1_part2.js +0 -76
  60. package/adventofcode/day1/bin/day1_part2.php +0 -88
  61. package/adventofcode/day1/bin/day1_part2.scala +0 -81
  62. package/adventofcode/day1/bin/day1_part2.swift +0 -91
  63. package/adventofcode/day1/bin/day_one.java +0 -38
  64. package/adventofcode/day1/bin/day_one_part_two.java +0 -57
  65. package/adventofcode/day1/bin/operatorsOf.java +0 -37
  66. package/adventofcode/day1/bin/operatorsOf_5.java +0 -10
  67. package/adventofcode/day1/bin/operatorsOfboolean_5.java +0 -10
  68. package/adventofcode/day1/bin/variant.hpp +0 -2416
  69. package/adventofcode/day1/compile.bat +0 -7
  70. package/adventofcode/day1/compile2.bat +0 -7
  71. package/adventofcode/day1/day1.clj +0 -19
  72. package/adventofcode/day1/day1_part2.clj +0 -43
  73. package/adventofcode/day1/input1.txt +0 -1
  74. package/adventofcode/day2/bin/LambdaSignature1.class +0 -0
  75. package/adventofcode/day2/bin/LambdaSignature1.java +0 -3
  76. package/adventofcode/day2/bin/LambdaSignature2.class +0 -0
  77. package/adventofcode/day2/bin/LambdaSignature2.java +0 -3
  78. package/adventofcode/day2/bin/day2.cpp +0 -133
  79. package/adventofcode/day2/bin/day2.go +0 -85
  80. package/adventofcode/day2/bin/day2.js +0 -45
  81. package/adventofcode/day2/bin/day2.php +0 -59
  82. package/adventofcode/day2/bin/day2.scala +0 -54
  83. package/adventofcode/day2/bin/day2.swift +0 -62
  84. package/adventofcode/day2/bin/day2_part2.cpp +0 -150
  85. package/adventofcode/day2/bin/day2_part2.go +0 -101
  86. package/adventofcode/day2/bin/day2_part2.js +0 -54
  87. package/adventofcode/day2/bin/day2_part2.php +0 -80
  88. package/adventofcode/day2/bin/day2_part2.scala +0 -68
  89. package/adventofcode/day2/bin/day2_part2.swift +0 -82
  90. package/adventofcode/day2/bin/day_two.java +0 -61
  91. package/adventofcode/day2/bin/day_two_part_two$1$1$1.class +0 -0
  92. package/adventofcode/day2/bin/day_two_part_two$1$1.class +0 -0
  93. package/adventofcode/day2/bin/day_two_part_two$1.class +0 -0
  94. package/adventofcode/day2/bin/day_two_part_two.class +0 -0
  95. package/adventofcode/day2/bin/day_two_part_two.java +0 -80
  96. package/adventofcode/day2/bin/operatorsOf.class +0 -0
  97. package/adventofcode/day2/bin/operatorsOf.java +0 -18
  98. package/adventofcode/day2/bin/variant.hpp +0 -2416
  99. package/adventofcode/day2/compile.bat +0 -7
  100. package/adventofcode/day2/compile2.bat +0 -7
  101. package/adventofcode/day2/day2.clj +0 -60
  102. package/adventofcode/day2/day2_part2.clj +0 -69
  103. package/adventofcode/day2/input1.txt +0 -1
  104. package/adventofcode/day3/bin/Grid.java +0 -92
  105. package/adventofcode/day3/bin/GridRow.java +0 -5
  106. package/adventofcode/day3/bin/LambdaSignature1.java +0 -3
  107. package/adventofcode/day3/bin/LambdaSignature2.java +0 -3
  108. package/adventofcode/day3/bin/LambdaSignature3.java +0 -3
  109. package/adventofcode/day3/bin/day3.cpp +0 -64
  110. package/adventofcode/day3/bin/day3.go +0 -55
  111. package/adventofcode/day3/bin/day3.js +0 -42
  112. package/adventofcode/day3/bin/day3.php +0 -41
  113. package/adventofcode/day3/bin/day3.scala +0 -52
  114. package/adventofcode/day3/bin/day3.swift +0 -43
  115. package/adventofcode/day3/bin/day3_part2.cpp +0 -216
  116. package/adventofcode/day3/bin/day3_part2.go +0 -188
  117. package/adventofcode/day3/bin/day3_part2.js +0 -123
  118. package/adventofcode/day3/bin/day3_part2.php +0 -135
  119. package/adventofcode/day3/bin/day3_part2.swift +0 -131
  120. package/adventofcode/day3/bin/day_three_part_two.java +0 -43
  121. package/adventofcode/day3/bin/day_two.java +0 -42
  122. package/adventofcode/day3/bin/operatorsOf.java +0 -14
  123. package/adventofcode/day3/bin/variant.hpp +0 -2416
  124. package/adventofcode/day3/compile.bat +0 -7
  125. package/adventofcode/day3/compile2.bat +0 -7
  126. package/adventofcode/day3/day3.clj +0 -42
  127. package/adventofcode/day3/day3_part2.clj +0 -112
  128. package/adventofcode/day4/bin/LambdaSignature1.java +0 -3
  129. package/adventofcode/day4/bin/day4.cpp +0 -118
  130. package/adventofcode/day4/bin/day4.go +0 -75
  131. package/adventofcode/day4/bin/day4.js +0 -40
  132. package/adventofcode/day4/bin/day4.php +0 -52
  133. package/adventofcode/day4/bin/day4.scala +0 -47
  134. package/adventofcode/day4/bin/day4.swift +0 -56
  135. package/adventofcode/day4/bin/day4_part2.go +0 -129
  136. package/adventofcode/day4/bin/day4_part2.js +0 -72
  137. package/adventofcode/day4/bin/day_four.java +0 -41
  138. package/adventofcode/day4/bin/inputData.java +0 -7
  139. package/adventofcode/day4/bin/operatorsOf.java +0 -11
  140. package/adventofcode/day4/bin/variant.hpp +0 -2416
  141. package/adventofcode/day4/compile.bat +0 -7
  142. package/adventofcode/day4/compile2.bat +0 -7
  143. package/adventofcode/day4/day4.clj +0 -32
  144. package/adventofcode/day4/day4_part2.clj +0 -44
  145. package/adventofcode/day4/input.clj +0 -519
  146. package/adventofcode/day4/input.txt +0 -512
  147. package/bin/api.ts +0 -24471
  148. package/bin/compiler.ts +0 -24482
  149. package/compiler/ColorConsole.clj +0 -22
  150. package/compiler/ContextOperators.clj +0 -75
  151. package/compiler/FlowEnterVarDef.clj +0 -223
  152. package/compiler/InputFileSystem.clj +0 -276
  153. package/compiler/RangerDocs.clj +0 -7
  154. package/compiler/TFactory.clj +0 -146
  155. package/compiler/TFiles.clj +0 -23
  156. package/compiler/TFlow.clj +0 -39
  157. package/compiler/TNodeFactory.clj +0 -84
  158. package/compiler/TTypes.clj +0 -188
  159. package/compiler/VirtualCompiler.clj +0 -800
  160. package/compiler/bin/ng_Compiler.js +0 -23779
  161. package/compiler/commonmark_plugin.clj +0 -359
  162. package/compiler/feat2.bat +0 -2
  163. package/compiler/feats.bat +0 -9
  164. package/compiler/feature_tests.clj +0 -192
  165. package/compiler/index.js +0 -2
  166. package/compiler/issue_57.clj +0 -25
  167. package/compiler/makefile_plugin.clj +0 -135
  168. package/compiler/markdown_plugin.clj +0 -386
  169. package/compiler/maven_plugin.clj +0 -162
  170. package/compiler/ng_AndroidPageWriter.clj +0 -299
  171. package/compiler/ng_CodeNode.clj +0 -756
  172. package/compiler/ng_CodeNodeCompilerExtensions.clj +0 -839
  173. package/compiler/ng_Compiler.clj +0 -49
  174. package/compiler/ng_CompilerGeneric.clj +0 -260
  175. package/compiler/ng_CompilerOrig.clj +0 -854
  176. package/compiler/ng_DictNode.clj +0 -346
  177. package/compiler/ng_DictNode2.clj +0 -316
  178. package/compiler/ng_Execute.clj +0 -138
  179. package/compiler/ng_Execute1.clj +0 -129
  180. package/compiler/ng_FlowWork.clj +0 -3951
  181. package/compiler/ng_LiveCompiler.clj +0 -1109
  182. package/compiler/ng_RagnerJavaScriptClassWriter.clj +0 -402
  183. package/compiler/ng_RangerActiveOperators.clj +0 -86
  184. package/compiler/ng_RangerAppClassDesc.clj +0 -400
  185. package/compiler/ng_RangerAppEnums.clj +0 -86
  186. package/compiler/ng_RangerAppFunctionDesc.clj +0 -127
  187. package/compiler/ng_RangerAppMessages.clj +0 -15
  188. package/compiler/ng_RangerAppOperatorDesc.clj +0 -20
  189. package/compiler/ng_RangerAppParamDesc.clj +0 -388
  190. package/compiler/ng_RangerAppWriterContext.clj +0 -1793
  191. package/compiler/ng_RangerArgMatch.clj +0 -638
  192. package/compiler/ng_RangerCSharpClassWriter.clj +0 -484
  193. package/compiler/ng_RangerCppClassWriter.clj +0 -1023
  194. package/compiler/ng_RangerDocGenerator.clj +0 -305
  195. package/compiler/ng_RangerFlowParser.clj +0 -4992
  196. package/compiler/ng_RangerFlowParserOrig.clj +0 -4002
  197. package/compiler/ng_RangerGenericClassWriter.clj +0 -573
  198. package/compiler/ng_RangerGolangClassWriter.clj +0 -1766
  199. package/compiler/ng_RangerImmutableExtension.clj +0 -77
  200. package/compiler/ng_RangerJava7ClassWriter.clj +0 -961
  201. package/compiler/ng_RangerJavaScriptClassWriter.clj +0 -1042
  202. package/compiler/ng_RangerKotlinClassWriter.clj +0 -372
  203. package/compiler/ng_RangerLanguageWriters.clj +0 -14
  204. package/compiler/ng_RangerLispParser.clj +0 -873
  205. package/compiler/ng_RangerPHPClassWriter.clj +0 -643
  206. package/compiler/ng_RangerPlugin.clj +0 -41
  207. package/compiler/ng_RangerRangerClassWriter.clj +0 -357
  208. package/compiler/ng_RangerRustClassWriter.clj +0 -420
  209. package/compiler/ng_RangerScalaClassWriter.clj +0 -818
  210. package/compiler/ng_RangerSerializeClass.clj +0 -502
  211. package/compiler/ng_RangerServiceBuilder.clj +0 -63
  212. package/compiler/ng_RangerSwift3ClassWriter.clj +0 -809
  213. package/compiler/ng_RangerSwiftClassWriter.clj +0 -0
  214. package/compiler/ng_RangerTypeClass.clj +0 -45
  215. package/compiler/ng_SourceParser.clj +0 -241
  216. package/compiler/ng_SourceParser2.clj +0 -214
  217. package/compiler/ng_WebPageWriter.clj +0 -39
  218. package/compiler/ng_jsonParser.clj +0 -340
  219. package/compiler/ng_p_test.clj +0 -1711
  220. package/compiler/ng_parser.clj +0 -911
  221. package/compiler/ng_parser2.clj +0 -735
  222. package/compiler/ng_parser2_backup.clj +0 -1679
  223. package/compiler/ng_parser_backup.clj +0 -886
  224. package/compiler/ng_parser_ok.clj +0 -1718
  225. package/compiler/ng_parser_ok2.clj +0 -1717
  226. package/compiler/ng_parser_std_match.clj +0 -687
  227. package/compiler/ng_parser_std_match2.clj +0 -1012
  228. package/compiler/ng_parser_v2.clj +0 -1251
  229. package/compiler/ng_ui.clj +0 -403
  230. package/compiler/ng_ui_test.clj +0 -18
  231. package/compiler/ng_writer.clj +0 -338
  232. package/compiler/ng_xmlParser.clj +0 -472
  233. package/compiler/ng_xmlParser2.clj +0 -317
  234. package/compiler/ng_xmlParser3.clj +0 -251
  235. package/compiler/opdoc.bat +0 -4
  236. package/compiler/operators.md +0 -290
  237. package/compiler/p.bat +0 -4
  238. package/compiler/package.json +0 -10
  239. package/compiler/pcmd.bat +0 -4
  240. package/compiler/pcmd2.bat +0 -3
  241. package/compiler/plaintext_plugin.clj +0 -69
  242. package/compiler/plugin.bat +0 -19
  243. package/compiler/plugin2.bat +0 -4
  244. package/compiler/plugin_app.bat +0 -3
  245. package/compiler/plugin_apps.clj +0 -27
  246. package/compiler/plugins.bat +0 -10
  247. package/compiler/reveal_plugin.clj +0 -409
  248. package/compiler/simplePlugin.clj +0 -780
  249. package/compiler/t.bat +0 -3
  250. package/compiler/test_any.clj +0 -43
  251. package/compiler/test_call.clj +0 -141
  252. package/compiler/test_chain.clj +0 -79
  253. package/compiler/test_json.clj +0 -10
  254. package/compiler/test_lambda.clj +0 -153
  255. package/compiler/test_pcmd.clj +0 -32
  256. package/compiler/test_pcmd2.clj +0 -29
  257. package/compiler/test_plugin.clj +0 -237
  258. package/compiler/test_readfile.clj +0 -13
  259. package/compiler/test_reveal.clj +0 -19
  260. package/compiler/test_slides.clj +0 -312
  261. package/compiler/test_types.clj +0 -143
  262. package/compiler/test_types2.clj +0 -49
  263. package/compiler/test_types3.clj +0 -53
  264. package/compiler/test_var.clj +0 -40
  265. package/compiler/tonpm.bat +0 -14
  266. package/compiler/tonpm2.bat +0 -12
  267. package/compiler/ui_plugin.clj +0 -507
  268. package/compiler/ui_plugin2.clj +0 -427
  269. package/compiler/update-git.bat +0 -3
  270. package/compiler/vcomp.bat +0 -4
  271. package/compiler/viewbuilder_Android.clj +0 -176
  272. package/compiler/viewbuilder_Web.clj +0 -105
  273. package/dist/bin/api.js +0 -32422
  274. package/dist/bin/api.js.map +0 -1
  275. package/dist/bin/compiler.d.ts +0 -1638
  276. package/dist/bin/compiler.js +0 -32444
  277. package/dist/bin/compiler.js.map +0 -1
  278. package/examples/3D/bin/test_3d.js +0 -329
  279. package/examples/3D/test_3d.clj +0 -385
  280. package/examples/EVGColor/EVGColor.clj +0 -310
  281. package/examples/EVGColor/EVGColorContext.clj +0 -176
  282. package/examples/EVGColor/bin/EVGColor.js +0 -286
  283. package/examples/EVGColor/bin/minimized.js +0 -286
  284. package/examples/SVGPath/SVGPath.clj +0 -625
  285. package/examples/SVGPath/Vec2.clj +0 -103
  286. package/examples/SVGPath/bin/SVGPath.cpp +0 -887
  287. package/examples/SVGPath/bin/SVGPath.js +0 -682
  288. package/examples/SVGPath/bin/minimized.js +0 -578
  289. package/examples/SVGPath/bin/variant.hpp +0 -2416
  290. package/examples/minification/Vec2.clj +0 -103
  291. package/examples/minification/bin/minified.js +0 -44
  292. package/examples/minification/bin/test.js +0 -117
  293. package/examples/minification/test.clj +0 -13
  294. package/fiddle/VirtualCompiler.js +0 -23495
  295. package/fiddle/browser_editor.js +0 -13240
  296. package/fiddle/compileEnv.js +0 -1
  297. package/fiddle/compileEnv.json +0 -1
  298. package/fiddle/lang_data.js +0 -1
  299. package/index.html +0 -18
  300. package/native/httpd/HttpTester.clj +0 -33
  301. package/native/httpd/RangerWebService.clj +0 -81
  302. package/operators.md +0 -290
  303. package/tsconfig.json +0 -29
  304. package/versions/cpp/compiler.cpp +0 -15032
  305. package/versions/es6/compiler.js +0 -12860
  306. package/versions/go/compiler.go +0 -21338
  307. package/versions/java/AfterCodeNode.java +0 -4
  308. package/versions/java/ClassJoinPoint.java +0 -6
  309. package/versions/java/CodeFile.java +0 -42
  310. package/versions/java/CodeFileSystem.java +0 -72
  311. package/versions/java/CodeNode.java +0 -807
  312. package/versions/java/CodeSlice.java +0 -13
  313. package/versions/java/CodeWriter.java +0 -185
  314. package/versions/java/ColorConsole.java +0 -8
  315. package/versions/java/CompilerInterface.java +0 -213
  316. package/versions/java/DictNode.java +0 -353
  317. package/versions/java/LiveCompiler.java +0 -772
  318. package/versions/java/NodeEvalState.java +0 -24
  319. package/versions/java/OpFindResult.java +0 -6
  320. package/versions/java/RangerAppArrayValue.java +0 -7
  321. package/versions/java/RangerAppClassDesc.java +0 -217
  322. package/versions/java/RangerAppEnum.java +0 -14
  323. package/versions/java/RangerAppFunctionDesc.java +0 -20
  324. package/versions/java/RangerAppHashValue.java +0 -11
  325. package/versions/java/RangerAppInterfaceImpl.java +0 -6
  326. package/versions/java/RangerAppMethodVariants.java +0 -6
  327. package/versions/java/RangerAppParamDesc.java +0 -321
  328. package/versions/java/RangerAppTodo.java +0 -6
  329. package/versions/java/RangerAppValue.java +0 -10
  330. package/versions/java/RangerAppWriterContext.java +0 -800
  331. package/versions/java/RangerArgMatch.java +0 -317
  332. package/versions/java/RangerBackReference.java +0 -7
  333. package/versions/java/RangerCSharpClassWriter.java +0 -287
  334. package/versions/java/RangerCompilerMessage.java +0 -9
  335. package/versions/java/RangerCppClassWriter.java +0 -725
  336. package/versions/java/RangerFlowParser.java +0 -2142
  337. package/versions/java/RangerGenericClassWriter.java +0 -367
  338. package/versions/java/RangerGolangClassWriter.java +0 -1379
  339. package/versions/java/RangerJava7ClassWriter.java +0 -652
  340. package/versions/java/RangerJavaScriptClassWriter.java +0 -305
  341. package/versions/java/RangerKotlinClassWriter.java +0 -380
  342. package/versions/java/RangerLispParser.java +0 -845
  343. package/versions/java/RangerNodeValue.java +0 -9
  344. package/versions/java/RangerPHPClassWriter.java +0 -527
  345. package/versions/java/RangerParamEventHandler.java +0 -6
  346. package/versions/java/RangerParamEventList.java +0 -5
  347. package/versions/java/RangerParamEventMap.java +0 -27
  348. package/versions/java/RangerRangerClassWriter.java +0 -268
  349. package/versions/java/RangerRefForce.java +0 -7
  350. package/versions/java/RangerScalaClassWriter.java +0 -365
  351. package/versions/java/RangerSerializeClass.java +0 -148
  352. package/versions/java/RangerSwift3ClassWriter.java +0 -548
  353. package/versions/java/RangerTypeClass.java +0 -17
  354. package/versions/java/SourceCode.java +0 -65
  355. package/versions/php/compiler.php +0 -13830
  356. package/versions/swift3/compiler.swift +0 -12542
  357. /package/{lib/ACEEditor.clj → dist/lib/ACEEditor.rgr} +0 -0
  358. /package/{lib/SQL.clj → dist/lib/SQL.rgr} +0 -0
  359. /package/{lib/ServiceLib.clj → dist/lib/ServiceLib.rgr} +0 -0
  360. /package/{lib/Time.clj → dist/lib/Time.rgr} +0 -0
  361. /package/{lib/TypedArrays.clj → dist/lib/TypedArrays.rgr} +0 -0
  362. /package/{lib/WebLib.clj → dist/lib/WebLib.rgr} +0 -0
  363. /package/{lib/WebServerLib.clj → dist/lib/WebServerLib.rgr} +0 -0
@@ -1,1042 +0,0 @@
1
-
2
- Import "ng_WebPageWriter.clj"
3
-
4
- class RangerJavaScriptClassWriter {
5
-
6
- Extends (RangerGenericClassWriter)
7
- def compiler:LiveCompiler
8
- def thisName:string "this"
9
- def wrote_header:boolean false
10
-
11
- def target_flow false
12
- def target_typescript false
13
-
14
- fn lineEnding:string () {
15
- return ";"
16
- }
17
-
18
- fn adjustType:string (tn:string) {
19
- if (tn == "this") {
20
- return "this"
21
- }
22
- return tn
23
- }
24
-
25
- fn CreateTsUnions (parser:RangerFlowParser ctx:RangerAppWriterContext wr:CodeWriter) {
26
- def root (ctx.getRoot())
27
- root.definedClasses.forEach({
28
- ; index == name
29
- ; item == class description
30
- if(item.is_union) {
31
- ; TODO: implement system class unions too...
32
- wr.out( ( "type union_" + index + " = " ) false)
33
- wr.indent(1)
34
- def cnt 0
35
- item.is_union_of.forEach({
36
- if (ctx.isDefinedClass(item)) {
37
- def cl (ctx.findClass(item))
38
- if( false == (cl.isNormalClass() ) ) {
39
- return
40
- }
41
- if( cnt > 0 ) {
42
- wr.out("|" false)
43
- }
44
- wr.out( (this.getObjectTypeString( item ctx ) ) false )
45
- cnt = cnt + 1
46
- } {
47
- if( cnt > 0 ) {
48
- wr.out("|" false)
49
- }
50
- wr.out( (this.getObjectTypeString( item ctx ) ) false )
51
- cnt = cnt + 1
52
- }
53
- })
54
- wr.indent(-1)
55
- wr.out(";" true)
56
- }
57
- })
58
- }
59
-
60
- fn writeFnCall:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
61
- if node.hasFnCall {
62
- def fc:CodeNode (node.getFirst())
63
-
64
- if( (!null? node.fnDesc) && (!null? node.fnDesc.nameNode) ) {
65
- def fnName:CodeNode node.fnDesc.nameNode
66
- if( fnName.hasFlag('async') ) {
67
- wr.out('await ' false)
68
- }
69
- }
70
-
71
- this.WriteVRef(fc ctx wr)
72
- wr.out("(" false)
73
- def givenArgs:CodeNode (node.getSecond())
74
- ctx.setInExpr();
75
- def cnt 0
76
- for node.fnDesc.params arg:RangerAppParamDesc i {
77
- if( arg.nameNode.hasFlag('keyword')) {
78
- continue
79
- }
80
- if (cnt > 0) {
81
- wr.out(', ' false)
82
- }
83
- cnt = cnt + 1
84
- if( (array_length givenArgs.children) <= i) {
85
- def defVal@(optional):CodeNode (arg.nameNode.getFlag("default"))
86
- if (!null? defVal) {
87
- def fc:CodeNode (defVal.vref_annotation.getFirst())
88
- this.WalkNode(fc ctx wr)
89
- } {
90
- ctx.addError(node "Default argument was missing")
91
- }
92
- continue
93
- }
94
- def n:CodeNode (itemAt givenArgs.children i)
95
- this.WalkNode(n ctx wr)
96
- }
97
- ctx.unsetInExpr()
98
- wr.out(")" false)
99
-
100
- if(has node.methodChain) {
101
- ; wr.newline()
102
- ; wr.indent(1)
103
- for node.methodChain cc:CallChain i {
104
- wr.out("." + cc.methodName , false)
105
- wr.out("(" false)
106
- ctx.setInExpr()
107
- for cc.args.children arg:CodeNode i {
108
- if (i > 0) {
109
- wr.out(", " false)
110
- }
111
- this.WalkNode( arg ctx wr)
112
- }
113
- ctx.unsetInExpr()
114
- wr.out(")" false)
115
- }
116
- ; wr.indent(-1)
117
- }
118
-
119
- if ((ctx.expressionLevel()) == 0) {
120
- wr.out(";" true)
121
- }
122
- }
123
- }
124
-
125
- fn CreateCallExpression(node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
126
- if node.has_call {
127
- def obj:CodeNode (node.getSecond())
128
- def method:CodeNode (node.getThird())
129
- def args:CodeNode (itemAt node.children 3)
130
-
131
- if( (!null? node.fnDesc) && (!null? node.fnDesc.nameNode) ) {
132
- def fnName:CodeNode node.fnDesc.nameNode
133
- if( fnName.hasFlag('async') ) {
134
- wr.out('await ' false)
135
- }
136
- }
137
-
138
- wr.out("(" false)
139
- ctx.setInExpr()
140
- this.WalkNode( obj ctx wr)
141
- ctx.unsetInExpr()
142
- wr.out(")." false)
143
- wr.out(method.vref false)
144
- ; this.WriteVRef(fc ctx wr)
145
- wr.out("(" false)
146
- ctx.setInExpr()
147
- for args.children arg:CodeNode i {
148
- if (i > 0) {
149
- wr.out(", " false)
150
- }
151
- ; TODO: optionality check here ?
152
- this.WalkNode(arg ctx wr)
153
- }
154
- ctx.unsetInExpr()
155
- wr.out(")" false)
156
- if ((ctx.expressionLevel()) == 0) {
157
- wr.out(";" true)
158
- }
159
- }
160
- }
161
-
162
- ; typescript type
163
- fn getObjectTypeString:string (type_string:string ctx:RangerAppWriterContext) {
164
- switch type_string {
165
- case "int" {
166
- return "number"
167
- }
168
- case "string" {
169
- return "string"
170
- }
171
- case "charbuffer" {
172
- return "string"
173
- }
174
- case "char" {
175
- return "number"
176
- }
177
- case "boolean" {
178
- return "boolean"
179
- }
180
- case "double" {
181
- return "number"
182
- }
183
- }
184
- if(ctx.isDefinedClass(type_string)) {
185
- def cc (ctx.findClass(type_string))
186
- if(cc.is_system) {
187
- def current_sys (ctx)
188
- def sName (unwrap (get cc.systemNames "es6"))
189
- return sName
190
- }
191
- ; define the unions
192
- if(cc.is_union) {
193
- return ("union_" + cc.name)
194
- }
195
- }
196
- return type_string
197
- }
198
- fn getTypeString:string (type_string:string) {
199
- switch type_string {
200
- case "int" {
201
- return "number"
202
- }
203
- case "string" {
204
- return "string"
205
- }
206
- case "charbuffer" {
207
- return "string"
208
- }
209
- case "char" {
210
- return "number"
211
- }
212
- case "boolean" {
213
- return "boolean"
214
- }
215
- case "double" {
216
- return "number"
217
- }
218
- }
219
- return type_string
220
- }
221
-
222
- fn writeTypeDef:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
223
- def v_type:RangerNodeType node.value_type
224
- def t_name:string node.type_name
225
- def a_name:string node.array_type
226
- def k_name:string node.key_type
227
- if ((v_type == RangerNodeType.Object) || (v_type == RangerNodeType.VRef) || (v_type == RangerNodeType.NoType)) {
228
- v_type = (node.typeNameAsType(ctx))
229
- }
230
- if (node.eval_type != RangerNodeType.NoType) {
231
- v_type = node.eval_type
232
- if ( (strlen node.eval_type_name) > 0 ) {
233
- t_name = node.eval_type_name
234
- }
235
- if ( (strlen node.eval_array_type) > 0 ) {
236
- a_name = node.eval_array_type
237
- }
238
- if ( (strlen node.eval_key_type) > 0 ) {
239
- k_name = node.eval_key_type
240
- }
241
- }
242
- ; std::function<int (int, int)>
243
- switch v_type {
244
- case RangerNodeType.ExpressionType {
245
-
246
- ; (n: number) => any
247
- def rv:CodeNode (itemAt node.expression_value.children 0)
248
- def sec:CodeNode (itemAt node.expression_value.children 1)
249
- def fc:CodeNode (sec.getFirst())
250
-
251
- wr.out("(" false)
252
- for sec.children arg:CodeNode i {
253
- if( i > 0 ) {
254
- wr.out(", " false)
255
- }
256
- this.WalkNode( arg ctx wr )
257
- wr.out(":" false)
258
- this.writeTypeDef( arg ctx wr)
259
- }
260
- wr.out(") => " false )
261
-
262
- if( target_typescript ) {
263
- if(node.hasFlag('async')) {
264
- wr.out('Promise<' false)
265
- }
266
- }
267
- this.writeTypeDef( rv ctx wr)
268
-
269
- if( target_typescript ) {
270
- if(node.hasFlag('async')) {
271
- wr.out('>' false)
272
- }
273
- }
274
-
275
- }
276
- case RangerNodeType.Enum {
277
- wr.out("number" false)
278
- }
279
- case RangerNodeType.Integer {
280
- wr.out("number" false)
281
- }
282
- case RangerNodeType.Char {
283
- wr.out("number" false)
284
- }
285
- case RangerNodeType.CharBuffer {
286
- wr.out("string" false)
287
- }
288
- case RangerNodeType.Double {
289
- wr.out("number" false)
290
- }
291
- case RangerNodeType.String {
292
- wr.out("string" false)
293
- }
294
- case RangerNodeType.Boolean {
295
- wr.out("boolean" false)
296
- }
297
- case RangerNodeType.Hash {
298
- wr.out((((("{[key:" + (this.getObjectTypeString(k_name ctx))) + "]:") + (this.getObjectTypeString(a_name ctx)))) + "}" , false)
299
- }
300
- case RangerNodeType.Array {
301
- wr.out((("Array<" + (this.getObjectTypeString(a_name ctx))) + ">") false)
302
- }
303
- default {
304
- if (node.type_name == "void") {
305
- wr.out("void" false)
306
- return
307
- }
308
- if(ctx.isDefinedClass(t_name)) {
309
- def cc (ctx.findClass(t_name))
310
-
311
- if(cc.is_system) {
312
- def current_sys (ctx)
313
- def sName (unwrap (get cc.systemNames "es6"))
314
- wr.out(sName false)
315
- return
316
- }
317
-
318
- if(cc.is_union) {
319
- wr.out("union_" false)
320
- wr.out(t_name false)
321
- return
322
- }
323
- def cc:RangerAppClassDesc (ctx.findClass(t_name))
324
- wr.out(cc.name false)
325
- return
326
- }
327
- wr.out((this.getTypeString(t_name)) false))
328
- }
329
- }
330
- }
331
-
332
-
333
- fn WriteVRef:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
334
- if (node.eval_type == RangerNodeType.Enum) {
335
- if( (array_length node.ns) > 1) {
336
- def rootObjName:string (itemAt node.ns 0)
337
- def enumName:string (itemAt node.ns 1)
338
- def e@(optional):RangerAppEnum (ctx.getEnum(rootObjName))
339
- if (!null? e) {
340
- wr.out(("" + (unwrap (get e.values enumName))) false)
341
- return
342
- }
343
- }
344
- }
345
- if ((array_length node.nsp) > 0) {
346
- for node.nsp p:RangerAppParamDesc i {
347
- if (i > 0) {
348
- wr.out("." false)
349
- }
350
- if (i == 0) {
351
- ; if (p.nameNode.hasFlag("optional")) {
352
- ; }
353
- def part:string (itemAt node.ns 0)
354
- if ((part != "this") && (ctx.isMemberVariable(part))) {
355
- def uc@(optional):RangerAppClassDesc (ctx.getCurrentClass())
356
- def currC:RangerAppClassDesc (unwrap uc)
357
- def up@(optional):RangerAppParamDesc (currC.findVariable(part))
358
- if (!null? up) {
359
- wr.out( "this." false)
360
- }
361
- }
362
- if(part == "this") {
363
- wr.out("this" false)
364
- continue
365
- }
366
- }
367
- if ((strlen p.compiledName) > 0) {
368
- wr.out((this.adjustType(p.compiledName)) false)
369
- } {
370
- if ((strlen p.name) > 0) {
371
- wr.out((this.adjustType(p.name)) false)
372
- } {
373
- wr.out((this.adjustType( (itemAt node.ns i))) false)
374
- }
375
- }
376
- }
377
- return
378
- }
379
- if node.hasParamDesc {
380
- def part:string (itemAt node.ns 0)
381
- if ((part != "this") && (ctx.isMemberVariable(part))) {
382
- def uc@(optional):RangerAppClassDesc (ctx.getCurrentClass())
383
- def currC:RangerAppClassDesc (unwrap uc)
384
- def up@(optional):RangerAppParamDesc (currC.findVariable(part))
385
- if (!null? up) {
386
- wr.out("this." false)
387
- }
388
- }
389
- def p:RangerAppParamDesc node.paramDesc
390
- wr.out(p.compiledName false)
391
- return
392
- }
393
- def b_was_static:boolean false
394
- for node.ns part:string i {
395
- if (i > 0) {
396
- if ((i == 1) && b_was_static) {
397
- wr.out("." false)
398
- } {
399
- wr.out("." false)
400
- }
401
- }
402
- if (i == 0) {
403
- if (ctx.hasClass(part)) {
404
- b_was_static = true
405
- } {
406
- wr.out("" false)
407
- }
408
- if ((part != "this") && (ctx.isMemberVariable(part))) {
409
- def uc@(optional):RangerAppClassDesc (ctx.getCurrentClass())
410
- def currC:RangerAppClassDesc (unwrap uc)
411
- def up@(optional):RangerAppParamDesc (currC.findVariable(part))
412
- if (!null? up) {
413
- wr.out("this." false)
414
- }
415
- }
416
- }
417
- wr.out((this.adjustType(part)) false)
418
- }
419
- }
420
- fn writeVarInitDef:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
421
- if node.hasParamDesc {
422
- def nn:CodeNode (itemAt node.children 1)
423
- def p:RangerAppParamDesc nn.paramDesc
424
- def remove_unused:boolean (ctx.hasCompilerFlag("remove-unused-class-vars"))
425
-
426
- if ((p.ref_cnt == 0) && (remove_unused || (p.is_class_variable == false))) {
427
- return
428
- }
429
-
430
- def was_set false
431
-
432
- if ((array_length node.children) > 2) {
433
- wr.out(("this." + p.compiledName + " = ") , false)
434
- ctx.setInExpr()
435
- def value:CodeNode (node.getThird())
436
- this.WalkNode(value ctx wr)
437
- ctx.unsetInExpr()
438
- was_set = true
439
- } {
440
- if (nn.value_type == RangerNodeType.Array) {
441
- wr.out(("this." + p.compiledName ) , false)
442
- if(nn.hasFlag("immutable")) {
443
- wr.out(" = require('immutable').List()" false)
444
- } {
445
- wr.out(" = []" false)
446
- }
447
- was_set = true
448
- }
449
- if (nn.value_type == RangerNodeType.Hash) {
450
- wr.out(("this." + p.compiledName ) , false)
451
- ; wr.out(" = {}" false)
452
- if(nn.hasFlag("immutable")) {
453
- wr.out(" = require('immutable').Map()" false)
454
- } {
455
- wr.out(" = {}" false)
456
- }
457
- was_set = true
458
- }
459
- }
460
- if was_set {
461
- wr.out(";" false)
462
- if ((p.ref_cnt == 0) && (p.is_class_variable == true)) {
463
- wr.out(" /** note: unused */" false)
464
- }
465
- wr.newline()
466
- }
467
- }
468
- }
469
- fn writeVarDef:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
470
- if node.hasParamDesc {
471
- def nn:CodeNode (itemAt node.children 1)
472
- def p:RangerAppParamDesc nn.paramDesc
473
- def opt_js:boolean (ctx.hasCompilerFlag("optimize-js"))
474
- if ((p.ref_cnt == 0) && (p.is_class_variable == false)) {
475
- wr.out("/** unused: " false)
476
- }
477
- def has_value false
478
- if ((array_length node.children) > 2) {
479
- has_value = true
480
- }
481
-
482
- if ((p.set_cnt > 0) || p.is_class_variable || (has_value == false)) {
483
- wr.out(("let " + p.compiledName) false)
484
- } {
485
- wr.out(("const " + p.compiledName) false)
486
- }
487
-
488
- if target_typescript {
489
- wr.out(" : " false)
490
- this.writeTypeDef((unwrap p.nameNode) ctx wr)
491
- wr.out(" " false)
492
- }
493
-
494
- if ((array_length node.children) > 2) {
495
- wr.out(" = " false)
496
- ctx.setInExpr()
497
- def value:CodeNode (node.getThird())
498
- this.WalkNode(value ctx wr)
499
- ctx.unsetInExpr()
500
- } {
501
- ; the compiler could call the operators here with possibly some parameters ?
502
- if (nn.value_type == RangerNodeType.Array) {
503
- if(nn.hasFlag("immutable")) {
504
- wr.out(" = require('immutable').List()" false)
505
- } {
506
- wr.out(" = []" false)
507
- }
508
- }
509
- if (nn.value_type == RangerNodeType.Hash) {
510
- if(nn.hasFlag("immutable")) {
511
- wr.out(" = require('immutable').Map()" false)
512
- } {
513
- wr.out(" = {}" false)
514
- }
515
- }
516
- }
517
- if ((p.ref_cnt == 0) && (p.is_class_variable == true)) {
518
- wr.out(" /** note: unused */" false)
519
- }
520
- if ((p.ref_cnt == 0) && (p.is_class_variable == false)) {
521
- wr.out(" **/ " true)
522
- } {
523
- wr.out(";" false)
524
- wr.newline()
525
- }
526
- }
527
- }
528
- fn writeClassVarDef:void (p:RangerAppParamDesc ctx:RangerAppWriterContext wr:CodeWriter) {
529
- if target_typescript {
530
- wr.out( p.compiledName false)
531
- wr.out(": " false)
532
- this.writeTypeDef( (unwrap p.nameNode) ctx wr)
533
- wr.out(";" true)
534
- }
535
- }
536
-
537
- fn CreateLambdaCall:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
538
- def fName:CodeNode (itemAt node.children 0)
539
- def args:CodeNode (itemAt node.children 1)
540
- ctx.setInExpr()
541
-
542
- def currM ( ctx.getCurrentMethod( ))
543
-
544
- if( (!null? currM.nameNode) && (currM.nameNode.hasFlag('async'))) {
545
- wr.out('await ' false)
546
- }
547
- this.WalkNode( fName ctx wr)
548
- ; this.WriteVRef(fName ctx wr)
549
- wr.out("(" false)
550
- for args.children arg:CodeNode i {
551
- if (i > 0) {
552
- wr.out(", " false)
553
- }
554
- this.WalkNode( arg ctx wr)
555
- }
556
- wr.out(")" false)
557
- ctx.unsetInExpr()
558
- if ((ctx.expressionLevel()) == 0) {
559
- wr.out(";" true)
560
- }
561
- }
562
-
563
- fn CreateLambda:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
564
- def lambdaCtx (unwrap node.lambda_ctx)
565
- def fName:CodeNode (itemAt node.children 0)
566
- def args:CodeNode (itemAt node.children 1)
567
- def body:CodeNode (itemAt node.children 2)
568
-
569
- if ((ctx.expressionLevel()) > 0) {
570
- wr.out('(' false)
571
- }
572
-
573
- if( fName.hasFlag('async') ) {
574
- wr.out('async ' false)
575
- }
576
-
577
- wr.out("(" false)
578
- for args.children arg:CodeNode i {
579
- if (i > 0) {
580
- wr.out(', ' false)
581
- }
582
- if(arg.flow_done == false) {
583
- this.compiler.parser.WalkNode( arg lambdaCtx wr)
584
- }
585
- this.WalkNode(arg lambdaCtx wr)
586
- if target_typescript {
587
- wr.out(' : ' false)
588
- this.writeTypeDef( arg ctx wr)
589
- }
590
- }
591
- wr.out(')' false)
592
- if(target_typescript) {
593
- wr.out(":" false)
594
- if( fName.hasFlag('async') ) {
595
- wr.out(' Promise<' false)
596
- }
597
- this.writeTypeDef( fName ctx wr)
598
- if( fName.hasFlag('async') ) {
599
- wr.out('>' false)
600
- }
601
- }
602
- wr.out(' => { ' true)
603
- wr.indent(1)
604
- lambdaCtx.restartExpressionLevel()
605
- for body.children item:CodeNode i {
606
- ; print "lambda row " + (item.getCode())
607
- ; if(has item.register_expressions) {
608
- ; print "Lambda had register expressions at : " + (item.getCode())
609
- ; }
610
- this.WalkNode(item lambdaCtx wr)
611
- }
612
- wr.newline()
613
- wr.indent(-1)
614
- wr.out("}" false)
615
-
616
- if ((ctx.expressionLevel()) > 0) {
617
- wr.out(')' false)
618
- } {
619
- wr.out('' true)
620
- }
621
-
622
- }
623
-
624
- fn writeArgsDef:void (fnDesc:RangerAppFunctionDesc ctx:RangerAppWriterContext wr:CodeWriter) {
625
- def cnt 0
626
- def pms (filter (fnDesc.params) {
627
- if( item.nameNode.hasFlag('keyword')) {
628
- return false
629
- }
630
- return true
631
- })
632
- for pms arg:RangerAppParamDesc i {
633
- if (cnt > 0) {
634
- wr.out(', ' false)
635
- }
636
- cnt = cnt + 1
637
- wr.out( arg.compiledName false)
638
- if target_typescript {
639
- wr.out(' : ' false)
640
- this.writeTypeDef( (unwrap arg.nameNode) ctx wr)
641
- }
642
- }
643
- }
644
-
645
- fn writeClass:void (node:CodeNode ctx:RangerAppWriterContext orig_wr:CodeWriter) {
646
-
647
- def cl:RangerAppClassDesc node.clDesc
648
- def is_react_native:boolean false
649
- def is_rn_default false
650
-
651
- target_typescript = (ctx.hasCompilerFlag("typescript"))
652
-
653
- if( (ctx.hasCompilerFlag('dead4main')) || (ctx.hasCompilerSetting('dceclass'))) {
654
- if(cl.is_used_by_main == false) {
655
- return
656
- }
657
- }
658
-
659
- if(cl.is_interface) {
660
- orig_wr.out("// interface : " + cl.name , true)
661
- return
662
- }
663
- if (null? cl) {
664
- return
665
- }
666
- if(cl.nameNode.hasFlag("ReactNative")) {
667
- is_react_native = true
668
- set this.compFlags "ReactNative" true
669
- }
670
- if(cl.nameNode.hasFlag("default")) {
671
- is_rn_default = true
672
- }
673
- def wr:CodeWriter orig_wr
674
- def importFork:CodeWriter (wr.fork())
675
- if (wrote_header == false) {
676
- wrote_header = true
677
-
678
- if(ctx.hasCompilerFlag("nodecli")) {
679
- wr.out("#!/usr/bin/env node" true)
680
- }
681
-
682
- ; write the npm exports at the end of the file if required...
683
- if( (ctx.hasCompilerFlag("nodemodule")) && (target_typescript == false)) {
684
- def root (ctx.getRoot())
685
- root.definedClasses.forEach({
686
-
687
- if( (ctx.hasCompilerFlag('dead4main')) || (ctx.hasCompilerSetting('dceclass'))) {
688
- if(item.is_used_by_main == false) {
689
- return
690
- }
691
- }
692
- if(item.isNormalClass()) {
693
- def theEnd (wr.getTag("file_end"))
694
- theEnd.out( ("module.exports." + item.name + " = " + item.name + ";") true )
695
- }
696
- })
697
- }
698
- ; javascript option for the flow types...
699
- target_flow = (ctx.hasCompilerFlag("flow"))
700
- if( target_typescript ) {
701
- this.CreateTsUnions( (unwrap this.compiler.parser) ctx wr )
702
- }
703
- if(ctx.hasCompilerFlag("npm")) {
704
- this.writeNpmPackage( node ctx wr )
705
- }
706
- }
707
- def b_extd:boolean false
708
-
709
- def do_export false
710
-
711
- if( is_react_native || target_typescript ) {
712
- do_export = true
713
- if( cl.is_system || cl.is_operator_class ) {
714
- do_export = false
715
- }
716
- }
717
-
718
- if do_export {
719
- wr.out("export " false)
720
- if(is_rn_default) {
721
- wr.out(" default " false)
722
- }
723
- }
724
-
725
- wr.out("class " + cl.name +" " , false)
726
-
727
- if is_react_native {
728
- wr.out(" extends Component " false)
729
- } {
730
- for cl.extends_classes pName:string i {
731
- if( i == 0) {
732
- wr.out(" extends " false)
733
- }
734
- wr.out(pName false)
735
- b_extd = true
736
- }
737
- }
738
-
739
- wr.out( " {" true)
740
- wr.indent(1)
741
- ; define the class variables
742
- for cl.variables pvar:RangerAppParamDesc i {
743
- this.writeClassVarDef( pvar ctx wr)
744
- }
745
-
746
- if(is_react_native == false) {
747
-
748
- wr.out("constructor(" false)
749
-
750
- if cl.has_constructor {
751
- def constr:RangerAppFunctionDesc (unwrap cl.constructor_fn)
752
- this.writeArgsDef(constr ctx wr)
753
- }
754
- wr.out(") {" true)
755
- wr.indent(1)
756
-
757
- if(b_extd) {
758
- wr.out("super()" true)
759
- }
760
-
761
- for cl.variables pvar:RangerAppParamDesc i {
762
- this.writeVarInitDef(( unwrap pvar.node ) ctx wr)
763
- }
764
- if cl.has_constructor {
765
- def constr:RangerAppFunctionDesc cl.constructor_fn
766
- wr.newline()
767
- def subCtx:RangerAppWriterContext ( unwrap constr.fnCtx )
768
- subCtx.is_function = true
769
- this.WalkNode(( unwrap constr.fnBody ) subCtx wr)
770
- }
771
- wr.newline()
772
- wr.indent(-1)
773
- wr.out("}" true)
774
- }
775
- for cl.defined_variants fnVar:string i {
776
- def mVs:RangerAppMethodVariants (get cl.method_variants fnVar)
777
- for mVs.variants variant:RangerAppFunctionDesc i {
778
-
779
- if( variant.nameNode.hasFlag('async') ) {
780
- wr.out('async ' false)
781
- }
782
- wr.out((("" + variant.compiledName) + " (") false)
783
- this.writeArgsDef(variant ctx wr)
784
- wr.out(")" false)
785
-
786
- if target_typescript {
787
- wr.out(" : " false)
788
-
789
- if( variant.nameNode.hasFlag('async') ) {
790
- wr.out(' Promise<' false)
791
- }
792
- this.writeTypeDef( (unwrap variant.nameNode ) ctx wr)
793
- if( variant.nameNode.hasFlag('async') ) {
794
- wr.out('>' false)
795
- }
796
- wr.out(" " false)
797
- }
798
-
799
- wr.out(" {" true)
800
- wr.indent(1)
801
- wr.newline()
802
- def subCtx:RangerAppWriterContext ( unwrap variant.fnCtx )
803
- subCtx.is_function = true
804
- subCtx.localVariables.forEach({
805
- if(item.is_register) {
806
- wr.out( ('// register ' + item.name) true)
807
- }
808
- })
809
- this.WalkNode(( unwrap variant.fnBody ) subCtx wr)
810
- wr.newline()
811
- wr.indent(-1)
812
- wr.out("};" true)
813
- }
814
- }
815
-
816
- if target_typescript {
817
- for cl.static_methods variant:RangerAppFunctionDesc i {
818
- if (variant.nameNode.hasFlag("main")) {
819
- continue _
820
- }
821
-
822
- wr.out("// typescript static " true)
823
-
824
- wr.out("static " false)
825
- if( variant.nameNode.hasFlag('async') ) {
826
- wr.out('async ' false)
827
- }
828
- wr.out((("" + variant.compiledName) + " (") false)
829
- this.writeArgsDef(variant ctx wr)
830
- wr.out(")" false)
831
- wr.out(" : " false)
832
-
833
- if( variant.nameNode.hasFlag('async') ) {
834
- wr.out(' Promise<' false)
835
- }
836
- this.writeTypeDef( (unwrap variant.nameNode ) ctx wr)
837
- if( variant.nameNode.hasFlag('async') ) {
838
- wr.out('> ' false)
839
- }
840
-
841
-
842
- wr.out(" " false)
843
- wr.out(" {" true)
844
- wr.indent(1)
845
- wr.newline()
846
- def subCtx:RangerAppWriterContext ( unwrap variant.fnCtx )
847
- subCtx.is_function = true
848
- this.WalkNode(( unwrap variant.fnBody ) subCtx wr)
849
- wr.newline()
850
- wr.indent(-1)
851
- wr.out("};" true)
852
-
853
- }
854
- }
855
-
856
- wr.indent(-1)
857
- wr.out("}" true)
858
-
859
- if ( target_typescript == false ) {
860
- for cl.static_methods variant:RangerAppFunctionDesc i {
861
- if (variant.nameNode.hasFlag("main")) {
862
- continue _
863
- } {
864
- def asyncKeyword ""
865
- if( variant.nameNode.hasFlag('async') ) {
866
- asyncKeyword = 'async '
867
- }
868
- wr.out((((cl.name + ".") + variant.compiledName) + " = " + asyncKeyword + "function(") false)
869
- this.writeArgsDef(variant ctx wr)
870
- wr.out(") {" true)
871
- }
872
- wr.indent(1)
873
- wr.newline()
874
- def subCtx:RangerAppWriterContext ( unwrap variant.fnCtx )
875
- subCtx.is_function = true
876
- this.WalkNode(( unwrap variant.fnBody ) subCtx wr)
877
- wr.newline()
878
- wr.indent(-1)
879
- wr.out("};" true)
880
- }
881
- }
882
- if( (ctx.hasCompilerFlag("nodemodule")) == false ) {
883
- for cl.static_methods variant:RangerAppFunctionDesc i {
884
- ctx.disableCurrentClass()
885
- if ( (variant.nameNode.hasFlag("main")) && (variant.nameNode.code.filename == (ctx.getRootFile()))) {
886
-
887
- def asyncKeyword ""
888
- if( variant.nameNode.hasFlag('async') ) {
889
- asyncKeyword = 'async '
890
- }
891
-
892
- def theEnd (wr.getTag("file_end"))
893
- theEnd.out("/* static JavaSript main routine at the end of the JS file */" false)
894
- theEnd.newline()
895
- theEnd.out( (asyncKeyword + "function __js_main() {") true)
896
- theEnd.indent(1)
897
- this.WalkNode(( unwrap variant.fnBody ) ctx theEnd)
898
- theEnd.newline()
899
- theEnd.indent(-1)
900
- theEnd.out("}" true)
901
- theEnd.out("__js_main();" true)
902
- }
903
- }
904
- }
905
- }
906
-
907
- fn BuildAST:CodeNode ( code_string:string) {
908
- def lang_code:SourceCode (new SourceCode ( code_string ) )
909
- lang_code.filename = "services"
910
- def lang_parser:RangerLispParser (new RangerLispParser (lang_code))
911
- lang_parser.parse(false)
912
- def node@(lives):CodeNode (unwrap lang_parser.rootNode)
913
- return node
914
- }
915
-
916
- fn CreateServices (parser:RangerFlowParser ctx:RangerAppWriterContext orig_wr:CodeWriter) {
917
-
918
- if(ctx.hasCompilerFlag("client")) {
919
- ctx.addError( (CodeNode.blockNode()) "client service writing for target JavaScript is not implemented")
920
- return
921
- }
922
-
923
- def root (ctx.getRoot())
924
-
925
- def serviceBlock (CodeNode.blockNode())
926
-
927
- def wr (new CodeWriter)
928
- wr.out("class test_webservice {" true)
929
- wr.indent(1)
930
- wr.out("fn run () {" true)
931
- wr.indent(1)
932
- wr.out("def www (create_web_server)" true)
933
- wr.out("prepare_server www" true);
934
- root.appServices.forEach({
935
-
936
- try {
937
-
938
- def paramList (item.getThird())
939
- def param (paramList.getFirst())
940
-
941
- wr.out("www.post_route(\"/" + item.appGUID + "\" {" , true)
942
- wr.indent(1)
943
- wr.out("def obj (" + (param.type_name) + ".fromDictionary( (from_string (get_post_data req ))) )" , true)
944
- wr.out("def service (new appServices)" true)
945
- wr.out("def data (service." + item.appGUID + "(obj))" , true)
946
- wr.out("res.send((to_string (data.toDictionary())))" , true)
947
- wr.indent(-1)
948
- wr.out("})" true)
949
-
950
- def nn (item.getSecond())
951
- nn.vref = item.appGUID
952
- def params (item.getThird())
953
-
954
- def block_index 3
955
- def ch_len ( ( array_length item.children ) - 1)
956
- for item.children cb:CodeNode i {
957
- if( i > 3 ) {
958
- if( (strlen cb.vref) > 0 ) {
959
- if( ( ctx.hasCompilerFlag(cb.vref) ) && ( i < ch_len ) ) {
960
- block_index = i + 1
961
- }
962
- }
963
- }
964
- }
965
-
966
- def codeBlock (unwrap (item.getChild(block_index)) )
967
- push serviceBlock.children (r.op "fn" nn params codeBlock)
968
-
969
-
970
- } {
971
- ctx.addError( item "Invalid service function")
972
- }
973
- })
974
- wr.indent(-1)
975
- wr.out("www.startServer( 1777, {" , true)
976
- wr.indent(1)
977
- wr.out("print \"Server started\"" true)
978
- wr.indent(-1)
979
- wr.out("}" true)
980
- wr.out("}" true)
981
- wr.indent(-1)
982
- wr.out("}" true)
983
-
984
- def codeNode (this.BuildAST( (wr.getCode() )) )
985
- def serviceClassDef (r.op "class" (r.vref "appServices") serviceBlock )
986
-
987
- def subCtx (root.fork())
988
- def theEnd (orig_wr.getTag("file_end"))
989
-
990
- parser.WalkCollectMethods( serviceClassDef root theEnd )
991
- parser.WalkCollectMethods( codeNode root theEnd )
992
- parser.WalkNode( serviceClassDef root theEnd )
993
- parser.WalkNode( codeNode root theEnd )
994
-
995
- theEnd.out("(new test_webservice).run();" true)
996
-
997
- }
998
-
999
- fn CreatePages (parser:RangerFlowParser ctx:RangerAppWriterContext orig_wr:CodeWriter) {
1000
-
1001
- def wr:CodeWriter (orig_wr.getFileWriter("." ("pages.js")))
1002
-
1003
- ; TODO: the application container could be here
1004
- wr.out("class theApplicationClass {" true)
1005
- wr.indent(1)
1006
- ctx.appPages.forEach({
1007
- this.CreatePage(parser item ctx wr)
1008
- })
1009
- wr.indent(-1)
1010
- wr.out("}" true)
1011
- }
1012
-
1013
- fn CreatePage (parser:RangerFlowParser node:CodeNode ctx:RangerAppWriterContext orig_wr:CodeWriter) {
1014
- def writer (new WebPageWriter)
1015
- writer.classWriter = this
1016
- writer.CreatePage( parser node ctx orig_wr )
1017
- }
1018
-
1019
- fn writeNpmPackage ( node:CodeNode ctx:RangerAppWriterContext orig_wr:CodeWriter ) {
1020
- def wr:CodeWriter (orig_wr.getFileWriter("." ("package.json")))
1021
- def opts ([] "name" "version" "description" "author" "license")
1022
- wr.out("{" true)
1023
- wr.indent(1)
1024
- opts.forEach({
1025
- if( (ctx.hasCompilerSetting(item)) == false ) {
1026
- ctx.addError( node ("NPM package requires option -" + item + "=<value>") )
1027
- } {
1028
- wr.out( ('"' + item + '" : "' + (ctx.getCompilerSetting(item)) + '",') true)
1029
- }
1030
- })
1031
- def target_file (ctx.getCompilerSetting("o"))
1032
- if( ctx.hasCompilerFlag("nodecli")) {
1033
- wr.out( ('"bin": {"' + (ctx.getCompilerSetting("name")) +'":"' + target_file + '"},') true)
1034
- }
1035
- wr.out('"scripts":{},' true)
1036
- wr.out( ('"main":"' + target_file + '"') true)
1037
- wr.indent(-1)
1038
- wr.out("}" true)
1039
- }
1040
-
1041
- }
1042
-