@trioforge/brigadier 0.0.0-stage → 0.1.1

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.
package/out/java.luau ADDED
@@ -0,0 +1,424 @@
1
+ -- Compiled with roblox-ts v3.0.0
2
+ -- The parts of the Java standard library Brigadier relies on, with Java's behaviour.
3
+ local RuntimeException
4
+ do
5
+ RuntimeException = setmetatable({}, {
6
+ __tostring = function()
7
+ return "RuntimeException"
8
+ end,
9
+ })
10
+ RuntimeException.__index = RuntimeException
11
+ function RuntimeException.new(...)
12
+ local self = setmetatable({}, RuntimeException)
13
+ return self:constructor(...) or self
14
+ end
15
+ function RuntimeException:constructor(message)
16
+ self.message = message
17
+ self.simpleName = "RuntimeException"
18
+ end
19
+ function RuntimeException:getMessage()
20
+ return self.message
21
+ end
22
+ function RuntimeException:toString()
23
+ return if self.message == nil then `java.lang.{self.simpleName}` else `java.lang.{self.simpleName}: {self.message}`
24
+ end
25
+ function RuntimeException:__tostring()
26
+ return self:toString()
27
+ end
28
+ end
29
+ local IllegalArgumentException
30
+ do
31
+ local super = RuntimeException
32
+ IllegalArgumentException = setmetatable({}, {
33
+ __tostring = function()
34
+ return "IllegalArgumentException"
35
+ end,
36
+ __index = super,
37
+ })
38
+ IllegalArgumentException.__index = IllegalArgumentException
39
+ function IllegalArgumentException.new(...)
40
+ local self = setmetatable({}, IllegalArgumentException)
41
+ return self:constructor(...) or self
42
+ end
43
+ function IllegalArgumentException:constructor(...)
44
+ super.constructor(self, ...)
45
+ self.simpleName = "IllegalArgumentException"
46
+ end
47
+ function IllegalArgumentException:toString()
48
+ return super.toString(self)
49
+ end
50
+ function IllegalArgumentException:__tostring()
51
+ return self:toString()
52
+ end
53
+ end
54
+ local IllegalStateException
55
+ do
56
+ local super = RuntimeException
57
+ IllegalStateException = setmetatable({}, {
58
+ __tostring = function()
59
+ return "IllegalStateException"
60
+ end,
61
+ __index = super,
62
+ })
63
+ IllegalStateException.__index = IllegalStateException
64
+ function IllegalStateException.new(...)
65
+ local self = setmetatable({}, IllegalStateException)
66
+ return self:constructor(...) or self
67
+ end
68
+ function IllegalStateException:constructor(...)
69
+ super.constructor(self, ...)
70
+ self.simpleName = "IllegalStateException"
71
+ end
72
+ function IllegalStateException:toString()
73
+ return super.toString(self)
74
+ end
75
+ function IllegalStateException:__tostring()
76
+ return self:toString()
77
+ end
78
+ end
79
+ local UnsupportedOperationException
80
+ do
81
+ local super = RuntimeException
82
+ UnsupportedOperationException = setmetatable({}, {
83
+ __tostring = function()
84
+ return "UnsupportedOperationException"
85
+ end,
86
+ __index = super,
87
+ })
88
+ UnsupportedOperationException.__index = UnsupportedOperationException
89
+ function UnsupportedOperationException.new(...)
90
+ local self = setmetatable({}, UnsupportedOperationException)
91
+ return self:constructor(...) or self
92
+ end
93
+ function UnsupportedOperationException:constructor(...)
94
+ super.constructor(self, ...)
95
+ self.simpleName = "UnsupportedOperationException"
96
+ end
97
+ function UnsupportedOperationException:toString()
98
+ return super.toString(self)
99
+ end
100
+ function UnsupportedOperationException:__tostring()
101
+ return self:toString()
102
+ end
103
+ end
104
+ local IndexOutOfBoundsException
105
+ do
106
+ local super = RuntimeException
107
+ IndexOutOfBoundsException = setmetatable({}, {
108
+ __tostring = function()
109
+ return "IndexOutOfBoundsException"
110
+ end,
111
+ __index = super,
112
+ })
113
+ IndexOutOfBoundsException.__index = IndexOutOfBoundsException
114
+ function IndexOutOfBoundsException.new(...)
115
+ local self = setmetatable({}, IndexOutOfBoundsException)
116
+ return self:constructor(...) or self
117
+ end
118
+ function IndexOutOfBoundsException:constructor(...)
119
+ super.constructor(self, ...)
120
+ self.simpleName = "IndexOutOfBoundsException"
121
+ end
122
+ function IndexOutOfBoundsException:toString()
123
+ return super.toString(self)
124
+ end
125
+ function IndexOutOfBoundsException:__tostring()
126
+ return self:toString()
127
+ end
128
+ end
129
+ local StringIndexOutOfBoundsException
130
+ do
131
+ local super = IndexOutOfBoundsException
132
+ StringIndexOutOfBoundsException = setmetatable({}, {
133
+ __tostring = function()
134
+ return "StringIndexOutOfBoundsException"
135
+ end,
136
+ __index = super,
137
+ })
138
+ StringIndexOutOfBoundsException.__index = StringIndexOutOfBoundsException
139
+ function StringIndexOutOfBoundsException.new(...)
140
+ local self = setmetatable({}, StringIndexOutOfBoundsException)
141
+ return self:constructor(...) or self
142
+ end
143
+ function StringIndexOutOfBoundsException:constructor(...)
144
+ super.constructor(self, ...)
145
+ self.simpleName = "StringIndexOutOfBoundsException"
146
+ end
147
+ function StringIndexOutOfBoundsException:toString()
148
+ return super.toString(self)
149
+ end
150
+ function StringIndexOutOfBoundsException:__tostring()
151
+ return self:toString()
152
+ end
153
+ end
154
+ -- Raises an error value again unchanged. `throw` would prefix a string with the rethrowing line.
155
+ local function rethrow(err)
156
+ error(err, 0)
157
+ end
158
+ -- String concatenation of an Object: null prints as "null".
159
+ local function str(value)
160
+ return if value == nil then "null" else tostring(value)
161
+ end
162
+ -- String.substring and String.charAt use 0-based byte offsets and throw where string.sub clamps.
163
+ local function substring(text, beginIndex, endIndex)
164
+ if endIndex == nil then
165
+ endIndex = #text
166
+ end
167
+ if beginIndex < 0 or endIndex > #text or beginIndex > endIndex then
168
+ error(StringIndexOutOfBoundsException.new(`begin {beginIndex}, end {endIndex}, length {#text}`))
169
+ end
170
+ local _text = text
171
+ local _arg0 = beginIndex + 1
172
+ local _endIndex = endIndex
173
+ return string.sub(_text, _arg0, _endIndex)
174
+ end
175
+ local function charAt(text, index)
176
+ if index < 0 or index >= #text then
177
+ error(StringIndexOutOfBoundsException.new(`index {index}, length {#text}`))
178
+ end
179
+ local _text = text
180
+ local _arg0 = index + 1
181
+ local _arg1 = index + 1
182
+ return string.sub(_text, _arg0, _arg1)
183
+ end
184
+ local function startsWith(text, prefix)
185
+ local _text = text
186
+ local _arg1 = #prefix
187
+ return string.sub(_text, 1, _arg1) == prefix
188
+ end
189
+ -- toLowerCase(Locale.ROOT) on ASCII, which keeps every offset where it was.
190
+ local function toLowerCase(text)
191
+ return string.lower(text)
192
+ end
193
+ -- String.compareTo: the difference of the first bytes that differ, or of the lengths.
194
+ local function compareStrings(a, b)
195
+ local length = math.min(#a, #b)
196
+ do
197
+ local index = 1
198
+ local _shouldIncrement = false
199
+ while true do
200
+ if _shouldIncrement then
201
+ index += 1
202
+ else
203
+ _shouldIncrement = true
204
+ end
205
+ if not (index <= length) then
206
+ break
207
+ end
208
+ local x = string.byte(a, index)
209
+ local y = string.byte(b, index)
210
+ if x ~= y then
211
+ return x - y
212
+ end
213
+ end
214
+ end
215
+ return #a - #b
216
+ end
217
+ local function definesEquals(value)
218
+ local _value = value
219
+ local _condition = type(_value) == "table"
220
+ if _condition then
221
+ _condition = getmetatable(value) ~= nil
222
+ if _condition then
223
+ local _equals = value.equals
224
+ _condition = type(_equals) == "function"
225
+ end
226
+ end
227
+ return _condition
228
+ end
229
+ -- Objects.equals, with Java's collection equality for arrays and maps.
230
+ local function objectsEquals(a, b)
231
+ if rawequal(a, b) then
232
+ return true
233
+ end
234
+ if a == nil or b == nil then
235
+ return false
236
+ end
237
+ if definesEquals(a) then
238
+ return a:equals(b)
239
+ end
240
+ local _a = a
241
+ local _condition = type(_a) == "table"
242
+ if _condition then
243
+ local _b = b
244
+ _condition = type(_b) == "table"
245
+ if _condition then
246
+ _condition = getmetatable(a) == nil and getmetatable(b) == nil
247
+ end
248
+ end
249
+ if _condition then
250
+ local left = a
251
+ local right = b
252
+ for key, value in pairs(left) do
253
+ if not objectsEquals(value, right[key]) then
254
+ return false
255
+ end
256
+ end
257
+ for key in pairs(right) do
258
+ if left[key] == nil then
259
+ return false
260
+ end
261
+ end
262
+ return true
263
+ end
264
+ return a == b
265
+ end
266
+ -- List.sort is stable and Brigadier relies on equal elements keeping their order. table.sort isn't.
267
+ local function stableSort(list, compare)
268
+ local _array = {}
269
+ local _length = #_array
270
+ table.move(list, 1, #list, _length + 1, _array)
271
+ local buffer = _array
272
+ local sortRange
273
+ sortRange = function(low, high)
274
+ if low >= high then
275
+ return nil
276
+ end
277
+ local middle = math.floor((low + high) / 2)
278
+ sortRange(low, middle)
279
+ sortRange(middle + 1, high)
280
+ do
281
+ local index = low
282
+ local _shouldIncrement = false
283
+ while true do
284
+ if _shouldIncrement then
285
+ index += 1
286
+ else
287
+ _shouldIncrement = true
288
+ end
289
+ if not (index <= high) then
290
+ break
291
+ end
292
+ buffer[index + 1] = list[index + 1]
293
+ end
294
+ end
295
+ local left = low
296
+ local right = middle + 1
297
+ do
298
+ local index = low
299
+ local _shouldIncrement = false
300
+ while true do
301
+ if _shouldIncrement then
302
+ index += 1
303
+ else
304
+ _shouldIncrement = true
305
+ end
306
+ if not (index <= high) then
307
+ break
308
+ end
309
+ if left <= middle and (right > high or compare(buffer[right + 1], buffer[left + 1]) >= 0) then
310
+ list[index + 1] = buffer[left + 1]
311
+ left += 1
312
+ else
313
+ list[index + 1] = buffer[right + 1]
314
+ right += 1
315
+ end
316
+ end
317
+ end
318
+ end
319
+ sortRange(0, #list - 1)
320
+ end
321
+ local LONG_MAX_DOUBLE = 2 ^ 63
322
+ -- Integer.toString and Long.toString. Long.MAX_VALUE is stored as 2^63, its nearest double.
323
+ local function formatInteger(value)
324
+ if value >= LONG_MAX_DOUBLE then
325
+ return "9223372036854775807"
326
+ end
327
+ return string.format("%d", value)
328
+ end
329
+ local function toFloat(value)
330
+ local single = string.unpack("<f", string.pack("<f", value))
331
+ return single
332
+ end
333
+ -- The shortest digits and exponent that `readsBack` accepts for a positive finite value.
334
+ local function shortest(value, maxDigits, readsBack)
335
+ local text = ""
336
+ do
337
+ local precision = 1
338
+ local _shouldIncrement = false
339
+ while true do
340
+ if _shouldIncrement then
341
+ precision += 1
342
+ else
343
+ _shouldIncrement = true
344
+ end
345
+ if not (precision <= maxDigits) then
346
+ break
347
+ end
348
+ text = string.format(`%.{precision - 1}e`, value)
349
+ if readsBack(tonumber(text)) then
350
+ break
351
+ end
352
+ end
353
+ end
354
+ local mantissa, exponent = string.match(text, "^([%d%.]+)e([%+%-]%d+)$")
355
+ local digits = string.gsub(mantissa, "%.", "")
356
+ digits = string.gsub(digits, "0+$", "")
357
+ return { if digits == "" then "0" else digits, tonumber(exponent) }
358
+ end
359
+ local function formatDecimal(value, maxDigits, readsBack)
360
+ if value ~= value then
361
+ return "NaN"
362
+ end
363
+ if value == math.huge then
364
+ return "Infinity"
365
+ end
366
+ if value == -math.huge then
367
+ return "-Infinity"
368
+ end
369
+ if value == 0 then
370
+ return if 1 / value < 0 then "-0.0" else "0.0"
371
+ end
372
+ local sign = if value < 0 then "-" else ""
373
+ local magnitude = math.abs(value)
374
+ local _binding = shortest(magnitude, maxDigits, readsBack)
375
+ local digits = _binding[1]
376
+ local exponent = _binding[2]
377
+ if magnitude >= 1e-3 and magnitude < 1e7 then
378
+ if exponent >= 0 then
379
+ local _arg1 = exponent + 1
380
+ local whole = string.sub(digits, 1, _arg1)
381
+ whole ..= string.rep("0", exponent + 1 - #whole)
382
+ local _arg0 = exponent + 2
383
+ local fraction = string.sub(digits, _arg0)
384
+ return `{sign}{whole}.{if fraction == "" then "0" else fraction}`
385
+ end
386
+ return `{sign}0.{string.rep("0", -exponent - 1)}{digits}`
387
+ end
388
+ local fraction = string.sub(digits, 2)
389
+ return `{sign}{string.sub(digits, 1, 1)}.{if fraction == "" then "0" else fraction}E{exponent}`
390
+ end
391
+ -- Double.toString and Float.toString print the fewest digits that read back as the same value, as JDK 19 and
392
+ -- later do. JDK 8 sometimes printed one more.
393
+ local function formatDouble(value)
394
+ return formatDecimal(value, 17, function(candidate)
395
+ return candidate == math.abs(value)
396
+ end)
397
+ end
398
+ local function formatFloat(value)
399
+ local single = toFloat(value)
400
+ return formatDecimal(single, 9, function(candidate)
401
+ return toFloat(candidate) == math.abs(single)
402
+ end)
403
+ end
404
+ return {
405
+ rethrow = rethrow,
406
+ str = str,
407
+ substring = substring,
408
+ charAt = charAt,
409
+ startsWith = startsWith,
410
+ toLowerCase = toLowerCase,
411
+ compareStrings = compareStrings,
412
+ objectsEquals = objectsEquals,
413
+ stableSort = stableSort,
414
+ formatInteger = formatInteger,
415
+ toFloat = toFloat,
416
+ formatDouble = formatDouble,
417
+ formatFloat = formatFloat,
418
+ RuntimeException = RuntimeException,
419
+ IllegalArgumentException = IllegalArgumentException,
420
+ IllegalStateException = IllegalStateException,
421
+ UnsupportedOperationException = UnsupportedOperationException,
422
+ IndexOutOfBoundsException = IndexOutOfBoundsException,
423
+ StringIndexOutOfBoundsException = StringIndexOutOfBoundsException,
424
+ }
@@ -0,0 +1,9 @@
1
+ export interface Message {
2
+ getString(): string;
3
+ }
4
+ export declare class LiteralMessage implements Message {
5
+ private readonly text;
6
+ constructor(text: string);
7
+ getString(): string;
8
+ toString(): string;
9
+ }
@@ -0,0 +1,29 @@
1
+ -- Compiled with roblox-ts v3.0.0
2
+ local LiteralMessage
3
+ do
4
+ LiteralMessage = setmetatable({}, {
5
+ __tostring = function()
6
+ return "LiteralMessage"
7
+ end,
8
+ })
9
+ LiteralMessage.__index = LiteralMessage
10
+ function LiteralMessage.new(...)
11
+ local self = setmetatable({}, LiteralMessage)
12
+ return self:constructor(...) or self
13
+ end
14
+ function LiteralMessage:constructor(text)
15
+ self.text = text
16
+ end
17
+ function LiteralMessage:getString()
18
+ return self.text
19
+ end
20
+ function LiteralMessage:toString()
21
+ return self.text
22
+ end
23
+ function LiteralMessage:__tostring()
24
+ return self:toString()
25
+ end
26
+ end
27
+ return {
28
+ LiteralMessage = LiteralMessage,
29
+ }
@@ -0,0 +1,41 @@
1
+ export interface ImmutableStringReader {
2
+ getString(): string;
3
+ getRemainingLength(): number;
4
+ getTotalLength(): number;
5
+ getCursor(): number;
6
+ getRead(): string;
7
+ getRemaining(): string;
8
+ canRead(length?: number): boolean;
9
+ peek(offset?: number): string;
10
+ }
11
+ export declare class StringReader implements ImmutableStringReader {
12
+ private readonly text;
13
+ private cursor;
14
+ constructor(other: string | StringReader);
15
+ static isAllowedNumber(c: string): boolean;
16
+ static isQuotedStringStart(c: string): boolean;
17
+ static isAllowedInUnquotedString(c: string): boolean;
18
+ getString(): string;
19
+ setCursor(cursor: number): void;
20
+ getRemainingLength(): number;
21
+ getTotalLength(): number;
22
+ getCursor(): number;
23
+ getRead(): string;
24
+ getRemaining(): string;
25
+ canRead(length?: number): boolean;
26
+ peek(offset?: number): string;
27
+ read(): string;
28
+ skip(): void;
29
+ skipWhitespace(): void;
30
+ private readNumber;
31
+ readInt(): number;
32
+ readLong(): number;
33
+ readDouble(): number;
34
+ readFloat(): number;
35
+ readUnquotedString(): string;
36
+ readQuotedString(): string;
37
+ readStringUntil(terminator: string): string;
38
+ readString(): string;
39
+ readBoolean(): boolean;
40
+ expect(c: string): void;
41
+ }