firefly-compiler 0.4.77 → 0.4.79

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 (135) hide show
  1. package/.hintrc +4 -4
  2. package/.vscode/settings.json +4 -4
  3. package/bin/Release.ff +153 -153
  4. package/bin/firefly.mjs +1 -1
  5. package/compiler/Builder.ff +257 -257
  6. package/compiler/Compiler.ff +227 -227
  7. package/compiler/Dependencies.ff +187 -187
  8. package/compiler/DependencyLock.ff +17 -17
  9. package/compiler/JsEmitter.ff +946 -946
  10. package/compiler/LspHook.ff +202 -202
  11. package/compiler/ModuleCache.ff +178 -178
  12. package/compiler/Workspace.ff +88 -88
  13. package/core/.firefly/include/package-lock.json +564 -394
  14. package/core/.firefly/include/package.json +5 -5
  15. package/core/.firefly/include/prepare.sh +1 -1
  16. package/core/.firefly/package.ff +2 -2
  17. package/core/Array.ff +265 -265
  18. package/core/Atomic.ff +64 -64
  19. package/core/Box.ff +7 -7
  20. package/core/BrowserSystem.ff +40 -40
  21. package/core/BuildSystem.ff +148 -148
  22. package/core/Crypto.ff +96 -96
  23. package/core/Equal.ff +36 -36
  24. package/core/HttpClient.ff +148 -148
  25. package/core/JsSystem.ff +69 -69
  26. package/core/Json.ff +434 -434
  27. package/core/List.ff +486 -486
  28. package/core/Lock.ff +144 -144
  29. package/core/NodeSystem.ff +216 -216
  30. package/core/Ordering.ff +161 -161
  31. package/core/Path.ff +401 -401
  32. package/core/Random.ff +134 -134
  33. package/core/RbMap.ff +216 -216
  34. package/core/Show.ff +43 -43
  35. package/core/SourceLocation.ff +68 -68
  36. package/core/String.ff +16 -0
  37. package/core/Task.ff +141 -141
  38. package/experimental/benchmarks/ListGrab.ff +23 -23
  39. package/experimental/benchmarks/ListGrab.java +55 -55
  40. package/experimental/benchmarks/Pyrotek45.ff +30 -30
  41. package/experimental/benchmarks/Pyrotek45.java +64 -64
  42. package/experimental/bidirectional/Bidi.ff +88 -88
  43. package/experimental/random/Index.ff +53 -53
  44. package/experimental/random/Process.ff +120 -120
  45. package/experimental/random/Scrape.ff +51 -51
  46. package/experimental/random/Symbols.ff +73 -73
  47. package/experimental/random/Tensor.ff +52 -52
  48. package/experimental/random/Units.ff +36 -36
  49. package/experimental/s3/S3TestAuthorizationHeader.ff +39 -38
  50. package/experimental/s3/S3TestPut.ff +16 -15
  51. package/experimental/tests/TestJson.ff +26 -26
  52. package/firefly.sh +0 -0
  53. package/fireflysite/.firefly/package.ff +4 -0
  54. package/fireflysite/CommunityOverview.ff +20 -0
  55. package/fireflysite/CountingButtonDemo.ff +58 -0
  56. package/fireflysite/DocumentParser.ff +218 -0
  57. package/fireflysite/ExamplesOverview.ff +40 -0
  58. package/fireflysite/FrontPage.ff +360 -0
  59. package/fireflysite/Guide.ff +411 -0
  60. package/fireflysite/GuideAll.ff +21 -0
  61. package/fireflysite/GuideBaseTypes.ff +168 -0
  62. package/fireflysite/GuideControlFlow.ff +212 -0
  63. package/fireflysite/GuideIntroduction.ff +52 -0
  64. package/fireflysite/Main.ff +137 -15
  65. package/fireflysite/MatchingPasswordsDemo.ff +82 -0
  66. package/fireflysite/PackagesOverview.ff +49 -0
  67. package/fireflysite/PostgresqlDemo.ff +34 -0
  68. package/fireflysite/Styles.ff +495 -0
  69. package/fireflysite/assets/NotoSansMono-Regular.ttf +0 -0
  70. package/fireflysite/assets/NunitoSans-VariableFont_YTLC,opsz,wdth,wght.ttf +0 -0
  71. package/fireflysite/assets/autocomplete-small.png +0 -0
  72. package/fireflysite/assets/autocomplete.png +0 -0
  73. package/fireflysite/assets/edit-time-error.png +0 -0
  74. package/fireflysite/assets/firefly-logo-notext.png +0 -0
  75. package/fireflysite/assets/firefly-logo-yellow.png +0 -0
  76. package/fireflysite/assets/markdown/ControlFlow.md +136 -0
  77. package/fireflysite/assets/markdown/Example.md +78 -0
  78. package/lsp/.firefly/package.ff +1 -1
  79. package/lsp/CompletionHandler.ff +828 -828
  80. package/lsp/Handler.ff +714 -714
  81. package/lsp/HoverHandler.ff +79 -79
  82. package/lsp/LanguageServer.ff +272 -272
  83. package/lsp/SignatureHelpHandler.ff +55 -55
  84. package/lsp/SymbolHandler.ff +181 -181
  85. package/lsp/TestReferences.ff +17 -17
  86. package/lsp/TestReferencesCase.ff +7 -7
  87. package/lsp/stderr.txt +1 -1
  88. package/lsp/stdout.txt +34 -34
  89. package/lux/.firefly/package.ff +1 -1
  90. package/lux/Css.ff +648 -648
  91. package/lux/CssTest.ff +48 -48
  92. package/lux/Lux.ff +487 -487
  93. package/lux/LuxEvent.ff +116 -116
  94. package/lux/Main.ff +123 -123
  95. package/lux/Main2.ff +143 -144
  96. package/output/js/ff/compiler/Builder.mjs +43 -43
  97. package/output/js/ff/compiler/Dependencies.mjs +3 -3
  98. package/output/js/ff/core/Array.mjs +59 -59
  99. package/output/js/ff/core/Atomic.mjs +36 -36
  100. package/output/js/ff/core/BrowserSystem.mjs +11 -11
  101. package/output/js/ff/core/BuildSystem.mjs +30 -30
  102. package/output/js/ff/core/Crypto.mjs +40 -40
  103. package/output/js/ff/core/HttpClient.mjs +56 -56
  104. package/output/js/ff/core/Json.mjs +147 -147
  105. package/output/js/ff/core/List.mjs +50 -50
  106. package/output/js/ff/core/Lock.mjs +97 -97
  107. package/output/js/ff/core/NodeSystem.mjs +83 -83
  108. package/output/js/ff/core/Ordering.mjs +8 -8
  109. package/output/js/ff/core/Path.mjs +231 -231
  110. package/output/js/ff/core/Random.mjs +56 -56
  111. package/output/js/ff/core/String.mjs +20 -0
  112. package/output/js/ff/core/Task.mjs +31 -31
  113. package/package.json +1 -1
  114. package/rpc/.firefly/package.ff +1 -1
  115. package/rpc/Rpc.ff +70 -70
  116. package/s3/.firefly/package.ff +1 -1
  117. package/s3/S3.ff +94 -94
  118. package/unsafejs/UnsafeJs.ff +19 -19
  119. package/vscode/LICENSE.txt +21 -21
  120. package/vscode/Prepublish.ff +15 -15
  121. package/vscode/README.md +16 -16
  122. package/vscode/client/package.json +22 -22
  123. package/vscode/client/src/extension.ts +104 -104
  124. package/vscode/icons/firefly-icon.svg +10 -10
  125. package/vscode/language-configuration.json +61 -61
  126. package/vscode/package-lock.json +3623 -3623
  127. package/vscode/package.json +15 -1
  128. package/vscode/snippets.json +241 -241
  129. package/vscode/syntaxes/firefly-markdown-injection.json +45 -0
  130. package/webserver/.firefly/include/package-lock.json +22 -16
  131. package/webserver/.firefly/include/package.json +5 -5
  132. package/webserver/.firefly/package.ff +2 -2
  133. package/webserver/WebServer.ff +685 -685
  134. package/websocket/.firefly/package.ff +1 -1
  135. package/websocket/WebSocket.ff +131 -131
@@ -0,0 +1,495 @@
1
+ import Css from ff:lux
2
+
3
+ mobileMediaQuery: String = "@media only screen and (max-width: 840px)"
4
+ mobileOrTabletMediaQuery: String = "@media only screen and (max-width: 1140px)"
5
+
6
+ pageCss: CssClass = CssClass(
7
+ [
8
+ Css.display("flex")
9
+ Css.flexDirection("column")
10
+ Css.minHeight("100vh")
11
+ Css.fontFamily("'Firefly Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif")
12
+ Css.textRendering("optimizeLegibility")
13
+ ]
14
+ [
15
+ CssNest("*:focus-visible", [
16
+ Css.outline("2px solid #ecc45e")
17
+ Css.outlineOffset("2px")
18
+ ], [])
19
+ ]
20
+ []
21
+ )
22
+
23
+ whiteLinkCss: CssClass = CssClass(
24
+ [
25
+ Css.color("#000000")
26
+ Css.textDecoration("none")
27
+ Css.fontWeight("600")
28
+ ]
29
+ [
30
+ CssNest("&:hover", [Css.textDecoration("underline")], [])
31
+ CssNest("&[aria-current='page']", [Css.color("#000000")], [])
32
+ ]
33
+ []
34
+ )
35
+
36
+ greenLinkCss: CssClass = CssClass(
37
+ [
38
+ Css.color("#4ec9b0")
39
+ Css.textDecoration("none")
40
+ ]
41
+ [
42
+ CssNest("&:hover", [Css.textDecoration("underline")], [])
43
+ ]
44
+ []
45
+ )
46
+
47
+ searchInputCss: CssClass = CssClass(
48
+ [
49
+ Css.appearance("none")
50
+ Css.boxSizing("border-box")
51
+ Css.marginLeft("20px")
52
+ Css.marginRight("25px")
53
+ Css.width("calc(100% - 20px - 25px)")
54
+ Css.display("flex")
55
+ Css.border("none")
56
+ Css.borderBottom("2px solid #000000")
57
+ Css.backgroundColor("#ffffff50")
58
+ Css.color("#000000")
59
+ Css.height("34px")
60
+ Css.fontSize("16px")
61
+ Css.borderRadius("0")
62
+ Css.paddingLeft("5px")
63
+ Css.paddingRight("5px")
64
+ Css.paddingTop("0")
65
+ Css.paddingBottom("0")
66
+ Css.marginBottom("20px")
67
+ ]
68
+ [
69
+ CssNest("&::placeholder", [
70
+ Css.color("#000000")
71
+ Css.opacity("unset")
72
+ Css.fontSize("16px")
73
+ ], [])
74
+ CssNest("&:focus::placeholder", [
75
+ Css.opacity("0")
76
+ ], [])
77
+ ]
78
+ []
79
+ )
80
+
81
+ guideCss: CssClass = CssClass(
82
+ [
83
+ Css.display("flex")
84
+ Css.minHeight("100vh")
85
+ ]
86
+ []
87
+ []
88
+ )
89
+
90
+ guideSidebarButtonCss: CssClass = CssClass(
91
+ [
92
+ Css.position("fixed")
93
+ Css.bottom("-68px")
94
+ Css.right("-65px")
95
+ Css.width("70px")
96
+ Css.height("70px")
97
+ Css.padding("0")
98
+ Css.boxSizing("border-box")
99
+ Css.background("""url('data:image/svg+xml,<svg width="50" height="50" viewBox="0 0 50 50" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(%23clip0_788_122)"><rect x="4" y="9" width="30" height="3" rx="1" fill="%23ecc45e"/><rect x="4" y="17" width="21" height="3" rx="1" fill="%23ecc45e"/><rect x="4" y="25" width="13" height="3" rx="1" fill="%23ecc45e"/></g><defs><clipPath id="clip0_788_122"><rect width="50" height="50" fill="white"/></clipPath></defs></svg>') no-repeat center""")
100
+ Css.backgroundSize("70px 70px")
101
+ Css.appearance("none")
102
+ Css.border("none")
103
+ Css.outline("none")
104
+ Css.transformOrigin("top left")
105
+ Css.transform("rotate(180deg) scale(0, 0)")
106
+ Css.transition("100ms transform")
107
+ ]
108
+ [
109
+ CssNest(mobileOrTabletMediaQuery, [
110
+ Css.display("block")
111
+ Css.transform("rotate(180deg) scale(1, 1)")
112
+ ], [])
113
+ ]
114
+ []
115
+ )
116
+
117
+ guideSidebarButtonOpenCss: CssClass = CssClass(
118
+ []
119
+ [
120
+ CssNest(mobileOrTabletMediaQuery, [
121
+ Css.transform("rotate(180deg) scale(0, 1)")
122
+ ], [])
123
+ ]
124
+ []
125
+ )
126
+
127
+ guideSidebarBackdropCss: CssClass = CssClass(
128
+ [
129
+ Css.display("none")
130
+ Css.position("fixed")
131
+ Css.top("0")
132
+ Css.bottom("0px")
133
+ Css.left("0")
134
+ Css.right("0px")
135
+ Css.backgroundColor("rgba(20, 20, 0, 0.7)")
136
+ Css.backdropFilter("blur(1px)")
137
+ Css.touchAction("none")
138
+ ]
139
+ []
140
+ []
141
+ )
142
+
143
+ guideSidebarBackdropOpenCss: CssClass = CssClass(
144
+ []
145
+ [
146
+ CssNest(mobileOrTabletMediaQuery, [
147
+ Css.display("block")
148
+ ], [])
149
+ ]
150
+ []
151
+ )
152
+
153
+ guideSidebarCss: CssClass = CssClass(
154
+ [
155
+ Css.position("fixed")
156
+ Css.top("0")
157
+ Css.bottom("0")
158
+ Css.left("0")
159
+ Css.width("300px")
160
+ Css.boxSizing("border-box")
161
+ Css.paddingTop("10px")
162
+ Css.backgroundColor("#ecc45e")
163
+ Css.overflowY("auto")
164
+ Css.transition("200ms transform")
165
+ Css.scrollbarWidth("thin")
166
+ Css.scrollbarColor("#333333 #ecc45e")
167
+ ]
168
+ [
169
+ CssNest(mobileOrTabletMediaQuery, [
170
+ Css.order("2")
171
+ Css.width("calc(100% - 50px)")
172
+ Css.maxWidth("300px")
173
+ Css.minHeight("auto")
174
+ Css.height("auto")
175
+ Css.paddingTop("20px")
176
+ Css.paddingBottom("20px")
177
+ Css.transform("translateX(-110%)")
178
+ Css.outline("1px solid rgba(0, 0, 0, 0.15)")
179
+ ], [])
180
+ CssNest("& *:focus-visible", [
181
+ Css.outline("2px solid #000000")
182
+ Css.outlineOffset("2px")
183
+ ], [])
184
+ ]
185
+ []
186
+ )
187
+
188
+ guideSidebarOpenCss: CssClass = CssClass(
189
+ []
190
+ [
191
+ CssNest(mobileOrTabletMediaQuery, [
192
+ Css.transform("translateX(0)")
193
+ ], [])
194
+ ]
195
+ []
196
+ )
197
+
198
+ guideSidebarLogoCss: CssClass = CssClass(
199
+ [
200
+ Css.display("flex")
201
+ Css.gap("20px")
202
+ Css.alignItems("center")
203
+ Css.justifyContent("center")
204
+ Css.fontSize("30px")
205
+ Css.letterSpacing("5px")
206
+ Css.textTransform("uppercase")
207
+ Css.color("inherit")
208
+ Css.textDecoration("none")
209
+ Css.height("100px")
210
+ ]
211
+ [
212
+ CssNest("&>img", [Css.width("100px")], [])
213
+ CssNest("&>div", [Css.width("145px")], [])
214
+ ]
215
+ []
216
+ )
217
+
218
+ guideSidebarUl1Css: CssClass = CssClass(
219
+ [
220
+ Css.display("flex")
221
+ Css.flexDirection("column")
222
+ Css.gap("35px")
223
+ Css.listStyle("none")
224
+ Css.margin("0px")
225
+ Css.padding("20px")
226
+ Css.opacity("0.85")
227
+ Css.transition("100ms opacity")
228
+ ]
229
+ [
230
+ CssNest(mobileOrTabletMediaQuery, [
231
+ Css.opacity("1.00")
232
+ ], [])
233
+ CssNest("&:hover", [
234
+ Css.opacity("1.00")
235
+ ], [])
236
+ ]
237
+ []
238
+ )
239
+
240
+ guideSidebarLi1Css: CssClass = CssClass(
241
+ [
242
+ Css.listStyle("none")
243
+ Css.fontSize("17px")
244
+ ]
245
+ []
246
+ []
247
+ )
248
+
249
+ guideSidebarUl2Css: CssClass = CssClass(
250
+ [
251
+ Css.display("flex")
252
+ Css.flexDirection("column")
253
+ Css.gap("15px")
254
+ Css.listStyle("none")
255
+ Css.margin("0px")
256
+ Css.paddingLeft("15px")
257
+ Css.paddingTop("20px")
258
+ Css.paddingRight("0")
259
+ Css.paddingBottom("5px")
260
+ Css.fontSize("17px")
261
+ ]
262
+ []
263
+ []
264
+ )
265
+
266
+ guideSidebarLi2Css: CssClass = CssClass(
267
+ [
268
+ Css.listStyle("none")
269
+ ]
270
+ []
271
+ []
272
+ )
273
+
274
+ guideMainCss: CssClass = CssClass(
275
+ [
276
+ Css.flex("1")
277
+ Css.display("flex")
278
+ Css.justifyContent("center")
279
+ Css.marginLeft("300px")
280
+ Css.paddingLeft("20px")
281
+ Css.paddingRight("calc(max(20px, 25vw - 300px))")
282
+ Css.paddingTop("80px")
283
+ Css.paddingBottom("80px")
284
+ Css.position("relative")
285
+ Css.boxSizing("content-box")
286
+ Css.color("#333333")
287
+ Css.fontWeight("500")
288
+ ]
289
+ [
290
+ CssNest(mobileOrTabletMediaQuery, [
291
+ Css.marginLeft("0")
292
+ Css.paddingLeft("20px")
293
+ Css.paddingRight("20px")
294
+ Css.paddingTop("40px")
295
+ Css.paddingBottom("70px")
296
+ ], [])
297
+ ]
298
+ []
299
+ )
300
+
301
+ guideDocumentCss: CssClass = CssClass(
302
+ [
303
+ Css.maxWidth("800px")
304
+ Css.width("100%")
305
+ Css.fontSize("17px")
306
+ Css.lineHeight("1.7")
307
+ ]
308
+ []
309
+ []
310
+ )
311
+
312
+ guideSplitCss: CssClass = CssClass(
313
+ [
314
+ Css.display("flex")
315
+ Css.gap("30px")
316
+ Css.justifyContent("space-between")
317
+ Css.alignItems("stretch")
318
+ Css.marginTop("170px")
319
+ Css.marginBottom("170px")
320
+ ]
321
+ [
322
+ CssNest("&>div:first-child", [
323
+ Css.width("calc(345px - 15px)")
324
+ Css.paddingTop("10px")
325
+ Css.paddingBottom("15px")
326
+ ], [])
327
+ CssNest("&>div:last-child", [
328
+ Css.width("calc(455px - 15px)")
329
+ ], [])
330
+ CssNest("&>div>:first-child", [
331
+ Css.marginTop("0")
332
+ ], [])
333
+ CssNest("&>div>:last-child", [
334
+ Css.marginBottom("0")
335
+ ], [])
336
+ CssNest("&>div>pre", [
337
+ Css.overflowX("hidden")
338
+ Css.minHeight("100%")
339
+ ], [])
340
+ CssNest(mobileMediaQuery, [
341
+ Css.flexDirection("column")
342
+ ], [
343
+ CssNest("&>div:first-child", [
344
+ Css.width("auto")
345
+ ], [])
346
+ CssNest("&>div:last-child", [
347
+ Css.width("auto")
348
+ ], [])
349
+ CssNest("&>div>pre", [
350
+ Css.overflowX("auto")
351
+ ], [])
352
+ ])
353
+ ]
354
+ []
355
+ )
356
+
357
+ guideSplitHeadingCss: CssClass = CssClass(
358
+ [
359
+ Css.fontSize("23px")
360
+ Css.fontWeight("600")
361
+ Css.margin("0")
362
+ ]
363
+ [
364
+ CssNest(mobileMediaQuery, [
365
+ Css.fontSize("21px")
366
+ ], [])
367
+ ]
368
+ []
369
+ )
370
+
371
+ guideH1Css: CssClass = CssClass(
372
+ [
373
+ Css.fontSize("32px")
374
+ Css.fontWeight("600")
375
+ Css.marginTop("0px")
376
+ ]
377
+ [
378
+ CssNest(mobileMediaQuery, [
379
+ Css.fontSize("26px")
380
+ ], [])
381
+ ]
382
+ []
383
+ )
384
+
385
+ guideH2Css: CssClass = CssClass(
386
+ [
387
+ Css.fontSize("28px")
388
+ Css.fontWeight("600")
389
+ Css.marginTop("70px")
390
+ ]
391
+ [
392
+ CssNest(mobileMediaQuery, [
393
+ Css.fontSize("23px")
394
+ ], [])
395
+ ]
396
+ []
397
+ )
398
+
399
+ guideCodeCss: CssClass = CssClass(
400
+ [
401
+ Css.fontFamily("'Firefly Mono', monospace")
402
+ Css.fontSize("15px")
403
+ Css.lineHeight("1.3")
404
+ Css.color("#000000")
405
+ ]
406
+ [
407
+ CssNest(mobileMediaQuery, [
408
+ Css.fontSize("14px")
409
+ Css.lineHeight("1.4")
410
+ ], [])
411
+ CssNest("pre>&", [
412
+ Css.color("#4ec9b0")
413
+ ], [])
414
+ ]
415
+ []
416
+ )
417
+
418
+ guideCodeBlockCss: CssClass = CssClass(
419
+ [
420
+ Css.lineHeight("1.3")
421
+ Css.background("#1f1f1f")
422
+ Css.padding("20px 25px")
423
+ Css.margin("30px 0")
424
+ Css.borderRadius("5px")
425
+ Css.boxSizing("border-box")
426
+ Css.overflowX("auto")
427
+ Css.maxWidth("100%")
428
+ ]
429
+ [
430
+ CssNest(mobileMediaQuery, [
431
+ Css.maxWidth("calc(100vw)")
432
+ Css.marginLeft("-20px")
433
+ Css.marginRight("-20px")
434
+ Css.borderRadius("0")
435
+ Css.borderLeft("none")
436
+ Css.borderRight("none")
437
+ Css.padding("20px 20px")
438
+ Css.lineHeight("1.4")
439
+ ], [])
440
+ ]
441
+ []
442
+ )
443
+
444
+ guideLinkCss: CssClass = CssClass(
445
+ [
446
+ Css.color("#000000")
447
+ Css.textDecoration("2px #ecc45e underline")
448
+ Css.fontWeight("600")
449
+ ]
450
+ [
451
+ CssNest("&:hover", [
452
+ Css.textDecoration("2px #ecc45e underline")
453
+ ], [])
454
+ ]
455
+ []
456
+ )
457
+
458
+ guideNextButtonCss: CssClass = CssClass(
459
+ [
460
+ Css.marginTop("100px")
461
+ ]
462
+ []
463
+ []
464
+ )
465
+
466
+ guideButtonCss: CssClass = CssClass(
467
+ [
468
+ Css.padding("15px 30px")
469
+ Css.borderRadius("5px")
470
+ Css.background("#ecc45e")
471
+ Css.color("#000000")
472
+ Css.border("2px solid black")
473
+ Css.textDecoration("none")
474
+ Css.fontSize("17px")
475
+ Css.fontWeight("600")
476
+ ]
477
+ [
478
+ CssNest(mobileMediaQuery, [
479
+ Css.fontSize("15px")
480
+ ], [])
481
+ CssNest("&::after", [
482
+ Css.content("' →'")
483
+ ], [])
484
+ ]
485
+ []
486
+ )
487
+
488
+ codeCommentCss: CssClass = CssClass([Css.color("#757c8a")], [], [])
489
+ codeStringCss: CssClass = CssClass([Css.color("#ce9178")], [], [])
490
+ codeNumberCss: CssClass = CssClass([Css.color("#b5cea8")], [], [])
491
+ codeKeywordCss: CssClass = CssClass([Css.color("#569cd6")], [], [])
492
+ codeTypeCss: CssClass = CssClass([Css.color("#4ec9b0")], [], [])
493
+ codeVariableCss: CssClass = CssClass([Css.color("#9cdcfe")], [], [])
494
+ codeCallCss: CssClass = CssClass([Css.color("#dcdcaa")], [], [])
495
+ codeOtherCss: CssClass = CssClass([Css.color("#cccccc")], [], [])
@@ -0,0 +1,136 @@
1
+ # Control flow
2
+
3
+ Firefly provides several ways to implement branching. Pattern matching is the most powerful, built directly into the language. `if`, `elseIf` and `else` do what you expect and are functions and methods in the standard library, implemented using the `Option` type. An then finally, there are exceptions.
4
+
5
+ # Pattern matching
6
+
7
+ Pattern matching allows you to check a given data structure against a pattern. For example, if we want to parse the command line arguments provided by the user, we could do it like this:
8
+
9
+ ```firefly
10
+ let pair = system.arguments().{
11
+ | [host] => Pair(host, 80)
12
+ | ["localhost", port] => Pair("localhost", port.grabInt())
13
+ | _ =>
14
+ system.writeErrorLine("Usage: 'localhost' | (host port)")
15
+ system.exit(0)
16
+ }
17
+ ```
18
+
19
+ In Firefly you construct a list of strings (`List[String]`) like this `["example.com", "80"]`, and using pattern matching you can de-construct in the same way.
20
+
21
+ ```firefly
22
+ data.{
23
+ | pattern1 => // case 1
24
+ | pattern2 => // case N
25
+ ...
26
+ }
27
+ ```
28
+
29
+ The patterns must be exhaustive, that is, for any possible value of the given type, there must be a matching pattern. In the example above, there are no value for the empty list `[]` , list with two values, where the first is not `"localhost"` or lists with more than 2 arguments. That's why we need the wildcard case at the end. Without this last case, the compiler would produce a compile-time error, stating that the patterns must be exhaustive.
30
+
31
+ Here are more examples — all exhaustive. Let's start with records:
32
+
33
+ ```firefly
34
+ pair.{
35
+ | Pair(first, second) =>
36
+ }
37
+ ```
38
+
39
+ Numbers
40
+
41
+ ```firefly
42
+ n.{
43
+ | 1 =>
44
+ | 2 =>
45
+ | n =>
46
+ }
47
+ ```
48
+
49
+ Booleans
50
+
51
+ ```firefly
52
+ n.{
53
+ | True =>
54
+ | False =>
55
+ }
56
+ ```
57
+
58
+ And you can combine pattern as needed. Imagine you have a pair of type `Pair[List[Bool], Pair(Int, String)]`
59
+
60
+
61
+ ```firefly
62
+ pair.{
63
+ | Pair([True, False], Pair(42, "foo")) =>
64
+ | other =>
65
+ }
66
+ ```
67
+
68
+
69
+ # Option
70
+
71
+ Sometimes you don't have a value. Other languages uses null for this purpose, but Firefly does not have null. Instead, we have `Option` from the core package.
72
+
73
+
74
+ ```firefly
75
+ data Option[T] {
76
+ None
77
+ Some(value: T)
78
+ }
79
+ ```
80
+
81
+ For some type `T`, say `String`, `Option[String]` is either some string or no value `None`. This way, the type system guides you to check for no-value.
82
+
83
+ Many functions and methods returns an `Option` in Firefly. For instance the `getInt` method on `String`. This method returns `Some[Int]` when the string consists only of digits and `None` otherwise. We can perform pattern matching on Option like this:
84
+
85
+ ```firefly
86
+ port.getInt().{
87
+ | None => 80
88
+ | Some(p) => p
89
+ }
90
+ ```
91
+
92
+ Many methods like `getInt` have a non-total counterpart `grabInt`, which returns an `Int`. But it will throw an exception when the input cannot be parsed. Options let's you code in an exception-safe manner.
93
+
94
+
95
+ # if - elseIf - else
96
+
97
+ You write if-statements in Firefly like this:
98
+
99
+ ```firefly
100
+ if(path == "/") {
101
+ response.writeText("<!doctype html>")
102
+ } elseIf {path.startsWith("/js/")} {
103
+ response.writeText("<script>")
104
+ } else {
105
+ response.writeStatus("404 Not found")
106
+ }
107
+ ```
108
+
109
+ You can also use it as an expression like this
110
+
111
+
112
+ ```firefly
113
+ let contentType = if(path == "/") {
114
+ "text/html; charset=UTF-8"
115
+ } elseIf(directory2.exists) {
116
+ "text/javascript; charset=UTF-8"
117
+ } else {
118
+ "text/plain; charset=UTF-8"
119
+ }
120
+ ```
121
+
122
+ `if`, `elseIf` and `else` are not keywords or construct build into Firefly. `if` is just a function defined like this:
123
+
124
+
125
+ ```firefly
126
+ if[T](condition: Bool, body: () => T): Option[T] {
127
+ condition.{
128
+ | False => None
129
+ | True => Some(body())
130
+ }
131
+ }
132
+ ```
133
+
134
+ # Exceptions
135
+
136
+ ...