firefly-compiler 0.4.36 → 0.4.46

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 (116) hide show
  1. package/.hintrc +4 -4
  2. package/.vscode/settings.json +4 -4
  3. package/bin/Release.ff +99 -49
  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 +186 -186
  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 +394 -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 -37
  21. package/core/Buffer.ff +3 -3
  22. package/core/BuildSystem.ff +148 -145
  23. package/core/Crypto.ff +96 -95
  24. package/core/Equal.ff +36 -36
  25. package/core/HttpClient.ff +87 -87
  26. package/core/Instant.ff +17 -0
  27. package/core/JsSystem.ff +69 -69
  28. package/core/Json.ff +434 -434
  29. package/core/List.ff +415 -415
  30. package/core/Lock.ff +144 -144
  31. package/core/NodeSystem.ff +189 -189
  32. package/core/Ordering.ff +161 -161
  33. package/core/Path.ff +401 -401
  34. package/core/Random.ff +134 -134
  35. package/core/RbMap.ff +216 -216
  36. package/core/Show.ff +43 -43
  37. package/core/SourceLocation.ff +68 -68
  38. package/core/Stream.ff +1 -1
  39. package/core/Task.ff +141 -141
  40. package/experimental/benchmarks/ListGrab.ff +23 -23
  41. package/experimental/benchmarks/ListGrab.java +55 -55
  42. package/experimental/benchmarks/Pyrotek45.ff +30 -30
  43. package/experimental/benchmarks/Pyrotek45.java +64 -64
  44. package/experimental/bidirectional/Bidi.ff +88 -88
  45. package/experimental/random/Index.ff +53 -53
  46. package/experimental/random/Process.ff +120 -120
  47. package/experimental/random/RunLength.ff +3 -3
  48. package/experimental/random/Scrape.ff +51 -51
  49. package/experimental/random/Symbols.ff +73 -73
  50. package/experimental/random/Tensor.ff +52 -52
  51. package/experimental/random/Units.ff +36 -36
  52. package/experimental/s3/S3TestAuthorizationHeader.ff +38 -38
  53. package/experimental/s3/S3TestPut.ff +15 -15
  54. package/experimental/tests/TestJson.ff +26 -26
  55. package/firefly.sh +0 -0
  56. package/fireflysite/Main.ff +13 -13
  57. package/lsp/.firefly/package.ff +1 -1
  58. package/lsp/CompletionHandler.ff +811 -811
  59. package/lsp/Handler.ff +714 -714
  60. package/lsp/HoverHandler.ff +79 -79
  61. package/lsp/LanguageServer.ff +272 -272
  62. package/lsp/SignatureHelpHandler.ff +55 -55
  63. package/lsp/SymbolHandler.ff +181 -181
  64. package/lsp/TestReferences.ff +16 -16
  65. package/lsp/TestReferencesCase.ff +7 -7
  66. package/lsp/stderr.txt +1 -1
  67. package/lsp/stdout.txt +34 -34
  68. package/lux/.firefly/package.ff +1 -1
  69. package/lux/Css.ff +648 -648
  70. package/lux/CssTest.ff +48 -48
  71. package/lux/Lux.ff +487 -487
  72. package/lux/LuxEvent.ff +116 -116
  73. package/lux/Main.ff +128 -128
  74. package/lux/Main2.ff +144 -144
  75. package/output/js/ff/compiler/Builder.mjs +43 -43
  76. package/output/js/ff/compiler/Dependencies.mjs +3 -3
  77. package/output/js/ff/core/Array.mjs +59 -59
  78. package/output/js/ff/core/Atomic.mjs +36 -36
  79. package/output/js/ff/core/BrowserSystem.mjs +19 -11
  80. package/output/js/ff/core/Buffer.mjs +7 -7
  81. package/output/js/ff/core/BuildSystem.mjs +38 -30
  82. package/output/js/ff/core/Crypto.mjs +67 -68
  83. package/output/js/ff/core/HttpClient.mjs +24 -24
  84. package/output/js/ff/core/Instant.mjs +38 -0
  85. package/output/js/ff/core/Json.mjs +147 -147
  86. package/output/js/ff/core/List.mjs +50 -50
  87. package/output/js/ff/core/Lock.mjs +97 -97
  88. package/output/js/ff/core/NodeSystem.mjs +77 -77
  89. package/output/js/ff/core/Ordering.mjs +8 -8
  90. package/output/js/ff/core/Path.mjs +231 -231
  91. package/output/js/ff/core/Random.mjs +56 -56
  92. package/output/js/ff/core/Stream.mjs +2 -2
  93. package/output/js/ff/core/Task.mjs +31 -31
  94. package/package.json +29 -29
  95. package/rpc/.firefly/package.ff +1 -1
  96. package/rpc/Rpc.ff +69 -69
  97. package/s3/.firefly/package.ff +1 -0
  98. package/{experimental/s3 → s3}/S3.ff +92 -92
  99. package/unsafejs/UnsafeJs.ff +19 -19
  100. package/vscode/LICENSE.txt +21 -21
  101. package/vscode/Prepublish.ff +15 -15
  102. package/vscode/README.md +16 -16
  103. package/vscode/client/package.json +22 -22
  104. package/vscode/client/src/extension.ts +104 -104
  105. package/vscode/icons/firefly-icon.svg +10 -10
  106. package/vscode/language-configuration.json +61 -61
  107. package/vscode/package-lock.json +3623 -3623
  108. package/vscode/package.json +160 -160
  109. package/vscode/snippets.json +241 -241
  110. package/webserver/.firefly/include/package-lock.json +16 -16
  111. package/webserver/.firefly/include/package.json +5 -5
  112. package/webserver/.firefly/package.ff +2 -2
  113. package/webserver/WebServer.ff +685 -685
  114. package/websocket/.firefly/package.ff +1 -1
  115. package/websocket/WebSocket.ff +131 -131
  116. package/crypto/SubtleCrypto.ff +0 -149
@@ -1,178 +1,178 @@
1
- import Syntax
2
-
3
- class ModuleCache(
4
- version: Int
5
- mutable parsedModules: Map[String, Pair[Module, Int]]
6
- mutable resolvedModules: Map[String, Pair[Module, Int]]
7
- mutable derivedModules: Map[String, Pair[Module, Int]]
8
- mutable inferredModules: Map[String, Pair[Module, Int]]
9
- mutable emittedModules: Map[String, Int]
10
- )
11
-
12
- new(version: Int): ModuleCache {
13
- ModuleCache(
14
- version = version
15
- parsedModules = Map.new()
16
- resolvedModules = Map.new()
17
- derivedModules = Map.new()
18
- inferredModules = Map.new()
19
- emittedModules = Map.new()
20
- )
21
- }
22
-
23
- extend self: ModuleCache {
24
-
25
- remove(keys: List[String]) {
26
- if(!keys.isEmpty()):
27
- self.parsedModules = self.parsedModules.removeList(keys)
28
- self.resolvedModules = self.resolvedModules.removeList(keys)
29
- self.derivedModules = self.derivedModules.removeList(keys)
30
- self.inferredModules = self.inferredModules.removeList(keys)
31
- self.emittedModules = self.emittedModules.removeList(keys)
32
- }
33
-
34
- invalidate(key: String) {
35
- //Log.trace("Invalidate: " + uri)
36
- self.parsedModules.get(key).each: | Pair(module, _) =>
37
- let moduleName = module.file.dropLast(3)
38
- self.remove([key])
39
- self.parsedModules.each {| k, Pair(m, _) =>
40
- if(m.imports.any {i => i.package == module.packagePair && i.file == moduleName}) {
41
- //Log.trace("Invalidating due to import of invalidated module: " + m.packagePair.groupName() + "/" + m.file)
42
- self.remove([k])
43
- }
44
- }
45
- }
46
-
47
- filesNotImporting(packagePair: PackagePair, moduleName: String): List[String] {
48
- self.parsedModules.toList().collect {| Pair(k, Pair(m, _)) =>
49
- if(!m.imports.any {i => i.package == packagePair && i.file == moduleName}): k
50
- }
51
- }
52
-
53
- without(newVersion: Int, path: Path): ModuleCache {
54
- let key = path.absolute()
55
- if(path.isFile()) {
56
- self.ModuleCache(
57
- version = newVersion
58
- parsedModules = self.parsedModules.remove(key)
59
- resolvedModules = self.resolvedModules.remove(key)
60
- derivedModules = self.derivedModules.remove(key)
61
- inferredModules = self.inferredModules.remove(key)
62
- emittedModules = self.emittedModules.remove(key)
63
- )
64
- } else {
65
- function invalidated(p: String): Bool {
66
- p.startsWith(key) && !p.contains(".firefly/dependencies") && !p.contains(".firefly\\dependencies")
67
- }
68
- self.ModuleCache(
69
- version = newVersion
70
- parsedModules = self.parsedModules.toList().filter {| Pair(p, _) => !invalidated(p)}.toMap()
71
- resolvedModules = self.resolvedModules.toList().filter {| Pair(p, _) => !invalidated(p)}.toMap()
72
- derivedModules = self.derivedModules.toList().filter {| Pair(p, _) => !invalidated(p)}.toMap()
73
- inferredModules = self.inferredModules.toList().filter {| Pair(p, _) => !invalidated(p)}.toMap()
74
- emittedModules = self.emittedModules.toList().filter {| Pair(p, _) => !invalidated(p)}.toMap()
75
- )
76
- }
77
- }
78
-
79
- mergeVersions(cache: ModuleCache): Unit {
80
- self.parsedModules = mergeVersionedMap(self.parsedModules, cache.parsedModules) {_.second}
81
- self.resolvedModules = mergeVersionedMap(self.resolvedModules, cache.resolvedModules) {_.second}
82
- self.derivedModules = mergeVersionedMap(self.derivedModules, cache.derivedModules) {_.second}
83
- self.inferredModules = mergeVersionedMap(self.inferredModules, cache.inferredModules) {_.second}
84
- self.emittedModules = mergeVersionedMap(self.emittedModules, cache.emittedModules) {_}
85
- }
86
-
87
- cacheParsedModule(
88
- packagePaths: Map[PackagePair, Path]
89
- packagePair: PackagePair
90
- moduleName: String
91
- body: Path => Module
92
- ): Module {
93
- let path = modulePath(packagePaths, packagePair, moduleName)
94
- self.parsedModules.get(path.absolute()).map {_.first}.else:
95
- let result = body(path)
96
- self.parsedModules = self.parsedModules.add(path.absolute(), Pair(result, self.version))
97
- result
98
- }
99
-
100
- cacheResolvedModule(
101
- packagePaths: Map[PackagePair, Path]
102
- packagePair: PackagePair
103
- moduleName: String
104
- body: Path => Module
105
- ): Module {
106
- let path = modulePath(packagePaths, packagePair, moduleName)
107
- self.resolvedModules.get(path.absolute()).map {_.first}.else:
108
- let result = body(path)
109
- self.resolvedModules = self.resolvedModules.add(path.absolute(), Pair(result, self.version))
110
- result
111
- }
112
-
113
- cacheDerivedModule(
114
- packagePaths: Map[PackagePair, Path]
115
- packagePair: PackagePair
116
- moduleName: String
117
- body: Path => Module
118
- ): Module {
119
- let path = modulePath(packagePaths, packagePair, moduleName)
120
- self.derivedModules.get(path.absolute()).map {_.first}.else:
121
- let result = body(path)
122
- self.derivedModules = self.derivedModules.add(path.absolute(), Pair(result, self.version))
123
- result
124
- }
125
-
126
- cacheInferredModule(
127
- packagePaths: Map[PackagePair, Path]
128
- packagePair: PackagePair
129
- moduleName: String
130
- body: Path => Module
131
- ): Module {
132
- let path = modulePath(packagePaths, packagePair, moduleName)
133
- self.inferredModules.get(path.absolute()).map {_.first}.else:
134
- let result = body(path)
135
- self.inferredModules = self.inferredModules.add(path.absolute(), Pair(result, self.version))
136
- result
137
- }
138
-
139
- cacheEmittedModule(
140
- packagePaths: Map[PackagePair, Path]
141
- packagePair: PackagePair
142
- moduleName: String
143
- body: Path => Unit
144
- ): Unit {
145
- let path = modulePath(packagePaths, packagePair, moduleName)
146
- if(!self.emittedModules.contains(path.absolute())):
147
- self.emittedModules = self.emittedModules.add(path.absolute(), self.version)
148
- try {
149
- body(path)
150
- } catchAny {error =>
151
- self.emittedModules = self.emittedModules.remove(path.absolute())
152
- error.rethrow()
153
- } grab()
154
- }
155
-
156
- }
157
-
158
- mergeVersionedMap[T](oldMap: Map[String, T], newMap: Map[String, T], getVersion: T => Int): Map[String, T] {
159
- mutable result = newMap
160
- oldMap.each {k, v =>
161
- if(!newMap.get(k).any {getVersion(_) >= getVersion(v)}) {
162
- result = result.add(k, v)
163
- }
164
- }
165
- result
166
- }
167
-
168
- modulePath(
169
- packagePaths: Map[PackagePair, Path]
170
- packagePair: PackagePair
171
- moduleName: String
172
- ): Path {
173
- let packagePath = packagePaths.get(packagePair).else {
174
- panic("Internal error - package path missing: " + packagePair.groupName())
175
- }
176
- let file = moduleName + ".ff"
177
- packagePath.slash(file)
178
- }
1
+ import Syntax
2
+
3
+ class ModuleCache(
4
+ version: Int
5
+ mutable parsedModules: Map[String, Pair[Module, Int]]
6
+ mutable resolvedModules: Map[String, Pair[Module, Int]]
7
+ mutable derivedModules: Map[String, Pair[Module, Int]]
8
+ mutable inferredModules: Map[String, Pair[Module, Int]]
9
+ mutable emittedModules: Map[String, Int]
10
+ )
11
+
12
+ new(version: Int): ModuleCache {
13
+ ModuleCache(
14
+ version = version
15
+ parsedModules = Map.new()
16
+ resolvedModules = Map.new()
17
+ derivedModules = Map.new()
18
+ inferredModules = Map.new()
19
+ emittedModules = Map.new()
20
+ )
21
+ }
22
+
23
+ extend self: ModuleCache {
24
+
25
+ remove(keys: List[String]) {
26
+ if(!keys.isEmpty()):
27
+ self.parsedModules = self.parsedModules.removeList(keys)
28
+ self.resolvedModules = self.resolvedModules.removeList(keys)
29
+ self.derivedModules = self.derivedModules.removeList(keys)
30
+ self.inferredModules = self.inferredModules.removeList(keys)
31
+ self.emittedModules = self.emittedModules.removeList(keys)
32
+ }
33
+
34
+ invalidate(key: String) {
35
+ //Log.trace("Invalidate: " + uri)
36
+ self.parsedModules.get(key).each: | Pair(module, _) =>
37
+ let moduleName = module.file.dropLast(3)
38
+ self.remove([key])
39
+ self.parsedModules.each {| k, Pair(m, _) =>
40
+ if(m.imports.any {i => i.package == module.packagePair && i.file == moduleName}) {
41
+ //Log.trace("Invalidating due to import of invalidated module: " + m.packagePair.groupName() + "/" + m.file)
42
+ self.remove([k])
43
+ }
44
+ }
45
+ }
46
+
47
+ filesNotImporting(packagePair: PackagePair, moduleName: String): List[String] {
48
+ self.parsedModules.toList().collect {| Pair(k, Pair(m, _)) =>
49
+ if(!m.imports.any {i => i.package == packagePair && i.file == moduleName}): k
50
+ }
51
+ }
52
+
53
+ without(newVersion: Int, path: Path): ModuleCache {
54
+ let key = path.absolute()
55
+ if(path.isFile()) {
56
+ self.ModuleCache(
57
+ version = newVersion
58
+ parsedModules = self.parsedModules.remove(key)
59
+ resolvedModules = self.resolvedModules.remove(key)
60
+ derivedModules = self.derivedModules.remove(key)
61
+ inferredModules = self.inferredModules.remove(key)
62
+ emittedModules = self.emittedModules.remove(key)
63
+ )
64
+ } else {
65
+ function invalidated(p: String): Bool {
66
+ p.startsWith(key) && !p.contains(".firefly/dependencies") && !p.contains(".firefly\\dependencies")
67
+ }
68
+ self.ModuleCache(
69
+ version = newVersion
70
+ parsedModules = self.parsedModules.toList().filter {| Pair(p, _) => !invalidated(p)}.toMap()
71
+ resolvedModules = self.resolvedModules.toList().filter {| Pair(p, _) => !invalidated(p)}.toMap()
72
+ derivedModules = self.derivedModules.toList().filter {| Pair(p, _) => !invalidated(p)}.toMap()
73
+ inferredModules = self.inferredModules.toList().filter {| Pair(p, _) => !invalidated(p)}.toMap()
74
+ emittedModules = self.emittedModules.toList().filter {| Pair(p, _) => !invalidated(p)}.toMap()
75
+ )
76
+ }
77
+ }
78
+
79
+ mergeVersions(cache: ModuleCache): Unit {
80
+ self.parsedModules = mergeVersionedMap(self.parsedModules, cache.parsedModules) {_.second}
81
+ self.resolvedModules = mergeVersionedMap(self.resolvedModules, cache.resolvedModules) {_.second}
82
+ self.derivedModules = mergeVersionedMap(self.derivedModules, cache.derivedModules) {_.second}
83
+ self.inferredModules = mergeVersionedMap(self.inferredModules, cache.inferredModules) {_.second}
84
+ self.emittedModules = mergeVersionedMap(self.emittedModules, cache.emittedModules) {_}
85
+ }
86
+
87
+ cacheParsedModule(
88
+ packagePaths: Map[PackagePair, Path]
89
+ packagePair: PackagePair
90
+ moduleName: String
91
+ body: Path => Module
92
+ ): Module {
93
+ let path = modulePath(packagePaths, packagePair, moduleName)
94
+ self.parsedModules.get(path.absolute()).map {_.first}.else:
95
+ let result = body(path)
96
+ self.parsedModules = self.parsedModules.add(path.absolute(), Pair(result, self.version))
97
+ result
98
+ }
99
+
100
+ cacheResolvedModule(
101
+ packagePaths: Map[PackagePair, Path]
102
+ packagePair: PackagePair
103
+ moduleName: String
104
+ body: Path => Module
105
+ ): Module {
106
+ let path = modulePath(packagePaths, packagePair, moduleName)
107
+ self.resolvedModules.get(path.absolute()).map {_.first}.else:
108
+ let result = body(path)
109
+ self.resolvedModules = self.resolvedModules.add(path.absolute(), Pair(result, self.version))
110
+ result
111
+ }
112
+
113
+ cacheDerivedModule(
114
+ packagePaths: Map[PackagePair, Path]
115
+ packagePair: PackagePair
116
+ moduleName: String
117
+ body: Path => Module
118
+ ): Module {
119
+ let path = modulePath(packagePaths, packagePair, moduleName)
120
+ self.derivedModules.get(path.absolute()).map {_.first}.else:
121
+ let result = body(path)
122
+ self.derivedModules = self.derivedModules.add(path.absolute(), Pair(result, self.version))
123
+ result
124
+ }
125
+
126
+ cacheInferredModule(
127
+ packagePaths: Map[PackagePair, Path]
128
+ packagePair: PackagePair
129
+ moduleName: String
130
+ body: Path => Module
131
+ ): Module {
132
+ let path = modulePath(packagePaths, packagePair, moduleName)
133
+ self.inferredModules.get(path.absolute()).map {_.first}.else:
134
+ let result = body(path)
135
+ self.inferredModules = self.inferredModules.add(path.absolute(), Pair(result, self.version))
136
+ result
137
+ }
138
+
139
+ cacheEmittedModule(
140
+ packagePaths: Map[PackagePair, Path]
141
+ packagePair: PackagePair
142
+ moduleName: String
143
+ body: Path => Unit
144
+ ): Unit {
145
+ let path = modulePath(packagePaths, packagePair, moduleName)
146
+ if(!self.emittedModules.contains(path.absolute())):
147
+ self.emittedModules = self.emittedModules.add(path.absolute(), self.version)
148
+ try {
149
+ body(path)
150
+ } catchAny {error =>
151
+ self.emittedModules = self.emittedModules.remove(path.absolute())
152
+ error.rethrow()
153
+ } grab()
154
+ }
155
+
156
+ }
157
+
158
+ mergeVersionedMap[T](oldMap: Map[String, T], newMap: Map[String, T], getVersion: T => Int): Map[String, T] {
159
+ mutable result = newMap
160
+ oldMap.each {k, v =>
161
+ if(!newMap.get(k).any {getVersion(_) >= getVersion(v)}) {
162
+ result = result.add(k, v)
163
+ }
164
+ }
165
+ result
166
+ }
167
+
168
+ modulePath(
169
+ packagePaths: Map[PackagePair, Path]
170
+ packagePair: PackagePair
171
+ moduleName: String
172
+ ): Path {
173
+ let packagePath = packagePaths.get(packagePair).else {
174
+ panic("Internal error - package path missing: " + packagePair.groupName())
175
+ }
176
+ let file = moduleName + ".ff"
177
+ packagePath.slash(file)
178
+ }
@@ -1,88 +1,88 @@
1
- import Syntax
2
-
3
- data Workspace(
4
- rules: List[WorkspaceRule]
5
- defaultLocation: String
6
- packageDirectory: String
7
- )
8
-
9
- data WorkspaceRule(
10
- packageGroup: String
11
- packageName: Option[String]
12
- location: String
13
- )
14
-
15
- centralLocation = "https://www.firefly-lang.org/packages/"
16
-
17
- loadWorkspace(path: Path): Workspace {
18
- let packageDirectory = if(path.extension() == ".ff") {path.parent().grab()} else {path}
19
- let workspaceFile = packageDirectory.slash(".firefly-workspace")
20
- if(workspaceFile.exists()) {
21
- parseWorkspaceFile(workspaceFile, packageDirectory)
22
- } elseIf {!packageDirectory.parent().isEmpty()} {
23
- loadWorkspace(packageDirectory.parent().grab())
24
- } else {
25
- Workspace([], centralLocation, ".")
26
- }
27
- }
28
-
29
- parseWorkspaceFile(path: Path, packageDirectory: Path): Workspace {
30
- let text = path.readText()
31
- mutable defaultLocation = None
32
- let lines = text.split('\n').map {_.replace("\r", "").takeWhile {_ != '#'}}.filter {_.size() != 0}
33
- let rules = lines.collect {line =>
34
- let columns = line.replace("\t", " ").split(' ').filter {_.size() != 0}
35
- defaultLocation.each {_ =>
36
- panic("Unexpected rule after the * rule: " + line)
37
- }
38
- if(columns.size() != 2) {
39
- panic("Could not parse workspace rule: " + line)
40
- }
41
- let package = columns.grab(0)
42
- let location = columns.grab(1)
43
- let fixedLocation = if(location.endsWith("/")) {location} else {location + "/"}
44
- if(package == "*") {
45
- defaultLocation = Some(fixedLocation)
46
- None
47
- } else {
48
- let packageParts = package.split(':')
49
- if(packageParts.size() != 2) {
50
- panic("Could not parse workspace package: " + package)
51
- }
52
- if(packageParts.grab(0) == "*") {
53
- panic("Unexpected wildcard: " + package)
54
- }
55
- Some(WorkspaceRule(
56
- packageGroup = packageParts.grab(0)
57
- packageName = if(packageParts.grab(1) != "*") {packageParts.grab(1)}
58
- location = fixedLocation
59
- ))
60
- }
61
- }
62
- Workspace(rules, defaultLocation.else {centralLocation}, packageDirectory.absolute())
63
- }
64
-
65
- extend self: Workspace {
66
-
67
- findPackageLocation(packagePair: PackagePair, version: Version): String {
68
- self.rules.find {rule =>
69
- rule.packageGroup == packagePair.group && rule.packageName.all {_ == packagePair.name}
70
- }.map {rule =>
71
- let prefix = if(rule.packageName == None) {packagePair.name + "/"} else {""}
72
- if(rule.location.contains(":")) {
73
- rule.location + prefix + tarGzName(packagePair, version)
74
- } else {
75
- self.packageDirectory + "/" + rule.location + prefix
76
- }
77
- }.else {
78
- self.defaultLocation + packagePair.group + "/" + packagePair.name + "/" +
79
- tarGzName(packagePair, version)
80
- }
81
- }
82
-
83
- }
84
-
85
- tarGzName(packagePair: PackagePair, version: Version): String {
86
- packagePair.group + "_" + packagePair.name + "_" +
87
- version.major + "_" + version.minor + "_" + version.patch + ".tar.gz"
88
- }
1
+ import Syntax
2
+
3
+ data Workspace(
4
+ rules: List[WorkspaceRule]
5
+ defaultLocation: String
6
+ packageDirectory: String
7
+ )
8
+
9
+ data WorkspaceRule(
10
+ packageGroup: String
11
+ packageName: Option[String]
12
+ location: String
13
+ )
14
+
15
+ centralLocation = "https://www.firefly-lang.org/packages/"
16
+
17
+ loadWorkspace(path: Path): Workspace {
18
+ let packageDirectory = if(path.extension() == ".ff") {path.parent().grab()} else {path}
19
+ let workspaceFile = packageDirectory.slash(".firefly-workspace")
20
+ if(workspaceFile.exists()) {
21
+ parseWorkspaceFile(workspaceFile, packageDirectory)
22
+ } elseIf {!packageDirectory.parent().isEmpty()} {
23
+ loadWorkspace(packageDirectory.parent().grab())
24
+ } else {
25
+ Workspace([], centralLocation, ".")
26
+ }
27
+ }
28
+
29
+ parseWorkspaceFile(path: Path, packageDirectory: Path): Workspace {
30
+ let text = path.readText()
31
+ mutable defaultLocation = None
32
+ let lines = text.split('\n').map {_.replace("\r", "").takeWhile {_ != '#'}}.filter {_.size() != 0}
33
+ let rules = lines.collect {line =>
34
+ let columns = line.replace("\t", " ").split(' ').filter {_.size() != 0}
35
+ defaultLocation.each {_ =>
36
+ panic("Unexpected rule after the * rule: " + line)
37
+ }
38
+ if(columns.size() != 2) {
39
+ panic("Could not parse workspace rule: " + line)
40
+ }
41
+ let package = columns.grab(0)
42
+ let location = columns.grab(1)
43
+ let fixedLocation = if(location.endsWith("/")) {location} else {location + "/"}
44
+ if(package == "*") {
45
+ defaultLocation = Some(fixedLocation)
46
+ None
47
+ } else {
48
+ let packageParts = package.split(':')
49
+ if(packageParts.size() != 2) {
50
+ panic("Could not parse workspace package: " + package)
51
+ }
52
+ if(packageParts.grab(0) == "*") {
53
+ panic("Unexpected wildcard: " + package)
54
+ }
55
+ Some(WorkspaceRule(
56
+ packageGroup = packageParts.grab(0)
57
+ packageName = if(packageParts.grab(1) != "*") {packageParts.grab(1)}
58
+ location = fixedLocation
59
+ ))
60
+ }
61
+ }
62
+ Workspace(rules, defaultLocation.else {centralLocation}, packageDirectory.absolute())
63
+ }
64
+
65
+ extend self: Workspace {
66
+
67
+ findPackageLocation(packagePair: PackagePair, version: Version): String {
68
+ self.rules.find {rule =>
69
+ rule.packageGroup == packagePair.group && rule.packageName.all {_ == packagePair.name}
70
+ }.map {rule =>
71
+ let prefix = if(rule.packageName == None) {packagePair.name + "/"} else {""}
72
+ if(rule.location.contains(":")) {
73
+ rule.location + prefix + tarGzName(packagePair, version)
74
+ } else {
75
+ self.packageDirectory + "/" + rule.location + prefix
76
+ }
77
+ }.else {
78
+ self.defaultLocation + packagePair.group + "/" + packagePair.name + "/" +
79
+ tarGzName(packagePair, version)
80
+ }
81
+ }
82
+
83
+ }
84
+
85
+ tarGzName(packagePair: PackagePair, version: Version): String {
86
+ packagePair.group + "_" + packagePair.name + "_" +
87
+ version.major + "_" + version.minor + "_" + version.patch + ".tar.gz"
88
+ }