@prisma-next/psl-parser 0.13.0 → 0.14.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/dist/index.d.mts +2 -2
- package/dist/index.mjs +3 -2
- package/dist/index.mjs.map +1 -1
- package/dist/{parser-Cw_zV0M5.mjs → parser-CaplKvRs.mjs} +110 -141
- package/dist/parser-CaplKvRs.mjs.map +1 -0
- package/dist/parser.mjs +1 -1
- package/dist/syntax.d.mts +115 -40
- package/dist/syntax.d.mts.map +1 -1
- package/dist/syntax.mjs +815 -105
- package/dist/syntax.mjs.map +1 -1
- package/dist/tokenizer-1hAHZzmp.mjs +228 -0
- package/dist/tokenizer-1hAHZzmp.mjs.map +1 -0
- package/dist/tokenizer.mjs +1 -190
- package/package.json +5 -5
- package/src/exports/index.ts +13 -2
- package/src/exports/syntax.ts +9 -4
- package/src/parse.ts +742 -0
- package/src/parser.ts +125 -196
- package/src/source-file.ts +89 -0
- package/src/syntax/ast/attributes.ts +5 -24
- package/src/syntax/ast/declarations.ts +14 -67
- package/src/syntax/ast/expressions.ts +187 -19
- package/src/syntax/ast/identifier.ts +4 -0
- package/src/syntax/ast/qualified-name.ts +87 -0
- package/src/syntax/ast/type-annotation.ts +11 -41
- package/src/syntax/ast-helpers.ts +12 -0
- package/src/syntax/syntax-kind.ts +8 -4
- package/src/tokenizer.ts +47 -7
- package/dist/parser-Cw_zV0M5.mjs.map +0 -1
- package/dist/tokenizer.mjs.map +0 -1
package/dist/tokenizer.mjs
CHANGED
|
@@ -1,191 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
var Tokenizer = class {
|
|
3
|
-
#source;
|
|
4
|
-
#pos;
|
|
5
|
-
#buffer;
|
|
6
|
-
constructor(source) {
|
|
7
|
-
this.#source = source;
|
|
8
|
-
this.#pos = 0;
|
|
9
|
-
this.#buffer = [];
|
|
10
|
-
}
|
|
11
|
-
next() {
|
|
12
|
-
const next = this.#buffer.shift();
|
|
13
|
-
if (next) return next;
|
|
14
|
-
return this.#scanNext();
|
|
15
|
-
}
|
|
16
|
-
peek(offset = 0) {
|
|
17
|
-
if (offset > this.#buffer.length) {
|
|
18
|
-
const last = this.#buffer.at(-1);
|
|
19
|
-
if (last?.kind === "Eof") return last;
|
|
20
|
-
}
|
|
21
|
-
const token = this.#buffer[offset];
|
|
22
|
-
if (token) return token;
|
|
23
|
-
while (this.#buffer.length <= offset) {
|
|
24
|
-
const token = this.#scanNext();
|
|
25
|
-
if (token.kind === "Eof") return token;
|
|
26
|
-
this.#buffer.push(token);
|
|
27
|
-
}
|
|
28
|
-
return this.#buffer[offset];
|
|
29
|
-
}
|
|
30
|
-
#scanNext() {
|
|
31
|
-
const token = scan(this.#source, this.#pos);
|
|
32
|
-
this.#pos += token.text.length;
|
|
33
|
-
return token;
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
function scan(source, pos) {
|
|
37
|
-
if (pos >= source.length) return {
|
|
38
|
-
kind: "Eof",
|
|
39
|
-
text: ""
|
|
40
|
-
};
|
|
41
|
-
return scanNewline(source, pos) ?? scanWhitespace(source, pos) ?? scanComment(source, pos) ?? scanAt(source, pos) ?? scanIdent(source, pos) ?? scanNumber(source, pos) ?? scanString(source, pos) ?? scanPunctuation(source, pos) ?? {
|
|
42
|
-
kind: "Invalid",
|
|
43
|
-
text: readChar(source, pos)
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function scanNewline(source, pos) {
|
|
47
|
-
const ch = source.charAt(pos);
|
|
48
|
-
if (ch !== "\r" && ch !== "\n") return void 0;
|
|
49
|
-
if (ch === "\r" && source.charAt(pos + 1) === "\n") return {
|
|
50
|
-
kind: "Newline",
|
|
51
|
-
text: "\r\n"
|
|
52
|
-
};
|
|
53
|
-
return {
|
|
54
|
-
kind: "Newline",
|
|
55
|
-
text: ch
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
function scanWhitespace(source, pos) {
|
|
59
|
-
const ch = source.charAt(pos);
|
|
60
|
-
if (ch !== " " && ch !== " ") return void 0;
|
|
61
|
-
let end = pos + 1;
|
|
62
|
-
while (end < source.length) {
|
|
63
|
-
const c = source.charAt(end);
|
|
64
|
-
if (c !== " " && c !== " ") break;
|
|
65
|
-
end++;
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
kind: "Whitespace",
|
|
69
|
-
text: source.slice(pos, end)
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
function scanComment(source, pos) {
|
|
73
|
-
if (source.charAt(pos) !== "/" || source.charAt(pos + 1) !== "/") return void 0;
|
|
74
|
-
let end = pos + 2;
|
|
75
|
-
while (end < source.length) {
|
|
76
|
-
const c = source.charAt(end);
|
|
77
|
-
if (c === "\n" || c === "\r") break;
|
|
78
|
-
end++;
|
|
79
|
-
}
|
|
80
|
-
return {
|
|
81
|
-
kind: "Comment",
|
|
82
|
-
text: source.slice(pos, end)
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
function scanAt(source, pos) {
|
|
86
|
-
if (source.charAt(pos) !== "@") return void 0;
|
|
87
|
-
if (source.charAt(pos + 1) === "@") return {
|
|
88
|
-
kind: "DoubleAt",
|
|
89
|
-
text: "@@"
|
|
90
|
-
};
|
|
91
|
-
return {
|
|
92
|
-
kind: "At",
|
|
93
|
-
text: "@"
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
function scanIdent(source, pos) {
|
|
97
|
-
const ch = readChar(source, pos);
|
|
98
|
-
if (!isIdentStart(ch)) return void 0;
|
|
99
|
-
let end = pos + ch.length;
|
|
100
|
-
while (end < source.length) {
|
|
101
|
-
const c = readChar(source, end);
|
|
102
|
-
if (isIdentPart(c)) end += c.length;
|
|
103
|
-
else break;
|
|
104
|
-
}
|
|
105
|
-
return {
|
|
106
|
-
kind: "Ident",
|
|
107
|
-
text: source.slice(pos, end)
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
function scanNumber(source, pos) {
|
|
111
|
-
let end = pos;
|
|
112
|
-
if (source.charAt(end) === "-") {
|
|
113
|
-
if (end + 1 >= source.length || !isDigit(source.charAt(end + 1))) return void 0;
|
|
114
|
-
end++;
|
|
115
|
-
} else if (!isDigit(source.charAt(end))) return;
|
|
116
|
-
end++;
|
|
117
|
-
while (end < source.length && isDigit(source.charAt(end))) end++;
|
|
118
|
-
if (source.charAt(end) === "." && end + 1 < source.length && isDigit(source.charAt(end + 1))) {
|
|
119
|
-
end++;
|
|
120
|
-
while (end < source.length && isDigit(source.charAt(end))) end++;
|
|
121
|
-
}
|
|
122
|
-
return {
|
|
123
|
-
kind: "NumberLiteral",
|
|
124
|
-
text: source.slice(pos, end)
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
function scanString(source, pos) {
|
|
128
|
-
if (source.charAt(pos) !== "\"") return void 0;
|
|
129
|
-
let end = pos + 1;
|
|
130
|
-
while (end < source.length) {
|
|
131
|
-
const c = source.charAt(end);
|
|
132
|
-
if (c === "\\" && end + 1 < source.length) {
|
|
133
|
-
end += 2;
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
if (c === "\"") {
|
|
137
|
-
end++;
|
|
138
|
-
return {
|
|
139
|
-
kind: "StringLiteral",
|
|
140
|
-
text: source.slice(pos, end)
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
if (c === "\n" || c === "\r") return {
|
|
144
|
-
kind: "StringLiteral",
|
|
145
|
-
text: source.slice(pos, end)
|
|
146
|
-
};
|
|
147
|
-
end++;
|
|
148
|
-
}
|
|
149
|
-
return {
|
|
150
|
-
kind: "StringLiteral",
|
|
151
|
-
text: source.slice(pos, end)
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
function scanPunctuation(source, pos) {
|
|
155
|
-
const kind = PUNCTUATION[source.charAt(pos)];
|
|
156
|
-
if (kind === void 0) return void 0;
|
|
157
|
-
return {
|
|
158
|
-
kind,
|
|
159
|
-
text: source.charAt(pos)
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
function readChar(source, pos) {
|
|
163
|
-
const cp = source.codePointAt(pos);
|
|
164
|
-
return cp !== void 0 ? String.fromCodePoint(cp) : "";
|
|
165
|
-
}
|
|
166
|
-
function isIdentStart(ch) {
|
|
167
|
-
return /\p{L}/u.test(ch) || ch === "_";
|
|
168
|
-
}
|
|
169
|
-
function isIdentPart(ch) {
|
|
170
|
-
return isIdentStart(ch) || isDigit(ch) || ch === "-";
|
|
171
|
-
}
|
|
172
|
-
function isDigit(ch) {
|
|
173
|
-
return ch >= "0" && ch <= "9";
|
|
174
|
-
}
|
|
175
|
-
const PUNCTUATION = {
|
|
176
|
-
"{": "LBrace",
|
|
177
|
-
"}": "RBrace",
|
|
178
|
-
"(": "LParen",
|
|
179
|
-
")": "RParen",
|
|
180
|
-
"[": "LBracket",
|
|
181
|
-
"]": "RBracket",
|
|
182
|
-
"=": "Equals",
|
|
183
|
-
"?": "Question",
|
|
184
|
-
".": "Dot",
|
|
185
|
-
",": "Comma",
|
|
186
|
-
":": "Colon"
|
|
187
|
-
};
|
|
188
|
-
//#endregion
|
|
1
|
+
import { t as Tokenizer } from "./tokenizer-1hAHZzmp.mjs";
|
|
189
2
|
export { Tokenizer };
|
|
190
|
-
|
|
191
|
-
//# sourceMappingURL=tokenizer.mjs.map
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/psl-parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"description": "Reusable parser for Prisma Schema Language (PSL)",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@prisma-next/framework-components": "0.
|
|
10
|
-
"@prisma-next/utils": "0.
|
|
9
|
+
"@prisma-next/framework-components": "0.14.0",
|
|
10
|
+
"@prisma-next/utils": "0.14.0"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
|
-
"@prisma-next/tsconfig": "0.
|
|
14
|
-
"@prisma-next/tsdown": "0.
|
|
13
|
+
"@prisma-next/tsconfig": "0.14.0",
|
|
14
|
+
"@prisma-next/tsdown": "0.14.0",
|
|
15
15
|
"tsdown": "0.22.1",
|
|
16
16
|
"typescript": "5.9.3",
|
|
17
17
|
"vitest": "4.1.8"
|
package/src/exports/index.ts
CHANGED
|
@@ -13,8 +13,15 @@ export type {
|
|
|
13
13
|
PslDiagnostic,
|
|
14
14
|
PslDiagnosticCode,
|
|
15
15
|
PslDocumentAst,
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
PslExtensionBlock,
|
|
17
|
+
PslExtensionBlockAttribute,
|
|
18
|
+
PslExtensionBlockAttributeArg,
|
|
19
|
+
PslExtensionBlockParamBare,
|
|
20
|
+
PslExtensionBlockParamList,
|
|
21
|
+
PslExtensionBlockParamOption,
|
|
22
|
+
PslExtensionBlockParamRef,
|
|
23
|
+
PslExtensionBlockParamScalarValue,
|
|
24
|
+
PslExtensionBlockParamValue,
|
|
18
25
|
PslField,
|
|
19
26
|
PslFieldAttribute,
|
|
20
27
|
PslModel,
|
|
@@ -26,5 +33,9 @@ export type {
|
|
|
26
33
|
PslTypeConstructorCall,
|
|
27
34
|
PslTypesBlock,
|
|
28
35
|
} from '@prisma-next/framework-components/psl-ast';
|
|
36
|
+
export {
|
|
37
|
+
flatPslModels,
|
|
38
|
+
namespacePslExtensionBlocks,
|
|
39
|
+
} from '@prisma-next/framework-components/psl-ast';
|
|
29
40
|
export { getPositionalArgument, parseQuotedStringLiteral } from '../attribute-helpers';
|
|
30
41
|
export { parsePslDocument } from '../parser';
|
package/src/exports/syntax.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export type { ParseDiagnostic, ParseResult } from '../parse';
|
|
2
|
+
export { parse } from '../parse';
|
|
3
|
+
export type { Position, Range } from '../source-file';
|
|
4
|
+
export { SourceFile } from '../source-file';
|
|
1
5
|
export {
|
|
2
6
|
AttributeArgListAst,
|
|
3
7
|
FieldAttributeAst,
|
|
@@ -5,12 +9,10 @@ export {
|
|
|
5
9
|
} from '../syntax/ast/attributes';
|
|
6
10
|
export type { NamespaceMemberAst } from '../syntax/ast/declarations';
|
|
7
11
|
export {
|
|
8
|
-
BlockDeclarationAst,
|
|
9
12
|
CompositeTypeDeclarationAst,
|
|
10
13
|
DocumentAst,
|
|
11
|
-
EnumDeclarationAst,
|
|
12
|
-
EnumValueDeclarationAst,
|
|
13
14
|
FieldDeclarationAst,
|
|
15
|
+
GenericBlockDeclarationAst,
|
|
14
16
|
KeyValuePairAst,
|
|
15
17
|
ModelDeclarationAst,
|
|
16
18
|
NamedTypeDeclarationAst,
|
|
@@ -25,13 +27,16 @@ export {
|
|
|
25
27
|
castExpression,
|
|
26
28
|
FunctionCallAst,
|
|
27
29
|
NumberLiteralExprAst,
|
|
30
|
+
ObjectFieldAst,
|
|
31
|
+
ObjectLiteralExprAst,
|
|
28
32
|
StringLiteralExprAst,
|
|
29
33
|
} from '../syntax/ast/expressions';
|
|
30
34
|
// AST wrappers
|
|
31
35
|
export { IdentifierAst } from '../syntax/ast/identifier';
|
|
36
|
+
export { QualifiedNameAst } from '../syntax/ast/qualified-name';
|
|
32
37
|
export { TypeAnnotationAst } from '../syntax/ast/type-annotation';
|
|
33
38
|
export type { AstNode } from '../syntax/ast-helpers';
|
|
34
|
-
export { filterChildren, findChildToken, findFirstChild } from '../syntax/ast-helpers';
|
|
39
|
+
export { filterChildren, findChildToken, findFirstChild, printSyntax } from '../syntax/ast-helpers';
|
|
35
40
|
export type { GreenElement, GreenNode, GreenToken } from '../syntax/green';
|
|
36
41
|
export { greenNode, greenToken } from '../syntax/green';
|
|
37
42
|
export { GreenNodeBuilder } from '../syntax/green-builder';
|