firefly-compiler 0.5.49 → 0.5.51

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 (132) hide show
  1. package/bin/Release.ff +3 -3
  2. package/bin/firefly.mjs +1 -1
  3. package/compiler/Builder.ff +11 -5
  4. package/compiler/Compiler.ff +14 -3
  5. package/compiler/JsEmitter.ff +6 -11
  6. package/compiler/Main.ff +10 -15
  7. package/compiler/ModuleCache.ff +2 -1
  8. package/core/Buffer.ff +26 -4
  9. package/core/BuildSystem.ff +49 -46
  10. package/core/JsValue.ff +5 -0
  11. package/experimental/date/Date.ff +604 -0
  12. package/experimental/date/Main.ff +51 -0
  13. package/experimental/random/AsciiBuffer.ff +15 -0
  14. package/experimental/rhymeapp/Main.ff +2 -3
  15. package/experimental/site/Main.ff +2 -2
  16. package/experimental/site2/Main.ff +2 -2
  17. package/firefly.sh +1 -1
  18. package/fireflysite/CommunityOverview.ff +3 -3
  19. package/fireflysite/CountingButtonDemo.ff +3 -3
  20. package/fireflysite/ExamplesOverview.ff +3 -12
  21. package/fireflysite/FrontPage.ff +3 -3
  22. package/fireflysite/GettingStarted.ff +3 -3
  23. package/fireflysite/Guide.ff +7 -187
  24. package/fireflysite/Html.ff +66 -0
  25. package/fireflysite/Main.ff +13 -77
  26. package/fireflysite/MatchingPasswordsDemo.ff +3 -3
  27. package/fireflysite/Menu.ff +59 -0
  28. package/fireflysite/PackagesOverview.ff +3 -3
  29. package/fireflysite/PostgresqlDemo.ff +3 -3
  30. package/fireflysite/RouteFront.ff +30 -0
  31. package/fireflysite/RouteNonMarkdown.ff +48 -0
  32. package/fireflysite/RouteReference.ff +40 -0
  33. package/fireflysite/Router.ff +33 -0
  34. package/fireflysite/Website.ff +133 -0
  35. package/fireflysite/assets/markdown/reference/{FunctionsAndMethods.md → functions-and-methods.md} +1 -1
  36. package/fireflysite/assets/markdown/reference/{StatementsAndExpressions.md → statements-and-expressions.md} +0 -1
  37. package/fireflysite/assets/markdown/reference/{StructuredConcurrency.md → structured-concurrency.md} +0 -1
  38. package/fireflysite/assets/markdown/reference.md +3 -0
  39. package/graph/.firefly/package.ff +1 -0
  40. package/graph/Graph.ff +79 -0
  41. package/lsp/CompletionHandler.ff +2 -2
  42. package/lux/CssTest.ff +2 -2
  43. package/lux/Main.ff +2 -2
  44. package/lux/Main2.ff +2 -2
  45. package/output/js/ff/compiler/Builder.mjs +44 -12
  46. package/output/js/ff/compiler/Compiler.mjs +28 -10
  47. package/output/js/ff/compiler/Dependencies.mjs +0 -2
  48. package/output/js/ff/compiler/DependencyLock.mjs +0 -2
  49. package/output/js/ff/compiler/Deriver.mjs +0 -2
  50. package/output/js/ff/compiler/Dictionaries.mjs +0 -2
  51. package/output/js/ff/compiler/Environment.mjs +0 -2
  52. package/output/js/ff/compiler/Inference.mjs +0 -2
  53. package/output/js/ff/compiler/JsEmitter.mjs +12 -30
  54. package/output/js/ff/compiler/JsImporter.mjs +0 -2
  55. package/output/js/ff/compiler/LspHook.mjs +0 -2
  56. package/output/js/ff/compiler/Main.mjs +24 -47
  57. package/output/js/ff/compiler/Main.run.mjs +25 -0
  58. package/output/js/ff/compiler/ModuleCache.mjs +4 -6
  59. package/output/js/ff/compiler/Parser.mjs +0 -2
  60. package/output/js/ff/compiler/Patterns.mjs +0 -2
  61. package/output/js/ff/compiler/Resolver.mjs +0 -2
  62. package/output/js/ff/compiler/Substitution.mjs +0 -2
  63. package/output/js/ff/compiler/Syntax.mjs +0 -2
  64. package/output/js/ff/compiler/Token.mjs +0 -2
  65. package/output/js/ff/compiler/Tokenizer.mjs +0 -2
  66. package/output/js/ff/compiler/Unification.mjs +0 -2
  67. package/output/js/ff/compiler/Wildcards.mjs +0 -2
  68. package/output/js/ff/compiler/Workspace.mjs +0 -2
  69. package/output/js/ff/core/Any.mjs +0 -2
  70. package/output/js/ff/core/Array.mjs +0 -2
  71. package/output/js/ff/core/AssetSystem.mjs +0 -2
  72. package/output/js/ff/core/Atomic.mjs +0 -2
  73. package/output/js/ff/core/Bool.mjs +0 -2
  74. package/output/js/ff/core/BrowserSystem.mjs +0 -2
  75. package/output/js/ff/core/Buffer.mjs +50 -10
  76. package/output/js/ff/core/BuildSystem.mjs +92 -72
  77. package/output/js/ff/core/Channel.mjs +0 -2
  78. package/output/js/ff/core/Char.mjs +0 -2
  79. package/output/js/ff/core/Core.mjs +0 -2
  80. package/output/js/ff/core/Crypto.mjs +0 -2
  81. package/output/js/ff/core/Date.mjs +0 -2
  82. package/output/js/ff/core/Duration.mjs +0 -2
  83. package/output/js/ff/core/Equal.mjs +0 -2
  84. package/output/js/ff/core/Error.mjs +0 -2
  85. package/output/js/ff/core/FileHandle.mjs +0 -2
  86. package/output/js/ff/core/Float.mjs +0 -2
  87. package/output/js/ff/core/HttpClient.mjs +0 -2
  88. package/output/js/ff/core/Int.mjs +0 -2
  89. package/output/js/ff/core/IntMap.mjs +0 -2
  90. package/output/js/ff/core/Js.mjs +0 -2
  91. package/output/js/ff/core/JsSystem.mjs +0 -2
  92. package/output/js/ff/core/JsValue.mjs +8 -2
  93. package/output/js/ff/core/Json.mjs +0 -2
  94. package/output/js/ff/core/List.mjs +0 -2
  95. package/output/js/ff/core/Lock.mjs +0 -2
  96. package/output/js/ff/core/Log.mjs +0 -2
  97. package/output/js/ff/core/Map.mjs +0 -2
  98. package/output/js/ff/core/NodeSystem.mjs +0 -2
  99. package/output/js/ff/core/Nothing.mjs +0 -2
  100. package/output/js/ff/core/Option.mjs +0 -2
  101. package/output/js/ff/core/Ordering.mjs +0 -2
  102. package/output/js/ff/core/Pair.mjs +0 -2
  103. package/output/js/ff/core/Path.mjs +0 -2
  104. package/output/js/ff/core/Queue.mjs +0 -2
  105. package/output/js/ff/core/Random.mjs +0 -2
  106. package/output/js/ff/core/RbMap.mjs +0 -2
  107. package/output/js/ff/core/Serializable.mjs +0 -2
  108. package/output/js/ff/core/Set.mjs +0 -2
  109. package/output/js/ff/core/Show.mjs +0 -2
  110. package/output/js/ff/core/SourceLocation.mjs +0 -2
  111. package/output/js/ff/core/Stream.mjs +0 -2
  112. package/output/js/ff/core/String.mjs +0 -2
  113. package/output/js/ff/core/StringMap.mjs +0 -2
  114. package/output/js/ff/core/Task.mjs +0 -2
  115. package/output/js/ff/core/Try.mjs +0 -2
  116. package/output/js/ff/core/Unit.mjs +0 -2
  117. package/package.json +1 -1
  118. package/vscode/client/src/extension.ts +1 -1
  119. package/vscode/package.json +1 -1
  120. package/vscode/snippets.json +2 -2
  121. package/webserver/WebRoute.ff +51 -14
  122. package/fireflysite/ReferenceAll.ff +0 -18
  123. /package/fireflysite/assets/markdown/reference/{BaseTypes.md → base-types.md} +0 -0
  124. /package/fireflysite/assets/markdown/reference/{EmittedJavascript.md → emitted-javascript.md} +0 -0
  125. /package/fireflysite/assets/markdown/reference/{Exceptions.md → exceptions.md} +0 -0
  126. /package/fireflysite/assets/markdown/reference/{JavascriptInterop.md → javascript-interop.md} +0 -0
  127. /package/fireflysite/assets/markdown/reference/{ModulesAndPackages.md → modules-and-packages.md} +0 -0
  128. /package/fireflysite/assets/markdown/reference/{PatternMatching.md → pattern-matching.md} +0 -0
  129. /package/fireflysite/assets/markdown/reference/{TraitsAndInstances.md → traits-and-instances.md} +0 -0
  130. /package/fireflysite/assets/markdown/reference/{UserDefinedTypes.md → user-defined-types.md} +0 -0
  131. /package/fireflysite/assets/markdown/scratch/{ControlFlow.md → control-flow.md} +0 -0
  132. /package/fireflysite/assets/markdown/{reference/OldStructuredConcurrency.md → scratch/old-structured-concurrency.md} +0 -0
@@ -15,6 +15,19 @@ instance Int: WebParameter {
15
15
  fromRouteParameter(value: Int): String {"" + value}
16
16
  }
17
17
 
18
+ instance Option[T: WebParameter]: WebParameter {
19
+ toRouteParameter(text: String): Option[Option[T]] {
20
+ if(text != "") {
21
+ toRouteParameter(text).map {Some(_)}
22
+ } else {
23
+ Some(None)
24
+ }
25
+ }
26
+ fromRouteParameter(value: Option[T]): String {
27
+ value.map {fromRouteParameter(_)}.else {""}
28
+ }
29
+ }
30
+
18
31
  data WebRoute0(urlPattern: String, segments: List[String])
19
32
  data WebRoute1[P1](urlPattern: String, segments: List[String])
20
33
  data WebRoute2[P1, P2](urlPattern: String, segments: List[String])
@@ -42,12 +55,16 @@ extend self[P1: WebParameter]: WebRoute1[P1] {
42
55
  mutable result = ""
43
56
  mutable parameter = 1
44
57
  self.segments.each {r =>
45
- result += "/"
46
58
  if(r.startsWith("{")) {
47
- if(parameter == 1) {result += fromRouteParameter(p1)}
59
+ let p = if(parameter == 1) {
60
+ fromRouteParameter(p1)
61
+ } else {
62
+ ""
63
+ }
64
+ if(p != "" || !r.endsWith("?}")) {result += "/" + p}
48
65
  parameter += 1
49
66
  } else {
50
- result += r
67
+ result += "/" + r
51
68
  }
52
69
  }
53
70
  if(self.urlPattern.endsWith("/")) {result += "/"}
@@ -60,13 +77,18 @@ extend self[P1: WebParameter, P2: WebParameter]: WebRoute2[P1, P2] {
60
77
  mutable result = ""
61
78
  mutable parameter = 0
62
79
  self.segments.each {r =>
63
- result += "/"
64
80
  if(r.startsWith("{")) {
65
- if(parameter == 1) {result += fromRouteParameter(p1)}
66
- if(parameter == 2) {result += fromRouteParameter(p2)}
81
+ let p = if(parameter == 1) {
82
+ fromRouteParameter(p1)
83
+ } elseIf {parameter == 2} {
84
+ fromRouteParameter(p2)
85
+ } else {
86
+ ""
87
+ }
88
+ if(p != "" || !r.endsWith("?}")) {result += "/" + p}
67
89
  parameter += 1
68
90
  } else {
69
- result += r
91
+ result += "/" + r
70
92
  }
71
93
  }
72
94
  if(self.urlPattern.endsWith("/")) {result += "/"}
@@ -88,11 +110,12 @@ extend self[C]: WebRouteHandler[C] {
88
110
 
89
111
  add1[P1: WebParameter](route: WebRoute1[P1], handle: (WebRequest[WebResponse], C, P1) => Unit) {
90
112
  self.handlers.push {request, segments, context =>
91
- if(segments.size() != route.segments.size()) {False} else:
92
- let matching = True
113
+ let paddedSegments = internalCheckSegments(segments, route.segments)
114
+ if(paddedSegments.isEmpty()) {False} else:
115
+ mutable matching = True
93
116
  mutable p1 = None
94
- segments.zip(route.segments).eachWhile {| Pair(s, r) =>
95
- if(r.startsWith("{")) {
117
+ paddedSegments.zip(route.segments).eachWhile {| Pair(s, r) =>
118
+ matching = if(r.startsWith("{")) {
96
119
  if(p1.isEmpty()) {
97
120
  p1 = toRouteParameter(s)
98
121
  !p1.isEmpty()
@@ -102,6 +125,7 @@ extend self[C]: WebRouteHandler[C] {
102
125
  } else {
103
126
  r == s
104
127
  }
128
+ matching
105
129
  }
106
130
  if(!matching) {False} else:
107
131
  handle(request, context, p1.grab())
@@ -111,11 +135,12 @@ extend self[C]: WebRouteHandler[C] {
111
135
 
112
136
  add2[P1: WebParameter, P2: WebParameter](route: WebRoute2[P1, P2], handle: (WebRequest[WebResponse], C, P1, P2) => Unit) {
113
137
  self.handlers.push {request, segments, context =>
114
- if(segments.size() != route.segments.size()) {False} else:
138
+ let paddedSegments = internalCheckSegments(segments, route.segments)
139
+ if(paddedSegments.isEmpty()) {False} else:
115
140
  mutable p1 = None
116
141
  mutable p2 = None
117
142
  mutable matching = True
118
- segments.zip(route.segments).eachWhile {| Pair(s, r) =>
143
+ paddedSegments.zip(route.segments).eachWhile {| Pair(s, r) =>
119
144
  matching = if(r.startsWith("{")) {
120
145
  if(p1.isEmpty()) {
121
146
  p1 = toRouteParameter(s)
@@ -139,12 +164,24 @@ extend self[C]: WebRouteHandler[C] {
139
164
 
140
165
  handle(request: WebRequest[WebResponse], context: C): Bool {
141
166
  let segments = request.readPath().split('/').filter {s => s != ""}
167
+ let trimmedSegments = if(segments.last().contains("")) {segments.dropLast()} else {segments}
142
168
  mutable handled = False
143
169
  self.handlers.eachWhile {| handler =>
144
- handled = handler(request, segments, context)
170
+ handled = handler(request, trimmedSegments, context)
145
171
  !handled
146
172
  }
147
173
  handled
148
174
  }
149
175
 
150
176
  }
177
+
178
+ internalCheckSegments(segments: List[String], patterns: List[String]): List[String] {
179
+ segments.{
180
+ | _ {segments.size() == patterns.size()} =>
181
+ segments
182
+ | _ {segments.size() == patterns.size() - 1} {patterns.indexWhere {_.endsWith("?}")} | Some(i)} =>
183
+ [...segments.takeFirst(i), "", ...segments.dropFirst(i)]
184
+ | _ =>
185
+ []
186
+ }
187
+ }
@@ -1,18 +0,0 @@
1
- import Guide
2
- import ReferenceIntroduction
3
-
4
- mock(): List[Document] {
5
- [
6
- ReferenceIntroduction.new()
7
- UnfetchedDocument("Modules and packages")
8
- UnfetchedDocument("Base types")
9
- UnfetchedDocument("User defined types")
10
- UnfetchedDocument("Statements and expressions")
11
- UnfetchedDocument("Functions and methods")
12
- UnfetchedDocument("Pattern matching")
13
- UnfetchedDocument("Traits and instances")
14
- UnfetchedDocument("Exceptions")
15
- UnfetchedDocument("Structured concurrency")
16
- UnfetchedDocument("JavaScript interop")
17
- ]
18
- }