@mirascript/typed 0.1.64 → 0.1.70
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/README.md +38 -27
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/json.d.ts +5 -2
- package/dist/json.d.ts.map +1 -1
- package/dist/json.js +129 -48
- package/dist/json.js.map +1 -1
- package/dist/parser.d.ts +29 -1
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +13 -0
- package/dist/parser.js.map +1 -1
- package/dist/simplifier.d.ts +48 -0
- package/dist/simplifier.d.ts.map +1 -0
- package/dist/simplifier.js +332 -0
- package/dist/simplifier.js.map +1 -0
- package/dist/stringify.d.ts +7 -0
- package/dist/stringify.d.ts.map +1 -0
- package/dist/stringify.js +186 -0
- package/dist/stringify.js.map +1 -0
- package/dist/type.js +601 -289
- package/dist/type.js.map +1 -1
- package/package.json +7 -6
- package/src/index.ts +2 -0
- package/src/json.ts +142 -59
- package/src/parser.ts +49 -1
- package/src/simplifier.ts +404 -0
- package/src/stringify.ts +191 -0
- package/src/type.peggy +49 -2
package/src/type.peggy
CHANGED
|
@@ -37,6 +37,11 @@ function union(types) {
|
|
|
37
37
|
return { kind: "union", types };
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
function intersection(types) {
|
|
41
|
+
if (types.length === 1) return types[0];
|
|
42
|
+
return { kind: "intersection", types };
|
|
43
|
+
}
|
|
44
|
+
|
|
40
45
|
function record(fields) {
|
|
41
46
|
for(let i = 0; i < fields.length; i++) {
|
|
42
47
|
fields[i].name ??= String(i);
|
|
@@ -55,6 +60,10 @@ function string(parts) {
|
|
|
55
60
|
}
|
|
56
61
|
return { kind: 'template', parts };
|
|
57
62
|
}
|
|
63
|
+
|
|
64
|
+
function tupleElement(type, spread) {
|
|
65
|
+
return { type, spread: spread ?? false };
|
|
66
|
+
}
|
|
58
67
|
}
|
|
59
68
|
|
|
60
69
|
Start
|
|
@@ -62,17 +71,22 @@ Start
|
|
|
62
71
|
/ _ @Type _
|
|
63
72
|
|
|
64
73
|
///////////////////////////////////////////////////////////////////////////////
|
|
65
|
-
// Type (union)
|
|
74
|
+
// Type (union / intersection)
|
|
66
75
|
///////////////////////////////////////////////////////////////////////////////
|
|
67
76
|
|
|
68
77
|
Type
|
|
69
78
|
= UnionType
|
|
70
79
|
|
|
71
80
|
UnionType
|
|
72
|
-
= _ ( "|" _ )? u:
|
|
81
|
+
= _ ( "|" _ )? u:IntersectionType|1.., _ "|" _ | {
|
|
73
82
|
return union(u);
|
|
74
83
|
}
|
|
75
84
|
|
|
85
|
+
IntersectionType
|
|
86
|
+
= _ ( "&" _ )? i:PostfixType|1.., _ "&" _ | {
|
|
87
|
+
return intersection(i);
|
|
88
|
+
}
|
|
89
|
+
|
|
76
90
|
///////////////////////////////////////////////////////////////////////////////
|
|
77
91
|
// Array
|
|
78
92
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -91,6 +105,8 @@ PostfixType
|
|
|
91
105
|
|
|
92
106
|
PrimaryType
|
|
93
107
|
= FunctionType
|
|
108
|
+
/ ReflectionType
|
|
109
|
+
/ TupleType
|
|
94
110
|
/ name:Identifier generic:(_ "<" _ @TypeArgList _ ">")? {
|
|
95
111
|
if (generic) {
|
|
96
112
|
if (name === 'array') {
|
|
@@ -110,6 +126,10 @@ PrimaryType
|
|
|
110
126
|
if (BUILT_IN_TYPES.has(name)) {
|
|
111
127
|
return name;
|
|
112
128
|
}
|
|
129
|
+
// `type` is a non-reserved keyword — allow it as a plain named type
|
|
130
|
+
if (name === 'type') {
|
|
131
|
+
return name;
|
|
132
|
+
}
|
|
113
133
|
return named(name);
|
|
114
134
|
}
|
|
115
135
|
/ lit:String {
|
|
@@ -120,6 +140,33 @@ PrimaryType
|
|
|
120
140
|
/ RecordType
|
|
121
141
|
|
|
122
142
|
|
|
143
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
144
|
+
// Reflection
|
|
145
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
146
|
+
|
|
147
|
+
ReflectionType
|
|
148
|
+
= "type" _ "(" _ name:Identifier _ ")" {
|
|
149
|
+
return { kind: "reflection", name };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
153
|
+
// Tuple
|
|
154
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
155
|
+
|
|
156
|
+
TupleType
|
|
157
|
+
= "[" _ elements:TupleElementList? _ "]" {
|
|
158
|
+
return { kind: "tuple", elements: elements ?? [] };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
TupleElementList
|
|
162
|
+
= @TupleElement|1.., _ "," _ | ( _ "," _ )?
|
|
163
|
+
|
|
164
|
+
TupleElement
|
|
165
|
+
= spread:".."? _ type:Type {
|
|
166
|
+
return tupleElement(type, spread != null);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
|
|
123
170
|
///////////////////////////////////////////////////////////////////////////////
|
|
124
171
|
// Generics
|
|
125
172
|
///////////////////////////////////////////////////////////////////////////////
|