@grain/stdlib 0.6.5 → 0.7.0
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/CHANGELOG.md +64 -0
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/array.gr +55 -7
- package/array.md +123 -77
- package/bigint.md +30 -30
- package/buffer.gr +20 -53
- package/buffer.md +47 -47
- package/bytes.gr +111 -35
- package/bytes.md +111 -32
- package/char.gr +201 -99
- package/char.md +361 -34
- package/exception.gr +11 -11
- package/exception.md +26 -1
- package/float32.gr +327 -3
- package/float32.md +606 -19
- package/float64.gr +320 -3
- package/float64.md +606 -19
- package/fs.gr +1082 -0
- package/fs.md +630 -0
- package/hash.gr +142 -88
- package/hash.md +102 -14
- package/int16.md +23 -23
- package/int32.gr +25 -4
- package/int32.md +65 -30
- package/int64.gr +26 -1
- package/int64.md +65 -30
- package/int8.md +23 -23
- package/json.gr +366 -51
- package/json.md +418 -2
- package/list.gr +387 -49
- package/list.md +492 -69
- package/map.gr +20 -12
- package/map.md +44 -38
- package/marshal.gr +41 -40
- package/marshal.md +2 -2
- package/number.gr +159 -30
- package/number.md +215 -38
- package/option.md +21 -21
- package/package.json +5 -3
- package/path.gr +48 -0
- package/path.md +103 -12
- package/pervasives.gr +2 -2
- package/pervasives.md +37 -37
- package/priorityqueue.gr +7 -7
- package/priorityqueue.md +19 -19
- package/queue.gr +183 -29
- package/queue.md +296 -40
- package/random.md +6 -6
- package/range.gr +4 -4
- package/range.md +6 -6
- package/rational.md +16 -16
- package/regex.gr +52 -51
- package/regex.md +11 -11
- package/result.md +16 -16
- package/runtime/atof/common.md +39 -39
- package/runtime/atof/decimal.gr +6 -6
- package/runtime/atof/decimal.md +8 -8
- package/runtime/atof/lemire.gr +5 -5
- package/runtime/atof/lemire.md +1 -1
- package/runtime/atof/parse.gr +16 -16
- package/runtime/atof/parse.md +2 -2
- package/runtime/atof/slow.md +1 -1
- package/runtime/atof/table.md +2 -2
- package/runtime/atoi/parse.gr +3 -3
- package/runtime/atoi/parse.md +1 -1
- package/runtime/bigint.gr +15 -47
- package/runtime/bigint.md +54 -60
- package/runtime/compare.gr +2 -2
- package/runtime/compare.md +1 -1
- package/runtime/dataStructures.md +33 -33
- package/runtime/debugPrint.gr +4 -1
- package/runtime/debugPrint.md +9 -9
- package/runtime/equal.gr +99 -77
- package/runtime/equal.md +1 -1
- package/runtime/exception.gr +62 -82
- package/runtime/exception.md +62 -11
- package/runtime/gc.gr +39 -45
- package/runtime/gc.md +4 -4
- package/runtime/malloc.gr +7 -7
- package/runtime/malloc.md +4 -4
- package/runtime/math/kernel/cos.gr +70 -0
- package/runtime/math/kernel/cos.md +14 -0
- package/runtime/math/kernel/sin.gr +65 -0
- package/runtime/math/kernel/sin.md +14 -0
- package/runtime/math/kernel/tan.gr +136 -0
- package/runtime/math/kernel/tan.md +14 -0
- package/runtime/math/rempio2.gr +244 -0
- package/runtime/math/rempio2.md +14 -0
- package/runtime/math/trig.gr +130 -0
- package/runtime/math/trig.md +28 -0
- package/runtime/math/umuldi.gr +26 -0
- package/runtime/math/umuldi.md +14 -0
- package/runtime/numberUtils.gr +29 -29
- package/runtime/numberUtils.md +12 -12
- package/runtime/numbers.gr +373 -381
- package/runtime/numbers.md +79 -73
- package/runtime/string.gr +37 -105
- package/runtime/string.md +3 -9
- package/runtime/unsafe/constants.md +24 -24
- package/runtime/unsafe/conv.md +13 -13
- package/runtime/unsafe/memory.gr +24 -20
- package/runtime/unsafe/memory.md +27 -7
- package/runtime/unsafe/offsets.gr +36 -0
- package/runtime/unsafe/offsets.md +88 -0
- package/runtime/unsafe/panic.gr +28 -0
- package/runtime/unsafe/panic.md +14 -0
- package/runtime/unsafe/tags.md +32 -32
- package/runtime/unsafe/wasmf32.md +28 -28
- package/runtime/unsafe/wasmf64.md +28 -28
- package/runtime/unsafe/wasmi32.md +47 -47
- package/runtime/unsafe/wasmi64.md +50 -50
- package/runtime/utf8.gr +189 -0
- package/runtime/utf8.md +117 -0
- package/runtime/wasi.gr +4 -2
- package/runtime/wasi.md +138 -138
- package/set.gr +18 -11
- package/set.md +42 -36
- package/stack.gr +171 -2
- package/stack.md +297 -15
- package/string.gr +352 -557
- package/string.md +77 -34
- package/uint16.gr +81 -0
- package/uint16.md +183 -22
- package/uint32.gr +25 -4
- package/uint32.md +63 -28
- package/uint64.gr +25 -5
- package/uint64.md +63 -28
- package/uint8.gr +81 -0
- package/uint8.md +183 -22
- package/uri.gr +57 -53
- package/uri.md +11 -12
- package/wasi/file.gr +67 -59
- package/wasi/file.md +39 -39
- package/wasi/process.md +5 -5
- package/wasi/random.md +3 -3
- package/wasi/time.md +4 -4
- package/runtime/utils/printing.gr +0 -60
- package/runtime/utils/printing.md +0 -26
package/range.md
CHANGED
|
@@ -44,7 +44,7 @@ Functions and constants included in the Range module.
|
|
|
44
44
|
</details>
|
|
45
45
|
|
|
46
46
|
```grain
|
|
47
|
-
inRange
|
|
47
|
+
inRange: (value: Number, range: Range<Number>) => Bool
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
Checks if the given number is within the range.
|
|
@@ -87,7 +87,7 @@ Range.inRange(10, { rangeStart: 0, rangeEnd: 2 }) == false
|
|
|
87
87
|
</details>
|
|
88
88
|
|
|
89
89
|
```grain
|
|
90
|
-
forEach
|
|
90
|
+
forEach: (fn: (Number => Void), range: Range<Number>) => Void
|
|
91
91
|
```
|
|
92
92
|
|
|
93
93
|
Calls the given function with each number in the range.
|
|
@@ -124,7 +124,7 @@ Range.forEach(val => print(val), { rangeStart: 0, rangeEnd: 2 })
|
|
|
124
124
|
</details>
|
|
125
125
|
|
|
126
126
|
```grain
|
|
127
|
-
map
|
|
127
|
+
map: (fn: (Number => a), range: Range<Number>) => List<a>
|
|
128
128
|
```
|
|
129
129
|
|
|
130
130
|
Produces a list by calling the given function on each number included in the range.
|
|
@@ -173,7 +173,7 @@ Functions and constants included in the Range.Inclusive module.
|
|
|
173
173
|
</details>
|
|
174
174
|
|
|
175
175
|
```grain
|
|
176
|
-
inRange
|
|
176
|
+
inRange: (value: Number, range: Range<Number>) => Bool
|
|
177
177
|
```
|
|
178
178
|
|
|
179
179
|
Checks if the given number is within the range.
|
|
@@ -216,7 +216,7 @@ Range.Inclusive.inRange(10, { rangeStart: 0, rangeEnd: 2 }) == false
|
|
|
216
216
|
</details>
|
|
217
217
|
|
|
218
218
|
```grain
|
|
219
|
-
forEach
|
|
219
|
+
forEach: (fn: (Number => Void), range: Range<Number>) => Void
|
|
220
220
|
```
|
|
221
221
|
|
|
222
222
|
Calls the given function with each number in the range.
|
|
@@ -253,7 +253,7 @@ Range.Inclusive.forEach(val => print(val), { rangeStart: 0, rangeEnd: 2 })
|
|
|
253
253
|
</details>
|
|
254
254
|
|
|
255
255
|
```grain
|
|
256
|
-
map
|
|
256
|
+
map: (fn: (Number => a), range: Range<Number>) => List<a>
|
|
257
257
|
```
|
|
258
258
|
|
|
259
259
|
Produces a list by calling the given function on each number included in the range.
|
package/rational.md
CHANGED
|
@@ -33,7 +33,7 @@ No other changes yet.
|
|
|
33
33
|
</details>
|
|
34
34
|
|
|
35
35
|
```grain
|
|
36
|
-
fromNumber
|
|
36
|
+
fromNumber: (number: Number) => Rational
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
Converts a Number to a Rational.
|
|
@@ -58,7 +58,7 @@ No other changes yet.
|
|
|
58
58
|
</details>
|
|
59
59
|
|
|
60
60
|
```grain
|
|
61
|
-
toNumber
|
|
61
|
+
toNumber: (rational: Rational) => Number
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
Converts a Rational to a Number.
|
|
@@ -83,7 +83,7 @@ No other changes yet.
|
|
|
83
83
|
</details>
|
|
84
84
|
|
|
85
85
|
```grain
|
|
86
|
-
numerator
|
|
86
|
+
numerator: (x: Rational) => Number
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
Finds the numerator of the rational number.
|
|
@@ -108,7 +108,7 @@ No other changes yet.
|
|
|
108
108
|
</details>
|
|
109
109
|
|
|
110
110
|
```grain
|
|
111
|
-
denominator
|
|
111
|
+
denominator: (x: Rational) => Number
|
|
112
112
|
```
|
|
113
113
|
|
|
114
114
|
Finds the denominator of the rational number.
|
|
@@ -133,7 +133,7 @@ No other changes yet.
|
|
|
133
133
|
</details>
|
|
134
134
|
|
|
135
135
|
```grain
|
|
136
|
-
toIntegerRatio
|
|
136
|
+
toIntegerRatio: (x: Rational) => (Number, Number)
|
|
137
137
|
```
|
|
138
138
|
|
|
139
139
|
Gets the numerator and denominator of the rational.
|
|
@@ -168,7 +168,7 @@ No other changes yet.
|
|
|
168
168
|
</details>
|
|
169
169
|
|
|
170
170
|
```grain
|
|
171
|
-
fromIntegerRatio
|
|
171
|
+
fromIntegerRatio: (numerator: Number, denominator: Number) => Rational
|
|
172
172
|
```
|
|
173
173
|
|
|
174
174
|
Creates a rational from a numerator and denominator.
|
|
@@ -211,7 +211,7 @@ No other changes yet.
|
|
|
211
211
|
</details>
|
|
212
212
|
|
|
213
213
|
```grain
|
|
214
|
-
(+)
|
|
214
|
+
(+): (x: Rational, y: Rational) => Rational
|
|
215
215
|
```
|
|
216
216
|
|
|
217
217
|
Computes the sum of its operands.
|
|
@@ -244,7 +244,7 @@ No other changes yet.
|
|
|
244
244
|
</details>
|
|
245
245
|
|
|
246
246
|
```grain
|
|
247
|
-
(-)
|
|
247
|
+
(-): (x: Rational, y: Rational) => Rational
|
|
248
248
|
```
|
|
249
249
|
|
|
250
250
|
Computes the difference of its operands.
|
|
@@ -277,7 +277,7 @@ No other changes yet.
|
|
|
277
277
|
</details>
|
|
278
278
|
|
|
279
279
|
```grain
|
|
280
|
-
(*)
|
|
280
|
+
(*): (x: Rational, y: Rational) => Rational
|
|
281
281
|
```
|
|
282
282
|
|
|
283
283
|
Computes the product of its operands.
|
|
@@ -310,7 +310,7 @@ No other changes yet.
|
|
|
310
310
|
</details>
|
|
311
311
|
|
|
312
312
|
```grain
|
|
313
|
-
(/)
|
|
313
|
+
(/): (x: Rational, y: Rational) => Rational
|
|
314
314
|
```
|
|
315
315
|
|
|
316
316
|
Computes the quotient of its operands.
|
|
@@ -343,7 +343,7 @@ No other changes yet.
|
|
|
343
343
|
</details>
|
|
344
344
|
|
|
345
345
|
```grain
|
|
346
|
-
(==)
|
|
346
|
+
(==): (x: Rational, y: Rational) => Bool
|
|
347
347
|
```
|
|
348
348
|
|
|
349
349
|
Checks if the first value is equal to the second value.
|
|
@@ -376,7 +376,7 @@ No other changes yet.
|
|
|
376
376
|
</details>
|
|
377
377
|
|
|
378
378
|
```grain
|
|
379
|
-
(!=)
|
|
379
|
+
(!=): (x: Rational, y: Rational) => Bool
|
|
380
380
|
```
|
|
381
381
|
|
|
382
382
|
Checks if the first value is not equal to the second value.
|
|
@@ -409,7 +409,7 @@ No other changes yet.
|
|
|
409
409
|
</details>
|
|
410
410
|
|
|
411
411
|
```grain
|
|
412
|
-
(<)
|
|
412
|
+
(<): (x: Rational, y: Rational) => Bool
|
|
413
413
|
```
|
|
414
414
|
|
|
415
415
|
Checks if the first value is less than the second value.
|
|
@@ -442,7 +442,7 @@ No other changes yet.
|
|
|
442
442
|
</details>
|
|
443
443
|
|
|
444
444
|
```grain
|
|
445
|
-
(>)
|
|
445
|
+
(>): (x: Rational, y: Rational) => Bool
|
|
446
446
|
```
|
|
447
447
|
|
|
448
448
|
Checks if the first value is greater than the second value.
|
|
@@ -475,7 +475,7 @@ No other changes yet.
|
|
|
475
475
|
</details>
|
|
476
476
|
|
|
477
477
|
```grain
|
|
478
|
-
(<=)
|
|
478
|
+
(<=): (x: Rational, y: Rational) => Bool
|
|
479
479
|
```
|
|
480
480
|
|
|
481
481
|
Checks if the first value is less than or equal to the second value.
|
|
@@ -513,7 +513,7 @@ No other changes yet.
|
|
|
513
513
|
</details>
|
|
514
514
|
|
|
515
515
|
```grain
|
|
516
|
-
(>=)
|
|
516
|
+
(>=): (x: Rational, y: Rational) => Bool
|
|
517
517
|
```
|
|
518
518
|
|
|
519
519
|
Checks if the first value is greater than or equal to the second value.
|
package/regex.gr
CHANGED
|
@@ -118,11 +118,11 @@ let withConfig = (buf: RegExBuf, config: RegExParserConfig) => {
|
|
|
118
118
|
// Parsing internals for recursive descent
|
|
119
119
|
|
|
120
120
|
let parseErr = (buf: RegExBuf, msg: String, posShift) => {
|
|
121
|
-
"Invalid Regular Expression: "
|
|
122
|
-
msg
|
|
123
|
-
" (position "
|
|
124
|
-
toString(unbox(buf.cursor) + posShift)
|
|
125
|
-
")"
|
|
121
|
+
"Invalid Regular Expression: "
|
|
122
|
+
++ msg
|
|
123
|
+
++ " (position "
|
|
124
|
+
++ toString(unbox(buf.cursor) + posShift)
|
|
125
|
+
++ ")"
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
let next = (buf: RegExBuf) => {
|
|
@@ -167,11 +167,11 @@ let eat = (buf: RegExBuf, char: Char) => {
|
|
|
167
167
|
Err(
|
|
168
168
|
parseErr(
|
|
169
169
|
buf,
|
|
170
|
-
"Expected character '"
|
|
171
|
-
Char.toString(char)
|
|
172
|
-
", but found character '"
|
|
173
|
-
Char.toString(ret)
|
|
174
|
-
"'",
|
|
170
|
+
"Expected character '"
|
|
171
|
+
++ Char.toString(char)
|
|
172
|
+
++ ", but found character '"
|
|
173
|
+
++ Char.toString(ret)
|
|
174
|
+
++ "'",
|
|
175
175
|
0
|
|
176
176
|
),
|
|
177
177
|
)
|
|
@@ -244,8 +244,8 @@ and rangeUnion = (rng1, rng2) => {
|
|
|
244
244
|
match ((rng1, rng2)) {
|
|
245
245
|
([], _) => rng2,
|
|
246
246
|
(_, []) => rng1,
|
|
247
|
-
([(r1start, r1end), ...r1tl], [(r2start, r2end), ...r2tl]) when r1start
|
|
248
|
-
r2start => {
|
|
247
|
+
([(r1start, r1end), ...r1tl], [(r2start, r2end), ...r2tl]) when r1start
|
|
248
|
+
<= r2start => {
|
|
249
249
|
if (r1end + 1 >= r2start) {
|
|
250
250
|
if (r1end <= r2end) {
|
|
251
251
|
rangeUnion([(r1start, r2end), ...r2tl], r1tl)
|
|
@@ -687,8 +687,8 @@ and parsePosixCharClass = (buf: RegExBuf) => {
|
|
|
687
687
|
Ok(_) => Ok(List.join("", List.reverse(acc))),
|
|
688
688
|
}
|
|
689
689
|
},
|
|
690
|
-
Ok(c) when Char.code('a') <= Char.code(c)
|
|
691
|
-
Char.code(c) <= Char.code('z') => {
|
|
690
|
+
Ok(c) when Char.code('a') <= Char.code(c)
|
|
691
|
+
&& Char.code(c) <= Char.code('z') => {
|
|
692
692
|
ignore(eat(buf, c))
|
|
693
693
|
loop([Char.toString(c), ...acc])
|
|
694
694
|
},
|
|
@@ -857,9 +857,10 @@ and parseRangeRest = (
|
|
|
857
857
|
} else {
|
|
858
858
|
match (peek(buf)) {
|
|
859
859
|
Err(e) => Err(e),
|
|
860
|
-
Ok(c) when Char.code('a') <= Char.code(c)
|
|
861
|
-
Char.code(c) <= Char.code('z')
|
|
862
|
-
Char.code('A') <= Char.code(c)
|
|
860
|
+
Ok(c) when Char.code('a') <= Char.code(c)
|
|
861
|
+
&& Char.code(c) <= Char.code('z')
|
|
862
|
+
|| Char.code('A') <= Char.code(c)
|
|
863
|
+
&& Char.code(c) <= Char.code('Z') => {
|
|
863
864
|
match (mustSpanFrom) {
|
|
864
865
|
Some(_) =>
|
|
865
866
|
Err(
|
|
@@ -874,9 +875,9 @@ and parseRangeRest = (
|
|
|
874
875
|
match (parseClass(buf)) {
|
|
875
876
|
Err(e) =>
|
|
876
877
|
Err(
|
|
877
|
-
"Invalid Regular Expression: illegal alphebetic escape (position "
|
|
878
|
-
toString(curPos)
|
|
879
|
-
")",
|
|
878
|
+
"Invalid Regular Expression: illegal alphebetic escape (position "
|
|
879
|
+
++ toString(curPos)
|
|
880
|
+
++ ")",
|
|
880
881
|
),
|
|
881
882
|
Ok(range1) => {
|
|
882
883
|
match (rangeAddCaseAware(rng, spanFrom, buf.config)) {
|
|
@@ -1011,8 +1012,8 @@ let rec parseAtom = (buf: RegExBuf) => {
|
|
|
1011
1012
|
match (parseTest(buf)) {
|
|
1012
1013
|
Err(e) => Err(e),
|
|
1013
1014
|
Ok(test) => {
|
|
1014
|
-
let tstSpanNumGroups = unbox(buf.config.groupNumber)
|
|
1015
|
-
tstPreNumGroups
|
|
1015
|
+
let tstSpanNumGroups = unbox(buf.config.groupNumber)
|
|
1016
|
+
- tstPreNumGroups
|
|
1016
1017
|
match (parsePCEs(buf, false)) {
|
|
1017
1018
|
Err(e) => Err(e),
|
|
1018
1019
|
Ok(pces) => {
|
|
@@ -1252,8 +1253,8 @@ and parseTest = (buf: RegExBuf) => {
|
|
|
1252
1253
|
ignore(eat(buf, '?'))
|
|
1253
1254
|
parseLook(buf)
|
|
1254
1255
|
},
|
|
1255
|
-
Ok(c) when Char.code(c) >= Char.code('0')
|
|
1256
|
-
Char.code(c) <= Char.code('9') => {
|
|
1256
|
+
Ok(c) when Char.code(c) >= Char.code('0')
|
|
1257
|
+
&& Char.code(c) <= Char.code('9') => {
|
|
1257
1258
|
buf.config.references := true
|
|
1258
1259
|
let curPos = unbox(buf.cursor)
|
|
1259
1260
|
match (parseInteger(buf, 0)) {
|
|
@@ -1285,8 +1286,8 @@ and parseInteger = (buf: RegExBuf, n) => {
|
|
|
1285
1286
|
} else {
|
|
1286
1287
|
match (peek(buf)) {
|
|
1287
1288
|
Err(c) => Err(c),
|
|
1288
|
-
Ok(c) when Char.code(c) >= Char.code('0')
|
|
1289
|
-
Char.code(c) <= Char.code('9') => {
|
|
1289
|
+
Ok(c) when Char.code(c) >= Char.code('0')
|
|
1290
|
+
&& Char.code(c) <= Char.code('9') => {
|
|
1290
1291
|
ignore(next(buf))
|
|
1291
1292
|
parseInteger(buf, 10 * n + (Char.code(c) - Char.code('0')))
|
|
1292
1293
|
},
|
|
@@ -1503,11 +1504,11 @@ and parseUnicodeCategories = (buf: RegExBuf, pC: String) => {
|
|
|
1503
1504
|
Err(
|
|
1504
1505
|
parseErr(
|
|
1505
1506
|
buf,
|
|
1506
|
-
"Unrecognized property name in `\\"
|
|
1507
|
-
pC
|
|
1508
|
-
"`: `"
|
|
1509
|
-
s
|
|
1510
|
-
"`",
|
|
1507
|
+
"Unrecognized property name in `\\"
|
|
1508
|
+
++ pC
|
|
1509
|
+
++ "`: `"
|
|
1510
|
+
++ s
|
|
1511
|
+
++ "`",
|
|
1511
1512
|
0
|
|
1512
1513
|
),
|
|
1513
1514
|
),
|
|
@@ -1566,8 +1567,8 @@ and parseBackslashLiteral = (buf: RegExBuf) => {
|
|
|
1566
1567
|
match (peek(buf)) {
|
|
1567
1568
|
Err(e) => Err(e),
|
|
1568
1569
|
// pregexp:
|
|
1569
|
-
Ok(c) when buf.config.isPerlRegExp
|
|
1570
|
-
(Char.code(c) >= Char.code('0') && Char.code(c) <= Char.code('9')) => {
|
|
1570
|
+
Ok(c) when buf.config.isPerlRegExp
|
|
1571
|
+
&& (Char.code(c) >= Char.code('0') && Char.code(c) <= Char.code('9')) => {
|
|
1571
1572
|
buf.config.references := true
|
|
1572
1573
|
match (parseInteger(buf, 0)) {
|
|
1573
1574
|
Err(e) => Err(e),
|
|
@@ -1576,10 +1577,10 @@ and parseBackslashLiteral = (buf: RegExBuf) => {
|
|
|
1576
1577
|
},
|
|
1577
1578
|
}
|
|
1578
1579
|
},
|
|
1579
|
-
Ok(c) when buf.config.isPerlRegExp
|
|
1580
|
-
(
|
|
1581
|
-
Char.code(c) >= Char.code('a') && Char.code(c) <= Char.code('z')
|
|
1582
|
-
Char.code(c) >= Char.code('A') && Char.code(c) <= Char.code('Z')
|
|
1580
|
+
Ok(c) when buf.config.isPerlRegExp
|
|
1581
|
+
&& (
|
|
1582
|
+
Char.code(c) >= Char.code('a') && Char.code(c) <= Char.code('z')
|
|
1583
|
+
|| Char.code(c) >= Char.code('A') && Char.code(c) <= Char.code('Z')
|
|
1583
1584
|
) => {
|
|
1584
1585
|
match (c) {
|
|
1585
1586
|
'p' => {
|
|
@@ -2304,8 +2305,8 @@ let charMatcherIterated = (toMatch, max) =>
|
|
|
2304
2305
|
|
|
2305
2306
|
let subArraysEqual = (arr1, start1, arr2, start2, length) => {
|
|
2306
2307
|
if (
|
|
2307
|
-
Array.length(arr1) - start1 < length
|
|
2308
|
-
Array.length(arr2) - start2 < length
|
|
2308
|
+
Array.length(arr1) - start1 < length
|
|
2309
|
+
|| Array.length(arr2) - start2 < length
|
|
2309
2310
|
) {
|
|
2310
2311
|
return false
|
|
2311
2312
|
}
|
|
@@ -2328,8 +2329,8 @@ let stringMatcher = (toMatch, len, next_m) =>
|
|
|
2328
2329
|
stack,
|
|
2329
2330
|
) => {
|
|
2330
2331
|
if ({
|
|
2331
|
-
pos + len <= limit
|
|
2332
|
-
subArraysEqual(
|
|
2332
|
+
pos + len <= limit
|
|
2333
|
+
&& subArraysEqual(
|
|
2333
2334
|
buf.matchInputExploded,
|
|
2334
2335
|
pos,
|
|
2335
2336
|
String.explode(toMatch),
|
|
@@ -2350,8 +2351,8 @@ let stringTailMatcher = (toMatch, len) =>
|
|
|
2350
2351
|
stack,
|
|
2351
2352
|
) => {
|
|
2352
2353
|
if ({
|
|
2353
|
-
pos + len <= limit
|
|
2354
|
-
subArraysEqual(
|
|
2354
|
+
pos + len <= limit
|
|
2355
|
+
&& subArraysEqual(
|
|
2355
2356
|
buf.matchInputExploded,
|
|
2356
2357
|
pos,
|
|
2357
2358
|
String.explode(toMatch),
|
|
@@ -2584,8 +2585,8 @@ let isWordChar = c => {
|
|
|
2584
2585
|
|
|
2585
2586
|
let isWordBoundary = (buf, pos, start, limit, end) => {
|
|
2586
2587
|
!(
|
|
2587
|
-
(pos == start || !isWordChar(matchBufChar(buf, pos - 1)))
|
|
2588
|
-
(pos == end || !isWordChar(matchBufChar(buf, pos)))
|
|
2588
|
+
(pos == start || !isWordChar(matchBufChar(buf, pos - 1)))
|
|
2589
|
+
== (pos == end || !isWordChar(matchBufChar(buf, pos)))
|
|
2589
2590
|
)
|
|
2590
2591
|
}
|
|
2591
2592
|
|
|
@@ -2922,8 +2923,8 @@ let makeReferenceMatcher = eq =>
|
|
|
2922
2923
|
Some((refStart, refEnd)) => {
|
|
2923
2924
|
let len = refEnd - refStart
|
|
2924
2925
|
if (
|
|
2925
|
-
pos + len <= limit
|
|
2926
|
-
subArraysEqual(
|
|
2926
|
+
pos + len <= limit
|
|
2927
|
+
&& subArraysEqual(
|
|
2927
2928
|
buf.matchInputExploded,
|
|
2928
2929
|
refStart,
|
|
2929
2930
|
buf.matchInputExploded,
|
|
@@ -3448,8 +3449,8 @@ let checkMustString = (ms, buf: MatchBuf, pos, endPos) => {
|
|
|
3448
3449
|
None => true,
|
|
3449
3450
|
Some(ms) => {
|
|
3450
3451
|
let toCheck = if (
|
|
3451
|
-
pos == 0
|
|
3452
|
-
endPos == Array.length(buf.matchInputExploded)
|
|
3452
|
+
pos == 0
|
|
3453
|
+
&& endPos == Array.length(buf.matchInputExploded)
|
|
3453
3454
|
) {
|
|
3454
3455
|
buf.matchInput
|
|
3455
3456
|
} else {
|
|
@@ -3819,8 +3820,8 @@ let computeReplacement = (
|
|
|
3819
3820
|
} else {
|
|
3820
3821
|
let c = replacementExploded[pos]
|
|
3821
3822
|
if (
|
|
3822
|
-
Char.code('0') <= Char.code(c)
|
|
3823
|
-
Char.code(c) <= Char.code('9')
|
|
3823
|
+
Char.code('0') <= Char.code(c)
|
|
3824
|
+
&& Char.code(c) <= Char.code('9')
|
|
3824
3825
|
) {
|
|
3825
3826
|
dLoop(pos + 1, 10 * accum + (Char.code(c) - Char.code('0')))
|
|
3826
3827
|
} else {
|
package/regex.md
CHANGED
|
@@ -66,7 +66,7 @@ No other changes yet.
|
|
|
66
66
|
</details>
|
|
67
67
|
|
|
68
68
|
```grain
|
|
69
|
-
make
|
|
69
|
+
make: (regexString: String) => Result<RegularExpression, String>
|
|
70
70
|
```
|
|
71
71
|
|
|
72
72
|
Compiles the given pattern string into a regular expression object.
|
|
@@ -179,7 +179,7 @@ No other changes yet.
|
|
|
179
179
|
</details>
|
|
180
180
|
|
|
181
181
|
```grain
|
|
182
|
-
isMatch
|
|
182
|
+
isMatch: (rx: RegularExpression, string: String) => Bool
|
|
183
183
|
```
|
|
184
184
|
|
|
185
185
|
Determines if the given regular expression has a match in the given string.
|
|
@@ -211,7 +211,7 @@ No other changes yet.
|
|
|
211
211
|
</details>
|
|
212
212
|
|
|
213
213
|
```grain
|
|
214
|
-
isMatchRange
|
|
214
|
+
isMatchRange:
|
|
215
215
|
(rx: RegularExpression, string: String, start: Number, end: Number) => Bool
|
|
216
216
|
```
|
|
217
217
|
|
|
@@ -250,7 +250,7 @@ No other changes yet.
|
|
|
250
250
|
</details>
|
|
251
251
|
|
|
252
252
|
```grain
|
|
253
|
-
find
|
|
253
|
+
find: (rx: RegularExpression, string: String) => Option<MatchResult>
|
|
254
254
|
```
|
|
255
255
|
|
|
256
256
|
Returns the first match for the given regular expression contained within the given string.
|
|
@@ -282,7 +282,7 @@ No other changes yet.
|
|
|
282
282
|
</details>
|
|
283
283
|
|
|
284
284
|
```grain
|
|
285
|
-
findRange
|
|
285
|
+
findRange:
|
|
286
286
|
(rx: RegularExpression, string: String, start: Number, end: Number) =>
|
|
287
287
|
Option<MatchResult>
|
|
288
288
|
```
|
|
@@ -314,7 +314,7 @@ Regex.findRange(Result.unwrap(Regex.make("ca+[at]")), "caaat", 0, 5)
|
|
|
314
314
|
### Regex.**findAll**
|
|
315
315
|
|
|
316
316
|
```grain
|
|
317
|
-
findAll
|
|
317
|
+
findAll: (rx: RegularExpression, string: String) => List<MatchResult>
|
|
318
318
|
```
|
|
319
319
|
|
|
320
320
|
Returns all matches for the given regular expression contained within the given string.
|
|
@@ -340,7 +340,7 @@ No other changes yet.
|
|
|
340
340
|
</details>
|
|
341
341
|
|
|
342
342
|
```grain
|
|
343
|
-
findAllRange
|
|
343
|
+
findAllRange:
|
|
344
344
|
(rx: RegularExpression, string: String, start: Number, end: Number) =>
|
|
345
345
|
List<MatchResult>
|
|
346
346
|
```
|
|
@@ -377,7 +377,7 @@ No other changes yet.
|
|
|
377
377
|
</details>
|
|
378
378
|
|
|
379
379
|
```grain
|
|
380
|
-
replace
|
|
380
|
+
replace:
|
|
381
381
|
(rx: RegularExpression, toSearch: String, replacement: String) => String
|
|
382
382
|
```
|
|
383
383
|
|
|
@@ -419,7 +419,7 @@ No other changes yet.
|
|
|
419
419
|
</details>
|
|
420
420
|
|
|
421
421
|
```grain
|
|
422
|
-
replaceAll
|
|
422
|
+
replaceAll:
|
|
423
423
|
(rx: RegularExpression, toSearch: String, replacement: String) => String
|
|
424
424
|
```
|
|
425
425
|
|
|
@@ -454,7 +454,7 @@ No other changes yet.
|
|
|
454
454
|
</details>
|
|
455
455
|
|
|
456
456
|
```grain
|
|
457
|
-
split
|
|
457
|
+
split: (rx: RegularExpression, str: String) => List<String>
|
|
458
458
|
```
|
|
459
459
|
|
|
460
460
|
Splits the given string at the first match for the given regular expression.
|
|
@@ -489,7 +489,7 @@ No other changes yet.
|
|
|
489
489
|
</details>
|
|
490
490
|
|
|
491
491
|
```grain
|
|
492
|
-
splitAll
|
|
492
|
+
splitAll: (rx: RegularExpression, str: String) => List<String>
|
|
493
493
|
```
|
|
494
494
|
|
|
495
495
|
Splits the given string at every match for the given regular expression.
|
package/result.md
CHANGED
|
@@ -36,7 +36,7 @@ No other changes yet.
|
|
|
36
36
|
</details>
|
|
37
37
|
|
|
38
38
|
```grain
|
|
39
|
-
isOk
|
|
39
|
+
isOk: (result: Result<a, b>) => Bool
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
Checks if the Result is the `Ok` variant.
|
|
@@ -61,7 +61,7 @@ No other changes yet.
|
|
|
61
61
|
</details>
|
|
62
62
|
|
|
63
63
|
```grain
|
|
64
|
-
isErr
|
|
64
|
+
isErr: (result: Result<a, b>) => Bool
|
|
65
65
|
```
|
|
66
66
|
|
|
67
67
|
Checks if the Result is the `Err` variant.
|
|
@@ -86,7 +86,7 @@ No other changes yet.
|
|
|
86
86
|
</details>
|
|
87
87
|
|
|
88
88
|
```grain
|
|
89
|
-
toOption
|
|
89
|
+
toOption: (result: Result<a, b>) => Option<a>
|
|
90
90
|
```
|
|
91
91
|
|
|
92
92
|
Converts the Result to an Option. An error value is discarded and replaced with `None`.
|
|
@@ -111,7 +111,7 @@ No other changes yet.
|
|
|
111
111
|
</details>
|
|
112
112
|
|
|
113
113
|
```grain
|
|
114
|
-
flatMap
|
|
114
|
+
flatMap: (fn: (a => Result<b, c>), result: Result<a, c>) => Result<b, c>
|
|
115
115
|
```
|
|
116
116
|
|
|
117
117
|
If the Result is `Ok(value)`, applies the given function to the `value` to produce a new Result.
|
|
@@ -137,7 +137,7 @@ No other changes yet.
|
|
|
137
137
|
</details>
|
|
138
138
|
|
|
139
139
|
```grain
|
|
140
|
-
flatMapErr
|
|
140
|
+
flatMapErr: (fn: (a => Result<b, c>), result: Result<b, a>) => Result<b, c>
|
|
141
141
|
```
|
|
142
142
|
|
|
143
143
|
If the Result is an `Err(value)`, applies the given function to the `value` to produce a new Result.
|
|
@@ -163,7 +163,7 @@ No other changes yet.
|
|
|
163
163
|
</details>
|
|
164
164
|
|
|
165
165
|
```grain
|
|
166
|
-
map
|
|
166
|
+
map: (fn: (a => b), result: Result<a, c>) => Result<b, c>
|
|
167
167
|
```
|
|
168
168
|
|
|
169
169
|
If the Result is `Ok(value)`, applies the given function to the `value` and wraps the new value in an `Ok` variant.
|
|
@@ -189,7 +189,7 @@ No other changes yet.
|
|
|
189
189
|
</details>
|
|
190
190
|
|
|
191
191
|
```grain
|
|
192
|
-
mapErr
|
|
192
|
+
mapErr: (fn: (a => b), result: Result<c, a>) => Result<c, b>
|
|
193
193
|
```
|
|
194
194
|
|
|
195
195
|
If the Result is `Err(value)`, applies the given function to the `value` and wraps the new value in an `Err` variant.
|
|
@@ -215,7 +215,7 @@ No other changes yet.
|
|
|
215
215
|
</details>
|
|
216
216
|
|
|
217
217
|
```grain
|
|
218
|
-
mapWithDefault
|
|
218
|
+
mapWithDefault: (fn: (a => b), def: b, result: Result<a, c>) => b
|
|
219
219
|
```
|
|
220
220
|
|
|
221
221
|
If the Result is `Ok(value)`, applies the given function to the `value` to produce a new value, otherwise uses the default value.
|
|
@@ -243,7 +243,7 @@ No other changes yet.
|
|
|
243
243
|
</details>
|
|
244
244
|
|
|
245
245
|
```grain
|
|
246
|
-
mapWithDefaultFn
|
|
246
|
+
mapWithDefaultFn:
|
|
247
247
|
(fnOk: (a => b), fnErr: (c => b), result: Result<a, c>) => b
|
|
248
248
|
```
|
|
249
249
|
|
|
@@ -280,7 +280,7 @@ Returns:
|
|
|
280
280
|
</details>
|
|
281
281
|
|
|
282
282
|
```grain
|
|
283
|
-
(||)
|
|
283
|
+
(||): (result1: Result<a, b>, result2: Result<a, b>) => Result<a, b>
|
|
284
284
|
```
|
|
285
285
|
|
|
286
286
|
Behaves like a logical OR (`||`) where the first Result is only returned if it is the `Ok` variant and falling back to the second Result in all other cases.
|
|
@@ -313,7 +313,7 @@ Returns:
|
|
|
313
313
|
</details>
|
|
314
314
|
|
|
315
315
|
```grain
|
|
316
|
-
(&&)
|
|
316
|
+
(&&): (result1: Result<a, b>, result2: Result<a, b>) => Result<a, b>
|
|
317
317
|
```
|
|
318
318
|
|
|
319
319
|
Behaves like a logical AND (`&&`) where the first Result is only returned if it is the `Err` variant and falling back to the second Result in all other cases.
|
|
@@ -339,7 +339,7 @@ No other changes yet.
|
|
|
339
339
|
</details>
|
|
340
340
|
|
|
341
341
|
```grain
|
|
342
|
-
peek
|
|
342
|
+
peek: (fnOk: (a => b), fnErr: (c => d), result: Result<a, c>) => Void
|
|
343
343
|
```
|
|
344
344
|
|
|
345
345
|
If the Result is `Ok(value)`, applies the `fnOk` function to the `value` without producing a new value.
|
|
@@ -362,7 +362,7 @@ No other changes yet.
|
|
|
362
362
|
</details>
|
|
363
363
|
|
|
364
364
|
```grain
|
|
365
|
-
peekOk
|
|
365
|
+
peekOk: (fn: (a => b), result: Result<a, c>) => Void
|
|
366
366
|
```
|
|
367
367
|
|
|
368
368
|
If the Result is `Ok(value)`, applies the given function to the `value` without producing a new value.
|
|
@@ -382,7 +382,7 @@ No other changes yet.
|
|
|
382
382
|
</details>
|
|
383
383
|
|
|
384
384
|
```grain
|
|
385
|
-
peekErr
|
|
385
|
+
peekErr: (fn: (a => b), result: Result<c, a>) => Void
|
|
386
386
|
```
|
|
387
387
|
|
|
388
388
|
If the Result is `Err(value)`, applies the given function to the `value` without producing a new value.
|
|
@@ -402,7 +402,7 @@ No other changes yet.
|
|
|
402
402
|
</details>
|
|
403
403
|
|
|
404
404
|
```grain
|
|
405
|
-
expect
|
|
405
|
+
expect: (msg: String, result: Result<a, b>) => a
|
|
406
406
|
```
|
|
407
407
|
|
|
408
408
|
Extracts the value inside an `Ok` result, otherwise throw an
|
|
@@ -441,7 +441,7 @@ No other changes yet.
|
|
|
441
441
|
</details>
|
|
442
442
|
|
|
443
443
|
```grain
|
|
444
|
-
unwrap
|
|
444
|
+
unwrap: (result: Result<a, b>) => a
|
|
445
445
|
```
|
|
446
446
|
|
|
447
447
|
Extracts the value inside an `Ok` result, otherwise throw an
|