functionalscript 0.2.6 → 0.3.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/.github/workflows/ci.yml +19 -4
- package/CHANGELOG.md +5 -0
- package/com/cpp/{module.f.mjs → module.f.ts} +65 -44
- package/com/cpp/{test.f.mjs → test.f.ts} +1 -1
- package/com/cpp/testlib.f.ts +8 -0
- package/com/cs/{module.f.mjs → module.f.ts} +47 -38
- package/com/cs/{test.f.mjs → test.f.ts} +2 -2
- package/com/cs/testlib.f.ts +8 -0
- package/com/rust/module.f.ts +287 -0
- package/com/rust/{test.f.mjs → test.f.ts} +1 -1
- package/com/rust/testlib.f.ts +8 -0
- package/com/test/{build.f.mjs → build.f.ts} +47 -45
- package/com/test/{build.mjs → build.ts} +7 -6
- package/com/types/module.f.ts +62 -0
- package/com/types/{testlib.f.mjs → testlib.f.ts} +2 -3
- package/commonjs/build/module.f.ts +100 -0
- package/commonjs/build/{test.f.mjs → test.f.ts} +21 -17
- package/commonjs/module/function/module.f.ts +13 -0
- package/commonjs/module/module.f.ts +41 -0
- package/commonjs/module.f.ts +7 -0
- package/commonjs/{module.mjs → module.ts} +12 -9
- package/commonjs/package/dependencies/module.f.ts +22 -0
- package/commonjs/package/dependencies/{test.f.mjs → test.f.ts} +1 -1
- package/commonjs/package/module.f.ts +31 -0
- package/commonjs/package/{test.f.mjs → test.f.ts} +1 -1
- package/commonjs/path/{module.f.mjs → module.f.ts} +72 -67
- package/commonjs/path/{test.f.mjs → test.f.ts} +25 -19
- package/commonjs/{test.mjs → test.ts} +5 -4
- package/crypto/prime_field/{module.f.mjs → module.f.ts} +40 -37
- package/crypto/prime_field/{test.f.mjs → test.f.ts} +7 -5
- package/crypto/secp/{module.f.mjs → module.f.ts} +44 -44
- package/crypto/secp/{test.f.mjs → test.f.ts} +16 -11
- package/crypto/sha2/{module.f.mjs → module.f.ts} +61 -46
- package/crypto/sha2/{test.f.mjs → test.f.ts} +12 -9
- package/deno.json +71 -0
- package/dev/README.md +8 -0
- package/dev/index.ts +3 -0
- package/dev/{module.f.mjs → module.f.ts} +0 -2
- package/dev/{module.mjs → module.ts} +65 -60
- package/dev/test/{module.f.mjs → module.f.ts} +57 -70
- package/dev/{test.f.mjs → test.f.ts} +7 -5
- package/dev/test.ts +53 -0
- package/djs/{module.f.mjs → module.f.ts} +31 -31
- package/djs/parser/{module.f.mjs → module.f.ts} +190 -182
- package/djs/parser/{test.f.mjs → test.f.ts} +173 -150
- package/djs/serializer/module.f.ts +90 -0
- package/djs/{test.f.mjs → test.f.ts} +4 -4
- package/djs/tokenizer/{module.f.mjs → module.f.ts} +35 -42
- package/djs/tokenizer/{test.f.mjs → test.f.ts} +9 -8
- package/fsc/{module.f.mjs → module.f.ts} +41 -44
- package/fsc/{test.f.mjs → test.f.ts} +8 -6
- package/fsm/module.f.ts +107 -0
- package/fsm/{test.f.mjs → test.f.ts} +10 -9
- package/html/module.f.ts +108 -0
- package/html/{test.f.mjs → test.f.ts} +10 -7
- package/issues/lang/3110-function.md +25 -1
- package/issues/{test.f.mjs → test.f.ts} +3 -2
- package/js/tokenizer/module.f.ts +882 -0
- package/js/tokenizer/{test.f.mjs → test.f.ts} +11 -10
- package/json/module.f.ts +94 -0
- package/json/parser/{module.f.mjs → module.f.ts} +113 -109
- package/json/parser/{test.f.mjs → test.f.ts} +10 -9
- package/json/serializer/module.f.ts +70 -0
- package/json/serializer/{test.f.mjs → test.f.ts} +3 -3
- package/json/{test.f.mjs → test.f.ts} +3 -3
- package/json/tokenizer/{module.f.mjs → module.f.ts} +29 -36
- package/json/tokenizer/{test.f.mjs → test.f.ts} +9 -8
- package/nanvm-lib/src/extension.rs +15 -4
- package/nanvm-lib/src/interface.rs +7 -10
- package/nanvm-lib/src/lib.rs +3 -3
- package/nanvm-lib/src/naive.rs +10 -3
- package/nanvm-lib/src/nanenum.rs +5 -1
- package/nanvm-lib/tests/{test.f.mjs → test.f.ts} +7 -6
- package/nodejs/version/{main.mjs → main.ts} +1 -1
- package/nodejs/version/module.f.ts +42 -0
- package/nodejs/version/{test.f.mjs → test.f.ts} +11 -12
- package/package.json +9 -9
- package/text/ascii/{module.f.mjs → module.f.ts} +10 -8
- package/text/ascii/{test.f.mjs → test.f.ts} +4 -4
- package/text/module.f.ts +30 -0
- package/text/sgr/{module.f.mjs → module.f.ts} +3 -5
- package/text/{test.f.mjs → test.f.ts} +5 -4
- package/text/utf16/module.f.ts +108 -0
- package/text/utf16/{test.f.mjs → test.f.ts} +7 -6
- package/text/utf8/{module.f.mjs → module.f.ts} +29 -23
- package/text/utf8/{test.f.mjs → test.f.ts} +4 -4
- package/tsconfig.json +4 -1
- package/types/array/module.f.ts +89 -0
- package/types/array/{test.f.mjs → test.f.ts} +3 -3
- package/types/bigfloat/{module.f.mjs → module.f.ts} +25 -20
- package/types/bigfloat/{test.f.mjs → test.f.ts} +1 -1
- package/types/bigint/{module.f.mjs → module.f.ts} +29 -28
- package/types/bigint/{test.f.mjs → test.f.ts} +2 -2
- package/types/bit_vec/{module.f.mjs → module.f.ts} +16 -37
- package/types/bit_vec/{test.f.mjs → test.f.ts} +1 -1
- package/types/btree/find/module.f.ts +92 -0
- package/types/btree/find/{test.f.mjs → test.f.ts} +20 -16
- package/types/btree/{module.f.mjs → module.f.ts} +9 -9
- package/types/btree/remove/{module.f.mjs → module.f.ts} +43 -53
- package/types/btree/remove/{test.f.mjs → test.f.ts} +19 -15
- package/types/btree/set/{module.f.mjs → module.f.ts} +17 -20
- package/types/btree/set/{test.f.mjs → test.f.ts} +96 -66
- package/types/btree/{test.f.mjs → test.f.ts} +34 -26
- package/types/btree/types/module.f.ts +27 -0
- package/types/byte_set/module.f.ts +70 -0
- package/types/byte_set/{test.f.mjs → test.f.ts} +8 -7
- package/types/function/compare/module.f.ts +26 -0
- package/types/function/compare/{test.f.mjs → test.f.ts} +1 -1
- package/types/function/module.f.ts +43 -0
- package/types/function/operator/module.f.ts +63 -0
- package/types/function/test.f.ts +20 -0
- package/types/list/module.f.ts +345 -0
- package/types/list/{test.f.mjs → test.f.ts} +30 -24
- package/types/map/module.f.ts +65 -0
- package/types/map/{test.f.mjs → test.f.ts} +6 -5
- package/types/nibble_set/module.f.ts +34 -0
- package/types/nibble_set/{test.f.mjs → test.f.ts} +3 -3
- package/types/nullable/module.f.ts +9 -0
- package/types/nullable/{test.f.mjs → test.f.ts} +2 -2
- package/types/number/module.f.ts +16 -0
- package/types/number/{test.f.mjs → test.f.ts} +7 -5
- package/types/object/module.f.ts +30 -0
- package/types/object/{test.f.mjs → test.f.ts} +2 -2
- package/types/range/module.f.ts +10 -0
- package/types/range/{test.f.mjs → test.f.ts} +1 -1
- package/types/range_map/module.f.ts +70 -0
- package/types/range_map/{test.f.mjs → test.f.ts} +82 -57
- package/types/result/module.f.ts +20 -0
- package/types/result/{module.mjs → module.ts} +4 -3
- package/types/sorted_list/module.f.ts +83 -0
- package/types/sorted_list/{test.f.mjs → test.f.ts} +14 -12
- package/types/sorted_set/module.f.ts +36 -0
- package/types/sorted_set/{test.f.mjs → test.f.ts} +14 -12
- package/types/string/module.f.ts +24 -0
- package/types/string/{test.f.mjs → test.f.ts} +2 -2
- package/types/string_set/module.f.ts +37 -0
- package/types/string_set/{test.f.mjs → test.f.ts} +2 -2
- package/com/cpp/testlib.f.mjs +0 -8
- package/com/cs/testlib.f.mjs +0 -8
- package/com/rust/module.f.mjs +0 -272
- package/com/rust/testlib.f.mjs +0 -8
- package/com/types/module.f.mjs +0 -67
- package/commonjs/build/module.f.mjs +0 -100
- package/commonjs/module/function/module.f.mjs +0 -21
- package/commonjs/module/module.f.mjs +0 -53
- package/commonjs/module.f.mjs +0 -11
- package/commonjs/package/dependencies/module.f.mjs +0 -22
- package/commonjs/package/module.f.mjs +0 -36
- package/dev/index.mjs +0 -3
- package/dev/test.mjs +0 -60
- package/fsm/module.f.mjs +0 -99
- package/html/module.f.mjs +0 -102
- package/js/tokenizer/module.f.mjs +0 -872
- package/json/module.f.mjs +0 -89
- package/json/serializer/module.f.mjs +0 -87
- package/jsr.json +0 -66
- package/nodejs/version/module.f.mjs +0 -47
- package/out/com/cpp/module.f.d.mts +0 -7
- package/out/com/cpp/module.f.mjs +0 -130
- package/out/com/cpp/test.f.d.mts +0 -2
- package/out/com/cpp/test.f.mjs +0 -40
- package/out/com/cpp/testlib.f.d.mts +0 -2
- package/out/com/cpp/testlib.f.mjs +0 -7
- package/out/com/cs/module.f.d.mts +0 -7
- package/out/com/cs/module.f.mjs +0 -104
- package/out/com/cs/test.f.d.mts +0 -2
- package/out/com/cs/test.f.mjs +0 -43
- package/out/com/cs/testlib.f.d.mts +0 -2
- package/out/com/cs/testlib.f.mjs +0 -7
- package/out/com/rust/module.f.d.mts +0 -23
- package/out/com/rust/module.f.mjs +0 -224
- package/out/com/rust/test.f.d.mts +0 -2
- package/out/com/rust/test.f.mjs +0 -123
- package/out/com/rust/testlib.f.d.mts +0 -2
- package/out/com/rust/testlib.f.mjs +0 -7
- package/out/com/test/build.d.mts +0 -1
- package/out/com/test/build.f.d.mts +0 -26
- package/out/com/test/build.f.mjs +0 -98
- package/out/com/test/build.mjs +0 -40
- package/out/com/types/module.f.d.mts +0 -23
- package/out/com/types/module.f.mjs +0 -51
- package/out/com/types/testlib.f.d.mts +0 -44
- package/out/com/types/testlib.f.mjs +0 -30
- package/out/commonjs/build/module.f.d.mts +0 -20
- package/out/commonjs/build/module.f.mjs +0 -107
- package/out/commonjs/build/test.f.d.mts +0 -3
- package/out/commonjs/build/test.f.mjs +0 -102
- package/out/commonjs/module/function/module.f.d.mts +0 -5
- package/out/commonjs/module/function/module.f.mjs +0 -15
- package/out/commonjs/module/module.f.d.mts +0 -52
- package/out/commonjs/module/module.f.mjs +0 -48
- package/out/commonjs/module.d.mts +0 -3
- package/out/commonjs/module.f.d.mts +0 -2
- package/out/commonjs/module.f.mjs +0 -10
- package/out/commonjs/module.mjs +0 -26
- package/out/commonjs/package/dependencies/module.f.d.mts +0 -6
- package/out/commonjs/package/dependencies/module.f.mjs +0 -21
- package/out/commonjs/package/dependencies/test.f.d.mts +0 -2
- package/out/commonjs/package/dependencies/test.f.mjs +0 -15
- package/out/commonjs/package/module.f.d.mts +0 -21
- package/out/commonjs/package/module.f.mjs +0 -40
- package/out/commonjs/package/test.f.d.mts +0 -2
- package/out/commonjs/package/test.f.mjs +0 -27
- package/out/commonjs/path/module.f.d.mts +0 -60
- package/out/commonjs/path/module.f.mjs +0 -171
- package/out/commonjs/path/test.f.d.mts +0 -25
- package/out/commonjs/path/test.f.mjs +0 -231
- package/out/commonjs/test.d.mts +0 -8
- package/out/commonjs/test.mjs +0 -87
- package/out/crypto/prime_field/module.f.d.mts +0 -67
- package/out/crypto/prime_field/module.f.mjs +0 -110
- package/out/crypto/prime_field/test.f.d.mts +0 -13
- package/out/crypto/prime_field/test.f.mjs +0 -152
- package/out/crypto/secp/module.f.d.mts +0 -110
- package/out/crypto/secp/module.f.mjs +0 -173
- package/out/crypto/secp/test.f.d.mts +0 -5
- package/out/crypto/secp/test.f.mjs +0 -78
- package/out/crypto/sha2/module.f.d.mts +0 -15
- package/out/crypto/sha2/module.f.mjs +0 -172
- package/out/crypto/sha2/test.f.d.mts +0 -10
- package/out/crypto/sha2/test.f.mjs +0 -86
- package/out/dev/index.d.mts +0 -1
- package/out/dev/index.mjs +0 -2
- package/out/dev/module.d.mts +0 -26
- package/out/dev/module.f.d.mts +0 -1
- package/out/dev/module.f.mjs +0 -2
- package/out/dev/module.mjs +0 -167
- package/out/dev/test/module.f.d.mts +0 -25
- package/out/dev/test/module.f.mjs +0 -134
- package/out/dev/test.d.mts +0 -3
- package/out/dev/test.f.d.mts +0 -9
- package/out/dev/test.f.mjs +0 -58
- package/out/dev/test.mjs +0 -52
- package/out/djs/module.f.d.mts +0 -20
- package/out/djs/module.f.mjs +0 -79
- package/out/djs/parser/module.f.d.mts +0 -56
- package/out/djs/parser/module.f.mjs +0 -448
- package/out/djs/parser/test.f.d.mts +0 -13
- package/out/djs/parser/test.f.mjs +0 -569
- package/out/djs/test.f.d.mts +0 -12
- package/out/djs/test.f.mjs +0 -84
- package/out/djs/tokenizer/module.f.d.mts +0 -13
- package/out/djs/tokenizer/module.f.mjs +0 -91
- package/out/djs/tokenizer/test.f.d.mts +0 -7
- package/out/djs/tokenizer/test.f.mjs +0 -530
- package/out/fsc/module.f.d.mts +0 -7
- package/out/fsc/module.f.mjs +0 -105
- package/out/fsc/test.f.d.mts +0 -4
- package/out/fsc/test.f.mjs +0 -19
- package/out/fsm/module.f.d.mts +0 -14
- package/out/fsm/module.f.mjs +0 -80
- package/out/fsm/test.f.d.mts +0 -5
- package/out/fsm/test.f.mjs +0 -138
- package/out/html/module.f.d.mts +0 -17
- package/out/html/module.f.mjs +0 -80
- package/out/html/test.f.d.mts +0 -10
- package/out/html/test.f.mjs +0 -45
- package/out/issues/test.f.d.mts +0 -16
- package/out/issues/test.f.mjs +0 -66
- package/out/js/tokenizer/module.f.d.mts +0 -163
- package/out/js/tokenizer/module.f.mjs +0 -729
- package/out/js/tokenizer/test.f.d.mts +0 -9
- package/out/js/tokenizer/test.f.mjs +0 -906
- package/out/json/module.f.d.mts +0 -33
- package/out/json/module.f.mjs +0 -89
- package/out/json/parser/module.f.d.mts +0 -32
- package/out/json/parser/module.f.mjs +0 -224
- package/out/json/parser/test.f.d.mts +0 -5
- package/out/json/parser/test.f.mjs +0 -329
- package/out/json/serializer/module.f.d.mts +0 -36
- package/out/json/serializer/module.f.mjs +0 -67
- package/out/json/serializer/test.f.d.mts +0 -8
- package/out/json/serializer/test.f.mjs +0 -87
- package/out/json/test.f.d.mts +0 -8
- package/out/json/test.f.mjs +0 -61
- package/out/json/tokenizer/module.f.d.mts +0 -13
- package/out/json/tokenizer/module.f.mjs +0 -78
- package/out/json/tokenizer/test.f.d.mts +0 -6
- package/out/json/tokenizer/test.f.mjs +0 -420
- package/out/nanvm-lib/tests/test.f.d.mts +0 -36
- package/out/nanvm-lib/tests/test.f.mjs +0 -87
- package/out/nodejs/version/main.d.mts +0 -1
- package/out/nodejs/version/main.mjs +0 -3
- package/out/nodejs/version/module.f.d.mts +0 -12
- package/out/nodejs/version/module.f.mjs +0 -34
- package/out/nodejs/version/test.f.d.mts +0 -2
- package/out/nodejs/version/test.f.mjs +0 -97
- package/out/text/ascii/module.f.d.mts +0 -70
- package/out/text/ascii/module.f.mjs +0 -154
- package/out/text/ascii/test.f.d.mts +0 -4
- package/out/text/ascii/test.f.mjs +0 -14
- package/out/text/module.f.d.mts +0 -13
- package/out/text/module.f.mjs +0 -19
- package/out/text/sgr/module.f.d.mts +0 -12
- package/out/text/sgr/module.f.mjs +0 -17
- package/out/text/test.f.d.mts +0 -2
- package/out/text/test.f.mjs +0 -19
- package/out/text/utf16/module.f.d.mts +0 -12
- package/out/text/utf16/module.f.mjs +0 -86
- package/out/text/utf16/test.f.d.mts +0 -6
- package/out/text/utf16/test.f.mjs +0 -145
- package/out/text/utf8/module.f.d.mts +0 -10
- package/out/text/utf8/module.f.mjs +0 -126
- package/out/text/utf8/test.f.d.mts +0 -6
- package/out/text/utf8/test.f.mjs +0 -175
- package/out/types/array/module.f.d.mts +0 -31
- package/out/types/array/module.f.mjs +0 -95
- package/out/types/array/test.f.d.mts +0 -10
- package/out/types/array/test.f.mjs +0 -116
- package/out/types/bigfloat/module.f.d.mts +0 -6
- package/out/types/bigfloat/module.f.mjs +0 -77
- package/out/types/bigfloat/test.f.d.mts +0 -6
- package/out/types/bigfloat/test.f.mjs +0 -349
- package/out/types/bigint/module.f.d.mts +0 -29
- package/out/types/bigint/module.f.mjs +0 -114
- package/out/types/bigint/test.f.d.mts +0 -16
- package/out/types/bigint/test.f.mjs +0 -199
- package/out/types/bit_vec/module.f.d.mts +0 -158
- package/out/types/bit_vec/module.f.mjs +0 -194
- package/out/types/bit_vec/test.f.d.mts +0 -23
- package/out/types/bit_vec/test.f.mjs +0 -210
- package/out/types/btree/find/module.f.d.mts +0 -36
- package/out/types/btree/find/module.f.mjs +0 -137
- package/out/types/btree/find/test.f.d.mts +0 -2
- package/out/types/btree/find/test.f.mjs +0 -156
- package/out/types/btree/module.f.d.mts +0 -5
- package/out/types/btree/module.f.mjs +0 -34
- package/out/types/btree/remove/module.f.d.mts +0 -14
- package/out/types/btree/remove/module.f.mjs +0 -209
- package/out/types/btree/remove/test.f.d.mts +0 -7
- package/out/types/btree/remove/test.f.mjs +0 -638
- package/out/types/btree/set/module.f.d.mts +0 -5
- package/out/types/btree/set/module.f.mjs +0 -114
- package/out/types/btree/set/test.f.d.mts +0 -2
- package/out/types/btree/set/test.f.mjs +0 -390
- package/out/types/btree/test.f.d.mts +0 -13
- package/out/types/btree/test.f.mjs +0 -83
- package/out/types/btree/types/module.f.d.mts +0 -14
- package/out/types/btree/types/module.f.mjs +0 -50
- package/out/types/byte_set/module.f.d.mts +0 -25
- package/out/types/byte_set/module.f.mjs +0 -42
- package/out/types/byte_set/test.f.d.mts +0 -13
- package/out/types/byte_set/test.f.mjs +0 -123
- package/out/types/function/compare/module.f.d.mts +0 -23
- package/out/types/function/compare/module.f.mjs +0 -22
- package/out/types/function/compare/test.f.d.mts +0 -2
- package/out/types/function/compare/test.f.mjs +0 -8
- package/out/types/function/module.f.d.mts +0 -51
- package/out/types/function/module.f.mjs +0 -44
- package/out/types/function/operator/module.f.d.mts +0 -60
- package/out/types/function/operator/module.f.mjs +0 -60
- package/out/types/function/test.f.d.mts +0 -2
- package/out/types/function/test.f.mjs +0 -15
- package/out/types/list/module.f.d.mts +0 -82
- package/out/types/list/module.f.mjs +0 -269
- package/out/types/list/test.f.d.mts +0 -38
- package/out/types/list/test.f.mjs +0 -401
- package/out/types/map/module.f.d.mts +0 -21
- package/out/types/map/module.f.mjs +0 -54
- package/out/types/map/test.f.d.mts +0 -5
- package/out/types/map/test.f.mjs +0 -115
- package/out/types/nibble_set/module.f.d.mts +0 -16
- package/out/types/nibble_set/module.f.mjs +0 -19
- package/out/types/nibble_set/test.f.d.mts +0 -13
- package/out/types/nibble_set/test.f.mjs +0 -90
- package/out/types/nullable/module.f.d.mts +0 -9
- package/out/types/nullable/module.f.mjs +0 -9
- package/out/types/nullable/test.f.d.mts +0 -2
- package/out/types/nullable/test.f.mjs +0 -12
- package/out/types/number/module.f.d.mts +0 -7
- package/out/types/number/module.f.mjs +0 -12
- package/out/types/number/test.f.d.mts +0 -11
- package/out/types/number/test.f.mjs +0 -126
- package/out/types/object/module.f.d.mts +0 -22
- package/out/types/object/module.f.mjs +0 -27
- package/out/types/object/test.f.d.mts +0 -5
- package/out/types/object/test.f.mjs +0 -17
- package/out/types/range/module.f.d.mts +0 -6
- package/out/types/range/module.f.mjs +0 -6
- package/out/types/range/test.f.d.mts +0 -2
- package/out/types/range/test.f.mjs +0 -18
- package/out/types/range_map/module.f.d.mts +0 -19
- package/out/types/range_map/module.f.mjs +0 -84
- package/out/types/range_map/test.f.d.mts +0 -6
- package/out/types/range_map/test.f.mjs +0 -201
- package/out/types/result/module.d.mts +0 -7
- package/out/types/result/module.f.d.mts +0 -22
- package/out/types/result/module.f.mjs +0 -25
- package/out/types/result/module.mjs +0 -16
- package/out/types/sorted_list/module.f.d.mts +0 -53
- package/out/types/sorted_list/module.f.mjs +0 -102
- package/out/types/sorted_list/test.f.d.mts +0 -5
- package/out/types/sorted_list/test.f.mjs +0 -66
- package/out/types/sorted_set/module.f.d.mts +0 -19
- package/out/types/sorted_set/module.f.mjs +0 -29
- package/out/types/sorted_set/test.f.d.mts +0 -6
- package/out/types/sorted_set/test.f.mjs +0 -80
- package/out/types/string/module.f.d.mts +0 -9
- package/out/types/string/module.f.mjs +0 -17
- package/out/types/string/test.f.d.mts +0 -15
- package/out/types/string/test.f.mjs +0 -58
- package/out/types/string_set/module.f.d.mts +0 -13
- package/out/types/string_set/module.f.mjs +0 -29
- package/out/types/string_set/test.f.d.mts +0 -5
- package/out/types/string_set/test.f.mjs +0 -65
- package/text/module.f.mjs +0 -27
- package/text/utf16/module.f.mjs +0 -96
- package/types/array/module.f.mjs +0 -119
- package/types/btree/find/module.f.mjs +0 -125
- package/types/btree/types/module.f.mjs +0 -64
- package/types/byte_set/module.f.mjs +0 -61
- package/types/function/compare/module.f.mjs +0 -29
- package/types/function/module.f.mjs +0 -50
- package/types/function/operator/module.f.mjs +0 -78
- package/types/function/test.f.mjs +0 -17
- package/types/list/module.f.mjs +0 -320
- package/types/map/module.f.mjs +0 -67
- package/types/nibble_set/module.f.mjs +0 -28
- package/types/nullable/module.f.mjs +0 -11
- package/types/number/module.f.mjs +0 -16
- package/types/object/module.f.mjs +0 -33
- package/types/range/module.f.mjs +0 -8
- package/types/range_map/module.f.mjs +0 -84
- package/types/result/module.f.mjs +0 -28
- package/types/sorted_list/module.f.mjs +0 -107
- package/types/sorted_set/module.f.mjs +0 -38
- package/types/string/module.f.mjs +0 -22
- package/types/string_set/module.f.mjs +0 -36
|
@@ -0,0 +1,882 @@
|
|
|
1
|
+
import * as operator from '../../types/function/operator/module.f.ts'
|
|
2
|
+
import * as range_map from '../../types/range_map/module.f.ts'
|
|
3
|
+
const { merge, fromRange, get } = range_map
|
|
4
|
+
import * as list from '../../types/list/module.f.ts'
|
|
5
|
+
import * as map from '../../types/map/module.f.ts'
|
|
6
|
+
const { at } = map
|
|
7
|
+
import * as _range from '../../types/range/module.f.ts'
|
|
8
|
+
const { one } = _range
|
|
9
|
+
const { empty, stateScan, flat, toArray, reduce: listReduce, scan } = list
|
|
10
|
+
import * as bigfloatT from '../../types/bigfloat/module.f.ts'
|
|
11
|
+
const { fromCharCode } = String
|
|
12
|
+
import * as ascii from '../../text/ascii/module.f.ts'
|
|
13
|
+
const { range } = ascii
|
|
14
|
+
const {
|
|
15
|
+
//
|
|
16
|
+
backspace,
|
|
17
|
+
ht,
|
|
18
|
+
lf,
|
|
19
|
+
ff,
|
|
20
|
+
cr,
|
|
21
|
+
//
|
|
22
|
+
exclamationMark,
|
|
23
|
+
percentSign,
|
|
24
|
+
ampersand,
|
|
25
|
+
asterisk,
|
|
26
|
+
lessThanSign,
|
|
27
|
+
equalsSign,
|
|
28
|
+
greaterThanSign,
|
|
29
|
+
questionMark,
|
|
30
|
+
circumflexAccent,
|
|
31
|
+
verticalLine,
|
|
32
|
+
tilde,
|
|
33
|
+
//
|
|
34
|
+
space,
|
|
35
|
+
quotationMark,
|
|
36
|
+
leftParenthesis,
|
|
37
|
+
rightParenthesis,
|
|
38
|
+
plusSign,
|
|
39
|
+
comma,
|
|
40
|
+
hyphenMinus,
|
|
41
|
+
fullStop,
|
|
42
|
+
solidus,
|
|
43
|
+
//
|
|
44
|
+
digitRange,
|
|
45
|
+
digit0,
|
|
46
|
+
colon,
|
|
47
|
+
//
|
|
48
|
+
latinCapitalLetterRange,
|
|
49
|
+
latinCapitalLetterA,
|
|
50
|
+
latinCapitalLetterE,
|
|
51
|
+
//
|
|
52
|
+
leftSquareBracket,
|
|
53
|
+
reverseSolidus,
|
|
54
|
+
rightSquareBracket,
|
|
55
|
+
lowLine,
|
|
56
|
+
//
|
|
57
|
+
latinSmallLetterRange,
|
|
58
|
+
latinSmallLetterA,
|
|
59
|
+
latinSmallLetterB,
|
|
60
|
+
latinSmallLetterE,
|
|
61
|
+
latinSmallLetterF,
|
|
62
|
+
latinSmallLetterN,
|
|
63
|
+
latinSmallLetterR,
|
|
64
|
+
latinSmallLetterT,
|
|
65
|
+
latinSmallLetterU,
|
|
66
|
+
//
|
|
67
|
+
leftCurlyBracket,
|
|
68
|
+
rightCurlyBracket,
|
|
69
|
+
dollarSign
|
|
70
|
+
} = ascii.ascii
|
|
71
|
+
|
|
72
|
+
export type StringToken = {
|
|
73
|
+
readonly kind: 'string'
|
|
74
|
+
readonly value: string
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export type NumberToken = {
|
|
78
|
+
readonly kind: 'number'
|
|
79
|
+
readonly value: string
|
|
80
|
+
readonly bf: bigfloatT.BigFloat
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export type BigIntToken = {
|
|
84
|
+
readonly kind: 'bigint'
|
|
85
|
+
readonly value: bigint
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export type ErrorToken = {readonly kind: 'error', message: ErrorMessage}
|
|
89
|
+
|
|
90
|
+
export type WhitespaceToken = {readonly kind: 'ws'}
|
|
91
|
+
|
|
92
|
+
export type NewLineToken = {readonly kind: 'nl'}
|
|
93
|
+
|
|
94
|
+
type TrueToken = {readonly kind: 'true'}
|
|
95
|
+
|
|
96
|
+
type FalseToken = {readonly kind: 'false'}
|
|
97
|
+
|
|
98
|
+
type NullToken = {readonly kind: 'null'}
|
|
99
|
+
|
|
100
|
+
type UndefinedToken = {readonly kind: 'undefined'}
|
|
101
|
+
|
|
102
|
+
type KeywordToken = |
|
|
103
|
+
{readonly kind: 'arguments' | 'await' | 'break' | 'case' | 'catch' | 'class' | 'const' | 'continue' } |
|
|
104
|
+
{readonly kind: 'debugger' | 'default' | 'delete' | 'do' | 'else' | 'enum' | 'eval' | 'export' } |
|
|
105
|
+
{readonly kind: 'extends' | 'finally' | 'for' | 'function' | 'if' | 'implements' | 'import' | 'in' } |
|
|
106
|
+
{readonly kind: 'instanceof' | 'interface' | 'let' | 'new' | 'package' | 'private' | 'protected' | 'public' } |
|
|
107
|
+
{readonly kind: 'return' | 'static' | 'super' | 'switch' | 'this' | 'throw' | 'try' | 'typeof' } |
|
|
108
|
+
{readonly kind: 'var' | 'void' | 'while' | 'with' | 'yield' }
|
|
109
|
+
|
|
110
|
+
export type IdToken = {
|
|
111
|
+
readonly kind: 'id'
|
|
112
|
+
readonly value: string
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
type OperatorToken =|
|
|
116
|
+
{readonly kind: '{' | '}' | ':' | ',' | '[' | ']' } |
|
|
117
|
+
{readonly kind: '.' | '=' } |
|
|
118
|
+
{readonly kind: '(' | ')' } |
|
|
119
|
+
{readonly kind: '==' | '!=' | '===' | '!==' | '>' | '>=' | '<' | '<=' } |
|
|
120
|
+
{readonly kind: '+' | '-' | '*' | '/' | '%' | '++' | '--' | '**' } |
|
|
121
|
+
{readonly kind: '+=' | '-=' | '*=' | '/=' | '%=' | '**='} |
|
|
122
|
+
{readonly kind: '&' | '|' | '^' | '~' | '<<' | '>>' | '>>>' } |
|
|
123
|
+
{readonly kind: '&=' | '|=' | '^=' | '<<=' | '>>=' | '>>>='} |
|
|
124
|
+
{readonly kind: '&&' | '||' | '!' | '??' } |
|
|
125
|
+
{readonly kind: '&&=' | '||=' | '??=' } |
|
|
126
|
+
{readonly kind: '?' | '?.' | '=>'}
|
|
127
|
+
|
|
128
|
+
export type CommentToken = {
|
|
129
|
+
readonly kind: '//' | '/*'
|
|
130
|
+
readonly value: string
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export type JsToken = |
|
|
134
|
+
KeywordToken |
|
|
135
|
+
TrueToken |
|
|
136
|
+
FalseToken |
|
|
137
|
+
NullToken |
|
|
138
|
+
WhitespaceToken |
|
|
139
|
+
NewLineToken |
|
|
140
|
+
StringToken |
|
|
141
|
+
NumberToken |
|
|
142
|
+
ErrorToken |
|
|
143
|
+
IdToken |
|
|
144
|
+
BigIntToken |
|
|
145
|
+
UndefinedToken |
|
|
146
|
+
OperatorToken |
|
|
147
|
+
CommentToken
|
|
148
|
+
|
|
149
|
+
const rangeOneNine = range('19')
|
|
150
|
+
|
|
151
|
+
const rangeSetNewLine = [
|
|
152
|
+
one(lf),
|
|
153
|
+
one(cr)
|
|
154
|
+
]
|
|
155
|
+
|
|
156
|
+
const rangeSetWhiteSpace = [
|
|
157
|
+
one(ht),
|
|
158
|
+
one(space)
|
|
159
|
+
]
|
|
160
|
+
|
|
161
|
+
const rangeSetTerminalForNumber = [
|
|
162
|
+
...rangeSetWhiteSpace,
|
|
163
|
+
...rangeSetNewLine,
|
|
164
|
+
one(exclamationMark),
|
|
165
|
+
one(percentSign),
|
|
166
|
+
one(ampersand),
|
|
167
|
+
one(leftParenthesis),
|
|
168
|
+
one(rightParenthesis),
|
|
169
|
+
one(asterisk),
|
|
170
|
+
one(comma),
|
|
171
|
+
one(solidus),
|
|
172
|
+
one(colon),
|
|
173
|
+
one(lessThanSign),
|
|
174
|
+
one(equalsSign),
|
|
175
|
+
one(greaterThanSign),
|
|
176
|
+
one(questionMark),
|
|
177
|
+
one(circumflexAccent),
|
|
178
|
+
one(leftSquareBracket),
|
|
179
|
+
one(rightSquareBracket),
|
|
180
|
+
one(leftCurlyBracket),
|
|
181
|
+
one(verticalLine),
|
|
182
|
+
one(rightCurlyBracket),
|
|
183
|
+
one(tilde),
|
|
184
|
+
]
|
|
185
|
+
|
|
186
|
+
const rangeSmallAF = range('af')
|
|
187
|
+
const rangeCapitalAF = range('AF')
|
|
188
|
+
|
|
189
|
+
const rangeIdStart = [
|
|
190
|
+
latinSmallLetterRange,
|
|
191
|
+
latinCapitalLetterRange,
|
|
192
|
+
one(lowLine),
|
|
193
|
+
one(dollarSign)
|
|
194
|
+
]
|
|
195
|
+
|
|
196
|
+
const rangeOpStart = [
|
|
197
|
+
one(exclamationMark),
|
|
198
|
+
one(percentSign),
|
|
199
|
+
one(ampersand),
|
|
200
|
+
one(leftParenthesis),
|
|
201
|
+
one(rightParenthesis),
|
|
202
|
+
one(asterisk),
|
|
203
|
+
one(plusSign),
|
|
204
|
+
one(comma),
|
|
205
|
+
one(hyphenMinus),
|
|
206
|
+
one(fullStop),
|
|
207
|
+
one(solidus),
|
|
208
|
+
one(colon),
|
|
209
|
+
one(lessThanSign),
|
|
210
|
+
one(equalsSign),
|
|
211
|
+
one(greaterThanSign),
|
|
212
|
+
one(questionMark),
|
|
213
|
+
one(circumflexAccent),
|
|
214
|
+
one(leftSquareBracket),
|
|
215
|
+
one(rightSquareBracket),
|
|
216
|
+
one(leftCurlyBracket),
|
|
217
|
+
one(verticalLine),
|
|
218
|
+
one(rightCurlyBracket),
|
|
219
|
+
one(tilde)
|
|
220
|
+
]
|
|
221
|
+
|
|
222
|
+
const rangeId = [digitRange, ...rangeIdStart]
|
|
223
|
+
|
|
224
|
+
type TokenizerState = |
|
|
225
|
+
InitialState |
|
|
226
|
+
ParseIdState |
|
|
227
|
+
ParseStringState |
|
|
228
|
+
ParseEscapeCharState |
|
|
229
|
+
ParseUnicodeCharState |
|
|
230
|
+
ParseNumberState |
|
|
231
|
+
InvalidNumberState |
|
|
232
|
+
ParseOperatorState |
|
|
233
|
+
ParseWhitespaceState |
|
|
234
|
+
ParseNewLineState |
|
|
235
|
+
ParseCommentState |
|
|
236
|
+
EofState
|
|
237
|
+
|
|
238
|
+
type ErrorMessage = |
|
|
239
|
+
'" are missing' |
|
|
240
|
+
'unescaped character' |
|
|
241
|
+
'invalid hex value' |
|
|
242
|
+
'unexpected character' |
|
|
243
|
+
'invalid number' |
|
|
244
|
+
'invalid token' |
|
|
245
|
+
'*\/ expected' |
|
|
246
|
+
'unterminated string literal' |
|
|
247
|
+
'eof'
|
|
248
|
+
|
|
249
|
+
type InitialState = { readonly kind: 'initial'}
|
|
250
|
+
|
|
251
|
+
type ParseIdState = { readonly kind: 'id', readonly value: string}
|
|
252
|
+
|
|
253
|
+
type ParseWhitespaceState = { readonly kind: 'ws'}
|
|
254
|
+
|
|
255
|
+
type ParseNewLineState = { readonly kind: 'nl'}
|
|
256
|
+
|
|
257
|
+
type ParseStringState = { readonly kind: 'string', readonly value: string}
|
|
258
|
+
|
|
259
|
+
type ParseEscapeCharState = { readonly kind: 'escapeChar', readonly value: string}
|
|
260
|
+
|
|
261
|
+
type ParseOperatorState = { readonly kind: 'op', readonly value: string}
|
|
262
|
+
|
|
263
|
+
type ParseMinusState = { readonly kind: '-'}
|
|
264
|
+
|
|
265
|
+
type ParseCommentState = {
|
|
266
|
+
readonly kind: '//' | '/*' | '/**'
|
|
267
|
+
readonly value: string
|
|
268
|
+
readonly newLine: boolean
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
type ParseUnicodeCharState = {
|
|
272
|
+
readonly kind: 'unicodeChar'
|
|
273
|
+
readonly value: string
|
|
274
|
+
readonly unicode: number
|
|
275
|
+
readonly hexIndex: number
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
type ParseNumberState = {
|
|
279
|
+
readonly kind: 'number'
|
|
280
|
+
readonly numberKind: '0' | 'int' | '.' | 'fractional' | 'e' | 'e+' | 'e-' | 'expDigits' | 'bigint'
|
|
281
|
+
readonly value: string
|
|
282
|
+
readonly b: ParseNumberBuffer
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
type ParseNumberBuffer = {
|
|
286
|
+
readonly s: -1n | 1n
|
|
287
|
+
readonly m: bigint
|
|
288
|
+
readonly f: number
|
|
289
|
+
readonly es: -1 | 1
|
|
290
|
+
readonly e: number
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
type InvalidNumberState = { readonly kind: 'invalidNumber'}
|
|
294
|
+
|
|
295
|
+
type EofState = { readonly kind: 'eof'}
|
|
296
|
+
|
|
297
|
+
type CharCodeOrEof = number|null
|
|
298
|
+
|
|
299
|
+
type ToToken = (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
300
|
+
|
|
301
|
+
type CreateToToken<T> = (state: T) => ToToken
|
|
302
|
+
|
|
303
|
+
type RangeSet = list.List<_range.Range>
|
|
304
|
+
|
|
305
|
+
type RangeFunc<T> = (def: CreateToToken<T>) => (RangeMapToToken<T>)
|
|
306
|
+
|
|
307
|
+
type RangeMapToToken<T> = range_map.RangeMapArray<CreateToToken<T>>
|
|
308
|
+
|
|
309
|
+
const appendChar
|
|
310
|
+
: (old: string) => (input: number) => string
|
|
311
|
+
= old => input => `${old}${fromCharCode(input)}`
|
|
312
|
+
|
|
313
|
+
const union
|
|
314
|
+
: <T>(def: CreateToToken<T>) => (a: CreateToToken<T>) => (b: CreateToToken<T>) => CreateToToken<T>
|
|
315
|
+
= def => a => b => {
|
|
316
|
+
if (a === def || a === b) { return b }
|
|
317
|
+
if (b === def) { return a }
|
|
318
|
+
throw [a, b]
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const rangeMapMerge
|
|
322
|
+
: <T>(def: CreateToToken<T>) => range_map.RangeMerge<CreateToToken<T>>
|
|
323
|
+
= def => merge({
|
|
324
|
+
union: union(def),
|
|
325
|
+
equal: operator.strictEqual,
|
|
326
|
+
})
|
|
327
|
+
|
|
328
|
+
const rangeFunc
|
|
329
|
+
: <T>(r: _range.Range) => (f: CreateToToken<T>) => RangeFunc<T>
|
|
330
|
+
= r => f => def => fromRange(def)(r)(f)
|
|
331
|
+
|
|
332
|
+
const scanRangeOp
|
|
333
|
+
: <T>(def: CreateToToken<T>) => (operator.Scan<RangeFunc<T>, RangeMapToToken<T>>)
|
|
334
|
+
= def => f => [f(def), scanRangeOp(def)]
|
|
335
|
+
|
|
336
|
+
const reduceRangeMap
|
|
337
|
+
: <T>(def: CreateToToken<T>) => (a: list.List<RangeFunc<T>>) => RangeMapToToken<T>
|
|
338
|
+
= def => a => {
|
|
339
|
+
const rm = scan(scanRangeOp(def))(a)
|
|
340
|
+
return toArray(listReduce(rangeMapMerge(def))(empty)(rm))
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
const scanRangeSetOp
|
|
344
|
+
: <T>(def: CreateToToken<T>) => (f: CreateToToken<T>) => (operator.Scan<_range.Range, RangeMapToToken<T>>)
|
|
345
|
+
= def => f => r => [fromRange(def)(r)(f), scanRangeSetOp(def)(f)]
|
|
346
|
+
|
|
347
|
+
const rangeSetFunc
|
|
348
|
+
: <T>(rs: list.List<_range.Range>) => (f: CreateToToken<T>) => RangeFunc<T>
|
|
349
|
+
= rs => f => def => {
|
|
350
|
+
const rm = scan(scanRangeSetOp(def)(f))(rs)
|
|
351
|
+
return toArray(listReduce(rangeMapMerge(def))(empty)(rm))
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const create = <T>(def: CreateToToken<T>) => (a: list.List<RangeFunc<T>>): CreateToToken<T> => {
|
|
355
|
+
const i = reduceRangeMap(def)(a)
|
|
356
|
+
const x
|
|
357
|
+
: (v: number) => (i: RangeMapToToken<T>) => (v: T) => ToToken
|
|
358
|
+
= get(def)
|
|
359
|
+
return v => c => x(c)(i)(v)(c)
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const digitToBigInt
|
|
363
|
+
: (digit: number) => bigint
|
|
364
|
+
= d => BigInt(d - digit0)
|
|
365
|
+
|
|
366
|
+
const startNumber
|
|
367
|
+
: (digit: number) => ParseNumberBuffer
|
|
368
|
+
= digit => ({ s: 1n, m: digitToBigInt(digit), f: 0, es: 1, e: 0 })
|
|
369
|
+
|
|
370
|
+
const startNegativeNumber
|
|
371
|
+
: ParseNumberBuffer
|
|
372
|
+
= { s: -1n, m: 0n, f: 0, es: 1, e: 0 }
|
|
373
|
+
|
|
374
|
+
const addIntDigit
|
|
375
|
+
: (digit: number) => (b: ParseNumberBuffer) => ParseNumberBuffer
|
|
376
|
+
= digit => b => ({ ... b, m: b.m * 10n + digitToBigInt(digit)})
|
|
377
|
+
|
|
378
|
+
const addFracDigit
|
|
379
|
+
: (digit: number) => (b: ParseNumberBuffer) => ParseNumberBuffer
|
|
380
|
+
= digit => b => ({ ... b, m: b.m * 10n + digitToBigInt(digit), f: b.f - 1})
|
|
381
|
+
|
|
382
|
+
const addExpDigit
|
|
383
|
+
: (digit: number) => (b: ParseNumberBuffer) => ParseNumberBuffer
|
|
384
|
+
= digit => b => ({ ... b, e: b.e * 10 + digit - digit0})
|
|
385
|
+
|
|
386
|
+
const bufferToNumberToken
|
|
387
|
+
: (s: ParseNumberState) => JsToken
|
|
388
|
+
= ({numberKind, value, b}) =>
|
|
389
|
+
{
|
|
390
|
+
if (numberKind === 'bigint')
|
|
391
|
+
return { kind: 'bigint', value: b.s * b.m }
|
|
392
|
+
return { kind: 'number', value: value, bf: [b.s * b.m, b.f + b.es * b.e] }
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#keywords
|
|
397
|
+
*/
|
|
398
|
+
const keywordEntries
|
|
399
|
+
: list.List<map.Entry<JsToken>>
|
|
400
|
+
= [
|
|
401
|
+
['arguments', { kind: 'arguments'}],
|
|
402
|
+
['await', { kind: 'await'}],
|
|
403
|
+
['break', { kind: 'break'}],
|
|
404
|
+
['case', { kind: 'case'}],
|
|
405
|
+
['catch', { kind: 'catch'}],
|
|
406
|
+
['class', { kind: 'class'}],
|
|
407
|
+
['const', { kind: 'const'}],
|
|
408
|
+
['continue', { kind: 'continue'}],
|
|
409
|
+
['debugger', { kind: 'debugger'}],
|
|
410
|
+
['default', { kind: 'default'}],
|
|
411
|
+
['delete', { kind: 'delete'}],
|
|
412
|
+
['do', { kind: 'do'}],
|
|
413
|
+
['else', { kind: 'else'}],
|
|
414
|
+
['enum', { kind: 'enum'}],
|
|
415
|
+
['eval', { kind: 'eval'}],
|
|
416
|
+
['export', { kind: 'export'}],
|
|
417
|
+
['extends', { kind: 'extends'}],
|
|
418
|
+
['false', { kind: 'false'}],
|
|
419
|
+
['finally', { kind: 'finally'}],
|
|
420
|
+
['for', { kind: 'for'}],
|
|
421
|
+
['function', { kind: 'function'}],
|
|
422
|
+
['if', { kind: 'if'}],
|
|
423
|
+
['implements', { kind: 'implements'}],
|
|
424
|
+
['import', { kind: 'import'}],
|
|
425
|
+
['in', { kind: 'in'}],
|
|
426
|
+
['instanceof', { kind: 'instanceof'}],
|
|
427
|
+
['interface', { kind: 'interface'}],
|
|
428
|
+
['let', { kind: 'let'}],
|
|
429
|
+
['new', { kind: 'new'}],
|
|
430
|
+
['null', { kind: 'null'}],
|
|
431
|
+
['package', { kind: 'package'}],
|
|
432
|
+
['private', { kind: 'private'}],
|
|
433
|
+
['protected', { kind: 'protected'}],
|
|
434
|
+
['public', { kind: 'public'}],
|
|
435
|
+
['return', { kind: 'return'}],
|
|
436
|
+
['static', { kind: 'static'}],
|
|
437
|
+
['super', { kind: 'super'}],
|
|
438
|
+
['switch', { kind: 'switch'}],
|
|
439
|
+
['this', { kind: 'this'}],
|
|
440
|
+
['throw', { kind: 'throw'}],
|
|
441
|
+
['true', { kind: 'true'}],
|
|
442
|
+
['try', { kind: 'try'}],
|
|
443
|
+
['typeof', { kind: 'typeof'}],
|
|
444
|
+
['undefined', { kind: 'undefined'}],
|
|
445
|
+
['var', { kind: 'var'}],
|
|
446
|
+
['void', { kind: 'void'}],
|
|
447
|
+
['while', { kind: 'while'}],
|
|
448
|
+
['with', { kind: 'with'}],
|
|
449
|
+
['yield', { kind: 'yield'}],
|
|
450
|
+
]
|
|
451
|
+
|
|
452
|
+
const keywordMap = map.fromEntries(keywordEntries)
|
|
453
|
+
|
|
454
|
+
export const isKeywordToken
|
|
455
|
+
: (token: JsToken) => Boolean
|
|
456
|
+
= token => at(token.kind)(keywordMap) !== null
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators
|
|
460
|
+
*/
|
|
461
|
+
const operatorEntries
|
|
462
|
+
: list.List<map.Entry<JsToken>>
|
|
463
|
+
= [
|
|
464
|
+
['!', { kind: '!'}],
|
|
465
|
+
['!=', { kind: '!='}],
|
|
466
|
+
['!==', { kind: '!=='}],
|
|
467
|
+
['%', { kind: '%'}],
|
|
468
|
+
['%=', { kind: '%='}],
|
|
469
|
+
['&', { kind: '&'}],
|
|
470
|
+
['&&', { kind: '&&'}],
|
|
471
|
+
['&&=', { kind: '&&='}],
|
|
472
|
+
['&=', { kind: '&='}],
|
|
473
|
+
['(', { kind: '('}],
|
|
474
|
+
[')', { kind: ')'}],
|
|
475
|
+
['*', { kind: '*'}],
|
|
476
|
+
['**', { kind: '**'}],
|
|
477
|
+
['**=', { kind: '**='}],
|
|
478
|
+
['*=', { kind: '*='}],
|
|
479
|
+
['+', { kind: '+'}],
|
|
480
|
+
['++', { kind: '++'}],
|
|
481
|
+
['+=', { kind: '+='}],
|
|
482
|
+
[',', { kind: ','}],
|
|
483
|
+
['-', { kind: '-'}],
|
|
484
|
+
['--', { kind: '--'}],
|
|
485
|
+
['-=', { kind: '-='}],
|
|
486
|
+
['.', { kind: '.'}],
|
|
487
|
+
['/', { kind: '/'}],
|
|
488
|
+
['/=', { kind: '/='}],
|
|
489
|
+
[':', { kind: ':'}],
|
|
490
|
+
['<', { kind: '<'}],
|
|
491
|
+
['<<', { kind: '<<'}],
|
|
492
|
+
['<<=', { kind: '<<='}],
|
|
493
|
+
['<=', {kind: '<='}],
|
|
494
|
+
['=', { kind: '='}],
|
|
495
|
+
['==', { kind: '=='}],
|
|
496
|
+
['===', { kind: '==='}],
|
|
497
|
+
['=>', {kind: '=>'}],
|
|
498
|
+
['>', { kind: '>'}],
|
|
499
|
+
['>=', { kind: '>='}],
|
|
500
|
+
['>>', { kind: '>>'}],
|
|
501
|
+
['>>=', {kind: '>>='}],
|
|
502
|
+
['>>>', {kind: '>>>'}],
|
|
503
|
+
['>>>=', {kind: '>>>='}],
|
|
504
|
+
['?', { kind: '?'}],
|
|
505
|
+
['?.', { kind: '?.'}],
|
|
506
|
+
['??', { kind: '??'}],
|
|
507
|
+
['??=', { kind: '??='}],
|
|
508
|
+
['^', { kind: '^'}],
|
|
509
|
+
['^=', { kind: '^='}],
|
|
510
|
+
['[', { kind: '['}],
|
|
511
|
+
[']', { kind: ']'}],
|
|
512
|
+
['{', { kind: '{'}],
|
|
513
|
+
['|', { kind: '|'}],
|
|
514
|
+
['|=', { kind: '|='}],
|
|
515
|
+
['||', { kind: '||'}],
|
|
516
|
+
['||=', { kind: '||='}],
|
|
517
|
+
['}', { kind: '}'}],
|
|
518
|
+
['~', { kind: '~' }]
|
|
519
|
+
]
|
|
520
|
+
|
|
521
|
+
const operatorMap = map.fromEntries(operatorEntries)
|
|
522
|
+
|
|
523
|
+
const getOperatorToken
|
|
524
|
+
: (op: string) => JsToken
|
|
525
|
+
= op => at(op)(operatorMap) ?? { kind: 'error', message: 'invalid token' }
|
|
526
|
+
|
|
527
|
+
const hasOperatorToken
|
|
528
|
+
: (op: string) => Boolean
|
|
529
|
+
= op => at(op)(operatorMap) !== null
|
|
530
|
+
|
|
531
|
+
const initialStateOp
|
|
532
|
+
: (state: InitialState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
533
|
+
= create((state: TokenizerState) => () => [[{ kind: 'error', message: 'unexpected character' }], state])([
|
|
534
|
+
rangeFunc<TokenizerState>(rangeOneNine)(() => input => [empty, { kind: 'number', value: fromCharCode(input), b: startNumber(input), numberKind: 'int' }]),
|
|
535
|
+
rangeSetFunc<TokenizerState>(rangeIdStart)(() => input => [empty, { kind: 'id', value: fromCharCode(input) }]),
|
|
536
|
+
rangeSetFunc<TokenizerState>(rangeSetWhiteSpace)(() => () => [empty, { kind: 'ws' }]),
|
|
537
|
+
rangeSetFunc<TokenizerState>(rangeSetNewLine)(() => () => [empty, { kind: 'nl' }]),
|
|
538
|
+
rangeFunc<TokenizerState>(one(quotationMark))(() => () => [empty, { kind: 'string', value: '' }]),
|
|
539
|
+
rangeFunc<TokenizerState>(one(digit0))(() => input => [empty, { kind: 'number', value: fromCharCode(input), b: startNumber(input), numberKind: '0' }]),
|
|
540
|
+
rangeSetFunc<TokenizerState>(rangeOpStart)(() => input => [empty, { kind: 'op', value: fromCharCode(input) }])
|
|
541
|
+
])
|
|
542
|
+
|
|
543
|
+
const invalidNumberToToken
|
|
544
|
+
: (state: ParseNumberState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
545
|
+
= () => input => {
|
|
546
|
+
const next = tokenizeOp({ kind: 'initial' })(input)
|
|
547
|
+
return [{ first: { kind: 'error', message: 'invalid number' }, tail: next[0] }, next[1]]
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
const fullStopToToken
|
|
551
|
+
: (state: ParseNumberState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
552
|
+
= state => input => {
|
|
553
|
+
switch (state.numberKind) {
|
|
554
|
+
case '0':
|
|
555
|
+
case 'int': return [empty, { kind: 'number', value: appendChar(state.value)(input), b: state.b, numberKind: '.' }]
|
|
556
|
+
default: return tokenizeOp({ kind: 'invalidNumber' })(input)
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
const digit0ToToken
|
|
561
|
+
: (state: ParseNumberState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
562
|
+
= state => input => {
|
|
563
|
+
switch (state.numberKind) {
|
|
564
|
+
case '0': return tokenizeOp({ kind: 'invalidNumber' })(input)
|
|
565
|
+
case '.':
|
|
566
|
+
case 'fractional': return [empty, { kind: 'number', value: appendChar(state.value)(input), b: addFracDigit(input)(state.b), numberKind: 'fractional' }]
|
|
567
|
+
case 'e':
|
|
568
|
+
case 'e+':
|
|
569
|
+
case 'e-':
|
|
570
|
+
case 'expDigits': return [empty, { kind: 'number', value: appendChar(state.value)(input), b: addExpDigit(input)(state.b), numberKind: 'expDigits' }]
|
|
571
|
+
default: return [empty, { kind: 'number', value: appendChar(state.value)(input), b: addIntDigit(input)(state.b), numberKind: state.numberKind }]
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
const digit19ToToken
|
|
576
|
+
: (state: ParseNumberState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
577
|
+
= state => input => {
|
|
578
|
+
switch (state.numberKind) {
|
|
579
|
+
case '0': return tokenizeOp({ kind: 'invalidNumber' })(input)
|
|
580
|
+
case '.':
|
|
581
|
+
case 'fractional': return [empty, { kind: 'number', value: appendChar(state.value)(input), b: addFracDigit(input)(state.b), numberKind: 'fractional' }]
|
|
582
|
+
case 'e':
|
|
583
|
+
case 'e+':
|
|
584
|
+
case 'e-':
|
|
585
|
+
case 'expDigits': return [empty, { kind: 'number', value: appendChar(state.value)(input), b: addExpDigit(input)(state.b), numberKind: 'expDigits' }]
|
|
586
|
+
default: return [empty, { kind: 'number', value: appendChar(state.value)(input), b: addIntDigit(input)(state.b), numberKind: 'int' }]
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
const expToToken
|
|
591
|
+
: (state: ParseNumberState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
592
|
+
= state => input => {
|
|
593
|
+
switch (state.numberKind) {
|
|
594
|
+
case '0':
|
|
595
|
+
case 'int':
|
|
596
|
+
case 'fractional': return [empty, { kind: 'number', value: appendChar(state.value)(input), b: state.b, numberKind: 'e' }]
|
|
597
|
+
default: return tokenizeOp({ kind: 'invalidNumber' })(input)
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
const hyphenMinusToToken
|
|
602
|
+
: (state: ParseNumberState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
603
|
+
= state => input => {
|
|
604
|
+
switch (state.numberKind) {
|
|
605
|
+
case 'e': return [empty, { kind: 'number', value: appendChar(state.value)(input), b: { ... state.b, es: -1}, numberKind: 'e-' }]
|
|
606
|
+
default: return terminalToToken(state)(input)
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
const plusSignToToken
|
|
611
|
+
: (state: ParseNumberState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
612
|
+
= state => input => {
|
|
613
|
+
switch (state.numberKind) {
|
|
614
|
+
case 'e': return [empty, { kind: 'number', value: appendChar(state.value)(input), b: state.b, numberKind: 'e+' }]
|
|
615
|
+
default: return tokenizeOp({ kind: 'invalidNumber' })(input)
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
const terminalToToken
|
|
620
|
+
: (state: ParseNumberState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
621
|
+
= state => input => {
|
|
622
|
+
switch (state.numberKind) {
|
|
623
|
+
case '.':
|
|
624
|
+
case 'e':
|
|
625
|
+
case 'e+':
|
|
626
|
+
case 'e-':
|
|
627
|
+
{
|
|
628
|
+
const next = tokenizeOp({ kind: 'initial' })(input)
|
|
629
|
+
return [{ first: { kind: 'error', message: 'invalid number' }, tail: next[0] }, next[1]]
|
|
630
|
+
}
|
|
631
|
+
default:
|
|
632
|
+
{
|
|
633
|
+
const next = tokenizeOp({ kind: 'initial' })(input)
|
|
634
|
+
return [{ first: bufferToNumberToken(state), tail: next[0] }, next[1]]
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
const bigintToToken
|
|
640
|
+
: (state: ParseNumberState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
641
|
+
= state => input => {
|
|
642
|
+
switch (state.numberKind) {
|
|
643
|
+
case '0':
|
|
644
|
+
case 'int':
|
|
645
|
+
{
|
|
646
|
+
return [empty, { kind: 'number', value: state.value, b: state.b, numberKind: 'bigint' }]
|
|
647
|
+
}
|
|
648
|
+
default:
|
|
649
|
+
{
|
|
650
|
+
const next = tokenizeOp({ kind: 'initial' })(input)
|
|
651
|
+
return [{ first: { kind: 'error', message: 'invalid number' }, tail: next[0] }, next[1]]
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
const parseNumberStateOp
|
|
657
|
+
: (state: ParseNumberState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
658
|
+
= create(invalidNumberToToken)([
|
|
659
|
+
rangeFunc<ParseNumberState>(one(fullStop))(fullStopToToken),
|
|
660
|
+
rangeFunc<ParseNumberState>(one(digit0))(digit0ToToken),
|
|
661
|
+
rangeFunc<ParseNumberState>(rangeOneNine)(digit19ToToken),
|
|
662
|
+
rangeSetFunc<ParseNumberState>([one(latinSmallLetterE), one(latinCapitalLetterE)])(expToToken),
|
|
663
|
+
rangeFunc<ParseNumberState>(one(hyphenMinus))(hyphenMinusToToken),
|
|
664
|
+
rangeFunc<ParseNumberState>(one(plusSign))(plusSignToToken),
|
|
665
|
+
rangeSetFunc<ParseNumberState>(rangeSetTerminalForNumber)(terminalToToken),
|
|
666
|
+
rangeFunc<ParseNumberState>(one(latinSmallLetterN))(bigintToToken),
|
|
667
|
+
])
|
|
668
|
+
|
|
669
|
+
const invalidNumberStateOp
|
|
670
|
+
: (state: InvalidNumberState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
671
|
+
= create(() => () => [empty, { kind: 'invalidNumber' }])([
|
|
672
|
+
rangeSetFunc(rangeSetTerminalForNumber)(() => input => {
|
|
673
|
+
const next = tokenizeOp({ kind: 'initial' })(input)
|
|
674
|
+
return [{ first: { kind: 'error', message: 'invalid number' }, tail: next[0] }, next[1]]
|
|
675
|
+
})
|
|
676
|
+
])
|
|
677
|
+
|
|
678
|
+
const parseStringStateOp
|
|
679
|
+
: (state: ParseStringState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
680
|
+
= create((state: ParseStringState) => input => [empty, { kind: 'string', value: appendChar(state.value)(input) }])([
|
|
681
|
+
rangeFunc<ParseStringState>(one(quotationMark))(state => () => [[{ kind: 'string', value: state.value }], { kind: 'initial' }]),
|
|
682
|
+
rangeFunc<ParseStringState>(one(reverseSolidus))(state => () => [empty, { kind: 'escapeChar', value: state.value }]),
|
|
683
|
+
rangeSetFunc<ParseStringState>(rangeSetNewLine)(() => () => [[{ kind: 'error', message: 'unterminated string literal'}], { kind: 'nl'}])
|
|
684
|
+
])
|
|
685
|
+
|
|
686
|
+
const parseEscapeDefault
|
|
687
|
+
: (state: ParseEscapeCharState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
688
|
+
= state => input => {
|
|
689
|
+
const next = tokenizeOp({ kind: 'string', value: state.value })(input)
|
|
690
|
+
return [{ first: { kind: 'error', message: 'unescaped character' }, tail: next[0] }, next[1]]
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
const parseEscapeCharStateOp
|
|
694
|
+
: (state: ParseEscapeCharState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
695
|
+
= create(parseEscapeDefault)([
|
|
696
|
+
rangeSetFunc<ParseEscapeCharState>([one(quotationMark), one(reverseSolidus), one(solidus)])(state => input => [empty, { kind: 'string', value: appendChar(state.value)(input) }]),
|
|
697
|
+
rangeFunc<ParseEscapeCharState>(one(latinSmallLetterB))(state => () => [empty, { kind: 'string', value: appendChar(state.value)(backspace) }]),
|
|
698
|
+
rangeFunc<ParseEscapeCharState>(one(latinSmallLetterF))(state => () => [empty, { kind: 'string', value: appendChar(state.value)(ff) }]),
|
|
699
|
+
rangeFunc<ParseEscapeCharState>(one(latinSmallLetterN))(state => () => [empty, { kind: 'string', value: appendChar(state.value)(lf) }]),
|
|
700
|
+
rangeFunc<ParseEscapeCharState>(one(latinSmallLetterR))(state => () => [empty, { kind: 'string', value: appendChar(state.value)(cr) }]),
|
|
701
|
+
rangeFunc<ParseEscapeCharState>(one(latinSmallLetterT))(state => () => [empty, { kind: 'string', value: appendChar(state.value)(ht) }]),
|
|
702
|
+
rangeFunc<ParseEscapeCharState>(one(latinSmallLetterU))(state => () => [empty, { kind: 'unicodeChar', value: state.value, unicode: 0, hexIndex: 0 }]),
|
|
703
|
+
])
|
|
704
|
+
|
|
705
|
+
const parseUnicodeCharDefault
|
|
706
|
+
: (state: ParseUnicodeCharState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
707
|
+
= state => input => {
|
|
708
|
+
const next = tokenizeOp({ kind: 'string', value: state.value })(input)
|
|
709
|
+
return [{ first: { kind: 'error', message: 'invalid hex value' }, tail: next[0] }, next[1]]
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
const parseUnicodeCharHex
|
|
713
|
+
: (offser: number) => (state: ParseUnicodeCharState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
714
|
+
= offset => state => input => {
|
|
715
|
+
const hexValue = input - offset
|
|
716
|
+
const newUnicode = state.unicode | (hexValue << (3 - state.hexIndex) * 4)
|
|
717
|
+
return [empty, state.hexIndex === 3 ?
|
|
718
|
+
{ kind: 'string', value: appendChar(state.value)(newUnicode) } :
|
|
719
|
+
{ kind: 'unicodeChar', value: state.value, unicode: newUnicode, hexIndex: state.hexIndex + 1 }]
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
const parseUnicodeCharStateOp
|
|
723
|
+
: (state: ParseUnicodeCharState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
724
|
+
= create(parseUnicodeCharDefault)([
|
|
725
|
+
rangeFunc<ParseUnicodeCharState>(digitRange)(parseUnicodeCharHex(digit0)),
|
|
726
|
+
rangeFunc<ParseUnicodeCharState>(rangeSmallAF)(parseUnicodeCharHex(latinSmallLetterA - 10)),
|
|
727
|
+
rangeFunc<ParseUnicodeCharState>(rangeCapitalAF)(parseUnicodeCharHex(latinCapitalLetterA - 10))
|
|
728
|
+
])
|
|
729
|
+
|
|
730
|
+
const idToToken
|
|
731
|
+
: (s: string) => JsToken
|
|
732
|
+
= s => at(s)(keywordMap) ?? { kind: 'id', value: s }
|
|
733
|
+
|
|
734
|
+
const parseIdDefault
|
|
735
|
+
: (state: ParseIdState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
736
|
+
= state => input => {
|
|
737
|
+
const keyWordToken = idToToken(state.value)
|
|
738
|
+
const next = tokenizeOp({ kind: 'initial' })(input)
|
|
739
|
+
return [{ first: keyWordToken, tail: next[0] }, next[1]]
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
const parseIdStateOp
|
|
743
|
+
: (state: ParseIdState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
744
|
+
= create(parseIdDefault)([
|
|
745
|
+
rangeSetFunc<ParseIdState>(rangeId)(state => input => [empty, { kind: 'id', value: appendChar(state.value)(input) }])
|
|
746
|
+
])
|
|
747
|
+
|
|
748
|
+
const parseOperatorStateOp
|
|
749
|
+
: (state: ParseOperatorState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
750
|
+
= state => input => {
|
|
751
|
+
const nextStateValue = appendChar(state.value)(input)
|
|
752
|
+
switch (nextStateValue)
|
|
753
|
+
{
|
|
754
|
+
case '//': return [empty, { kind: '//', value: '', newLine: false }]
|
|
755
|
+
case '/*': return [empty, { kind: '/*', value: '', newLine: false }]
|
|
756
|
+
default: {
|
|
757
|
+
if (hasOperatorToken(nextStateValue))
|
|
758
|
+
return [empty, { kind: 'op', value: nextStateValue }]
|
|
759
|
+
const next = tokenizeOp({ kind: 'initial' })(input)
|
|
760
|
+
return [{ first: getOperatorToken(state.value), tail: next[0] }, next[1]]
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
const parseSinglelineCommentStateOp
|
|
766
|
+
: (state: ParseCommentState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
767
|
+
= create((state: ParseCommentState) => input => [empty, { ...state, value: appendChar(state.value)(input) }])([
|
|
768
|
+
rangeSetFunc<ParseCommentState>(rangeSetNewLine)(state => () => [[{ kind: '//', value: state.value }], { kind: 'nl' }])
|
|
769
|
+
])
|
|
770
|
+
|
|
771
|
+
const parseMultilineCommentStateOp
|
|
772
|
+
: (state: ParseCommentState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
773
|
+
= create((state: ParseCommentState) => input => [empty, { ...state, value: appendChar(state.value)(input) }])([
|
|
774
|
+
rangeFunc<ParseCommentState>(one(asterisk))(state => () => [empty, { ...state, kind: '/**' }]),
|
|
775
|
+
rangeSetFunc<ParseCommentState>(rangeSetNewLine)(state => input => [empty, { ...state, value: appendChar(state.value)(input), newLine: true }]),
|
|
776
|
+
])
|
|
777
|
+
|
|
778
|
+
const parseMultilineCommentAsteriskStateOp
|
|
779
|
+
: (state: ParseCommentState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
780
|
+
= create((state: ParseCommentState) => input => [empty, { ...state, kind: '/*', value: appendChar(appendChar(state.value)(asterisk))(input)}])([
|
|
781
|
+
rangeFunc<ParseCommentState>(one(asterisk))(state => () => [empty, { ...state, value: appendChar(state.value)(asterisk) }]),
|
|
782
|
+
rangeSetFunc<ParseCommentState>(rangeSetNewLine)(state => input => [empty, { kind: '/*', value: appendChar(appendChar(state.value)(asterisk))(input), newLine: true }]),
|
|
783
|
+
rangeFunc<ParseCommentState>(one(solidus))(state => () => {
|
|
784
|
+
const tokens
|
|
785
|
+
: list.List<JsToken>
|
|
786
|
+
= state.newLine ? [{ kind: '/*', value: state.value }, { kind: 'nl' }] : [{ kind: '/*', value: state.value }]
|
|
787
|
+
return [tokens, { kind: 'initial' }]
|
|
788
|
+
})
|
|
789
|
+
])
|
|
790
|
+
|
|
791
|
+
const parseWhitespaceDefault
|
|
792
|
+
: (state: ParseWhitespaceState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
793
|
+
= () => input => {
|
|
794
|
+
const next = tokenizeOp({ kind: 'initial' })(input)
|
|
795
|
+
return [{ first: { kind: 'ws' }, tail: next[0] }, next[1]]
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
const parseWhitespaceStateOp
|
|
799
|
+
: (state: ParseWhitespaceState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
800
|
+
= create(parseWhitespaceDefault)([
|
|
801
|
+
rangeSetFunc<ParseWhitespaceState>(rangeSetWhiteSpace)(state => () => [empty, state]),
|
|
802
|
+
rangeSetFunc<ParseWhitespaceState>(rangeSetNewLine)(() => () => [empty, { kind: 'nl' }])
|
|
803
|
+
])
|
|
804
|
+
|
|
805
|
+
const parseNewLineDefault
|
|
806
|
+
: (state: ParseNewLineState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
807
|
+
= state => input => {
|
|
808
|
+
const next = tokenizeOp({ kind: 'initial' })(input)
|
|
809
|
+
return [{ first: { kind: 'nl' }, tail: next[0] }, next[1]]
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
const parseNewLineStateOp
|
|
813
|
+
: (state: ParseNewLineState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
814
|
+
= create(parseNewLineDefault)([
|
|
815
|
+
rangeSetFunc<ParseNewLineState>(rangeSetWhiteSpace)(state => () => [empty, state]),
|
|
816
|
+
rangeSetFunc<ParseNewLineState>(rangeSetNewLine)(state => () => [empty, state])
|
|
817
|
+
])
|
|
818
|
+
|
|
819
|
+
const eofStateOp
|
|
820
|
+
: (state: EofState) => (input: number) => readonly[list.List<JsToken>, TokenizerState]
|
|
821
|
+
= create((state: EofState) => () => [[{ kind: 'error', message: 'eof' }], state])([])
|
|
822
|
+
|
|
823
|
+
const tokenizeCharCodeOp
|
|
824
|
+
:operator.StateScan<number, TokenizerState, list.List<JsToken>>
|
|
825
|
+
= state => {
|
|
826
|
+
switch (state.kind) {
|
|
827
|
+
case 'initial': return initialStateOp(state)
|
|
828
|
+
case 'id': return parseIdStateOp(state)
|
|
829
|
+
case 'string': return parseStringStateOp(state)
|
|
830
|
+
case 'escapeChar': return parseEscapeCharStateOp(state)
|
|
831
|
+
case 'unicodeChar': return parseUnicodeCharStateOp(state)
|
|
832
|
+
case 'invalidNumber': return invalidNumberStateOp(state)
|
|
833
|
+
case 'number': return parseNumberStateOp(state)
|
|
834
|
+
case 'op': return parseOperatorStateOp(state)
|
|
835
|
+
case '//': return parseSinglelineCommentStateOp(state)
|
|
836
|
+
case '/*': return parseMultilineCommentStateOp(state)
|
|
837
|
+
case '/**': return parseMultilineCommentAsteriskStateOp(state)
|
|
838
|
+
case 'ws': return parseWhitespaceStateOp(state)
|
|
839
|
+
case 'nl': return parseNewLineStateOp(state)
|
|
840
|
+
case 'eof': return eofStateOp(state)
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
const tokenizeEofOp
|
|
845
|
+
: (state: TokenizerState) => readonly[list.List<JsToken>, TokenizerState]
|
|
846
|
+
= state => {
|
|
847
|
+
switch (state.kind) {
|
|
848
|
+
case 'initial': return [empty, { kind: 'eof' }]
|
|
849
|
+
case 'id': return [[idToToken(state.value)], { kind: 'eof' }]
|
|
850
|
+
case 'string':
|
|
851
|
+
case 'escapeChar':
|
|
852
|
+
case 'unicodeChar': return [[{ kind: 'error', message: '" are missing' }], { kind: 'eof' }]
|
|
853
|
+
case 'invalidNumber': return [[{ kind: 'error', message: 'invalid number' }], { kind: 'eof' }]
|
|
854
|
+
case 'number':
|
|
855
|
+
switch (state.numberKind) {
|
|
856
|
+
case '.':
|
|
857
|
+
case 'e':
|
|
858
|
+
case 'e+':
|
|
859
|
+
case 'e-': return [[{ kind: 'error', message: 'invalid number' }], { kind: 'eof', }]
|
|
860
|
+
default: return [[bufferToNumberToken(state)], { kind: 'eof' }]
|
|
861
|
+
}
|
|
862
|
+
case 'op': return [[getOperatorToken(state.value)], { kind: 'eof' }]
|
|
863
|
+
case '//': return [[{kind: '//', value: state.value}], { kind: 'eof' }]
|
|
864
|
+
case '/*':
|
|
865
|
+
case '/**': return [[{ kind: 'error', message: '*/ expected' }], { kind: 'eof', }]
|
|
866
|
+
case 'ws': return [[{kind: 'ws'}], { kind: 'eof' }]
|
|
867
|
+
case 'nl': return [[{kind: 'nl'}], { kind: 'eof' }]
|
|
868
|
+
case 'eof': return [[{ kind: 'error', message: 'eof' }], state]
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
const tokenizeOp
|
|
873
|
+
: operator.StateScan<CharCodeOrEof, TokenizerState, list.List<JsToken>>
|
|
874
|
+
= state => input => input === null ? tokenizeEofOp(state) : tokenizeCharCodeOp(state)(input)
|
|
875
|
+
|
|
876
|
+
const scanTokenize = stateScan(tokenizeOp)
|
|
877
|
+
|
|
878
|
+
const initial = scanTokenize({ kind: 'initial' })
|
|
879
|
+
|
|
880
|
+
export const tokenize
|
|
881
|
+
= (input: list.List<number>): list.List<JsToken> =>
|
|
882
|
+
flat(initial(flat<number|null>([input satisfies list.List<CharCodeOrEof>, [null]])))
|