functionalscript 0.3.4 → 0.3.5
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.d.ts +10 -0
- package/com/cpp/module.f.js +107 -0
- package/com/cpp/test.f.d.ts +2 -0
- package/com/cpp/{test.f.ts → test.f.js} +9 -11
- package/com/cpp/testlib.f.d.ts +2 -0
- package/com/cpp/testlib.f.js +5 -0
- package/com/cs/module.f.d.ts +12 -0
- package/com/cs/module.f.js +80 -0
- package/com/cs/test.f.d.ts +2 -0
- package/com/cs/{test.f.ts → test.f.js} +9 -11
- package/com/cs/testlib.f.d.ts +2 -0
- package/com/cs/testlib.f.js +5 -0
- package/com/rust/module.f.d.ts +15 -0
- package/com/rust/module.f.js +169 -0
- package/com/rust/test.f.d.ts +2 -0
- package/com/rust/{test.f.ts → test.f.js} +7 -7
- package/com/rust/testlib.f.d.ts +2 -0
- package/com/rust/testlib.f.js +5 -0
- package/com/test/build.f.d.ts +20 -0
- package/com/test/build.f.js +58 -0
- package/com/types/module.f.d.ts +28 -0
- package/com/types/module.f.js +8 -0
- package/com/types/testlib.f.d.ts +44 -0
- package/com/types/{testlib.f.ts → testlib.f.js} +2 -3
- package/commonjs/build/module.f.d.ts +6 -0
- package/commonjs/build/module.f.js +69 -0
- package/commonjs/build/test.f.d.ts +2 -0
- package/commonjs/build/test.f.js +96 -0
- package/commonjs/module/function/{module.f.ts → module.f.d.ts} +5 -10
- package/commonjs/module/function/module.f.js +4 -0
- package/commonjs/module/module.f.d.ts +18 -0
- package/commonjs/module/module.f.js +12 -0
- package/commonjs/module.f.d.ts +6 -0
- package/commonjs/module.f.js +1 -0
- package/commonjs/package/dependencies/module.f.d.ts +7 -0
- package/commonjs/package/dependencies/module.f.js +13 -0
- package/commonjs/package/dependencies/test.f.d.ts +2 -0
- package/commonjs/package/dependencies/test.f.js +15 -0
- package/commonjs/package/module.f.d.ts +17 -0
- package/commonjs/package/module.f.js +18 -0
- package/commonjs/package/test.f.d.ts +2 -0
- package/commonjs/package/test.f.js +27 -0
- package/commonjs/path/module.f.d.ts +24 -0
- package/commonjs/path/module.f.js +114 -0
- package/commonjs/path/test.f.d.ts +25 -0
- package/commonjs/path/{test.f.ts → test.f.js} +123 -89
- package/crypto/prime_field/module.f.d.ts +43 -0
- package/crypto/prime_field/module.f.js +78 -0
- package/crypto/prime_field/test.f.d.ts +13 -0
- package/crypto/prime_field/test.f.js +149 -0
- package/crypto/secp/module.f.d.ts +68 -0
- package/crypto/secp/module.f.js +127 -0
- package/crypto/secp/test.f.d.ts +5 -0
- package/crypto/secp/test.f.js +72 -0
- package/crypto/sha2/module.f.d.ts +13 -0
- package/crypto/sha2/module.f.js +145 -0
- package/crypto/sha2/test.f.d.ts +9 -0
- package/crypto/sha2/test.f.js +82 -0
- package/dev/module.f.d.ts +1 -0
- package/dev/module.f.js +1 -0
- package/dev/test/module.f.d.ts +20 -0
- package/dev/test/module.f.js +75 -0
- package/dev/test.f.d.ts +9 -0
- package/dev/{test.f.ts → test.f.js} +22 -24
- package/djs/module.f.d.ts +17 -0
- package/djs/module.f.js +63 -0
- package/djs/parser/module.f.d.ts +12 -0
- package/djs/parser/module.f.js +333 -0
- package/djs/parser/test.f.d.ts +12 -0
- package/djs/parser/test.f.js +717 -0
- package/djs/serializer/module.f.d.ts +9 -0
- package/djs/serializer/module.f.js +81 -0
- package/djs/test/input.f.d.ts +2 -0
- package/djs/test/input.f.js +4 -0
- package/djs/test/m.f.d.ts +2 -0
- package/djs/test/m.f.js +1 -0
- package/djs/test.f.d.ts +12 -0
- package/djs/test.f.js +84 -0
- package/djs/tokenizer/module.f.d.ts +8 -0
- package/djs/tokenizer/module.f.js +60 -0
- package/djs/tokenizer/test.f.d.ts +7 -0
- package/djs/tokenizer/test.f.js +529 -0
- package/fsc/module.f.d.ts +5 -0
- package/fsc/module.f.js +75 -0
- package/fsc/test.f.d.ts +4 -0
- package/fsc/test.f.js +19 -0
- package/fsm/module.f.d.ts +13 -0
- package/fsm/module.f.js +59 -0
- package/fsm/test.f.d.ts +5 -0
- package/fsm/test.f.js +137 -0
- package/html/module.f.d.ts +13 -0
- package/html/module.f.js +58 -0
- package/html/test.f.d.ts +9 -0
- package/html/test.f.js +42 -0
- package/issues/test.f.d.ts +16 -0
- package/issues/test.f.js +70 -0
- package/js/tokenizer/module.f.d.ts +86 -0
- package/js/tokenizer/module.f.js +503 -0
- package/js/tokenizer/test.f.d.ts +9 -0
- package/js/tokenizer/test.f.js +905 -0
- package/json/module.f.d.ts +20 -0
- package/json/module.f.js +68 -0
- package/json/parser/module.f.d.ts +5 -0
- package/json/parser/module.f.js +155 -0
- package/json/parser/test.f.d.ts +5 -0
- package/json/parser/test.f.js +328 -0
- package/json/serializer/module.f.d.ts +7 -0
- package/json/serializer/module.f.js +21 -0
- package/json/serializer/test.f.d.ts +8 -0
- package/json/serializer/test.f.js +87 -0
- package/json/test.f.d.ts +8 -0
- package/json/test.f.js +61 -0
- package/json/tokenizer/module.f.d.ts +8 -0
- package/json/tokenizer/module.f.js +52 -0
- package/json/tokenizer/test.f.d.ts +6 -0
- package/json/tokenizer/test.f.js +419 -0
- package/nanvm-lib/tests/test.f.d.ts +27 -0
- package/nanvm-lib/tests/test.f.js +84 -0
- package/nodejs/version/module.f.d.ts +11 -0
- package/nodejs/version/module.f.js +16 -0
- package/nodejs/version/test.f.d.ts +2 -0
- package/nodejs/version/{test.f.ts → test.f.js} +13 -22
- package/package.json +9 -5
- package/text/ascii/module.f.d.ts +129 -0
- package/text/ascii/module.f.js +148 -0
- package/text/ascii/test.f.d.ts +4 -0
- package/text/ascii/test.f.js +14 -0
- package/text/module.f.d.ts +8 -0
- package/text/module.f.js +10 -0
- package/text/sgr/module.f.d.ts +8 -0
- package/text/sgr/module.f.js +8 -0
- package/text/test.f.d.ts +2 -0
- package/text/test.f.js +18 -0
- package/text/utf16/module.f.d.ts +9 -0
- package/text/utf16/module.f.js +66 -0
- package/text/utf16/test.f.d.ts +6 -0
- package/text/utf16/test.f.js +144 -0
- package/text/utf8/module.f.d.ts +6 -0
- package/text/utf8/module.f.js +112 -0
- package/text/utf8/test.f.d.ts +6 -0
- package/text/utf8/test.f.js +175 -0
- package/types/array/module.f.d.ts +21 -0
- package/types/array/module.f.js +23 -0
- package/types/array/test.f.d.ts +10 -0
- package/types/array/test.f.js +116 -0
- package/types/bigfloat/module.f.d.ts +3 -0
- package/types/bigfloat/module.f.js +66 -0
- package/types/bigfloat/test.f.d.ts +6 -0
- package/types/bigfloat/test.f.js +349 -0
- package/types/bigint/module.f.d.ts +54 -0
- package/types/bigint/{module.f.ts → module.f.js} +42 -65
- package/types/bigint/test.f.d.ts +16 -0
- package/types/bigint/test.f.js +199 -0
- package/types/bit_vec/module.f.d.ts +134 -0
- package/types/bit_vec/{module.f.ts → module.f.js} +47 -65
- package/types/bit_vec/test.f.d.ts +22 -0
- package/types/bit_vec/test.f.js +210 -0
- package/types/btree/find/module.f.d.ts +20 -0
- package/types/btree/find/module.f.js +84 -0
- package/types/btree/find/test.f.d.ts +2 -0
- package/types/btree/find/test.f.js +152 -0
- package/types/btree/module.f.d.ts +4 -0
- package/types/btree/module.f.js +31 -0
- package/types/btree/remove/module.f.d.ts +4 -0
- package/types/btree/remove/module.f.js +174 -0
- package/types/btree/remove/test.f.d.ts +5 -0
- package/types/btree/remove/test.f.js +634 -0
- package/types/btree/set/module.f.d.ts +3 -0
- package/types/btree/set/module.f.js +103 -0
- package/types/btree/set/test.f.d.ts +2 -0
- package/types/btree/set/test.f.js +360 -0
- package/types/btree/test.f.d.ts +8 -0
- package/types/btree/test.f.js +75 -0
- package/types/btree/types/module.f.d.ts +11 -0
- package/types/btree/types/module.f.js +1 -0
- package/types/byte_set/module.f.d.ts +16 -0
- package/types/byte_set/module.f.js +28 -0
- package/types/byte_set/test.f.d.ts +12 -0
- package/types/byte_set/test.f.js +122 -0
- package/types/function/compare/module.f.d.ts +10 -0
- package/types/function/compare/module.f.js +7 -0
- package/types/function/compare/test.f.d.ts +2 -0
- package/types/function/compare/test.f.js +8 -0
- package/types/function/module.f.d.ts +28 -0
- package/types/function/module.f.js +19 -0
- package/types/function/operator/module.f.d.ts +20 -0
- package/types/function/operator/module.f.js +18 -0
- package/types/function/test.f.d.ts +2 -0
- package/types/function/test.f.js +12 -0
- package/types/list/module.f.d.ts +50 -0
- package/types/list/module.f.js +171 -0
- package/types/list/test.f.d.ts +22 -0
- package/types/list/test.f.js +395 -0
- package/types/map/module.f.d.ts +14 -0
- package/types/map/module.f.js +31 -0
- package/types/map/test.f.d.ts +5 -0
- package/types/map/test.f.js +114 -0
- package/types/nibble_set/module.f.d.ts +10 -0
- package/types/nibble_set/module.f.js +9 -0
- package/types/nibble_set/test.f.d.ts +12 -0
- package/types/nibble_set/test.f.js +90 -0
- package/types/nullable/module.f.d.ts +3 -0
- package/types/nullable/module.f.js +2 -0
- package/types/nullable/test.f.d.ts +2 -0
- package/types/nullable/test.f.js +12 -0
- package/types/number/module.f.d.ts +6 -0
- package/types/number/module.f.js +8 -0
- package/types/number/test.f.d.ts +11 -0
- package/types/number/test.f.js +124 -0
- package/types/object/module.f.d.ts +10 -0
- package/types/object/module.f.js +12 -0
- package/types/object/test.f.d.ts +5 -0
- package/types/object/test.f.js +17 -0
- package/types/range/module.f.d.ts +3 -0
- package/types/range/module.f.js +2 -0
- package/types/range/test.f.d.ts +2 -0
- package/types/range/test.f.js +18 -0
- package/types/range_map/module.f.d.ts +14 -0
- package/types/range_map/module.f.js +51 -0
- package/types/range_map/test.f.d.ts +6 -0
- package/types/range_map/test.f.js +176 -0
- package/types/result/module.f.d.ts +7 -0
- package/types/result/module.f.js +8 -0
- package/types/sorted_list/module.f.d.ts +16 -0
- package/types/sorted_list/module.f.js +56 -0
- package/types/sorted_list/test.f.d.ts +5 -0
- package/types/sorted_list/test.f.js +64 -0
- package/types/sorted_set/module.f.d.ts +7 -0
- package/types/sorted_set/module.f.js +14 -0
- package/types/sorted_set/test.f.d.ts +6 -0
- package/types/sorted_set/test.f.js +78 -0
- package/types/string/module.f.d.ts +6 -0
- package/types/string/module.f.js +11 -0
- package/types/string/test.f.d.ts +15 -0
- package/types/string/test.f.js +58 -0
- package/types/string_set/module.f.d.ts +9 -0
- package/types/string_set/module.f.js +22 -0
- package/types/string_set/test.f.d.ts +5 -0
- package/types/string_set/test.f.js +65 -0
- package/.github/FUNDING.yml +0 -12
- package/.github/dependabot.yml +0 -11
- package/.github/workflows/ci.yml +0 -88
- package/.github/workflows/npm-publish.yml +0 -53
- package/CHANGELOG.md +0 -29
- package/Cargo.lock +0 -18
- package/Cargo.toml +0 -7
- package/com/README.md +0 -3
- package/com/cpp/README.md +0 -80
- package/com/cpp/module.f.ts +0 -180
- package/com/cpp/nanocom.hpp +0 -195
- package/com/cpp/testlib.f.ts +0 -8
- package/com/cs/module.f.ts +0 -145
- package/com/cs/testlib.f.ts +0 -8
- package/com/proposals.md +0 -28
- package/com/rust/module.f.ts +0 -287
- package/com/rust/nanocom/Cargo.lock +0 -7
- package/com/rust/nanocom/Cargo.toml +0 -15
- package/com/rust/nanocom/README.md +0 -56
- package/com/rust/nanocom/src/class.rs +0 -6
- package/com/rust/nanocom/src/cobject.rs +0 -90
- package/com/rust/nanocom/src/guid.rs +0 -15
- package/com/rust/nanocom/src/hresult.rs +0 -7
- package/com/rust/nanocom/src/interface.rs +0 -9
- package/com/rust/nanocom/src/iunknown.rs +0 -13
- package/com/rust/nanocom/src/lib.rs +0 -20
- package/com/rust/nanocom/src/object.rs +0 -34
- package/com/rust/nanocom/src/ref.rs +0 -57
- package/com/rust/nanocom/src/vmt.rs +0 -7
- package/com/rust/nanocom/tests/it.rs +0 -186
- package/com/rust/nanocom/tests/itmod.rs +0 -195
- package/com/rust/testlib.f.ts +0 -8
- package/com/test/build.f.ts +0 -111
- package/com/test/build.ts +0 -45
- package/com/test/cpp/main.cpp +0 -74
- package/com/test/cs/Program.cs +0 -31
- package/com/test/cs/cs.csproj +0 -16
- package/com/test/rust/Cargo.toml +0 -12
- package/com/test/rust/src/lib.rs +0 -56
- package/com/types/module.f.ts +0 -62
- package/commonjs/README.md +0 -94
- package/commonjs/build/module.f.ts +0 -100
- package/commonjs/build/test.f.ts +0 -107
- package/commonjs/module/module.f.ts +0 -41
- package/commonjs/module.f.ts +0 -7
- package/commonjs/module.ts +0 -31
- package/commonjs/package/dependencies/module.f.ts +0 -22
- package/commonjs/package/dependencies/test.f.ts +0 -8
- package/commonjs/package/module.f.ts +0 -31
- package/commonjs/package/test.f.ts +0 -12
- package/commonjs/path/README.md +0 -17
- package/commonjs/path/module.f.ts +0 -171
- package/commonjs/test.ts +0 -64
- package/crypto/README.md +0 -3
- package/crypto/prime_field/module.f.ts +0 -114
- package/crypto/prime_field/test.f.ts +0 -95
- package/crypto/secp/module.f.ts +0 -182
- package/crypto/secp/test.f.ts +0 -68
- package/crypto/sha2/module.f.ts +0 -215
- package/crypto/sha2/test.f.ts +0 -83
- package/deno.json +0 -71
- package/dev/README.md +0 -8
- package/dev/index.ts +0 -3
- package/dev/module.f.ts +0 -1
- package/dev/module.ts +0 -195
- package/dev/test/module.f.ts +0 -135
- package/dev/test.ts +0 -53
- package/djs/README.md +0 -54
- package/djs/module.f.ts +0 -76
- package/djs/parser/module.f.ts +0 -509
- package/djs/parser/test.f.ts +0 -461
- package/djs/serializer/module.f.ts +0 -90
- package/djs/test.f.ts +0 -67
- package/djs/tokenizer/module.f.ts +0 -99
- package/djs/tokenizer/test.f.ts +0 -364
- package/doc/LANGUAGE.md +0 -255
- package/doc/README.md +0 -61
- package/doc/byte-code.md +0 -59
- package/doc/fa.md +0 -174
- package/doc/predefined.md +0 -143
- package/doc/proposals.md +0 -21
- package/doc/vm/README.md +0 -24
- package/doc/vm-rearchitecture.md +0 -129
- package/doc/vm.md +0 -150
- package/fsc/README.md +0 -111
- package/fsc/module.f.ts +0 -122
- package/fsc/test.f.ts +0 -21
- package/fsm/README.md +0 -113
- package/fsm/module.f.ts +0 -107
- package/fsm/test.f.ts +0 -139
- package/funding.json +0 -61
- package/html/README.md +0 -32
- package/html/module.f.ts +0 -109
- package/html/test.f.ts +0 -37
- package/issues/01-test-debug.md +0 -3
- package/issues/02-esm.md +0 -8
- package/issues/03-djs.md +0 -57
- package/issues/05-publish.md +0 -40
- package/issues/11-fs-load.md +0 -13
- package/issues/17-djs-extension.md +0 -6
- package/issues/README.md +0 -42
- package/issues/lang/1000-json.md +0 -50
- package/issues/lang/2110-default-export.md +0 -11
- package/issues/lang/2120-const.md +0 -14
- package/issues/lang/2130-default-import.md +0 -10
- package/issues/lang/2210-block-comment.md +0 -12
- package/issues/lang/2220-namespace-import.md +0 -25
- package/issues/lang/2310-undefined.md +0 -7
- package/issues/lang/2320-bigint.md +0 -7
- package/issues/lang/2330-property-accessor.md +0 -225
- package/issues/lang/2340-operators.md +0 -41
- package/issues/lang/2350-grouping.md +0 -11
- package/issues/lang/2360-built-in.md +0 -81
- package/issues/lang/2410-identifier-property.md +0 -9
- package/issues/lang/2420-line-comment.md +0 -10
- package/issues/lang/2430-trailing-comma.md +0 -13
- package/issues/lang/2440-shorthand.md +0 -8
- package/issues/lang/2450-destructuring.md +0 -12
- package/issues/lang/3110-function.md +0 -35
- package/issues/lang/3120-parameters.md +0 -9
- package/issues/lang/3130-body-const.md +0 -12
- package/issues/lang/3220-let.md +0 -11
- package/issues/lang/3240-export.md +0 -44
- package/issues/lang/3370-type-inference.md +0 -69
- package/issues/lang/3380-promise.md +0 -22
- package/issues/lang/3390-class.md +0 -3
- package/issues/lang/3410-expression.md +0 -12
- package/issues/lang/3420-one-parameter.md +0 -10
- package/issues/lang/3430-assignments.md +0 -23
- package/issues/lang/README.md +0 -193
- package/issues/test.f.ts +0 -58
- package/js/tokenizer/module.f.ts +0 -882
- package/js/tokenizer/test.f.ts +0 -617
- package/json/html/README.md +0 -49
- package/json/module.f.ts +0 -94
- package/json/parser/module.f.ts +0 -221
- package/json/parser/test.f.ts +0 -255
- package/json/serializer/module.f.ts +0 -74
- package/json/serializer/test.f.ts +0 -64
- package/json/test.f.ts +0 -48
- package/json/tokenizer/module.f.ts +0 -85
- package/json/tokenizer/test.f.ts +0 -290
- package/nanvm-lib/Cargo.toml +0 -6
- package/nanvm-lib/src/extension.rs +0 -130
- package/nanvm-lib/src/interface.rs +0 -133
- package/nanvm-lib/src/lib.rs +0 -7
- package/nanvm-lib/src/naive.rs +0 -236
- package/nanvm-lib/src/nanenum.rs +0 -236
- package/nanvm-lib/src/nullish.rs +0 -7
- package/nanvm-lib/src/sign.rs +0 -5
- package/nanvm-lib/src/simple.rs +0 -32
- package/nanvm-lib/tests/test.f.ts +0 -80
- package/nanvm-lib/tests/test.rs +0 -108
- package/nodejs/version/main.ts +0 -4
- package/nodejs/version/module.f.ts +0 -42
- package/text/README.md +0 -110
- package/text/ascii/module.f.ts +0 -219
- package/text/ascii/test.f.ts +0 -14
- package/text/module.f.ts +0 -30
- package/text/sgr/README.md +0 -3
- package/text/sgr/module.f.ts +0 -11
- package/text/test.f.ts +0 -19
- package/text/utf16/module.f.ts +0 -120
- package/text/utf16/test.f.ts +0 -107
- package/text/utf8/module.f.ts +0 -116
- package/text/utf8/test.f.ts +0 -125
- package/tsconfig.json +0 -104
- package/types/array/module.f.ts +0 -89
- package/types/array/test.f.ts +0 -88
- package/types/bigfloat/module.f.ts +0 -93
- package/types/bigfloat/test.f.ts +0 -218
- package/types/bigint/README.md +0 -35
- package/types/bigint/test.f.ts +0 -144
- package/types/bit_vec/README.md +0 -18
- package/types/bit_vec/test.f.ts +0 -129
- package/types/btree/README.md +0 -160
- package/types/btree/find/module.f.ts +0 -92
- package/types/btree/find/test.f.ts +0 -122
- package/types/btree/module.f.ts +0 -35
- package/types/btree/remove/module.f.ts +0 -151
- package/types/btree/remove/test.f.ts +0 -498
- package/types/btree/set/module.f.ts +0 -89
- package/types/btree/set/test.f.ts +0 -415
- package/types/btree/test.f.ts +0 -92
- package/types/btree/types/module.f.ts +0 -27
- package/types/byte_set/module.f.ts +0 -73
- package/types/byte_set/test.f.ts +0 -84
- package/types/function/compare/module.f.ts +0 -26
- package/types/function/compare/test.f.ts +0 -7
- package/types/function/module.f.ts +0 -43
- package/types/function/operator/module.f.ts +0 -65
- package/types/function/test.f.ts +0 -20
- package/types/list/module.f.ts +0 -350
- package/types/list/test.f.ts +0 -327
- package/types/map/module.f.ts +0 -65
- package/types/map/test.f.ts +0 -76
- package/types/nibble_set/module.f.ts +0 -34
- package/types/nibble_set/test.f.ts +0 -57
- package/types/nullable/module.f.ts +0 -9
- package/types/nullable/test.f.ts +0 -9
- package/types/number/module.f.ts +0 -20
- package/types/number/test.f.ts +0 -194
- package/types/object/module.f.ts +0 -30
- package/types/object/test.f.ts +0 -14
- package/types/range/module.f.ts +0 -10
- package/types/range/test.f.ts +0 -9
- package/types/range_map/module.f.ts +0 -70
- package/types/range_map/test.f.ts +0 -189
- package/types/result/module.f.ts +0 -20
- package/types/result/module.ts +0 -18
- package/types/sorted_list/module.f.ts +0 -83
- package/types/sorted_list/test.f.ts +0 -57
- package/types/sorted_set/module.f.ts +0 -36
- package/types/sorted_set/test.f.ts +0 -67
- package/types/string/module.f.ts +0 -26
- package/types/string/test.f.ts +0 -43
- package/types/string_set/module.f.ts +0 -37
- package/types/string_set/test.f.ts +0 -34
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
import * as operator from "../../types/function/operator/module.f.js";
|
|
2
|
+
import * as range_map from "../../types/range_map/module.f.js";
|
|
3
|
+
const { merge, fromRange, get } = range_map;
|
|
4
|
+
import * as list from "../../types/list/module.f.js";
|
|
5
|
+
import * as map from "../../types/map/module.f.js";
|
|
6
|
+
const { at } = map;
|
|
7
|
+
import * as _range from "../../types/range/module.f.js";
|
|
8
|
+
const { one } = _range;
|
|
9
|
+
const { empty, stateScan, flat, toArray, reduce: listReduce, scan } = list;
|
|
10
|
+
import * as bigfloatT from "../../types/bigfloat/module.f.js";
|
|
11
|
+
const { fromCharCode } = String;
|
|
12
|
+
import * as ascii from "../../text/ascii/module.f.js";
|
|
13
|
+
const { range } = ascii;
|
|
14
|
+
const {
|
|
15
|
+
//
|
|
16
|
+
backspace, ht, lf, ff, cr,
|
|
17
|
+
//
|
|
18
|
+
exclamationMark, percentSign, ampersand, asterisk, lessThanSign, equalsSign, greaterThanSign, questionMark, circumflexAccent, verticalLine, tilde,
|
|
19
|
+
//
|
|
20
|
+
space, quotationMark, leftParenthesis, rightParenthesis, plusSign, comma, hyphenMinus, fullStop, solidus,
|
|
21
|
+
//
|
|
22
|
+
digitRange, digit0, colon,
|
|
23
|
+
//
|
|
24
|
+
latinCapitalLetterRange, latinCapitalLetterA, latinCapitalLetterE,
|
|
25
|
+
//
|
|
26
|
+
leftSquareBracket, reverseSolidus, rightSquareBracket, lowLine,
|
|
27
|
+
//
|
|
28
|
+
latinSmallLetterRange, latinSmallLetterA, latinSmallLetterB, latinSmallLetterE, latinSmallLetterF, latinSmallLetterN, latinSmallLetterR, latinSmallLetterT, latinSmallLetterU,
|
|
29
|
+
//
|
|
30
|
+
leftCurlyBracket, rightCurlyBracket, dollarSign } = ascii;
|
|
31
|
+
const rangeOneNine = range('19');
|
|
32
|
+
const rangeSetNewLine = [
|
|
33
|
+
one(lf),
|
|
34
|
+
one(cr)
|
|
35
|
+
];
|
|
36
|
+
const rangeSetWhiteSpace = [
|
|
37
|
+
one(ht),
|
|
38
|
+
one(space)
|
|
39
|
+
];
|
|
40
|
+
const rangeSetTerminalForNumber = [
|
|
41
|
+
...rangeSetWhiteSpace,
|
|
42
|
+
...rangeSetNewLine,
|
|
43
|
+
one(exclamationMark),
|
|
44
|
+
one(percentSign),
|
|
45
|
+
one(ampersand),
|
|
46
|
+
one(leftParenthesis),
|
|
47
|
+
one(rightParenthesis),
|
|
48
|
+
one(asterisk),
|
|
49
|
+
one(comma),
|
|
50
|
+
one(solidus),
|
|
51
|
+
one(colon),
|
|
52
|
+
one(lessThanSign),
|
|
53
|
+
one(equalsSign),
|
|
54
|
+
one(greaterThanSign),
|
|
55
|
+
one(questionMark),
|
|
56
|
+
one(circumflexAccent),
|
|
57
|
+
one(leftSquareBracket),
|
|
58
|
+
one(rightSquareBracket),
|
|
59
|
+
one(leftCurlyBracket),
|
|
60
|
+
one(verticalLine),
|
|
61
|
+
one(rightCurlyBracket),
|
|
62
|
+
one(tilde),
|
|
63
|
+
];
|
|
64
|
+
const rangeSmallAF = range('af');
|
|
65
|
+
const rangeCapitalAF = range('AF');
|
|
66
|
+
const rangeIdStart = [
|
|
67
|
+
latinSmallLetterRange,
|
|
68
|
+
latinCapitalLetterRange,
|
|
69
|
+
one(lowLine),
|
|
70
|
+
one(dollarSign)
|
|
71
|
+
];
|
|
72
|
+
const rangeOpStart = [
|
|
73
|
+
one(exclamationMark),
|
|
74
|
+
one(percentSign),
|
|
75
|
+
one(ampersand),
|
|
76
|
+
one(leftParenthesis),
|
|
77
|
+
one(rightParenthesis),
|
|
78
|
+
one(asterisk),
|
|
79
|
+
one(plusSign),
|
|
80
|
+
one(comma),
|
|
81
|
+
one(hyphenMinus),
|
|
82
|
+
one(fullStop),
|
|
83
|
+
one(solidus),
|
|
84
|
+
one(colon),
|
|
85
|
+
one(lessThanSign),
|
|
86
|
+
one(equalsSign),
|
|
87
|
+
one(greaterThanSign),
|
|
88
|
+
one(questionMark),
|
|
89
|
+
one(circumflexAccent),
|
|
90
|
+
one(leftSquareBracket),
|
|
91
|
+
one(rightSquareBracket),
|
|
92
|
+
one(leftCurlyBracket),
|
|
93
|
+
one(verticalLine),
|
|
94
|
+
one(rightCurlyBracket),
|
|
95
|
+
one(tilde)
|
|
96
|
+
];
|
|
97
|
+
const rangeId = [digitRange, ...rangeIdStart];
|
|
98
|
+
const appendChar = old => input => `${old}${fromCharCode(input)}`;
|
|
99
|
+
const union = def => a => b => {
|
|
100
|
+
if (a === def || a === b) {
|
|
101
|
+
return b;
|
|
102
|
+
}
|
|
103
|
+
if (b === def) {
|
|
104
|
+
return a;
|
|
105
|
+
}
|
|
106
|
+
throw [a, b];
|
|
107
|
+
};
|
|
108
|
+
const rangeMapMerge = def => merge({
|
|
109
|
+
union: union(def),
|
|
110
|
+
equal: operator.strictEqual,
|
|
111
|
+
});
|
|
112
|
+
const rangeFunc = r => f => def => fromRange(def)(r)(f);
|
|
113
|
+
const scanRangeOp = def => f => [f(def), scanRangeOp(def)];
|
|
114
|
+
const reduceRangeMap = def => a => {
|
|
115
|
+
const rm = scan(scanRangeOp(def))(a);
|
|
116
|
+
return toArray(listReduce(rangeMapMerge(def))(empty)(rm));
|
|
117
|
+
};
|
|
118
|
+
const scanRangeSetOp = def => f => r => [fromRange(def)(r)(f), scanRangeSetOp(def)(f)];
|
|
119
|
+
const rangeSetFunc = rs => f => def => {
|
|
120
|
+
const rm = scan(scanRangeSetOp(def)(f))(rs);
|
|
121
|
+
return toArray(listReduce(rangeMapMerge(def))(empty)(rm));
|
|
122
|
+
};
|
|
123
|
+
const create = (def) => (a) => {
|
|
124
|
+
const i = reduceRangeMap(def)(a);
|
|
125
|
+
const x = get(def);
|
|
126
|
+
return v => c => x(c)(i)(v)(c);
|
|
127
|
+
};
|
|
128
|
+
const digitToBigInt = d => BigInt(d - digit0);
|
|
129
|
+
const startNumber = digit => ({ s: 1n, m: digitToBigInt(digit), f: 0, es: 1, e: 0 });
|
|
130
|
+
const startNegativeNumber = { s: -1n, m: 0n, f: 0, es: 1, e: 0 };
|
|
131
|
+
const addIntDigit = digit => b => ({ ...b, m: b.m * 10n + digitToBigInt(digit) });
|
|
132
|
+
const addFracDigit = digit => b => ({ ...b, m: b.m * 10n + digitToBigInt(digit), f: b.f - 1 });
|
|
133
|
+
const addExpDigit = digit => b => ({ ...b, e: b.e * 10 + digit - digit0 });
|
|
134
|
+
const bufferToNumberToken = ({ numberKind, value, b }) => {
|
|
135
|
+
if (numberKind === 'bigint')
|
|
136
|
+
return { kind: 'bigint', value: b.s * b.m };
|
|
137
|
+
return { kind: 'number', value: value, bf: [b.s * b.m, b.f + b.es * b.e] };
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#keywords
|
|
141
|
+
*/
|
|
142
|
+
const keywordEntries = [
|
|
143
|
+
['arguments', { kind: 'arguments' }],
|
|
144
|
+
['await', { kind: 'await' }],
|
|
145
|
+
['break', { kind: 'break' }],
|
|
146
|
+
['case', { kind: 'case' }],
|
|
147
|
+
['catch', { kind: 'catch' }],
|
|
148
|
+
['class', { kind: 'class' }],
|
|
149
|
+
['const', { kind: 'const' }],
|
|
150
|
+
['continue', { kind: 'continue' }],
|
|
151
|
+
['debugger', { kind: 'debugger' }],
|
|
152
|
+
['default', { kind: 'default' }],
|
|
153
|
+
['delete', { kind: 'delete' }],
|
|
154
|
+
['do', { kind: 'do' }],
|
|
155
|
+
['else', { kind: 'else' }],
|
|
156
|
+
['enum', { kind: 'enum' }],
|
|
157
|
+
['eval', { kind: 'eval' }],
|
|
158
|
+
['export', { kind: 'export' }],
|
|
159
|
+
['extends', { kind: 'extends' }],
|
|
160
|
+
['false', { kind: 'false' }],
|
|
161
|
+
['finally', { kind: 'finally' }],
|
|
162
|
+
['for', { kind: 'for' }],
|
|
163
|
+
['function', { kind: 'function' }],
|
|
164
|
+
['if', { kind: 'if' }],
|
|
165
|
+
['implements', { kind: 'implements' }],
|
|
166
|
+
['import', { kind: 'import' }],
|
|
167
|
+
['in', { kind: 'in' }],
|
|
168
|
+
['instanceof', { kind: 'instanceof' }],
|
|
169
|
+
['interface', { kind: 'interface' }],
|
|
170
|
+
['let', { kind: 'let' }],
|
|
171
|
+
['new', { kind: 'new' }],
|
|
172
|
+
['null', { kind: 'null' }],
|
|
173
|
+
['package', { kind: 'package' }],
|
|
174
|
+
['private', { kind: 'private' }],
|
|
175
|
+
['protected', { kind: 'protected' }],
|
|
176
|
+
['public', { kind: 'public' }],
|
|
177
|
+
['return', { kind: 'return' }],
|
|
178
|
+
['static', { kind: 'static' }],
|
|
179
|
+
['super', { kind: 'super' }],
|
|
180
|
+
['switch', { kind: 'switch' }],
|
|
181
|
+
['this', { kind: 'this' }],
|
|
182
|
+
['throw', { kind: 'throw' }],
|
|
183
|
+
['true', { kind: 'true' }],
|
|
184
|
+
['try', { kind: 'try' }],
|
|
185
|
+
['typeof', { kind: 'typeof' }],
|
|
186
|
+
['undefined', { kind: 'undefined' }],
|
|
187
|
+
['var', { kind: 'var' }],
|
|
188
|
+
['void', { kind: 'void' }],
|
|
189
|
+
['while', { kind: 'while' }],
|
|
190
|
+
['with', { kind: 'with' }],
|
|
191
|
+
['yield', { kind: 'yield' }],
|
|
192
|
+
];
|
|
193
|
+
const keywordMap = map.fromEntries(keywordEntries);
|
|
194
|
+
export const isKeywordToken = token => at(token.kind)(keywordMap) !== null;
|
|
195
|
+
/**
|
|
196
|
+
* @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators
|
|
197
|
+
*/
|
|
198
|
+
const operatorEntries = [
|
|
199
|
+
['!', { kind: '!' }],
|
|
200
|
+
['!=', { kind: '!=' }],
|
|
201
|
+
['!==', { kind: '!==' }],
|
|
202
|
+
['%', { kind: '%' }],
|
|
203
|
+
['%=', { kind: '%=' }],
|
|
204
|
+
['&', { kind: '&' }],
|
|
205
|
+
['&&', { kind: '&&' }],
|
|
206
|
+
['&&=', { kind: '&&=' }],
|
|
207
|
+
['&=', { kind: '&=' }],
|
|
208
|
+
['(', { kind: '(' }],
|
|
209
|
+
[')', { kind: ')' }],
|
|
210
|
+
['*', { kind: '*' }],
|
|
211
|
+
['**', { kind: '**' }],
|
|
212
|
+
['**=', { kind: '**=' }],
|
|
213
|
+
['*=', { kind: '*=' }],
|
|
214
|
+
['+', { kind: '+' }],
|
|
215
|
+
['++', { kind: '++' }],
|
|
216
|
+
['+=', { kind: '+=' }],
|
|
217
|
+
[',', { kind: ',' }],
|
|
218
|
+
['-', { kind: '-' }],
|
|
219
|
+
['--', { kind: '--' }],
|
|
220
|
+
['-=', { kind: '-=' }],
|
|
221
|
+
['.', { kind: '.' }],
|
|
222
|
+
['/', { kind: '/' }],
|
|
223
|
+
['/=', { kind: '/=' }],
|
|
224
|
+
[':', { kind: ':' }],
|
|
225
|
+
['<', { kind: '<' }],
|
|
226
|
+
['<<', { kind: '<<' }],
|
|
227
|
+
['<<=', { kind: '<<=' }],
|
|
228
|
+
['<=', { kind: '<=' }],
|
|
229
|
+
['=', { kind: '=' }],
|
|
230
|
+
['==', { kind: '==' }],
|
|
231
|
+
['===', { kind: '===' }],
|
|
232
|
+
['=>', { kind: '=>' }],
|
|
233
|
+
['>', { kind: '>' }],
|
|
234
|
+
['>=', { kind: '>=' }],
|
|
235
|
+
['>>', { kind: '>>' }],
|
|
236
|
+
['>>=', { kind: '>>=' }],
|
|
237
|
+
['>>>', { kind: '>>>' }],
|
|
238
|
+
['>>>=', { kind: '>>>=' }],
|
|
239
|
+
['?', { kind: '?' }],
|
|
240
|
+
['?.', { kind: '?.' }],
|
|
241
|
+
['??', { kind: '??' }],
|
|
242
|
+
['??=', { kind: '??=' }],
|
|
243
|
+
['^', { kind: '^' }],
|
|
244
|
+
['^=', { kind: '^=' }],
|
|
245
|
+
['[', { kind: '[' }],
|
|
246
|
+
[']', { kind: ']' }],
|
|
247
|
+
['{', { kind: '{' }],
|
|
248
|
+
['|', { kind: '|' }],
|
|
249
|
+
['|=', { kind: '|=' }],
|
|
250
|
+
['||', { kind: '||' }],
|
|
251
|
+
['||=', { kind: '||=' }],
|
|
252
|
+
['}', { kind: '}' }],
|
|
253
|
+
['~', { kind: '~' }]
|
|
254
|
+
];
|
|
255
|
+
const operatorMap = map.fromEntries(operatorEntries);
|
|
256
|
+
const getOperatorToken = op => at(op)(operatorMap) ?? { kind: 'error', message: 'invalid token' };
|
|
257
|
+
const hasOperatorToken = op => at(op)(operatorMap) !== null;
|
|
258
|
+
const initialStateOp = create((state) => () => [[{ kind: 'error', message: 'unexpected character' }], state])([
|
|
259
|
+
rangeFunc(rangeOneNine)(() => input => [empty, { kind: 'number', value: fromCharCode(input), b: startNumber(input), numberKind: 'int' }]),
|
|
260
|
+
rangeSetFunc(rangeIdStart)(() => input => [empty, { kind: 'id', value: fromCharCode(input) }]),
|
|
261
|
+
rangeSetFunc(rangeSetWhiteSpace)(() => () => [empty, { kind: 'ws' }]),
|
|
262
|
+
rangeSetFunc(rangeSetNewLine)(() => () => [empty, { kind: 'nl' }]),
|
|
263
|
+
rangeFunc(one(quotationMark))(() => () => [empty, { kind: 'string', value: '' }]),
|
|
264
|
+
rangeFunc(one(digit0))(() => input => [empty, { kind: 'number', value: fromCharCode(input), b: startNumber(input), numberKind: '0' }]),
|
|
265
|
+
rangeSetFunc(rangeOpStart)(() => input => [empty, { kind: 'op', value: fromCharCode(input) }])
|
|
266
|
+
]);
|
|
267
|
+
const invalidNumberToToken = () => input => {
|
|
268
|
+
const next = tokenizeOp({ kind: 'initial' })(input);
|
|
269
|
+
return [{ first: { kind: 'error', message: 'invalid number' }, tail: next[0] }, next[1]];
|
|
270
|
+
};
|
|
271
|
+
const fullStopToToken = state => input => {
|
|
272
|
+
switch (state.numberKind) {
|
|
273
|
+
case '0':
|
|
274
|
+
case 'int': return [empty, { kind: 'number', value: appendChar(state.value)(input), b: state.b, numberKind: '.' }];
|
|
275
|
+
default: return tokenizeOp({ kind: 'invalidNumber' })(input);
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
const digit0ToToken = state => input => {
|
|
279
|
+
switch (state.numberKind) {
|
|
280
|
+
case '0': return tokenizeOp({ kind: 'invalidNumber' })(input);
|
|
281
|
+
case '.':
|
|
282
|
+
case 'fractional': return [empty, { kind: 'number', value: appendChar(state.value)(input), b: addFracDigit(input)(state.b), numberKind: 'fractional' }];
|
|
283
|
+
case 'e':
|
|
284
|
+
case 'e+':
|
|
285
|
+
case 'e-':
|
|
286
|
+
case 'expDigits': return [empty, { kind: 'number', value: appendChar(state.value)(input), b: addExpDigit(input)(state.b), numberKind: 'expDigits' }];
|
|
287
|
+
default: return [empty, { kind: 'number', value: appendChar(state.value)(input), b: addIntDigit(input)(state.b), numberKind: state.numberKind }];
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
const digit19ToToken = state => input => {
|
|
291
|
+
switch (state.numberKind) {
|
|
292
|
+
case '0': return tokenizeOp({ kind: 'invalidNumber' })(input);
|
|
293
|
+
case '.':
|
|
294
|
+
case 'fractional': return [empty, { kind: 'number', value: appendChar(state.value)(input), b: addFracDigit(input)(state.b), numberKind: 'fractional' }];
|
|
295
|
+
case 'e':
|
|
296
|
+
case 'e+':
|
|
297
|
+
case 'e-':
|
|
298
|
+
case 'expDigits': return [empty, { kind: 'number', value: appendChar(state.value)(input), b: addExpDigit(input)(state.b), numberKind: 'expDigits' }];
|
|
299
|
+
default: return [empty, { kind: 'number', value: appendChar(state.value)(input), b: addIntDigit(input)(state.b), numberKind: 'int' }];
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
const expToToken = state => input => {
|
|
303
|
+
switch (state.numberKind) {
|
|
304
|
+
case '0':
|
|
305
|
+
case 'int':
|
|
306
|
+
case 'fractional': return [empty, { kind: 'number', value: appendChar(state.value)(input), b: state.b, numberKind: 'e' }];
|
|
307
|
+
default: return tokenizeOp({ kind: 'invalidNumber' })(input);
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
const hyphenMinusToToken = state => input => {
|
|
311
|
+
switch (state.numberKind) {
|
|
312
|
+
case 'e': return [empty, { kind: 'number', value: appendChar(state.value)(input), b: { ...state.b, es: -1 }, numberKind: 'e-' }];
|
|
313
|
+
default: return terminalToToken(state)(input);
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
const plusSignToToken = state => input => {
|
|
317
|
+
switch (state.numberKind) {
|
|
318
|
+
case 'e': return [empty, { kind: 'number', value: appendChar(state.value)(input), b: state.b, numberKind: 'e+' }];
|
|
319
|
+
default: return tokenizeOp({ kind: 'invalidNumber' })(input);
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
const terminalToToken = state => input => {
|
|
323
|
+
switch (state.numberKind) {
|
|
324
|
+
case '.':
|
|
325
|
+
case 'e':
|
|
326
|
+
case 'e+':
|
|
327
|
+
case 'e-':
|
|
328
|
+
{
|
|
329
|
+
const next = tokenizeOp({ kind: 'initial' })(input);
|
|
330
|
+
return [{ first: { kind: 'error', message: 'invalid number' }, tail: next[0] }, next[1]];
|
|
331
|
+
}
|
|
332
|
+
default:
|
|
333
|
+
{
|
|
334
|
+
const next = tokenizeOp({ kind: 'initial' })(input);
|
|
335
|
+
return [{ first: bufferToNumberToken(state), tail: next[0] }, next[1]];
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
const bigintToToken = state => input => {
|
|
340
|
+
switch (state.numberKind) {
|
|
341
|
+
case '0':
|
|
342
|
+
case 'int':
|
|
343
|
+
{
|
|
344
|
+
return [empty, { kind: 'number', value: state.value, b: state.b, numberKind: 'bigint' }];
|
|
345
|
+
}
|
|
346
|
+
default:
|
|
347
|
+
{
|
|
348
|
+
const next = tokenizeOp({ kind: 'initial' })(input);
|
|
349
|
+
return [{ first: { kind: 'error', message: 'invalid number' }, tail: next[0] }, next[1]];
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
const parseNumberStateOp = create(invalidNumberToToken)([
|
|
354
|
+
rangeFunc(one(fullStop))(fullStopToToken),
|
|
355
|
+
rangeFunc(one(digit0))(digit0ToToken),
|
|
356
|
+
rangeFunc(rangeOneNine)(digit19ToToken),
|
|
357
|
+
rangeSetFunc([one(latinSmallLetterE), one(latinCapitalLetterE)])(expToToken),
|
|
358
|
+
rangeFunc(one(hyphenMinus))(hyphenMinusToToken),
|
|
359
|
+
rangeFunc(one(plusSign))(plusSignToToken),
|
|
360
|
+
rangeSetFunc(rangeSetTerminalForNumber)(terminalToToken),
|
|
361
|
+
rangeFunc(one(latinSmallLetterN))(bigintToToken),
|
|
362
|
+
]);
|
|
363
|
+
const invalidNumberStateOp = create(() => () => [empty, { kind: 'invalidNumber' }])([
|
|
364
|
+
rangeSetFunc(rangeSetTerminalForNumber)(() => input => {
|
|
365
|
+
const next = tokenizeOp({ kind: 'initial' })(input);
|
|
366
|
+
return [{ first: { kind: 'error', message: 'invalid number' }, tail: next[0] }, next[1]];
|
|
367
|
+
})
|
|
368
|
+
]);
|
|
369
|
+
const parseStringStateOp = create((state) => input => [empty, { kind: 'string', value: appendChar(state.value)(input) }])([
|
|
370
|
+
rangeFunc(one(quotationMark))(state => () => [[{ kind: 'string', value: state.value }], { kind: 'initial' }]),
|
|
371
|
+
rangeFunc(one(reverseSolidus))(state => () => [empty, { kind: 'escapeChar', value: state.value }]),
|
|
372
|
+
rangeSetFunc(rangeSetNewLine)(() => () => [[{ kind: 'error', message: 'unterminated string literal' }], { kind: 'nl' }])
|
|
373
|
+
]);
|
|
374
|
+
const parseEscapeDefault = state => input => {
|
|
375
|
+
const next = tokenizeOp({ kind: 'string', value: state.value })(input);
|
|
376
|
+
return [{ first: { kind: 'error', message: 'unescaped character' }, tail: next[0] }, next[1]];
|
|
377
|
+
};
|
|
378
|
+
const parseEscapeCharStateOp = create(parseEscapeDefault)([
|
|
379
|
+
rangeSetFunc([one(quotationMark), one(reverseSolidus), one(solidus)])(state => input => [empty, { kind: 'string', value: appendChar(state.value)(input) }]),
|
|
380
|
+
rangeFunc(one(latinSmallLetterB))(state => () => [empty, { kind: 'string', value: appendChar(state.value)(backspace) }]),
|
|
381
|
+
rangeFunc(one(latinSmallLetterF))(state => () => [empty, { kind: 'string', value: appendChar(state.value)(ff) }]),
|
|
382
|
+
rangeFunc(one(latinSmallLetterN))(state => () => [empty, { kind: 'string', value: appendChar(state.value)(lf) }]),
|
|
383
|
+
rangeFunc(one(latinSmallLetterR))(state => () => [empty, { kind: 'string', value: appendChar(state.value)(cr) }]),
|
|
384
|
+
rangeFunc(one(latinSmallLetterT))(state => () => [empty, { kind: 'string', value: appendChar(state.value)(ht) }]),
|
|
385
|
+
rangeFunc(one(latinSmallLetterU))(state => () => [empty, { kind: 'unicodeChar', value: state.value, unicode: 0, hexIndex: 0 }]),
|
|
386
|
+
]);
|
|
387
|
+
const parseUnicodeCharDefault = state => input => {
|
|
388
|
+
const next = tokenizeOp({ kind: 'string', value: state.value })(input);
|
|
389
|
+
return [{ first: { kind: 'error', message: 'invalid hex value' }, tail: next[0] }, next[1]];
|
|
390
|
+
};
|
|
391
|
+
const parseUnicodeCharHex = offset => state => input => {
|
|
392
|
+
const hexValue = input - offset;
|
|
393
|
+
const newUnicode = state.unicode | (hexValue << (3 - state.hexIndex) * 4);
|
|
394
|
+
return [empty, state.hexIndex === 3 ?
|
|
395
|
+
{ kind: 'string', value: appendChar(state.value)(newUnicode) } :
|
|
396
|
+
{ kind: 'unicodeChar', value: state.value, unicode: newUnicode, hexIndex: state.hexIndex + 1 }];
|
|
397
|
+
};
|
|
398
|
+
const parseUnicodeCharStateOp = create(parseUnicodeCharDefault)([
|
|
399
|
+
rangeFunc(digitRange)(parseUnicodeCharHex(digit0)),
|
|
400
|
+
rangeFunc(rangeSmallAF)(parseUnicodeCharHex(latinSmallLetterA - 10)),
|
|
401
|
+
rangeFunc(rangeCapitalAF)(parseUnicodeCharHex(latinCapitalLetterA - 10))
|
|
402
|
+
]);
|
|
403
|
+
const idToToken = s => at(s)(keywordMap) ?? { kind: 'id', value: s };
|
|
404
|
+
const parseIdDefault = state => input => {
|
|
405
|
+
const keyWordToken = idToToken(state.value);
|
|
406
|
+
const next = tokenizeOp({ kind: 'initial' })(input);
|
|
407
|
+
return [{ first: keyWordToken, tail: next[0] }, next[1]];
|
|
408
|
+
};
|
|
409
|
+
const parseIdStateOp = create(parseIdDefault)([
|
|
410
|
+
rangeSetFunc(rangeId)(state => input => [empty, { kind: 'id', value: appendChar(state.value)(input) }])
|
|
411
|
+
]);
|
|
412
|
+
const parseOperatorStateOp = state => input => {
|
|
413
|
+
const nextStateValue = appendChar(state.value)(input);
|
|
414
|
+
switch (nextStateValue) {
|
|
415
|
+
case '//': return [empty, { kind: '//', value: '', newLine: false }];
|
|
416
|
+
case '/*': return [empty, { kind: '/*', value: '', newLine: false }];
|
|
417
|
+
default: {
|
|
418
|
+
if (hasOperatorToken(nextStateValue))
|
|
419
|
+
return [empty, { kind: 'op', value: nextStateValue }];
|
|
420
|
+
const next = tokenizeOp({ kind: 'initial' })(input);
|
|
421
|
+
return [{ first: getOperatorToken(state.value), tail: next[0] }, next[1]];
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
const parseSinglelineCommentStateOp = create((state) => input => [empty, { ...state, value: appendChar(state.value)(input) }])([
|
|
426
|
+
rangeSetFunc(rangeSetNewLine)(state => () => [[{ kind: '//', value: state.value }], { kind: 'nl' }])
|
|
427
|
+
]);
|
|
428
|
+
const parseMultilineCommentStateOp = create((state) => input => [empty, { ...state, value: appendChar(state.value)(input) }])([
|
|
429
|
+
rangeFunc(one(asterisk))(state => () => [empty, { ...state, kind: '/**' }]),
|
|
430
|
+
rangeSetFunc(rangeSetNewLine)(state => input => [empty, { ...state, value: appendChar(state.value)(input), newLine: true }]),
|
|
431
|
+
]);
|
|
432
|
+
const parseMultilineCommentAsteriskStateOp = create((state) => input => [empty, { ...state, kind: '/*', value: appendChar(appendChar(state.value)(asterisk))(input) }])([
|
|
433
|
+
rangeFunc(one(asterisk))(state => () => [empty, { ...state, value: appendChar(state.value)(asterisk) }]),
|
|
434
|
+
rangeSetFunc(rangeSetNewLine)(state => input => [empty, { kind: '/*', value: appendChar(appendChar(state.value)(asterisk))(input), newLine: true }]),
|
|
435
|
+
rangeFunc(one(solidus))(state => () => {
|
|
436
|
+
const tokens = state.newLine ? [{ kind: '/*', value: state.value }, { kind: 'nl' }] : [{ kind: '/*', value: state.value }];
|
|
437
|
+
return [tokens, { kind: 'initial' }];
|
|
438
|
+
})
|
|
439
|
+
]);
|
|
440
|
+
const parseWhitespaceDefault = () => input => {
|
|
441
|
+
const next = tokenizeOp({ kind: 'initial' })(input);
|
|
442
|
+
return [{ first: { kind: 'ws' }, tail: next[0] }, next[1]];
|
|
443
|
+
};
|
|
444
|
+
const parseWhitespaceStateOp = create(parseWhitespaceDefault)([
|
|
445
|
+
rangeSetFunc(rangeSetWhiteSpace)(state => () => [empty, state]),
|
|
446
|
+
rangeSetFunc(rangeSetNewLine)(() => () => [empty, { kind: 'nl' }])
|
|
447
|
+
]);
|
|
448
|
+
const parseNewLineDefault = state => input => {
|
|
449
|
+
const next = tokenizeOp({ kind: 'initial' })(input);
|
|
450
|
+
return [{ first: { kind: 'nl' }, tail: next[0] }, next[1]];
|
|
451
|
+
};
|
|
452
|
+
const parseNewLineStateOp = create(parseNewLineDefault)([
|
|
453
|
+
rangeSetFunc(rangeSetWhiteSpace)(state => () => [empty, state]),
|
|
454
|
+
rangeSetFunc(rangeSetNewLine)(state => () => [empty, state])
|
|
455
|
+
]);
|
|
456
|
+
const eofStateOp = create((state) => () => [[{ kind: 'error', message: 'eof' }], state])([]);
|
|
457
|
+
const tokenizeCharCodeOp = state => {
|
|
458
|
+
switch (state.kind) {
|
|
459
|
+
case 'initial': return initialStateOp(state);
|
|
460
|
+
case 'id': return parseIdStateOp(state);
|
|
461
|
+
case 'string': return parseStringStateOp(state);
|
|
462
|
+
case 'escapeChar': return parseEscapeCharStateOp(state);
|
|
463
|
+
case 'unicodeChar': return parseUnicodeCharStateOp(state);
|
|
464
|
+
case 'invalidNumber': return invalidNumberStateOp(state);
|
|
465
|
+
case 'number': return parseNumberStateOp(state);
|
|
466
|
+
case 'op': return parseOperatorStateOp(state);
|
|
467
|
+
case '//': return parseSinglelineCommentStateOp(state);
|
|
468
|
+
case '/*': return parseMultilineCommentStateOp(state);
|
|
469
|
+
case '/**': return parseMultilineCommentAsteriskStateOp(state);
|
|
470
|
+
case 'ws': return parseWhitespaceStateOp(state);
|
|
471
|
+
case 'nl': return parseNewLineStateOp(state);
|
|
472
|
+
case 'eof': return eofStateOp(state);
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
const tokenizeEofOp = state => {
|
|
476
|
+
switch (state.kind) {
|
|
477
|
+
case 'initial': return [empty, { kind: 'eof' }];
|
|
478
|
+
case 'id': return [[idToToken(state.value)], { kind: 'eof' }];
|
|
479
|
+
case 'string':
|
|
480
|
+
case 'escapeChar':
|
|
481
|
+
case 'unicodeChar': return [[{ kind: 'error', message: '" are missing' }], { kind: 'eof' }];
|
|
482
|
+
case 'invalidNumber': return [[{ kind: 'error', message: 'invalid number' }], { kind: 'eof' }];
|
|
483
|
+
case 'number':
|
|
484
|
+
switch (state.numberKind) {
|
|
485
|
+
case '.':
|
|
486
|
+
case 'e':
|
|
487
|
+
case 'e+':
|
|
488
|
+
case 'e-': return [[{ kind: 'error', message: 'invalid number' }], { kind: 'eof', }];
|
|
489
|
+
default: return [[bufferToNumberToken(state)], { kind: 'eof' }];
|
|
490
|
+
}
|
|
491
|
+
case 'op': return [[getOperatorToken(state.value)], { kind: 'eof' }];
|
|
492
|
+
case '//': return [[{ kind: '//', value: state.value }], { kind: 'eof' }];
|
|
493
|
+
case '/*':
|
|
494
|
+
case '/**': return [[{ kind: 'error', message: '*/ expected' }], { kind: 'eof', }];
|
|
495
|
+
case 'ws': return [[{ kind: 'ws' }], { kind: 'eof' }];
|
|
496
|
+
case 'nl': return [[{ kind: 'nl' }], { kind: 'eof' }];
|
|
497
|
+
case 'eof': return [[{ kind: 'error', message: 'eof' }], state];
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
const tokenizeOp = state => input => input === null ? tokenizeEofOp(state) : tokenizeCharCodeOp(state)(input);
|
|
501
|
+
const scanTokenize = stateScan(tokenizeOp);
|
|
502
|
+
const initial = scanTokenize({ kind: 'initial' });
|
|
503
|
+
export const tokenize = (input) => flat(initial(flat([input, [null]])));
|