@okcontract/lambdascript 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.copying +202 -0
- package/README.md +70 -0
- package/dist/ast.d.ts +73 -0
- package/dist/deps.d.ts +7 -0
- package/dist/env.d.ts +119 -0
- package/dist/equal.d.ts +3 -0
- package/dist/eval.d.ts +18 -0
- package/dist/find.d.ts +14 -0
- package/dist/highLevel.d.ts +11 -0
- package/dist/index.d.ts +14 -0
- package/dist/infer.d.ts +7 -0
- package/dist/json.d.ts +4 -0
- package/dist/lambdascript.js +6865 -0
- package/dist/lambdascript.umd.cjs +1 -0
- package/dist/lowLevel.d.ts +15 -0
- package/dist/merge.d.ts +1 -0
- package/dist/objectMap.d.ts +32 -0
- package/dist/parse.d.ts +7 -0
- package/dist/print.d.ts +5 -0
- package/dist/program.d.ts +77 -0
- package/dist/rational.d.ts +73 -0
- package/dist/stdlib.d.ts +43 -0
- package/dist/traverse.d.ts +7 -0
- package/dist/typeScheme.d.ts +19 -0
- package/dist/types.d.ts +113 -0
- package/dist/unify.d.ts +8 -0
- package/dist/utils.d.ts +13 -0
- package/package.json +59 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { NameConstant, NameLambda, NameList, NameObject, NameTuple, NameVariable } from "./ast";
|
|
2
|
+
export declare const NameAny = "any";
|
|
3
|
+
export type MonoType = (TypeVar | TypeConst | TypeFunction | TypeList | TypeObject | TypeGeneric | TypeConditional | TypeAny | TypeTuple) & {
|
|
4
|
+
/** optional label */
|
|
5
|
+
label?: string;
|
|
6
|
+
/** optional hint */
|
|
7
|
+
hint?: string;
|
|
8
|
+
};
|
|
9
|
+
export type TypeAny = {
|
|
10
|
+
kind: typeof NameAny;
|
|
11
|
+
};
|
|
12
|
+
export type TypeVar = {
|
|
13
|
+
kind: typeof NameVariable;
|
|
14
|
+
type: string;
|
|
15
|
+
};
|
|
16
|
+
export type TypeConst = {
|
|
17
|
+
kind: typeof NameConstant;
|
|
18
|
+
type: string;
|
|
19
|
+
};
|
|
20
|
+
export type TypeFunction = {
|
|
21
|
+
kind: typeof NameLambda;
|
|
22
|
+
argTypes: MonoType[];
|
|
23
|
+
/** type of variadic arguments */
|
|
24
|
+
argVariadic?: MonoType;
|
|
25
|
+
returnType: MonoType;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* TypeFunction constructor.
|
|
29
|
+
* @param argTypes
|
|
30
|
+
* @param returnType
|
|
31
|
+
* @param argVariadic
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
export declare const typeFunction: (argTypes: MonoType[], returnType: MonoType, argVariadic?: MonoType) => TypeFunction;
|
|
35
|
+
export type TypeList = {
|
|
36
|
+
kind: typeof NameList;
|
|
37
|
+
elementType: MonoType;
|
|
38
|
+
/** fixed-size list or tuples */
|
|
39
|
+
size?: number;
|
|
40
|
+
/** min length */
|
|
41
|
+
min?: number;
|
|
42
|
+
/** max length */
|
|
43
|
+
max?: number;
|
|
44
|
+
};
|
|
45
|
+
export declare const typeList: (elementType: MonoType) => TypeList;
|
|
46
|
+
export type TypeTuple = {
|
|
47
|
+
kind: typeof NameTuple;
|
|
48
|
+
elementTypes: MonoType[];
|
|
49
|
+
};
|
|
50
|
+
export declare const newTypeTuple: (elementTypes: MonoType[]) => TypeTuple;
|
|
51
|
+
export type TypeObject = {
|
|
52
|
+
kind: typeof NameObject;
|
|
53
|
+
fields: {
|
|
54
|
+
[key: string]: MonoType;
|
|
55
|
+
};
|
|
56
|
+
open: boolean;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* TypeObject constructor.
|
|
60
|
+
* @param fields
|
|
61
|
+
* @param open
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
export declare const newTypeObject: (fields: {
|
|
65
|
+
[key: string]: MonoType;
|
|
66
|
+
}, open?: boolean) => TypeObject;
|
|
67
|
+
export declare const NameGeneric = "generic";
|
|
68
|
+
export declare const NameConditional = "conditional";
|
|
69
|
+
export declare const NameExtends = "extends";
|
|
70
|
+
export type TypeGeneric = {
|
|
71
|
+
kind: typeof NameGeneric;
|
|
72
|
+
baseType: MonoType;
|
|
73
|
+
typeArgs: MonoType[];
|
|
74
|
+
};
|
|
75
|
+
export type TypeConditional = {
|
|
76
|
+
kind: typeof NameConditional;
|
|
77
|
+
check: TypeCheck;
|
|
78
|
+
trueType: MonoType;
|
|
79
|
+
falseType: MonoType;
|
|
80
|
+
};
|
|
81
|
+
export type TypeCheck = {
|
|
82
|
+
kind: typeof NameExtends;
|
|
83
|
+
left: MonoType;
|
|
84
|
+
right: MonoType;
|
|
85
|
+
};
|
|
86
|
+
export declare function newTypeVar(prefix: string): TypeVar;
|
|
87
|
+
/**
|
|
88
|
+
* refreshTypeVars generates a mapping for a list of type variables.
|
|
89
|
+
* @param vars
|
|
90
|
+
* @param prefix
|
|
91
|
+
* @returns
|
|
92
|
+
*/
|
|
93
|
+
export declare const refreshTypeVars: (vars: string[], prefix: string) => {
|
|
94
|
+
[orig: string]: string;
|
|
95
|
+
};
|
|
96
|
+
export declare const refreshTypeVarsAlpha: (vars: string[]) => {
|
|
97
|
+
[orig: string]: string;
|
|
98
|
+
};
|
|
99
|
+
export declare function isTypeVar(type: MonoType): type is TypeVar;
|
|
100
|
+
export declare const newTypeConst: (type: string) => TypeConst;
|
|
101
|
+
export declare function isTypeConst(type: MonoType): type is TypeConst;
|
|
102
|
+
export declare const typeAny: TypeAny;
|
|
103
|
+
/**
|
|
104
|
+
* Substitutes type variables in a type. Substitution is not recursive (i.e. it
|
|
105
|
+
* is not applied on the result of the provided function).
|
|
106
|
+
*
|
|
107
|
+
* The function returns the same object if no substitution happened. This allows
|
|
108
|
+
* for fast equality comparisons.
|
|
109
|
+
*
|
|
110
|
+
* @param fn Map a type variable name to a type. Return undefined if the type
|
|
111
|
+
* variable should not be substituted.
|
|
112
|
+
*/
|
|
113
|
+
export declare function mapType(fn: (varName: string) => MonoType | undefined, monoType: MonoType): MonoType;
|
package/dist/unify.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ASTNode } from "./ast";
|
|
2
|
+
import { type MonoType } from "./types";
|
|
3
|
+
export declare class TypeSubstitution {
|
|
4
|
+
private _current;
|
|
5
|
+
constructor();
|
|
6
|
+
_apply: (type: MonoType) => MonoType;
|
|
7
|
+
_unify: (type1: MonoType, type2: MonoType, typeVar?: string, node?: ASTNode) => void;
|
|
8
|
+
}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* length returns the length of a value.
|
|
3
|
+
* @param value any value (object, array, single value)
|
|
4
|
+
*/
|
|
5
|
+
export declare const length: (value: unknown) => number;
|
|
6
|
+
/**
|
|
7
|
+
* plural returns a label with "s" if value length is more than 1.
|
|
8
|
+
* Also, display the number (unless _count_ set to false).
|
|
9
|
+
* @param label name of entity
|
|
10
|
+
* @param value any value
|
|
11
|
+
* @param showCount display count (true by default)
|
|
12
|
+
*/
|
|
13
|
+
export declare const plural: (label: string, value: unknown, showCount?: boolean) => string;
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@okcontract/lambdascript",
|
|
3
|
+
"description": "lambdascript is a reactive functional scripting language",
|
|
4
|
+
"private": false,
|
|
5
|
+
"version": "0.1.0",
|
|
6
|
+
"main": "dist/lambdascript.js",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/lambdascript.js",
|
|
11
|
+
"require": "./dist/lambdascript.umd.cjs",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist/",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@biomejs/biome": "^1.8.3",
|
|
22
|
+
"@lezer/generator": "^1.6.0",
|
|
23
|
+
"@types/node": "^22.5.4",
|
|
24
|
+
"@vitest/coverage-v8": "^2.0.5",
|
|
25
|
+
"happy-dom": "^15.7.3",
|
|
26
|
+
"immer": "^10.0.3",
|
|
27
|
+
"terser": "^5.31.6",
|
|
28
|
+
"typescript": "^5.5.4",
|
|
29
|
+
"vite": "^5.2.11",
|
|
30
|
+
"vitest": "^2.0.5"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@lezer/lr": "^1.4.2",
|
|
34
|
+
"@okcontract/cells": "^0.3.3",
|
|
35
|
+
"@okcontract/graph": "^0.1.5"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"clean": "rm -rf dist",
|
|
39
|
+
"grammar": "lezer-generator src/parser/λs.grammar -o src/parser/λs.js",
|
|
40
|
+
"build": "npm run format && vite build",
|
|
41
|
+
"test": "vitest run",
|
|
42
|
+
"coverage": "vitest run --coverage",
|
|
43
|
+
"definitions": "tsc --project tsconfig.build.json",
|
|
44
|
+
"prepublishOnly": "npm test && npm run build && npm run check && npm run definitions",
|
|
45
|
+
"check": "npx @biomejs/biome check src",
|
|
46
|
+
"format": "npx @biomejs/biome format src --write && npx @biomejs/biome check src --write",
|
|
47
|
+
"formatReadme": "prettier README.md --prose-wrap always --print-width 78 -w"
|
|
48
|
+
},
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "git+https://github.com/okcontract/lambdascript.git"
|
|
52
|
+
},
|
|
53
|
+
"author": "Henri Binsztok",
|
|
54
|
+
"license": "Apache-2.0",
|
|
55
|
+
"bugs": {
|
|
56
|
+
"url": "https://github.com/okcontract/lambdascript/issues"
|
|
57
|
+
},
|
|
58
|
+
"homepage": "https://hbbio.github.io/lambdascript"
|
|
59
|
+
}
|