functionalscript 0.1.609 → 0.2.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/com/cpp/module.f.mjs +20 -25
- package/com/cpp/testlib.f.mjs +3 -4
- package/com/cs/module.f.mjs +18 -23
- package/com/cs/testlib.f.mjs +3 -5
- package/com/rust/module.f.mjs +25 -30
- package/com/rust/testlib.f.mjs +3 -5
- package/com/test/build.f.mjs +2 -2
- package/com/test/build.mjs +4 -4
- package/com/types/module.f.mjs +5 -12
- package/commonjs/build/module.f.mjs +23 -28
- package/commonjs/build/test.f.mjs +4 -4
- package/commonjs/module/function/module.f.mjs +0 -2
- package/commonjs/module/module.f.mjs +2 -9
- package/commonjs/module.f.mjs +0 -2
- package/commonjs/module.mjs +2 -7
- package/commonjs/package/dependencies/module.f.mjs +5 -10
- package/commonjs/package/dependencies/test.f.mjs +1 -1
- package/commonjs/package/module.f.mjs +6 -13
- package/commonjs/package/test.f.mjs +1 -1
- package/commonjs/path/module.f.mjs +12 -23
- package/commonjs/path/test.f.mjs +11 -11
- package/commonjs/test.mjs +1 -1
- package/dev/module.f.mjs +1 -4
- package/dev/module.mjs +1 -1
- package/dev/test/module.f.mjs +4 -6
- package/djs/module.f.mjs +12 -19
- package/djs/parser/module.f.mjs +18 -24
- package/djs/parser/test.f.mjs +9 -9
- package/djs/test.f.mjs +4 -4
- package/djs/tokenizer/module.f.mjs +18 -23
- package/djs/tokenizer/test.f.mjs +6 -6
- package/fsc/module.f.mjs +17 -24
- package/fsc/test.f.mjs +3 -3
- package/fsm/module.f.mjs +27 -38
- package/fsm/test.f.mjs +8 -8
- package/html/module.f.mjs +14 -23
- package/html/test.f.mjs +4 -4
- package/js/tokenizer/module.f.mjs +55 -62
- package/js/tokenizer/test.f.mjs +6 -6
- package/json/module.f.mjs +18 -31
- package/json/parser/module.f.mjs +9 -14
- package/json/parser/test.f.mjs +7 -7
- package/json/serializer/module.f.mjs +14 -29
- package/json/serializer/test.f.mjs +2 -2
- package/json/test.f.mjs +3 -3
- package/json/tokenizer/module.f.mjs +14 -19
- package/json/tokenizer/test.f.mjs +6 -6
- package/jsr.json +59 -59
- package/nodejs/version/main.mjs +1 -1
- package/nodejs/version/module.f.mjs +2 -7
- package/nodejs/version/test.f.mjs +3 -3
- package/out/com/cpp/module.f.d.mts +4 -0
- package/out/com/cpp/module.f.mjs +123 -0
- package/out/com/cpp/test.f.mjs +40 -0
- package/out/com/cpp/testlib.f.mjs +7 -0
- package/out/com/cs/module.f.d.mts +4 -0
- package/out/com/cs/module.f.mjs +95 -0
- package/out/com/cs/test.f.mjs +43 -0
- package/out/com/cs/testlib.f.mjs +7 -0
- package/{com → out/com}/rust/module.f.d.mts +3 -7
- package/out/com/rust/module.f.mjs +213 -0
- package/out/com/rust/test.f.mjs +123 -0
- package/out/com/rust/testlib.f.mjs +7 -0
- package/{com → out/com}/test/build.f.d.mts +2 -2
- package/out/com/test/build.f.mjs +98 -0
- package/out/com/test/build.mjs +40 -0
- package/{com → out/com}/types/module.f.d.mts +5 -10
- package/out/com/types/module.f.mjs +51 -0
- package/out/com/types/testlib.f.mjs +30 -0
- package/out/commonjs/build/module.f.d.mts +20 -0
- package/out/commonjs/build/module.f.mjs +107 -0
- package/out/commonjs/build/test.f.mjs +102 -0
- package/{commonjs → out/commonjs}/module/function/module.f.d.mts +0 -2
- package/out/commonjs/module/function/module.f.mjs +15 -0
- package/{commonjs → out/commonjs}/module/module.f.d.mts +16 -21
- package/out/commonjs/module/module.f.mjs +48 -0
- package/out/commonjs/module.d.mts +3 -0
- package/{commonjs → out/commonjs}/module.f.d.mts +0 -2
- package/out/commonjs/module.f.mjs +10 -0
- package/out/commonjs/module.mjs +26 -0
- package/out/commonjs/package/dependencies/module.f.d.mts +6 -0
- package/out/commonjs/package/dependencies/module.f.mjs +21 -0
- package/out/commonjs/package/dependencies/test.f.mjs +15 -0
- package/out/commonjs/package/module.f.d.mts +21 -0
- package/out/commonjs/package/module.f.mjs +40 -0
- package/out/commonjs/package/test.f.mjs +27 -0
- package/{commonjs → out/commonjs}/path/module.f.d.mts +25 -32
- package/out/commonjs/path/module.f.mjs +171 -0
- package/out/commonjs/path/test.f.mjs +231 -0
- package/out/commonjs/test.mjs +87 -0
- package/out/dev/index.mjs +2 -0
- package/out/dev/module.f.d.mts +1 -0
- package/out/dev/module.f.mjs +2 -0
- package/out/dev/module.mjs +167 -0
- package/{dev → out/dev}/test/module.f.d.mts +2 -3
- package/out/dev/test/module.f.mjs +134 -0
- package/out/dev/test.f.mjs +58 -0
- package/out/dev/test.mjs +52 -0
- package/{djs → out/djs}/module.f.d.mts +13 -18
- package/out/djs/module.f.mjs +75 -0
- package/{djs → out/djs}/parser/module.f.d.mts +11 -15
- package/out/djs/parser/module.f.mjs +432 -0
- package/out/djs/parser/test.f.mjs +535 -0
- package/out/djs/test.f.mjs +84 -0
- package/out/djs/tokenizer/module.f.d.mts +13 -0
- package/out/djs/tokenizer/module.f.mjs +87 -0
- package/out/djs/tokenizer/test.f.mjs +480 -0
- package/out/fsc/module.f.d.mts +7 -0
- package/out/fsc/module.f.mjs +105 -0
- package/out/fsc/test.f.mjs +19 -0
- package/out/fsm/module.f.d.mts +14 -0
- package/out/fsm/module.f.mjs +80 -0
- package/out/fsm/test.f.mjs +138 -0
- package/out/html/module.f.d.mts +15 -0
- package/out/html/module.f.mjs +94 -0
- package/out/html/test.f.mjs +45 -0
- package/out/issues/test.f.mjs +66 -0
- package/{js → out/js}/tokenizer/module.f.d.mts +10 -15
- package/out/js/tokenizer/module.f.mjs +686 -0
- package/out/js/tokenizer/test.f.mjs +844 -0
- package/out/json/module.f.d.mts +33 -0
- package/out/json/module.f.mjs +89 -0
- package/{json → out/json}/parser/module.f.d.mts +9 -13
- package/out/json/parser/module.f.mjs +224 -0
- package/out/json/parser/test.f.mjs +321 -0
- package/out/json/serializer/module.f.d.mts +36 -0
- package/out/json/serializer/module.f.mjs +67 -0
- package/out/json/serializer/test.f.mjs +87 -0
- package/out/json/test.f.mjs +61 -0
- package/out/json/tokenizer/module.f.d.mts +13 -0
- package/out/json/tokenizer/module.f.mjs +78 -0
- package/out/json/tokenizer/test.f.mjs +420 -0
- package/out/nanvm-lib/tests/test.f.mjs +87 -0
- package/out/nodejs/version/main.mjs +3 -0
- package/{nodejs → out/nodejs}/version/module.f.d.mts +4 -9
- package/out/nodejs/version/module.f.mjs +34 -0
- package/out/nodejs/version/test.f.mjs +97 -0
- package/{prime_field → out/prime_field}/module.f.d.mts +20 -23
- package/out/prime_field/module.f.mjs +87 -0
- package/out/prime_field/test.f.mjs +145 -0
- package/{secp → out/secp}/module.f.d.mts +27 -28
- package/out/secp/module.f.mjs +113 -0
- package/out/secp/test.f.mjs +63 -0
- package/out/sha2/module.f.d.mts +15 -0
- package/out/sha2/module.f.mjs +172 -0
- package/out/sha2/test.f.mjs +86 -0
- package/out/text/ascii/module.f.d.mts +70 -0
- package/out/text/ascii/module.f.mjs +154 -0
- package/out/text/ascii/test.f.mjs +14 -0
- package/out/text/module.f.d.mts +13 -0
- package/out/text/module.f.mjs +19 -0
- package/out/text/sgr/module.f.d.mts +12 -0
- package/out/text/sgr/module.f.mjs +17 -0
- package/out/text/test.f.mjs +19 -0
- package/out/text/utf16/module.f.d.mts +12 -0
- package/out/text/utf16/module.f.mjs +86 -0
- package/out/text/utf16/test.f.mjs +145 -0
- package/out/text/utf8/module.f.d.mts +10 -0
- package/out/text/utf8/module.f.mjs +126 -0
- package/out/text/utf8/test.f.mjs +175 -0
- package/{types → out/types}/array/module.f.d.mts +14 -24
- package/out/types/array/module.f.mjs +95 -0
- package/out/types/array/test.f.mjs +116 -0
- package/out/types/bigfloat/module.f.d.mts +6 -0
- package/out/types/bigfloat/module.f.mjs +77 -0
- package/out/types/bigfloat/test.f.mjs +349 -0
- package/out/types/bigint/module.f.d.mts +29 -0
- package/{types/bigint/module.f.d.mts → out/types/bigint/module.f.mjs} +64 -27
- package/out/types/bigint/test.f.mjs +192 -0
- package/{types → out/types}/btree/find/module.f.d.mts +20 -26
- package/out/types/btree/find/module.f.mjs +137 -0
- package/out/types/btree/find/test.f.mjs +156 -0
- package/out/types/btree/module.f.d.mts +5 -0
- package/out/types/btree/module.f.mjs +34 -0
- package/{types → out/types}/btree/remove/module.f.d.mts +7 -12
- package/out/types/btree/remove/module.f.mjs +209 -0
- package/out/types/btree/remove/test.f.mjs +638 -0
- package/{types → out/types}/btree/set/module.f.d.mts +3 -7
- package/out/types/btree/set/module.f.mjs +114 -0
- package/out/types/btree/set/test.f.mjs +390 -0
- package/out/types/btree/test.f.mjs +83 -0
- package/{types → out/types}/btree/types/module.f.d.mts +0 -2
- package/out/types/btree/types/module.f.mjs +50 -0
- package/out/types/byte_set/module.f.d.mts +25 -0
- package/out/types/byte_set/module.f.mjs +42 -0
- package/out/types/byte_set/test.f.mjs +123 -0
- package/{types → out/types}/function/compare/module.f.d.mts +9 -15
- package/out/types/function/compare/module.f.mjs +22 -0
- package/out/types/function/compare/test.f.mjs +8 -0
- package/{types → out/types}/function/module.f.d.mts +20 -27
- package/out/types/function/module.f.mjs +44 -0
- package/{types → out/types}/function/operator/module.f.d.mts +28 -43
- package/out/types/function/operator/module.f.mjs +60 -0
- package/out/types/function/test.f.mjs +15 -0
- package/out/types/list/module.f.d.mts +82 -0
- package/out/types/list/module.f.mjs +269 -0
- package/out/types/list/test.f.mjs +401 -0
- package/out/types/map/module.f.d.mts +21 -0
- package/out/types/map/module.f.mjs +54 -0
- package/out/types/map/test.f.mjs +115 -0
- package/out/types/nibble_set/module.f.d.mts +16 -0
- package/out/types/nibble_set/module.f.mjs +19 -0
- package/out/types/nibble_set/test.f.mjs +90 -0
- package/out/types/nullable/module.f.d.mts +9 -0
- package/out/types/nullable/module.f.mjs +9 -0
- package/out/types/nullable/test.f.mjs +12 -0
- package/out/types/number/module.f.d.mts +7 -0
- package/out/types/number/module.f.mjs +12 -0
- package/out/types/number/test.f.mjs +126 -0
- package/out/types/object/module.f.d.mts +22 -0
- package/out/types/object/module.f.mjs +27 -0
- package/out/types/object/test.f.mjs +17 -0
- package/out/types/range/module.f.d.mts +6 -0
- package/out/types/range/module.f.mjs +6 -0
- package/out/types/range/test.f.mjs +18 -0
- package/{types → out/types}/range_map/module.f.d.mts +9 -15
- package/out/types/range_map/module.f.mjs +84 -0
- package/out/types/range_map/test.f.mjs +201 -0
- package/out/types/result/module.d.mts +7 -0
- package/{types → out/types}/result/module.f.d.mts +6 -12
- package/out/types/result/module.f.mjs +25 -0
- package/out/types/result/module.mjs +16 -0
- package/{types → out/types}/sorted_list/module.f.d.mts +22 -28
- package/out/types/sorted_list/module.f.mjs +102 -0
- package/out/types/sorted_list/test.f.mjs +66 -0
- package/{types → out/types}/sorted_set/module.f.d.mts +6 -12
- package/out/types/sorted_set/module.f.mjs +29 -0
- package/out/types/sorted_set/test.f.mjs +80 -0
- package/out/types/string/module.f.d.mts +9 -0
- package/out/types/string/module.f.mjs +17 -0
- package/out/types/string/test.f.mjs +58 -0
- package/out/types/string_set/module.f.d.mts +13 -0
- package/out/types/string_set/module.f.mjs +29 -0
- package/out/types/string_set/test.f.mjs +65 -0
- package/package.json +5 -4
- package/prime_field/module.f.mjs +9 -12
- package/prime_field/test.f.mjs +1 -1
- package/secp/module.f.mjs +38 -39
- package/secp/test.f.mjs +4 -4
- package/sha2/module.f.mjs +7 -20
- package/sha2/test.f.mjs +4 -4
- package/text/ascii/module.f.mjs +5 -10
- package/text/ascii/test.f.mjs +3 -3
- package/text/module.f.mjs +7 -14
- package/text/sgr/module.f.mjs +2 -4
- package/text/test.f.mjs +3 -3
- package/text/utf16/module.f.mjs +17 -28
- package/text/utf16/test.f.mjs +5 -5
- package/text/utf8/module.f.mjs +9 -16
- package/text/utf8/test.f.mjs +4 -4
- package/tsconfig.json +2 -2
- package/types/array/module.f.mjs +8 -25
- package/types/array/test.f.mjs +3 -3
- package/types/bigfloat/module.f.mjs +3 -10
- package/types/bigfloat/test.f.mjs +1 -1
- package/types/bigint/module.f.mjs +11 -30
- package/types/bigint/test.f.mjs +1 -1
- package/types/btree/find/module.f.mjs +8 -17
- package/types/btree/find/test.f.mjs +7 -7
- package/types/btree/module.f.mjs +6 -11
- package/types/btree/remove/module.f.mjs +10 -17
- package/types/btree/remove/test.f.mjs +5 -5
- package/types/btree/set/module.f.mjs +4 -9
- package/types/btree/set/test.f.mjs +4 -4
- package/types/btree/test.f.mjs +9 -9
- package/types/btree/types/module.f.mjs +0 -2
- package/types/byte_set/module.f.mjs +14 -39
- package/types/byte_set/test.f.mjs +5 -5
- package/types/function/compare/module.f.mjs +3 -12
- package/types/function/compare/test.f.mjs +1 -1
- package/types/function/module.f.mjs +4 -15
- package/types/function/operator/module.f.mjs +14 -41
- package/types/function/test.f.mjs +1 -1
- package/types/list/module.f.mjs +45 -114
- package/types/list/test.f.mjs +10 -10
- package/types/map/module.f.mjs +15 -30
- package/types/map/test.f.mjs +2 -2
- package/types/nibble_set/module.f.mjs +7 -24
- package/types/nibble_set/test.f.mjs +2 -2
- package/types/nullable/module.f.mjs +2 -9
- package/types/nullable/test.f.mjs +1 -1
- package/types/number/module.f.mjs +8 -19
- package/types/number/test.f.mjs +1 -1
- package/types/object/module.f.mjs +9 -20
- package/types/object/test.f.mjs +1 -1
- package/types/range/module.f.mjs +2 -9
- package/types/range/test.f.mjs +1 -1
- package/types/range_map/module.f.mjs +9 -18
- package/types/range_map/test.f.mjs +32 -32
- package/types/result/module.f.mjs +3 -12
- package/types/result/module.mjs +2 -2
- package/types/sorted_list/module.f.mjs +10 -19
- package/types/sorted_list/test.f.mjs +7 -7
- package/types/sorted_set/module.f.mjs +7 -16
- package/types/sorted_set/test.f.mjs +7 -7
- package/types/string/module.f.mjs +10 -21
- package/types/string/test.f.mjs +2 -2
- package/types/string_set/module.f.mjs +12 -27
- package/types/string_set/test.f.mjs +1 -1
- package/com/cpp/module.f.d.mts +0 -8
- package/com/cs/module.f.d.mts +0 -8
- package/commonjs/build/module.f.d.mts +0 -24
- package/commonjs/module.d.mts +0 -7
- package/commonjs/package/dependencies/module.f.d.mts +0 -10
- package/commonjs/package/module.f.d.mts +0 -27
- package/dev/module.f.d.mts +0 -4
- package/djs/tokenizer/module.f.d.mts +0 -17
- package/fsc/module.f.d.mts +0 -12
- package/fsm/module.f.d.mts +0 -21
- package/html/module.f.d.mts +0 -20
- package/json/module.f.d.mts +0 -41
- package/json/serializer/module.f.d.mts +0 -45
- package/json/tokenizer/module.f.d.mts +0 -17
- package/sha2/module.f.d.mts +0 -23
- package/text/ascii/module.f.d.mts +0 -73
- package/text/module.f.d.mts +0 -18
- package/text/sgr/module.f.d.mts +0 -14
- package/text/utf16/module.f.d.mts +0 -19
- package/text/utf8/module.f.d.mts +0 -15
- package/types/bigfloat/module.f.d.mts +0 -11
- package/types/btree/module.f.d.mts +0 -9
- package/types/byte_set/module.f.d.mts +0 -38
- package/types/list/module.f.d.mts +0 -117
- package/types/map/module.f.d.mts +0 -30
- package/types/nibble_set/module.f.d.mts +0 -26
- package/types/nullable/module.f.d.mts +0 -14
- package/types/number/module.f.d.mts +0 -13
- package/types/object/module.f.d.mts +0 -29
- package/types/range/module.f.d.mts +0 -11
- package/types/result/module.d.mts +0 -7
- package/types/string/module.f.d.mts +0 -15
- package/types/string_set/module.f.d.mts +0 -21
- /package/{com → out/com}/cpp/test.f.d.mts +0 -0
- /package/{com → out/com}/cpp/testlib.f.d.mts +0 -0
- /package/{com → out/com}/cs/test.f.d.mts +0 -0
- /package/{com → out/com}/cs/testlib.f.d.mts +0 -0
- /package/{com → out/com}/rust/test.f.d.mts +0 -0
- /package/{com → out/com}/rust/testlib.f.d.mts +0 -0
- /package/{com → out/com}/test/build.d.mts +0 -0
- /package/{com → out/com}/types/testlib.f.d.mts +0 -0
- /package/{commonjs → out/commonjs}/build/test.f.d.mts +0 -0
- /package/{commonjs → out/commonjs}/package/dependencies/test.f.d.mts +0 -0
- /package/{commonjs → out/commonjs}/package/test.f.d.mts +0 -0
- /package/{commonjs → out/commonjs}/path/test.f.d.mts +0 -0
- /package/{commonjs → out/commonjs}/test.d.mts +0 -0
- /package/{dev → out/dev}/index.d.mts +0 -0
- /package/{dev → out/dev}/module.d.mts +0 -0
- /package/{dev → out/dev}/test.d.mts +0 -0
- /package/{dev → out/dev}/test.f.d.mts +0 -0
- /package/{djs → out/djs}/parser/test.f.d.mts +0 -0
- /package/{djs → out/djs}/test.f.d.mts +0 -0
- /package/{djs → out/djs}/tokenizer/test.f.d.mts +0 -0
- /package/{fsc → out/fsc}/test.f.d.mts +0 -0
- /package/{fsm → out/fsm}/test.f.d.mts +0 -0
- /package/{html → out/html}/test.f.d.mts +0 -0
- /package/{issues → out/issues}/test.f.d.mts +0 -0
- /package/{js → out/js}/tokenizer/test.f.d.mts +0 -0
- /package/{json → out/json}/parser/test.f.d.mts +0 -0
- /package/{json → out/json}/serializer/test.f.d.mts +0 -0
- /package/{json → out/json}/test.f.d.mts +0 -0
- /package/{json → out/json}/tokenizer/test.f.d.mts +0 -0
- /package/{nanvm-lib → out/nanvm-lib}/tests/test.f.d.mts +0 -0
- /package/{nodejs → out/nodejs}/version/main.d.mts +0 -0
- /package/{nodejs → out/nodejs}/version/test.f.d.mts +0 -0
- /package/{prime_field → out/prime_field}/test.f.d.mts +0 -0
- /package/{secp → out/secp}/test.f.d.mts +0 -0
- /package/{sha2 → out/sha2}/test.f.d.mts +0 -0
- /package/{text → out/text}/ascii/test.f.d.mts +0 -0
- /package/{text → out/text}/test.f.d.mts +0 -0
- /package/{text → out/text}/utf16/test.f.d.mts +0 -0
- /package/{text → out/text}/utf8/test.f.d.mts +0 -0
- /package/{types → out/types}/array/test.f.d.mts +0 -0
- /package/{types → out/types}/bigfloat/test.f.d.mts +0 -0
- /package/{types → out/types}/bigint/test.f.d.mts +0 -0
- /package/{types → out/types}/btree/find/test.f.d.mts +0 -0
- /package/{types → out/types}/btree/remove/test.f.d.mts +0 -0
- /package/{types → out/types}/btree/set/test.f.d.mts +0 -0
- /package/{types → out/types}/btree/test.f.d.mts +0 -0
- /package/{types → out/types}/byte_set/test.f.d.mts +0 -0
- /package/{types → out/types}/function/compare/test.f.d.mts +0 -0
- /package/{types → out/types}/function/test.f.d.mts +0 -0
- /package/{types → out/types}/list/test.f.d.mts +0 -0
- /package/{types → out/types}/map/test.f.d.mts +0 -0
- /package/{types → out/types}/nibble_set/test.f.d.mts +0 -0
- /package/{types → out/types}/nullable/test.f.d.mts +0 -0
- /package/{types → out/types}/number/test.f.d.mts +0 -0
- /package/{types → out/types}/object/test.f.d.mts +0 -0
- /package/{types → out/types}/range/test.f.d.mts +0 -0
- /package/{types → out/types}/range_map/test.f.d.mts +0 -0
- /package/{types → out/types}/sorted_list/test.f.d.mts +0 -0
- /package/{types → out/types}/sorted_set/test.f.d.mts +0 -0
- /package/{types → out/types}/string/test.f.d.mts +0 -0
- /package/{types → out/types}/string_set/test.f.d.mts +0 -0
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
// @ts-self-types="./module.f.d.mts"
|
|
2
|
+
import * as result from '../../types/result/module.f.mjs';
|
|
3
|
+
import * as list from '../../types/list/module.f.mjs';
|
|
4
|
+
const { fold, first, drop, toArray, map: listMap, length } = list;
|
|
5
|
+
import * as Operator from '../../types/function/operator/module.f.mjs';
|
|
6
|
+
import * as tokenizerT from '../tokenizer/module.f.mjs';
|
|
7
|
+
import * as map from '../../types/map/module.f.mjs';
|
|
8
|
+
const { setReplace, at } = map;
|
|
9
|
+
import * as o from '../../types/object/module.f.mjs';
|
|
10
|
+
const { fromMap } = o;
|
|
11
|
+
/** @typedef {[readonly string[], readonly DjsConst[]] } DjsModule */
|
|
12
|
+
/** @typedef {boolean|string|number|null|bigint|DjsModuleRef|DjsArray|DjsObject} DjsConst */
|
|
13
|
+
/** @typedef {['aref' | 'cref', number]} DjsModuleRef */
|
|
14
|
+
/** @typedef {['array', readonly DjsConst[]]} DjsArray */
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {{
|
|
17
|
+
* readonly [k in string]: DjsConst
|
|
18
|
+
* }} DjsObject
|
|
19
|
+
*/
|
|
20
|
+
/** @typedef {['array', list.List<DjsConst>]} DjsStackArray */
|
|
21
|
+
/** @typedef {['object', map.Map<DjsConst>, string]} DjsStackObject */
|
|
22
|
+
/**
|
|
23
|
+
* @typedef {|
|
|
24
|
+
* DjsStackArray |
|
|
25
|
+
* DjsStackObject
|
|
26
|
+
* } DjsStackElement
|
|
27
|
+
*/
|
|
28
|
+
/** @typedef {list.List<DjsStackElement>} DjsStack */
|
|
29
|
+
/** @typedef {InitialState | NewLineRequiredState | ImportState | ConstState | ExportState | ParseValueState | ResultState | ErrorState} ParserState */
|
|
30
|
+
/**
|
|
31
|
+
* @typedef {{
|
|
32
|
+
* readonly refs: map.Map<DjsModuleRef>
|
|
33
|
+
* readonly modules: list.List<string>
|
|
34
|
+
* readonly consts: list.List<DjsConst>
|
|
35
|
+
* }} ModuleState
|
|
36
|
+
*/
|
|
37
|
+
/**
|
|
38
|
+
* @typedef {{
|
|
39
|
+
* readonly state: ''
|
|
40
|
+
* readonly module: ModuleState
|
|
41
|
+
* }} InitialState
|
|
42
|
+
*/
|
|
43
|
+
/**
|
|
44
|
+
* @typedef {{
|
|
45
|
+
* readonly state: 'nl'
|
|
46
|
+
* readonly module: ModuleState
|
|
47
|
+
* }} NewLineRequiredState
|
|
48
|
+
*/
|
|
49
|
+
/**
|
|
50
|
+
* @typedef {{
|
|
51
|
+
* readonly state: 'import' | 'import+name' | 'import+from'
|
|
52
|
+
* readonly module: ModuleState
|
|
53
|
+
* }} ImportState
|
|
54
|
+
*/
|
|
55
|
+
/**
|
|
56
|
+
* @typedef {{
|
|
57
|
+
* readonly state: 'const' | 'const+name'
|
|
58
|
+
* readonly module: ModuleState
|
|
59
|
+
* }} ConstState
|
|
60
|
+
*/
|
|
61
|
+
/**
|
|
62
|
+
* @typedef {{
|
|
63
|
+
* readonly state: 'export'
|
|
64
|
+
* readonly module: ModuleState
|
|
65
|
+
* }} ExportState
|
|
66
|
+
*/
|
|
67
|
+
/**
|
|
68
|
+
* @typedef {{
|
|
69
|
+
* readonly state: 'constValue' | 'exportValue'
|
|
70
|
+
* readonly module: ModuleState
|
|
71
|
+
* readonly valueState: '' | '[' | '[v' | '[,' | '{' | '{k' | '{:' | '{v' | '{,'
|
|
72
|
+
* readonly top: DjsStackElement | null
|
|
73
|
+
* readonly stack: DjsStack
|
|
74
|
+
* }} ParseValueState
|
|
75
|
+
*/
|
|
76
|
+
/**
|
|
77
|
+
* @typedef {{
|
|
78
|
+
* readonly state: 'result'
|
|
79
|
+
* readonly module: ModuleState
|
|
80
|
+
* }} ResultState
|
|
81
|
+
*/
|
|
82
|
+
/**
|
|
83
|
+
* @typedef {{
|
|
84
|
+
* readonly state: 'error'
|
|
85
|
+
* readonly message: string
|
|
86
|
+
* }} ErrorState
|
|
87
|
+
*/
|
|
88
|
+
/** @type {(token: tokenizerT.DjsToken) => (state: InitialState) => ParserState}} */
|
|
89
|
+
const parseInitialOp = token => state => {
|
|
90
|
+
switch (token.kind) {
|
|
91
|
+
case 'ws':
|
|
92
|
+
case 'nl': return state;
|
|
93
|
+
case 'id': {
|
|
94
|
+
switch (token.value) {
|
|
95
|
+
case 'import': return { ...state, state: 'import' };
|
|
96
|
+
case 'const': return { ...state, state: 'const' };
|
|
97
|
+
case 'export': return { ...state, state: 'export' };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return { state: 'error', message: 'unexpected token' };
|
|
102
|
+
};
|
|
103
|
+
/** @type {(token: tokenizerT.DjsToken) => (state: NewLineRequiredState) => ParserState}} */
|
|
104
|
+
const parseNewLineRequiredOp = token => state => {
|
|
105
|
+
switch (token.kind) {
|
|
106
|
+
case 'ws': return state;
|
|
107
|
+
case 'nl': return { ...state, state: '' };
|
|
108
|
+
default: return { state: 'error', message: 'unexpected token' };
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
/** @type {(token: tokenizerT.DjsToken) => (state: ExportState) => ParserState}} */
|
|
112
|
+
const parseExportOp = token => state => {
|
|
113
|
+
switch (token.kind) {
|
|
114
|
+
case 'ws':
|
|
115
|
+
case 'nl': return state;
|
|
116
|
+
case 'id': {
|
|
117
|
+
if (token.value === 'default')
|
|
118
|
+
return { ...state, state: 'exportValue', valueState: '', top: null, stack: null };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return { state: 'error', message: 'unexpected token' };
|
|
122
|
+
};
|
|
123
|
+
/** @type {(token: tokenizerT.DjsToken) => (state: ConstState) => ParserState}} */
|
|
124
|
+
const parseConstOp = token => state => {
|
|
125
|
+
switch (token.kind) {
|
|
126
|
+
case 'ws':
|
|
127
|
+
case 'nl': return state;
|
|
128
|
+
case 'id': {
|
|
129
|
+
if (map.at(token.value)(state.module.refs) !== null)
|
|
130
|
+
return { state: 'error', message: 'duplicate id' };
|
|
131
|
+
/** @type {DjsModuleRef} */
|
|
132
|
+
let cref = ['cref', length(state.module.consts)];
|
|
133
|
+
let refs = map.setReplace(token.value)(cref)(state.module.refs);
|
|
134
|
+
return { ...state, state: 'const+name', module: { ...state.module, refs: refs } };
|
|
135
|
+
}
|
|
136
|
+
default: return { state: 'error', message: 'unexpected token' };
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
/** @type {(token: tokenizerT.DjsToken) => (state: ConstState) => ParserState}} */
|
|
140
|
+
const parseConstNameOp = token => state => {
|
|
141
|
+
switch (token.kind) {
|
|
142
|
+
case 'ws':
|
|
143
|
+
case 'nl': return state;
|
|
144
|
+
case '=': return { ...state, state: 'constValue', valueState: '', top: null, stack: null };
|
|
145
|
+
default: return { state: 'error', message: 'unexpected token' };
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
/** @type {(token: tokenizerT.DjsToken) => (state: ImportState) => ParserState}} */
|
|
149
|
+
const parseImportOp = token => state => {
|
|
150
|
+
switch (token.kind) {
|
|
151
|
+
case 'ws':
|
|
152
|
+
case 'nl': return state;
|
|
153
|
+
case 'id': {
|
|
154
|
+
if (map.at(token.value)(state.module.refs) !== null)
|
|
155
|
+
return { state: 'error', message: 'duplicate id' };
|
|
156
|
+
/** @type {DjsModuleRef} */
|
|
157
|
+
let aref = ['aref', length(state.module.modules)];
|
|
158
|
+
let refs = map.setReplace(token.value)(aref)(state.module.refs);
|
|
159
|
+
return { ...state, state: 'import+name', module: { ...state.module, refs: refs } };
|
|
160
|
+
}
|
|
161
|
+
default: return { state: 'error', message: 'unexpected token' };
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
/** @type {(token: tokenizerT.DjsToken) => (state: ImportState) => ParserState}} */
|
|
165
|
+
const parseImportNameOp = token => state => {
|
|
166
|
+
switch (token.kind) {
|
|
167
|
+
case 'ws':
|
|
168
|
+
case 'nl': return state;
|
|
169
|
+
case 'id': {
|
|
170
|
+
if (token.value === 'from')
|
|
171
|
+
return { ...state, state: 'import+from' };
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return { state: 'error', message: 'unexpected token' };
|
|
175
|
+
};
|
|
176
|
+
/** @type {(token: tokenizerT.DjsToken) => (state: ImportState) => ParserState}} */
|
|
177
|
+
const parseImportFromOp = token => state => {
|
|
178
|
+
switch (token.kind) {
|
|
179
|
+
case 'ws':
|
|
180
|
+
case 'nl': return state;
|
|
181
|
+
case 'string': {
|
|
182
|
+
const modules = list.concat(state.module.modules)([token.value]);
|
|
183
|
+
return { ...state, state: 'nl', module: { ...state.module, modules: modules } };
|
|
184
|
+
}
|
|
185
|
+
default: return { state: 'error', message: 'unexpected token' };
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
/** @type {(obj: DjsStackObject) => (key: string) => DjsStackObject} */
|
|
189
|
+
const addKeyToObject = obj => key => (['object', obj[1], key]);
|
|
190
|
+
/** @type {(obj: DjsStackObject) => (value: DjsConst) => DjsStackObject} */
|
|
191
|
+
const addValueToObject = obj => value => (['object', setReplace(obj[2])(value)(obj[1]), '']);
|
|
192
|
+
/** @type {(array: DjsStackArray) => (value: DjsConst) => DjsStackArray} */
|
|
193
|
+
const addToArray = array => value => (['array', list.concat(array[1])([value])]);
|
|
194
|
+
/** @type {(state: ParseValueState) => (key: string) => ParserState} */
|
|
195
|
+
const pushKey = state => key => {
|
|
196
|
+
if (state.top?.[0] === 'object') {
|
|
197
|
+
return { ...state, valueState: '{k', top: addKeyToObject(state.top)(key), stack: state.stack };
|
|
198
|
+
}
|
|
199
|
+
return { state: 'error', message: 'error' };
|
|
200
|
+
};
|
|
201
|
+
/** @type {(state: ParseValueState) => (value: DjsConst) => ParserState} */
|
|
202
|
+
const pushValue = state => value => {
|
|
203
|
+
if (state.top === null) {
|
|
204
|
+
let consts = list.concat(state.module.consts)([value]);
|
|
205
|
+
switch (state.state) {
|
|
206
|
+
case 'exportValue': return { ...state, state: 'result', module: { ...state.module, consts: consts } };
|
|
207
|
+
case 'constValue': return { ...state, state: 'nl', module: { ...state.module, consts: consts } };
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (state.top?.[0] === 'array') {
|
|
211
|
+
return { ...state, valueState: '[v', top: addToArray(state.top)(value), stack: state.stack };
|
|
212
|
+
}
|
|
213
|
+
return { ...state, valueState: '{v', top: addValueToObject(state.top)(value), stack: state.stack };
|
|
214
|
+
};
|
|
215
|
+
/** @type {(state: ParseValueState) => (name: string) => ParserState} */
|
|
216
|
+
const pushRef = state => name => {
|
|
217
|
+
const ref = at(name)(state.module.refs);
|
|
218
|
+
if (ref === null)
|
|
219
|
+
return { state: 'error', message: 'const not found' };
|
|
220
|
+
return pushValue(state)(ref);
|
|
221
|
+
};
|
|
222
|
+
/** @type {(state: ParseValueState) => ParserState} */
|
|
223
|
+
const startArray = state => {
|
|
224
|
+
const newStack = state.top === null ? null : { first: state.top, tail: state.stack };
|
|
225
|
+
return { ...state, valueState: '[', top: ['array', null], stack: newStack };
|
|
226
|
+
};
|
|
227
|
+
/** @type {(state: ParseValueState) => ParserState} */
|
|
228
|
+
const endArray = state => {
|
|
229
|
+
const top = state.top;
|
|
230
|
+
/** @type {ParseValueState} */
|
|
231
|
+
const newState = { ...state, valueState: '', top: first(null)(state.stack), stack: drop(1)(state.stack) };
|
|
232
|
+
if (top !== null && top[0] === 'array') {
|
|
233
|
+
/** @type {DjsArray} */
|
|
234
|
+
const array = ['array', toArray(top[1])];
|
|
235
|
+
return pushValue(newState)(array);
|
|
236
|
+
}
|
|
237
|
+
return pushValue(newState)(null);
|
|
238
|
+
};
|
|
239
|
+
/** @type {(state: ParseValueState) => ParserState} */
|
|
240
|
+
const startObject = state => {
|
|
241
|
+
const newStack = state.top === null ? null : { first: state.top, tail: state.stack };
|
|
242
|
+
return { ...state, valueState: '{', top: ['object', null, ''], stack: newStack };
|
|
243
|
+
};
|
|
244
|
+
/** @type {(state: ParseValueState) => ParserState} */
|
|
245
|
+
const endObject = state => {
|
|
246
|
+
const obj = state?.top !== null && state?.top[0] === 'object' ? fromMap(state.top[1]) : null;
|
|
247
|
+
/** @type {ParseValueState} */
|
|
248
|
+
const newState = { ...state, valueState: '', top: first(null)(state.stack), stack: drop(1)(state.stack) };
|
|
249
|
+
return pushValue(newState)(obj);
|
|
250
|
+
};
|
|
251
|
+
/** @type {(token: tokenizerT.DjsToken) => DjsConst} */
|
|
252
|
+
const tokenToValue = token => {
|
|
253
|
+
switch (token.kind) {
|
|
254
|
+
case 'null': return null;
|
|
255
|
+
case 'false': return false;
|
|
256
|
+
case 'true': return true;
|
|
257
|
+
case 'number': return parseFloat(token.value);
|
|
258
|
+
case 'string': return token.value;
|
|
259
|
+
case 'bigint': return token.value;
|
|
260
|
+
default: return null;
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
/** @type {(token: tokenizerT.DjsToken) => boolean} */
|
|
264
|
+
const isValueToken = token => {
|
|
265
|
+
switch (token.kind) {
|
|
266
|
+
case 'null':
|
|
267
|
+
case 'false':
|
|
268
|
+
case 'true':
|
|
269
|
+
case 'number':
|
|
270
|
+
case 'string':
|
|
271
|
+
case 'bigint': return true;
|
|
272
|
+
default: return false;
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
/** @type {(token: tokenizerT.DjsToken) => (state: ParseValueState) => ParserState}} */
|
|
276
|
+
const parseValueOp = token => state => {
|
|
277
|
+
if (isValueToken(token)) {
|
|
278
|
+
return pushValue(state)(tokenToValue(token));
|
|
279
|
+
}
|
|
280
|
+
if (token.kind === 'id') {
|
|
281
|
+
return pushRef(state)(token.value);
|
|
282
|
+
}
|
|
283
|
+
if (token.kind === '[') {
|
|
284
|
+
return startArray(state);
|
|
285
|
+
}
|
|
286
|
+
if (token.kind === '{') {
|
|
287
|
+
return startObject(state);
|
|
288
|
+
}
|
|
289
|
+
if (token.kind === 'ws') {
|
|
290
|
+
return state;
|
|
291
|
+
}
|
|
292
|
+
return { state: 'error', message: 'unexpected token' };
|
|
293
|
+
};
|
|
294
|
+
/** @type {(token: tokenizerT.DjsToken) => (state: ParseValueState) => ParserState}} */
|
|
295
|
+
const parseArrayStartOp = token => state => {
|
|
296
|
+
if (isValueToken(token)) {
|
|
297
|
+
return pushValue(state)(tokenToValue(token));
|
|
298
|
+
}
|
|
299
|
+
if (token.kind === 'id') {
|
|
300
|
+
return pushRef(state)(token.value);
|
|
301
|
+
}
|
|
302
|
+
if (token.kind === '[') {
|
|
303
|
+
return startArray(state);
|
|
304
|
+
}
|
|
305
|
+
if (token.kind === ']') {
|
|
306
|
+
return endArray(state);
|
|
307
|
+
}
|
|
308
|
+
if (token.kind === '{') {
|
|
309
|
+
return startObject(state);
|
|
310
|
+
}
|
|
311
|
+
if (token.kind === 'ws') {
|
|
312
|
+
return state;
|
|
313
|
+
}
|
|
314
|
+
return { state: 'error', message: 'unexpected token' };
|
|
315
|
+
};
|
|
316
|
+
/** @type {(token: tokenizerT.DjsToken) => (state: ParseValueState) => ParserState}} */
|
|
317
|
+
const parseArrayValueOp = token => state => {
|
|
318
|
+
if (token.kind === ']') {
|
|
319
|
+
return endArray(state);
|
|
320
|
+
}
|
|
321
|
+
if (token.kind === ',') {
|
|
322
|
+
return { ...state, valueState: '[,', top: state.top, stack: state.stack };
|
|
323
|
+
}
|
|
324
|
+
if (token.kind === 'ws') {
|
|
325
|
+
return state;
|
|
326
|
+
}
|
|
327
|
+
return { state: 'error', message: 'unexpected token' };
|
|
328
|
+
};
|
|
329
|
+
/** @type {(token: tokenizerT.DjsToken) => (state: ParseValueState) => ParserState}} */
|
|
330
|
+
const parseObjectStartOp = token => state => {
|
|
331
|
+
if (token.kind === 'string') {
|
|
332
|
+
return pushKey(state)(token.value);
|
|
333
|
+
}
|
|
334
|
+
if (token.kind === '}') {
|
|
335
|
+
return endObject(state);
|
|
336
|
+
}
|
|
337
|
+
if (token.kind === 'ws') {
|
|
338
|
+
return state;
|
|
339
|
+
}
|
|
340
|
+
return { state: 'error', message: 'unexpected token' };
|
|
341
|
+
};
|
|
342
|
+
/** @type {(token: tokenizerT.DjsToken) => (state: ParseValueState) => ParserState}} */
|
|
343
|
+
const parseObjectKeyOp = token => state => {
|
|
344
|
+
if (token.kind === ':') {
|
|
345
|
+
return { ...state, valueState: '{:', top: state.top, stack: state.stack };
|
|
346
|
+
}
|
|
347
|
+
if (token.kind === 'ws') {
|
|
348
|
+
return state;
|
|
349
|
+
}
|
|
350
|
+
return { state: 'error', message: 'unexpected token' };
|
|
351
|
+
};
|
|
352
|
+
/** @type {(token: tokenizerT.DjsToken) => (state: ParseValueState) => ParserState}} */
|
|
353
|
+
const parseObjectColonOp = token => state => {
|
|
354
|
+
if (isValueToken(token)) {
|
|
355
|
+
return pushValue(state)(tokenToValue(token));
|
|
356
|
+
}
|
|
357
|
+
if (token.kind === 'id') {
|
|
358
|
+
return pushRef(state)(token.value);
|
|
359
|
+
}
|
|
360
|
+
if (token.kind === '[') {
|
|
361
|
+
return startArray(state);
|
|
362
|
+
}
|
|
363
|
+
if (token.kind === '{') {
|
|
364
|
+
return startObject(state);
|
|
365
|
+
}
|
|
366
|
+
if (token.kind === 'ws') {
|
|
367
|
+
return state;
|
|
368
|
+
}
|
|
369
|
+
return { state: 'error', message: 'unexpected token' };
|
|
370
|
+
};
|
|
371
|
+
/** @type {(token: tokenizerT.DjsToken) => (state: ParseValueState) => ParserState}} */
|
|
372
|
+
const parseObjectNextOp = token => state => {
|
|
373
|
+
if (token.kind === '}') {
|
|
374
|
+
return endObject(state);
|
|
375
|
+
}
|
|
376
|
+
if (token.kind === ',') {
|
|
377
|
+
return { ...state, valueState: '{,', top: state.top, stack: state.stack };
|
|
378
|
+
}
|
|
379
|
+
if (token.kind === 'ws') {
|
|
380
|
+
return state;
|
|
381
|
+
}
|
|
382
|
+
return { state: 'error', message: 'unexpected token' };
|
|
383
|
+
};
|
|
384
|
+
/** @type {(token: tokenizerT.DjsToken) => (state: ParseValueState) => ParserState}} */
|
|
385
|
+
const parseObjectCommaOp = token => state => {
|
|
386
|
+
if (token.kind === 'string') {
|
|
387
|
+
return pushKey(state)(token.value);
|
|
388
|
+
}
|
|
389
|
+
if (token.kind === 'ws') {
|
|
390
|
+
return state;
|
|
391
|
+
}
|
|
392
|
+
return { state: 'error', message: 'unexpected token' };
|
|
393
|
+
};
|
|
394
|
+
/** @type {Operator.Fold<tokenizerT.DjsToken, ParserState>} */
|
|
395
|
+
const foldOp = token => state => {
|
|
396
|
+
switch (state.state) {
|
|
397
|
+
case '': return parseInitialOp(token)(state);
|
|
398
|
+
case 'nl': return parseNewLineRequiredOp(token)(state);
|
|
399
|
+
case 'import': return parseImportOp(token)(state);
|
|
400
|
+
case 'import+name': return parseImportNameOp(token)(state);
|
|
401
|
+
case 'import+from': return parseImportFromOp(token)(state);
|
|
402
|
+
case 'const': return parseConstOp(token)(state);
|
|
403
|
+
case 'const+name': return parseConstNameOp(token)(state);
|
|
404
|
+
case 'export': return parseExportOp(token)(state);
|
|
405
|
+
case 'result': return { state: 'error', message: 'unexpected token' };
|
|
406
|
+
case 'error': return { state: 'error', message: state.message };
|
|
407
|
+
case 'constValue':
|
|
408
|
+
case 'exportValue':
|
|
409
|
+
{
|
|
410
|
+
switch (state.valueState) {
|
|
411
|
+
case '': return parseValueOp(token)(state);
|
|
412
|
+
case '[': return parseArrayStartOp(token)(state);
|
|
413
|
+
case '[v': return parseArrayValueOp(token)(state);
|
|
414
|
+
case '[,': return parseValueOp(token)(state);
|
|
415
|
+
case '{': return parseObjectStartOp(token)(state);
|
|
416
|
+
case '{k': return parseObjectKeyOp(token)(state);
|
|
417
|
+
case '{:': return parseObjectColonOp(token)(state);
|
|
418
|
+
case '{v': return parseObjectNextOp(token)(state);
|
|
419
|
+
case '{,': return parseObjectCommaOp(token)(state);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
/** @type {(tokenList: list.List<tokenizerT.DjsToken>) => result.Result<DjsModule, string>} */
|
|
425
|
+
export const parse = tokenList => {
|
|
426
|
+
const state = fold(foldOp)({ state: '', module: { refs: null, modules: null, consts: null } })(tokenList);
|
|
427
|
+
switch (state.state) {
|
|
428
|
+
case 'result': return result.ok([toArray(state.module.modules), toArray(state.module.consts)]);
|
|
429
|
+
case 'error': return result.error(state.message);
|
|
430
|
+
default: return result.error('unexpected end');
|
|
431
|
+
}
|
|
432
|
+
};
|