functionalscript 0.4.3 → 0.4.4

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.
Files changed (60) hide show
  1. package/README.md +1 -1
  2. package/bnf/data/module.f.d.ts +12 -0
  3. package/bnf/data/module.f.js +85 -0
  4. package/bnf/data/test.f.d.ts +4 -0
  5. package/bnf/data/test.f.js +8 -0
  6. package/bnf/module.f.d.ts +55 -0
  7. package/bnf/module.f.js +98 -0
  8. package/bnf/test.f.d.ts +4 -0
  9. package/bnf/test.f.js +7 -0
  10. package/bnf/testlib.f.d.ts +3 -0
  11. package/bnf/{tag/test.f.js → testlib.f.js} +48 -44
  12. package/crypto/secp/module.f.d.ts +8 -0
  13. package/crypto/secp/module.f.js +30 -0
  14. package/crypto/secp/test.f.d.ts +3 -0
  15. package/crypto/secp/test.f.js +67 -3
  16. package/djs/ast/module.f.d.ts +10 -0
  17. package/djs/ast/module.f.js +52 -0
  18. package/djs/ast/test.f.d.ts +8 -0
  19. package/djs/ast/test.f.js +41 -0
  20. package/djs/module.f.d.ts +5 -15
  21. package/djs/module.f.js +1 -62
  22. package/djs/parser/module.f.d.ts +9 -9
  23. package/djs/parser/module.f.js +7 -8
  24. package/djs/parser/test.f.js +97 -97
  25. package/djs/serializer/module.f.d.ts +8 -4
  26. package/djs/serializer/module.f.js +9 -27
  27. package/djs/{test.f.d.ts → serializer/test.f.d.ts} +3 -3
  28. package/djs/{test.f.js → serializer/test.f.js} +13 -13
  29. package/djs/tokenizer/test.f.js +2 -2
  30. package/djs/transpiler/module.f.d.ts +15 -0
  31. package/djs/transpiler/module.f.js +57 -0
  32. package/djs/transpiler/test.f.d.ts +8 -0
  33. package/djs/transpiler/test.f.js +74 -0
  34. package/io/module.f.d.ts +12 -0
  35. package/io/virtual-io.f.d.ts +3 -0
  36. package/io/virtual-io.f.js +10 -0
  37. package/js/tokenizer/test.f.js +2 -2
  38. package/json/module.f.d.ts +2 -1
  39. package/json/tokenizer/test.f.js +2 -2
  40. package/nanvm-lib/tests/test.f.js +4 -4
  41. package/package.json +2 -2
  42. package/path/module.f.d.ts +2 -0
  43. package/path/module.f.js +34 -0
  44. package/path/test.f.d.ts +5 -0
  45. package/path/test.f.js +49 -0
  46. package/text/sgr/module.f.d.ts +19 -1
  47. package/text/sgr/module.f.js +26 -1
  48. package/text/sgr/test.f.d.ts +2 -0
  49. package/text/sgr/test.f.js +8 -0
  50. package/text/utf16/module.f.d.ts +116 -0
  51. package/text/utf16/module.f.js +285 -0
  52. package/text/utf16/test.f.d.ts +4 -0
  53. package/text/utf16/test.f.js +28 -0
  54. package/types/monoid/module.f.d.ts +3 -1
  55. package/types/monoid/module.f.js +2 -0
  56. package/types/object/module.f.d.ts +18 -0
  57. package/types/object/module.f.js +1 -1
  58. package/bnf/tag/module.f.d.ts +0 -30
  59. package/bnf/tag/module.f.js +0 -37
  60. /package/{bnf/tag/test.f.d.ts → io/module.f.js} +0 -0
@@ -0,0 +1,41 @@
1
+ import * as list from "../../types/object/module.f.js";
2
+ const { sort } = list;
3
+ import * as shared from "./module.f.js";
4
+ import { stringify } from "../serializer/module.f.js";
5
+ export default {
6
+ test: () => {
7
+ const djs = shared.run([1])([]);
8
+ const result = stringify(sort)(djs);
9
+ if (result !== '1') {
10
+ throw result;
11
+ }
12
+ },
13
+ testCref: () => {
14
+ const djs = shared.run([1, 2, 3, 4, 5, ['cref', 3]])([11, 12, 13, 14, 15]);
15
+ const result = stringify(sort)(djs);
16
+ if (result !== '4') {
17
+ throw result;
18
+ }
19
+ },
20
+ testAref: () => {
21
+ const djs = shared.run([1, 2, 3, 4, 5, ['aref', 3]])([11, 12, 13, 14, 15]);
22
+ const result = stringify(sort)(djs);
23
+ if (result !== '14') {
24
+ throw result;
25
+ }
26
+ },
27
+ testArray: () => {
28
+ const djs = shared.run([1, 2, 3, 4, 5, ['array', [['aref', 3], ['cref', 3]]]])([11, 12, 13, 14, 15]);
29
+ const result = stringify(sort)(djs);
30
+ if (result !== '[14,4]') {
31
+ throw result;
32
+ }
33
+ },
34
+ testObj: () => {
35
+ const djs = shared.run([1, 2, 3, 4, 5, { "key": { "key2": ['array', [['aref', 3], ['cref', 3]]] } }])([11, 12, 13, 14, 15]);
36
+ const result = stringify(sort)(djs);
37
+ if (result !== '{"key":{"key2":[14,4]}}') {
38
+ throw result;
39
+ }
40
+ },
41
+ };
package/djs/module.f.d.ts CHANGED
@@ -1,17 +1,7 @@
1
- import * as list from '../types/list/module.f.ts';
2
- import type * as O from '../types/object/module.f.ts';
3
- type Object = {
1
+ import type { Primitive as JsonPrimitive } from '../json/module.f.ts';
2
+ export type Object = {
4
3
  readonly [k in string]: Unknown;
5
4
  };
6
- type Array = readonly Unknown[];
7
- type Unknown = Object | boolean | string | number | null | Array | bigint | undefined;
8
- type Entry = O.Entry<Unknown>;
9
- type Entries = list.List<Entry>;
10
- type MapEntries = (entries: Entries) => Entries;
11
- export declare const serialize: (mapEntries: MapEntries) => (value: Unknown) => list.List<string>;
12
- /**
13
- * The standard `JSON.stringify` rules determined by
14
- * https://262.ecma-international.org/6.0/#sec-ordinary-object-internal-methods-and-internal-slots-ownpropertykeys
15
- */
16
- export declare const stringify: (mapEntries: MapEntries) => (value: Unknown) => string;
17
- export {};
5
+ export type Array = readonly Unknown[];
6
+ export type Primitive = JsonPrimitive | bigint | undefined;
7
+ export type Unknown = Primitive | Object | Array;
package/djs/module.f.js CHANGED
@@ -1,62 +1 @@
1
- import * as list from "../types/list/module.f.js";
2
- const { flat, map } = list;
3
- import * as string from "../types/string/module.f.js";
4
- const { concat } = string;
5
- import * as f from "../types/function/module.f.js";
6
- const { compose, fn } = f;
7
- const { entries } = Object;
8
- import * as bi from "../types/bigint/module.f.js";
9
- const { serialize: bigintSerialize } = bi;
10
- import * as j from "../json/serializer/module.f.js";
11
- const { objectWrap, arrayWrap, stringSerialize, numberSerialize, nullSerialize, boolSerialize } = j;
12
- import * as djs from "./serializer/module.f.js";
13
- const { undefinedSerialize } = djs;
14
- const colon = [':'];
15
- export const serialize = sort => {
16
- const propertySerialize = ([k, v]) => flat([
17
- stringSerialize(k),
18
- colon,
19
- f(v)
20
- ]);
21
- const mapPropertySerialize = map(propertySerialize);
22
- const objectSerialize = fn(entries)
23
- .then(sort)
24
- .then(mapPropertySerialize)
25
- .then(objectWrap)
26
- .result;
27
- const f = value => {
28
- switch (typeof value) {
29
- case 'boolean': {
30
- return boolSerialize(value);
31
- }
32
- case 'number': {
33
- return numberSerialize(value);
34
- }
35
- case 'string': {
36
- return stringSerialize(value);
37
- }
38
- case 'bigint': {
39
- return [bigintSerialize(value)];
40
- }
41
- default: {
42
- if (value === null) {
43
- return nullSerialize;
44
- }
45
- if (value === undefined) {
46
- return undefinedSerialize;
47
- }
48
- if (value instanceof Array) {
49
- return arraySerialize(value);
50
- }
51
- return objectSerialize(value);
52
- }
53
- }
54
- };
55
- const arraySerialize = compose(map(f))(arrayWrap);
56
- return f;
57
- };
58
- /**
59
- * The standard `JSON.stringify` rules determined by
60
- * https://262.ecma-international.org/6.0/#sec-ordinary-object-internal-methods-and-internal-slots-ownpropertykeys
61
- */
62
- export const stringify = sort => compose(serialize(sort))(concat);
1
+ export {};
@@ -1,12 +1,12 @@
1
1
  import * as result from '../../types/result/module.f.ts';
2
2
  import { type List } from '../../types/list/module.f.ts';
3
- import type * as tokenizerT from '../tokenizer/module.f.ts';
4
- export type DjsModule = [readonly string[], readonly DjsConst[]];
5
- export type DjsConst = boolean | string | number | null | bigint | undefined | DjsModuleRef | DjsArray | DjsObject;
6
- type DjsModuleRef = ['aref' | 'cref', number];
7
- type DjsArray = ['array', readonly DjsConst[]];
8
- export type DjsObject = {
9
- readonly [k in string]: DjsConst;
3
+ import type { DjsToken } from '../tokenizer/module.f.ts';
4
+ import { type Map } from '../../types/map/module.f.ts';
5
+ import type { Fs } from '../../io/module.f.ts';
6
+ import type { AstModule } from '../ast/module.f.ts';
7
+ export type ParseContext = {
8
+ readonly fs: Fs;
9
+ readonly complete: Map<result.Result<AstModule, string>>;
10
+ readonly stack: List<string>;
10
11
  };
11
- export declare const parse: (tokenList: List<tokenizerT.DjsToken>) => result.Result<DjsModule, string>;
12
- export {};
12
+ export declare const parseFromTokens: (tokenList: List<DjsToken>) => result.Result<AstModule, string>;
@@ -1,8 +1,7 @@
1
1
  import * as result from "../../types/result/module.f.js";
2
2
  import { fold, first, drop, toArray, length, concat } from "../../types/list/module.f.js";
3
3
  import { setReplace, at } from "../../types/map/module.f.js";
4
- import * as o from "../../types/object/module.f.js";
5
- const { fromMap } = o;
4
+ import { fromMap } from "../../types/object/module.f.js";
6
5
  const parseInitialOp = token => state => {
7
6
  switch (token.kind) {
8
7
  case 'ws':
@@ -59,8 +58,8 @@ const parseConstOp = token => state => {
59
58
  case 'id': {
60
59
  if (at(token.value)(state.module.refs) !== null)
61
60
  return { state: 'error', message: 'duplicate id' };
62
- let cref = ['cref', length(state.module.consts)];
63
- let refs = setReplace(token.value)(cref)(state.module.refs);
61
+ const cref = ['cref', length(state.module.consts)];
62
+ const refs = setReplace(token.value)(cref)(state.module.refs);
64
63
  return { ...state, state: 'const+name', module: { ...state.module, refs: refs } };
65
64
  }
66
65
  default: return { state: 'error', message: 'unexpected token' };
@@ -86,8 +85,8 @@ const parseImportOp = token => state => {
86
85
  if (at(token.value)(state.module.refs) !== null) {
87
86
  return { state: 'error', message: 'duplicate id' };
88
87
  }
89
- let aref = ['aref', length(state.module.modules)];
90
- let refs = setReplace(token.value)(aref)(state.module.refs);
88
+ const aref = ['aref', length(state.module.modules)];
89
+ const refs = setReplace(token.value)(aref)(state.module.refs);
91
90
  return { ...state, state: 'import+name', module: { ...state.module, refs: refs } };
92
91
  }
93
92
  default: return { state: 'error', message: 'unexpected token' };
@@ -130,7 +129,7 @@ const pushKey = state => key => {
130
129
  };
131
130
  const pushValue = state => value => {
132
131
  if (state.top === null) {
133
- let consts = concat(state.module.consts)([value]);
132
+ const consts = concat(state.module.consts)([value]);
134
133
  switch (state.state) {
135
134
  case 'exportValue': return { ...state, state: 'result', module: { ...state.module, consts: consts } };
136
135
  case 'constValue': return { ...state, state: 'nl', module: { ...state.module, consts: consts } };
@@ -321,7 +320,7 @@ const foldOp = token => state => {
321
320
  }
322
321
  }
323
322
  };
324
- export const parse = (tokenList) => {
323
+ export const parseFromTokens = (tokenList) => {
325
324
  const state = fold(foldOp)({ state: '', module: { refs: null, modules: null, consts: null } })(tokenList);
326
325
  switch (state.state) {
327
326
  case 'result': return result.ok([toArray(state.module.modules), toArray(state.module.consts)]);