@prisma-next/psl-parser 0.14.0-dev.3 → 0.14.0-dev.31
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 +28 -10
- package/dist/declarations-DWUyG1DT.mjs +829 -0
- package/dist/declarations-DWUyG1DT.mjs.map +1 -0
- package/dist/format.d.mts +19 -0
- package/dist/format.d.mts.map +1 -0
- package/dist/format.mjs +470 -0
- package/dist/format.mjs.map +1 -0
- package/dist/index.d.mts +136 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +472 -3
- package/dist/index.mjs.map +1 -1
- package/dist/parse-Ce9Em5k9.d.mts +358 -0
- package/dist/parse-Ce9Em5k9.d.mts.map +1 -0
- package/dist/parse-iG0rOMKS.mjs +618 -0
- package/dist/parse-iG0rOMKS.mjs.map +1 -0
- package/dist/syntax.d.mts +3 -347
- package/dist/syntax.d.mts.map +1 -1
- package/dist/syntax.mjs +2 -1420
- package/package.json +6 -6
- package/src/block-reconstruction.ts +139 -0
- package/src/exports/format.ts +3 -0
- package/src/exports/index.ts +27 -3
- package/src/exports/syntax.ts +7 -1
- package/src/extension-block.ts +107 -0
- package/src/format/emit.ts +603 -0
- package/src/format/error.ts +13 -0
- package/src/format/format.ts +13 -0
- package/src/format/options.ts +28 -0
- package/src/resolve.ts +120 -0
- package/src/source-file.ts +25 -0
- package/src/symbol-table.ts +446 -0
- package/src/syntax/ast/attributes.ts +5 -6
- package/src/syntax/ast/declarations.ts +45 -20
- package/src/syntax/ast/expressions.ts +12 -13
- package/src/syntax/ast/identifier.ts +2 -3
- package/src/syntax/ast/qualified-name.ts +3 -4
- package/src/syntax/ast/type-annotation.ts +4 -5
- package/src/syntax/ast-helpers.ts +3 -3
- package/dist/parser-CaplKvRs.mjs +0 -1145
- package/dist/parser-CaplKvRs.mjs.map +0 -1
- package/dist/parser-Dfi3Wfdq.d.mts +0 -7
- package/dist/parser-Dfi3Wfdq.d.mts.map +0 -1
- package/dist/parser.d.mts +0 -2
- package/dist/parser.mjs +0 -2
- package/dist/syntax.mjs.map +0 -1
- package/src/exports/parser.ts +0 -1
- package/src/parser.ts +0 -1642
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declarations-DWUyG1DT.mjs","names":["#penultimateSegment","#lastSegment","#separatorCount"],"sources":["../src/syntax/red.ts","../src/syntax/ast-helpers.ts","../src/syntax/ast/identifier.ts","../src/syntax/ast/qualified-name.ts","../src/syntax/ast/expressions.ts","../src/syntax/ast/attributes.ts","../src/syntax/ast/type-annotation.ts","../src/syntax/ast/declarations.ts"],"sourcesContent":["import type { Token } from '../tokenizer';\nimport type { GreenElement, GreenNode } from './green';\nimport type { SyntaxKind } from './syntax-kind';\n\n/**\n * A token in the red tree. Unlike the green-layer {@link Token} (kind + text\n * only), a red token also carries its absolute `offset` within the source,\n * computed lazily as the tree is walked.\n */\nexport interface SyntaxToken extends Token {\n readonly offset: number;\n}\n\nexport type SyntaxElement = SyntaxNode | SyntaxToken;\n\nexport class SyntaxNode {\n readonly green: GreenNode;\n readonly offset: number;\n readonly parent: SyntaxNode | undefined;\n\n constructor(green: GreenNode, offset: number, parent: SyntaxNode | undefined) {\n this.green = green;\n this.offset = offset;\n this.parent = parent;\n }\n\n get kind(): SyntaxKind {\n return this.green.kind;\n }\n\n get textLength(): number {\n return this.green.textLength;\n }\n\n get firstChild(): SyntaxElement | undefined {\n return childAt(this, 0);\n }\n\n get lastChild(): SyntaxElement | undefined {\n const len = this.green.children.length;\n if (len === 0) return undefined;\n return childAt(this, len - 1);\n }\n\n get nextSibling(): SyntaxElement | undefined {\n if (!this.parent) return undefined;\n const siblings = this.parent.green.children;\n let offset = this.parent.offset;\n let found = false;\n for (const child of siblings) {\n if (found) {\n return wrapElement(child, offset, this.parent);\n }\n const childLen = elementTextLength(child);\n if (child.type === 'node' && offset === this.offset && child === this.green) {\n found = true;\n }\n offset += childLen;\n }\n return undefined;\n }\n\n get prevSibling(): SyntaxElement | undefined {\n if (!this.parent) return undefined;\n const siblings = this.parent.green.children;\n let offset = this.parent.offset;\n let prev: { green: GreenElement; offset: number } | undefined;\n for (const child of siblings) {\n if (child.type === 'node' && offset === this.offset && child === this.green) {\n if (!prev) return undefined;\n return wrapElement(prev.green, prev.offset, this.parent);\n }\n prev = { green: child, offset };\n offset += elementTextLength(child);\n }\n return undefined;\n }\n\n *children(): Iterable<SyntaxElement> {\n let offset = this.offset;\n for (const child of this.green.children) {\n yield wrapElement(child, offset, this);\n offset += elementTextLength(child);\n }\n }\n\n *childNodes(): Iterable<SyntaxNode> {\n for (const child of this.children()) {\n if (child instanceof SyntaxNode) yield child;\n }\n }\n\n *ancestors(): Iterable<SyntaxNode> {\n let current: SyntaxNode | undefined = this.parent;\n while (current) {\n yield current;\n current = current.parent;\n }\n }\n\n *descendants(): Iterable<SyntaxElement> {\n const stack: SyntaxElement[] = [this];\n for (let el = stack.pop(); el !== undefined; el = stack.pop()) {\n yield el;\n if (el instanceof SyntaxNode) {\n const children = Array.from(el.children());\n for (let i = children.length - 1; i >= 0; i--) {\n const child = children[i];\n if (child !== undefined) {\n stack.push(child);\n }\n }\n }\n }\n }\n\n *tokens(): Iterable<SyntaxToken> {\n for (const el of this.descendants()) {\n if (!(el instanceof SyntaxNode)) {\n yield el;\n }\n }\n }\n}\n\nfunction elementTextLength(el: GreenElement): number {\n return el.type === 'token' ? el.text.length : el.textLength;\n}\n\nfunction wrapElement(green: GreenElement, offset: number, parent: SyntaxNode): SyntaxElement {\n if (green.type === 'token') {\n const token: SyntaxToken = { kind: green.kind, text: green.text, offset };\n return token;\n }\n return new SyntaxNode(green, offset, parent);\n}\n\nfunction childAt(node: SyntaxNode, index: number): SyntaxElement | undefined {\n const children = node.green.children;\n const target = children[index];\n if (target === undefined) return undefined;\n let offset = node.offset;\n for (let i = 0; i < index; i++) {\n const child = children[i];\n if (child !== undefined) {\n offset += elementTextLength(child);\n }\n }\n return wrapElement(target, offset, node);\n}\n\nexport function createSyntaxTree(green: GreenNode): SyntaxNode {\n return new SyntaxNode(green, 0, undefined);\n}\n","import type { TokenKind } from '../tokenizer';\nimport { SyntaxNode, type SyntaxToken } from './red';\n\nexport interface AstNode {\n readonly syntax: SyntaxNode;\n}\n\nexport function findChildToken(node: SyntaxNode, kind: TokenKind): SyntaxToken | undefined {\n for (const child of node.children()) {\n if (!(child instanceof SyntaxNode) && child.kind === kind) {\n return child;\n }\n }\n return undefined;\n}\n\nexport function findFirstChild<T>(\n node: SyntaxNode,\n cast: (node: SyntaxNode) => T | undefined,\n): T | undefined {\n for (const child of node.childNodes()) {\n const result = cast(child);\n if (result !== undefined) return result;\n }\n return undefined;\n}\n\nexport function* filterChildren<T>(\n node: SyntaxNode,\n cast: (node: SyntaxNode) => T | undefined,\n): Iterable<T> {\n for (const child of node.childNodes()) {\n const result = cast(child);\n if (result !== undefined) yield result;\n }\n}\n\n/**\n * Raw source text of a CST node, verbatim (quotes and brackets preserved). For\n * the decoded value of a string literal, decode it instead.\n */\nexport function printSyntax(node: SyntaxNode): string {\n let text = '';\n for (const token of node.tokens()) {\n text += token.text;\n }\n return text;\n}\n","import type { AstNode } from '../ast-helpers';\nimport { findChildToken } from '../ast-helpers';\nimport type { SyntaxNode, SyntaxToken } from '../red';\n\nexport class IdentifierAst implements AstNode {\n readonly syntax: SyntaxNode;\n\n constructor(syntax: SyntaxNode) {\n this.syntax = syntax;\n }\n\n token(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'Ident');\n }\n\n name(): string | undefined {\n return this.token()?.text;\n }\n\n static cast(node: SyntaxNode): IdentifierAst | undefined {\n return node.kind === 'Identifier' ? new IdentifierAst(node) : undefined;\n }\n}\n","import type { AstNode } from '../ast-helpers';\nimport { filterChildren, findChildToken, findFirstChild } from '../ast-helpers';\nimport { SyntaxNode, type SyntaxToken } from '../red';\nimport { IdentifierAst } from './identifier';\n\n/** A namespace-qualified name, e.g. `pgvector.Vector` or `supabase:auth.User`. */\nexport class QualifiedNameAst implements AstNode {\n readonly syntax: SyntaxNode;\n\n constructor(syntax: SyntaxNode) {\n this.syntax = syntax;\n }\n\n #lastSegment(): IdentifierAst | undefined {\n let last: IdentifierAst | undefined;\n for (const segment of filterChildren(this.syntax, IdentifierAst.cast)) {\n last = segment;\n }\n return last;\n }\n\n #penultimateSegment(): IdentifierAst | undefined {\n let last: IdentifierAst | undefined;\n let penultimate: IdentifierAst | undefined;\n for (const segment of filterChildren(this.syntax, IdentifierAst.cast)) {\n penultimate = last;\n last = segment;\n }\n return penultimate;\n }\n\n #separatorCount(kind: 'Dot' | 'Colon'): number {\n let count = 0;\n for (const child of this.syntax.children()) {\n if (!(child instanceof SyntaxNode) && child.kind === kind) count++;\n }\n return count;\n }\n\n colon(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'Colon');\n }\n\n dot(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'Dot');\n }\n\n space(): IdentifierAst | undefined {\n if (!this.colon()) return undefined;\n return findFirstChild(this.syntax, IdentifierAst.cast);\n }\n\n namespace(): IdentifierAst | undefined {\n if (!this.dot()) return undefined;\n return this.#penultimateSegment();\n }\n\n identifier(): IdentifierAst | undefined {\n return this.#lastSegment();\n }\n\n /**\n * Every identifier segment, in source order. A bare `Vector` yields\n * `['Vector']`; a qualified `pgvector.Vector` yields `['pgvector', 'Vector']`.\n */\n path(): readonly string[] {\n const segments: string[] = [];\n for (const segment of filterChildren(this.syntax, IdentifierAst.cast)) {\n const text = segment.token()?.text;\n if (text !== undefined) segments.push(text);\n }\n return segments;\n }\n\n /**\n * Flags a malformed name with more qualifier segments than allowed (a second\n * `:`-space or a second `.`-namespace).\n */\n isOverQualified(): boolean {\n return this.#separatorCount('Dot') > 1 || this.#separatorCount('Colon') > 1;\n }\n\n static cast(node: SyntaxNode): QualifiedNameAst | undefined {\n return node.kind === 'QualifiedName' ? new QualifiedNameAst(node) : undefined;\n }\n}\n","import type { AstNode } from '../ast-helpers';\nimport { filterChildren, findChildToken, findFirstChild } from '../ast-helpers';\nimport { SyntaxNode, type SyntaxToken } from '../red';\nimport { IdentifierAst } from './identifier';\nimport { QualifiedNameAst } from './qualified-name';\n\nexport class FunctionCallAst implements AstNode {\n readonly syntax: SyntaxNode;\n\n constructor(syntax: SyntaxNode) {\n this.syntax = syntax;\n }\n\n /** The qualified-name callee, or `undefined` when identifier segments sit directly under the node. */\n name(): QualifiedNameAst | undefined {\n return findFirstChild(this.syntax, QualifiedNameAst.cast);\n }\n\n /**\n * The dotted call path, in source order. A bare `Vector(…)` yields\n * `['Vector']`; a namespace-qualified `pgvector.Vector(…)` yields\n * `['pgvector', 'Vector']`. Empty when the call carries no identifier.\n */\n path(): readonly string[] {\n const qualified = this.name();\n const segments: string[] = [];\n for (const segment of filterChildren(qualified?.syntax ?? this.syntax, IdentifierAst.cast)) {\n const text = segment.token()?.text;\n if (text !== undefined) segments.push(text);\n }\n return segments;\n }\n\n lparen(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'LParen');\n }\n\n rparen(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'RParen');\n }\n\n *args(): Iterable<AttributeArgAst> {\n yield* filterChildren(this.syntax, AttributeArgAst.cast);\n }\n\n static cast(node: SyntaxNode): FunctionCallAst | undefined {\n return node.kind === 'FunctionCall' ? new FunctionCallAst(node) : undefined;\n }\n}\n\nexport class ArrayLiteralAst implements AstNode {\n readonly syntax: SyntaxNode;\n\n constructor(syntax: SyntaxNode) {\n this.syntax = syntax;\n }\n\n lbracket(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'LBracket');\n }\n\n rbracket(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'RBracket');\n }\n\n *elements(): Iterable<ExpressionAst> {\n yield* filterChildren(this.syntax, castExpression);\n }\n\n static cast(node: SyntaxNode): ArrayLiteralAst | undefined {\n return node.kind === 'ArrayLiteral' ? new ArrayLiteralAst(node) : undefined;\n }\n}\n\nconst HEX = /^[0-9a-fA-F]+$/;\n\nfunction decodeFixedHex(raw: string, start: number, width: number): string | undefined {\n if (start + width > raw.length) return undefined;\n const hex = raw.slice(start, start + width);\n if (!HEX.test(hex)) return undefined;\n return String.fromCharCode(Number.parseInt(hex, 16));\n}\n\nfunction decodeStringLiteral(raw: string): string {\n let out = '';\n let i = 0;\n while (i < raw.length) {\n const ch = raw.charAt(i);\n if (ch !== '\\\\' || i + 1 >= raw.length) {\n out += ch;\n i++;\n continue;\n }\n const next = raw.charAt(i + 1);\n switch (next) {\n case 'n':\n out += '\\n';\n i += 2;\n continue;\n case 'r':\n out += '\\r';\n i += 2;\n continue;\n case 't':\n out += '\\t';\n i += 2;\n continue;\n case '\"':\n out += '\"';\n i += 2;\n continue;\n case \"'\":\n out += \"'\";\n i += 2;\n continue;\n case '\\\\':\n out += '\\\\';\n i += 2;\n continue;\n case 'x': {\n const decoded = decodeFixedHex(raw, i + 2, 2);\n if (decoded === undefined) {\n out += '\\\\x';\n i += 2;\n continue;\n }\n out += decoded;\n i += 4;\n continue;\n }\n case 'u': {\n const decoded = decodeFixedHex(raw, i + 2, 4);\n if (decoded === undefined) {\n out += '\\\\u';\n i += 2;\n continue;\n }\n out += decoded;\n i += 6;\n continue;\n }\n default:\n out += `\\\\${next}`;\n i += 2;\n continue;\n }\n }\n return out;\n}\n\nexport class StringLiteralExprAst implements AstNode {\n readonly syntax: SyntaxNode;\n\n constructor(syntax: SyntaxNode) {\n this.syntax = syntax;\n }\n\n token(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'StringLiteral');\n }\n\n value(): string | undefined {\n const tok = this.token();\n if (!tok) return undefined;\n return decodeStringLiteral(tok.text.slice(1, -1));\n }\n\n static cast(node: SyntaxNode): StringLiteralExprAst | undefined {\n return node.kind === 'StringLiteralExpr' ? new StringLiteralExprAst(node) : undefined;\n }\n}\n\nexport class NumberLiteralExprAst implements AstNode {\n readonly syntax: SyntaxNode;\n\n constructor(syntax: SyntaxNode) {\n this.syntax = syntax;\n }\n\n token(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'NumberLiteral');\n }\n\n value(): number | undefined {\n const tok = this.token();\n if (!tok) return undefined;\n return Number(tok.text);\n }\n\n static cast(node: SyntaxNode): NumberLiteralExprAst | undefined {\n return node.kind === 'NumberLiteralExpr' ? new NumberLiteralExprAst(node) : undefined;\n }\n}\n\nexport class BooleanLiteralExprAst implements AstNode {\n readonly syntax: SyntaxNode;\n\n constructor(syntax: SyntaxNode) {\n this.syntax = syntax;\n }\n\n token(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'Ident');\n }\n\n value(): boolean | undefined {\n const tok = this.token();\n if (!tok) return undefined;\n if (tok.text === 'true') return true;\n if (tok.text === 'false') return false;\n return undefined;\n }\n\n static cast(node: SyntaxNode): BooleanLiteralExprAst | undefined {\n return node.kind === 'BooleanLiteralExpr' ? new BooleanLiteralExprAst(node) : undefined;\n }\n}\n\nexport class ObjectLiteralExprAst implements AstNode {\n readonly syntax: SyntaxNode;\n\n constructor(syntax: SyntaxNode) {\n this.syntax = syntax;\n }\n\n lbrace(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'LBrace');\n }\n\n rbrace(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'RBrace');\n }\n\n *fields(): Iterable<ObjectFieldAst> {\n yield* filterChildren(this.syntax, ObjectFieldAst.cast);\n }\n\n static cast(node: SyntaxNode): ObjectLiteralExprAst | undefined {\n return node.kind === 'ObjectLiteralExpr' ? new ObjectLiteralExprAst(node) : undefined;\n }\n}\n\nexport class ObjectFieldAst implements AstNode {\n readonly syntax: SyntaxNode;\n\n constructor(syntax: SyntaxNode) {\n this.syntax = syntax;\n }\n\n key(): IdentifierAst | undefined {\n for (const child of this.syntax.children()) {\n if (!(child instanceof SyntaxNode)) {\n if (child.kind === 'Colon') break;\n continue;\n }\n return IdentifierAst.cast(child);\n }\n return undefined;\n }\n\n /**\n * The field's logical key name, unquoted. An identifier key (`length:`) yields\n * its text; a string-literal key (`\"length\":`) yields the decoded string.\n * `undefined` when the field carries no key node.\n */\n keyName(): string | undefined {\n for (const child of this.syntax.children()) {\n if (!(child instanceof SyntaxNode)) {\n if (child.kind === 'Colon') break;\n continue;\n }\n const identifier = IdentifierAst.cast(child);\n if (identifier) return identifier.token()?.text;\n const stringKey = StringLiteralExprAst.cast(child);\n if (stringKey) return stringKey.value();\n return undefined;\n }\n return undefined;\n }\n\n colon(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'Colon');\n }\n\n value(): ExpressionAst | undefined {\n if (this.colon()) {\n let pastColon = false;\n for (const child of this.syntax.children()) {\n if (!(child instanceof SyntaxNode)) {\n if (child.kind === 'Colon') pastColon = true;\n continue;\n }\n if (pastColon) {\n const expr = castExpression(child);\n if (expr) return expr;\n }\n }\n return undefined;\n }\n return findFirstChild(this.syntax, castExpression);\n }\n\n static cast(node: SyntaxNode): ObjectFieldAst | undefined {\n return node.kind === 'ObjectField' ? new ObjectFieldAst(node) : undefined;\n }\n}\n\nexport type ExpressionAst =\n | FunctionCallAst\n | ArrayLiteralAst\n | StringLiteralExprAst\n | NumberLiteralExprAst\n | BooleanLiteralExprAst\n | ObjectLiteralExprAst\n | IdentifierAst;\n\nexport function castExpression(node: SyntaxNode): ExpressionAst | undefined {\n return (\n FunctionCallAst.cast(node) ??\n ArrayLiteralAst.cast(node) ??\n StringLiteralExprAst.cast(node) ??\n NumberLiteralExprAst.cast(node) ??\n BooleanLiteralExprAst.cast(node) ??\n ObjectLiteralExprAst.cast(node) ??\n IdentifierAst.cast(node)\n );\n}\n\nexport class AttributeArgAst implements AstNode {\n readonly syntax: SyntaxNode;\n\n constructor(syntax: SyntaxNode) {\n this.syntax = syntax;\n }\n\n name(): IdentifierAst | undefined {\n if (!this.colon()) return undefined;\n return findFirstChild(this.syntax, IdentifierAst.cast);\n }\n\n colon(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'Colon');\n }\n\n value(): ExpressionAst | undefined {\n if (this.colon()) {\n let pastColon = false;\n for (const child of this.syntax.children()) {\n if (!(child instanceof SyntaxNode)) {\n if (child.kind === 'Colon') pastColon = true;\n continue;\n }\n if (pastColon) {\n const expr = castExpression(child);\n if (expr) return expr;\n }\n }\n return undefined;\n }\n return findFirstChild(this.syntax, castExpression);\n }\n\n static cast(node: SyntaxNode): AttributeArgAst | undefined {\n return node.kind === 'AttributeArg' ? new AttributeArgAst(node) : undefined;\n }\n}\n","import type { AstNode } from '../ast-helpers';\nimport { filterChildren, findChildToken, findFirstChild } from '../ast-helpers';\nimport type { SyntaxNode, SyntaxToken } from '../red';\nimport { AttributeArgAst } from './expressions';\nimport { QualifiedNameAst } from './qualified-name';\n\nexport class AttributeArgListAst implements AstNode {\n readonly syntax: SyntaxNode;\n\n constructor(syntax: SyntaxNode) {\n this.syntax = syntax;\n }\n\n lparen(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'LParen');\n }\n\n rparen(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'RParen');\n }\n\n *args(): Iterable<AttributeArgAst> {\n yield* filterChildren(this.syntax, AttributeArgAst.cast);\n }\n\n static cast(node: SyntaxNode): AttributeArgListAst | undefined {\n return node.kind === 'AttributeArgList' ? new AttributeArgListAst(node) : undefined;\n }\n}\n\nexport class FieldAttributeAst implements AstNode {\n readonly syntax: SyntaxNode;\n\n constructor(syntax: SyntaxNode) {\n this.syntax = syntax;\n }\n\n at(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'At');\n }\n\n name(): QualifiedNameAst | undefined {\n return findFirstChild(this.syntax, QualifiedNameAst.cast);\n }\n\n argList(): AttributeArgListAst | undefined {\n return findFirstChild(this.syntax, AttributeArgListAst.cast);\n }\n\n static cast(node: SyntaxNode): FieldAttributeAst | undefined {\n return node.kind === 'FieldAttribute' ? new FieldAttributeAst(node) : undefined;\n }\n}\n\nexport class ModelAttributeAst implements AstNode {\n readonly syntax: SyntaxNode;\n\n constructor(syntax: SyntaxNode) {\n this.syntax = syntax;\n }\n\n doubleAt(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'DoubleAt');\n }\n\n name(): QualifiedNameAst | undefined {\n return findFirstChild(this.syntax, QualifiedNameAst.cast);\n }\n\n argList(): AttributeArgListAst | undefined {\n return findFirstChild(this.syntax, AttributeArgListAst.cast);\n }\n\n static cast(node: SyntaxNode): ModelAttributeAst | undefined {\n return node.kind === 'ModelAttribute' ? new ModelAttributeAst(node) : undefined;\n }\n}\n","import type { AstNode } from '../ast-helpers';\nimport { findChildToken, findFirstChild } from '../ast-helpers';\nimport type { SyntaxNode, SyntaxToken } from '../red';\nimport { AttributeArgListAst } from './attributes';\nimport { QualifiedNameAst } from './qualified-name';\n\nexport class TypeAnnotationAst implements AstNode {\n readonly syntax: SyntaxNode;\n\n constructor(syntax: SyntaxNode) {\n this.syntax = syntax;\n }\n\n /** The annotation's reference, doubling as the constructor callee when an {@link argList} follows. */\n name(): QualifiedNameAst | undefined {\n return findFirstChild(this.syntax, QualifiedNameAst.cast);\n }\n\n /** Present when the annotation is a constructor (`Vector(1536)`) rather than a plain reference. */\n argList(): AttributeArgListAst | undefined {\n return findFirstChild(this.syntax, AttributeArgListAst.cast);\n }\n\n isConstructor(): boolean {\n return this.argList() !== undefined;\n }\n\n lbracket(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'LBracket');\n }\n\n rbracket(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'RBracket');\n }\n\n questionMark(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'Question');\n }\n\n isList(): boolean {\n return this.lbracket() !== undefined;\n }\n\n isOptional(): boolean {\n return this.questionMark() !== undefined;\n }\n\n static cast(node: SyntaxNode): TypeAnnotationAst | undefined {\n return node.kind === 'TypeAnnotation' ? new TypeAnnotationAst(node) : undefined;\n }\n}\n","import type { AstNode } from '../ast-helpers';\nimport { filterChildren, findChildToken, findFirstChild } from '../ast-helpers';\nimport { SyntaxNode, type SyntaxToken } from '../red';\nimport { FieldAttributeAst, ModelAttributeAst } from './attributes';\nimport type { ExpressionAst } from './expressions';\nimport { castExpression } from './expressions';\nimport { IdentifierAst } from './identifier';\nimport { TypeAnnotationAst } from './type-annotation';\n\n/**\n * What may appear inside a `namespace` block: models, composite types, and\n * extension (block) declarations. `types {}` blocks and nested `namespace`\n * blocks are document-only, so they are not namespace members.\n */\nexport type NamespaceMemberAst =\n | ModelDeclarationAst\n | CompositeTypeDeclarationAst\n | GenericBlockDeclarationAst;\n\nexport type DeclarationAst = NamespaceMemberAst | TypesBlockAst | NamespaceDeclarationAst;\nexport type AttributeAst = FieldAttributeAst | ModelAttributeAst;\nexport type BlockMemberAst = FieldDeclarationAst | ModelAttributeAst;\nexport type GenericBlockMemberAst = KeyValuePairAst | ModelAttributeAst;\n\nfunction castNamespaceMember(node: SyntaxNode): NamespaceMemberAst | undefined {\n return (\n ModelDeclarationAst.cast(node) ??\n CompositeTypeDeclarationAst.cast(node) ??\n GenericBlockDeclarationAst.cast(node)\n );\n}\n\nexport class DocumentAst implements AstNode {\n readonly syntax: SyntaxNode;\n\n constructor(syntax: SyntaxNode) {\n this.syntax = syntax;\n }\n\n *declarations(): Iterable<DeclarationAst> {\n yield* filterChildren(\n this.syntax,\n (node) =>\n castNamespaceMember(node) ?? TypesBlockAst.cast(node) ?? NamespaceDeclarationAst.cast(node),\n );\n }\n\n static cast(node: SyntaxNode): DocumentAst | undefined {\n return node.kind === 'Document' ? new DocumentAst(node) : undefined;\n }\n}\n\nexport class ModelDeclarationAst implements AstNode {\n readonly syntax: SyntaxNode;\n\n constructor(syntax: SyntaxNode) {\n this.syntax = syntax;\n }\n\n keyword(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'Ident');\n }\n\n name(): IdentifierAst | undefined {\n return findFirstChild(this.syntax, IdentifierAst.cast);\n }\n\n lbrace(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'LBrace');\n }\n\n rbrace(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'RBrace');\n }\n\n *fields(): Iterable<FieldDeclarationAst> {\n yield* filterChildren(this.syntax, FieldDeclarationAst.cast);\n }\n\n *attributes(): Iterable<ModelAttributeAst> {\n yield* filterChildren(this.syntax, ModelAttributeAst.cast);\n }\n\n *members(): Iterable<BlockMemberAst> {\n yield* filterChildren(\n this.syntax,\n (node) => FieldDeclarationAst.cast(node) ?? ModelAttributeAst.cast(node),\n );\n }\n\n static cast(node: SyntaxNode): ModelDeclarationAst | undefined {\n return node.kind === 'ModelDeclaration' ? new ModelDeclarationAst(node) : undefined;\n }\n}\n\nexport class CompositeTypeDeclarationAst implements AstNode {\n readonly syntax: SyntaxNode;\n\n constructor(syntax: SyntaxNode) {\n this.syntax = syntax;\n }\n\n keyword(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'Ident');\n }\n\n name(): IdentifierAst | undefined {\n return findFirstChild(this.syntax, IdentifierAst.cast);\n }\n\n lbrace(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'LBrace');\n }\n\n rbrace(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'RBrace');\n }\n\n *fields(): Iterable<FieldDeclarationAst> {\n yield* filterChildren(this.syntax, FieldDeclarationAst.cast);\n }\n\n *attributes(): Iterable<ModelAttributeAst> {\n yield* filterChildren(this.syntax, ModelAttributeAst.cast);\n }\n\n *members(): Iterable<BlockMemberAst> {\n yield* filterChildren(\n this.syntax,\n (node) => FieldDeclarationAst.cast(node) ?? ModelAttributeAst.cast(node),\n );\n }\n\n static cast(node: SyntaxNode): CompositeTypeDeclarationAst | undefined {\n return node.kind === 'CompositeTypeDeclaration'\n ? new CompositeTypeDeclarationAst(node)\n : undefined;\n }\n}\n\nexport class NamespaceDeclarationAst implements AstNode {\n readonly syntax: SyntaxNode;\n\n constructor(syntax: SyntaxNode) {\n this.syntax = syntax;\n }\n\n keyword(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'Ident');\n }\n\n name(): IdentifierAst | undefined {\n return findFirstChild(this.syntax, IdentifierAst.cast);\n }\n\n lbrace(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'LBrace');\n }\n\n rbrace(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'RBrace');\n }\n\n *declarations(): Iterable<NamespaceMemberAst> {\n yield* filterChildren(this.syntax, castNamespaceMember);\n }\n\n static cast(node: SyntaxNode): NamespaceDeclarationAst | undefined {\n return node.kind === 'Namespace' ? new NamespaceDeclarationAst(node) : undefined;\n }\n}\n\nexport class TypesBlockAst implements AstNode {\n readonly syntax: SyntaxNode;\n\n constructor(syntax: SyntaxNode) {\n this.syntax = syntax;\n }\n\n keyword(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'Ident');\n }\n\n lbrace(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'LBrace');\n }\n\n rbrace(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'RBrace');\n }\n\n *declarations(): Iterable<NamedTypeDeclarationAst> {\n yield* filterChildren(this.syntax, NamedTypeDeclarationAst.cast);\n }\n\n static cast(node: SyntaxNode): TypesBlockAst | undefined {\n return node.kind === 'TypesBlock' ? new TypesBlockAst(node) : undefined;\n }\n}\n\nexport class GenericBlockDeclarationAst implements AstNode {\n readonly syntax: SyntaxNode;\n\n constructor(syntax: SyntaxNode) {\n this.syntax = syntax;\n }\n\n keyword(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'Ident');\n }\n\n name(): IdentifierAst | undefined {\n return findFirstChild(this.syntax, IdentifierAst.cast);\n }\n\n lbrace(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'LBrace');\n }\n\n rbrace(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'RBrace');\n }\n\n *entries(): Iterable<KeyValuePairAst> {\n yield* filterChildren(this.syntax, KeyValuePairAst.cast);\n }\n\n *attributes(): Iterable<ModelAttributeAst> {\n yield* filterChildren(this.syntax, ModelAttributeAst.cast);\n }\n\n *members(): Iterable<GenericBlockMemberAst> {\n yield* filterChildren(\n this.syntax,\n (node) => KeyValuePairAst.cast(node) ?? ModelAttributeAst.cast(node),\n );\n }\n\n static cast(node: SyntaxNode): GenericBlockDeclarationAst | undefined {\n return node.kind === 'GenericBlockDeclaration'\n ? new GenericBlockDeclarationAst(node)\n : undefined;\n }\n}\n\nexport class KeyValuePairAst implements AstNode {\n readonly syntax: SyntaxNode;\n\n constructor(syntax: SyntaxNode) {\n this.syntax = syntax;\n }\n\n key(): IdentifierAst | undefined {\n return findFirstChild(this.syntax, IdentifierAst.cast);\n }\n\n equals(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'Equals');\n }\n\n value(): ExpressionAst | undefined {\n let pastEquals = false;\n for (const child of this.syntax.children()) {\n if (!(child instanceof SyntaxNode)) {\n if (child.kind === 'Equals') pastEquals = true;\n continue;\n }\n if (pastEquals) {\n const expr = castExpression(child);\n if (expr) return expr;\n }\n }\n return undefined;\n }\n\n static cast(node: SyntaxNode): KeyValuePairAst | undefined {\n return node.kind === 'KeyValuePair' ? new KeyValuePairAst(node) : undefined;\n }\n}\n\nexport class FieldDeclarationAst implements AstNode {\n readonly syntax: SyntaxNode;\n\n constructor(syntax: SyntaxNode) {\n this.syntax = syntax;\n }\n\n name(): IdentifierAst | undefined {\n return findFirstChild(this.syntax, IdentifierAst.cast);\n }\n\n typeAnnotation(): TypeAnnotationAst | undefined {\n return findFirstChild(this.syntax, TypeAnnotationAst.cast);\n }\n\n *attributes(): Iterable<FieldAttributeAst> {\n yield* filterChildren(this.syntax, FieldAttributeAst.cast);\n }\n\n static cast(node: SyntaxNode): FieldDeclarationAst | undefined {\n return node.kind === 'FieldDeclaration' ? new FieldDeclarationAst(node) : undefined;\n }\n}\n\nexport class NamedTypeDeclarationAst implements AstNode {\n readonly syntax: SyntaxNode;\n\n constructor(syntax: SyntaxNode) {\n this.syntax = syntax;\n }\n\n name(): IdentifierAst | undefined {\n return findFirstChild(this.syntax, IdentifierAst.cast);\n }\n\n equals(): SyntaxToken | undefined {\n return findChildToken(this.syntax, 'Equals');\n }\n\n typeAnnotation(): TypeAnnotationAst | undefined {\n return findFirstChild(this.syntax, TypeAnnotationAst.cast);\n }\n\n *attributes(): Iterable<FieldAttributeAst> {\n yield* filterChildren(this.syntax, FieldAttributeAst.cast);\n }\n\n static cast(node: SyntaxNode): NamedTypeDeclarationAst | undefined {\n return node.kind === 'NamedTypeDeclaration' ? new NamedTypeDeclarationAst(node) : undefined;\n }\n}\n"],"mappings":";AAeA,IAAa,aAAb,MAAa,WAAW;CACtB;CACA;CACA;CAEA,YAAY,OAAkB,QAAgB,QAAgC;EAC5E,KAAK,QAAQ;EACb,KAAK,SAAS;EACd,KAAK,SAAS;CAChB;CAEA,IAAI,OAAmB;EACrB,OAAO,KAAK,MAAM;CACpB;CAEA,IAAI,aAAqB;EACvB,OAAO,KAAK,MAAM;CACpB;CAEA,IAAI,aAAwC;EAC1C,OAAO,QAAQ,MAAM,CAAC;CACxB;CAEA,IAAI,YAAuC;EACzC,MAAM,MAAM,KAAK,MAAM,SAAS;EAChC,IAAI,QAAQ,GAAG,OAAO,KAAA;EACtB,OAAO,QAAQ,MAAM,MAAM,CAAC;CAC9B;CAEA,IAAI,cAAyC;EAC3C,IAAI,CAAC,KAAK,QAAQ,OAAO,KAAA;EACzB,MAAM,WAAW,KAAK,OAAO,MAAM;EACnC,IAAI,SAAS,KAAK,OAAO;EACzB,IAAI,QAAQ;EACZ,KAAK,MAAM,SAAS,UAAU;GAC5B,IAAI,OACF,OAAO,YAAY,OAAO,QAAQ,KAAK,MAAM;GAE/C,MAAM,WAAW,kBAAkB,KAAK;GACxC,IAAI,MAAM,SAAS,UAAU,WAAW,KAAK,UAAU,UAAU,KAAK,OACpE,QAAQ;GAEV,UAAU;EACZ;CAEF;CAEA,IAAI,cAAyC;EAC3C,IAAI,CAAC,KAAK,QAAQ,OAAO,KAAA;EACzB,MAAM,WAAW,KAAK,OAAO,MAAM;EACnC,IAAI,SAAS,KAAK,OAAO;EACzB,IAAI;EACJ,KAAK,MAAM,SAAS,UAAU;GAC5B,IAAI,MAAM,SAAS,UAAU,WAAW,KAAK,UAAU,UAAU,KAAK,OAAO;IAC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,kBAAkB,IAAI;CAC3D;CAEA,OAAO,KAAK,MAAuD;EACjE,OAAO,KAAK,SAAS,yBAAyB,IAAI,wBAAwB,IAAI,IAAI,KAAA;CACpF;AACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { t as ParseDiagnostic } from "./parse-Ce9Em5k9.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/format/error.d.ts
|
|
4
|
+
declare class PslFormatError extends Error {
|
|
5
|
+
readonly diagnostics: readonly ParseDiagnostic[];
|
|
6
|
+
constructor(diagnostics: readonly ParseDiagnostic[]);
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/format/options.d.ts
|
|
10
|
+
interface FormatOptions {
|
|
11
|
+
readonly indent?: number | 'tab';
|
|
12
|
+
readonly newline?: 'LF' | 'CRLF';
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/format/format.d.ts
|
|
16
|
+
declare function format(source: string, options?: FormatOptions): string;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { type FormatOptions, PslFormatError, format };
|
|
19
|
+
//# sourceMappingURL=format.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.mts","names":[],"sources":["../src/format/error.ts","../src/format/options.ts","../src/format/format.ts"],"mappings":";;;cAEa,cAAA,SAAuB,KAAA;EAAA,SACzB,WAAA,WAAsB,eAAA;cAEnB,WAAA,WAAsB,eAAA;AAAA;;;UCLnB,aAAA;EAAA,SACN,MAAA;EAAA,SACA,OAAO;AAAA;;;iBCGF,MAAA,CAAO,MAAA,UAAgB,OAAA,GAAU,aAAa"}
|
package/dist/format.mjs
ADDED
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
import { a as KeyValuePairAst, c as NamespaceDeclarationAst, i as GenericBlockDeclarationAst, k as SyntaxNode, l as TypesBlockAst, o as ModelDeclarationAst, p as ModelAttributeAst, r as FieldDeclarationAst, s as NamedTypeDeclarationAst, t as CompositeTypeDeclarationAst } from "./declarations-DWUyG1DT.mjs";
|
|
2
|
+
import { t as parse } from "./parse-iG0rOMKS.mjs";
|
|
3
|
+
//#region src/format/error.ts
|
|
4
|
+
var PslFormatError = class extends Error {
|
|
5
|
+
diagnostics;
|
|
6
|
+
constructor(diagnostics) {
|
|
7
|
+
const summary = diagnostics[0]?.message ?? "unknown parse error";
|
|
8
|
+
const more = diagnostics.length > 1 ? ` (and ${diagnostics.length - 1} more)` : "";
|
|
9
|
+
super(`Cannot format PSL with parse errors: ${summary}${more}`);
|
|
10
|
+
this.name = "PslFormatError";
|
|
11
|
+
this.diagnostics = diagnostics;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/format/emit.ts
|
|
16
|
+
function emitDocument(document, indentUnit, newline) {
|
|
17
|
+
const writer = new LineWriter(indentUnit, newline);
|
|
18
|
+
emitTopLevel(writer, document);
|
|
19
|
+
return writer.finish();
|
|
20
|
+
}
|
|
21
|
+
var LineWriter = class {
|
|
22
|
+
#indentUnit;
|
|
23
|
+
#newline;
|
|
24
|
+
#out = [];
|
|
25
|
+
#depth = 0;
|
|
26
|
+
#line = "";
|
|
27
|
+
#lineOpen = false;
|
|
28
|
+
#prevKind;
|
|
29
|
+
#lastWasBlank = false;
|
|
30
|
+
#hasContent = false;
|
|
31
|
+
constructor(indentUnit, newline) {
|
|
32
|
+
this.#indentUnit = indentUnit;
|
|
33
|
+
this.#newline = newline;
|
|
34
|
+
}
|
|
35
|
+
indent() {
|
|
36
|
+
this.#depth += 1;
|
|
37
|
+
}
|
|
38
|
+
unindent() {
|
|
39
|
+
this.#depth = Math.max(0, this.#depth - 1);
|
|
40
|
+
}
|
|
41
|
+
lastIsBlank() {
|
|
42
|
+
return this.#lastWasBlank;
|
|
43
|
+
}
|
|
44
|
+
lineOpen() {
|
|
45
|
+
return this.#lineOpen;
|
|
46
|
+
}
|
|
47
|
+
prevKind() {
|
|
48
|
+
return this.#prevKind;
|
|
49
|
+
}
|
|
50
|
+
newline() {
|
|
51
|
+
if (!this.#lineOpen) return;
|
|
52
|
+
this.#out.push(`${this.#indentUnit.repeat(this.#depth)}${this.#line}`);
|
|
53
|
+
this.#line = "";
|
|
54
|
+
this.#lineOpen = false;
|
|
55
|
+
this.#prevKind = void 0;
|
|
56
|
+
this.#lastWasBlank = false;
|
|
57
|
+
this.#hasContent = true;
|
|
58
|
+
}
|
|
59
|
+
blank() {
|
|
60
|
+
this.newline();
|
|
61
|
+
if (!this.#hasContent || this.#lastWasBlank) return;
|
|
62
|
+
this.#out.push("");
|
|
63
|
+
this.#lastWasBlank = true;
|
|
64
|
+
}
|
|
65
|
+
write(token, space, padTo) {
|
|
66
|
+
if (this.#lineOpen && padTo !== void 0) this.#line = this.#line.padEnd(padTo);
|
|
67
|
+
else if (this.#lineOpen && space) this.#line += " ";
|
|
68
|
+
this.#line += token.text;
|
|
69
|
+
this.#lineOpen = true;
|
|
70
|
+
this.#prevKind = token.kind;
|
|
71
|
+
}
|
|
72
|
+
writeRaw(text) {
|
|
73
|
+
this.#line += text;
|
|
74
|
+
this.#lineOpen = true;
|
|
75
|
+
}
|
|
76
|
+
comment(text) {
|
|
77
|
+
if (this.#lineOpen) this.#line += ` ${text}`;
|
|
78
|
+
else this.#line = text;
|
|
79
|
+
this.#lineOpen = true;
|
|
80
|
+
this.newline();
|
|
81
|
+
}
|
|
82
|
+
finish() {
|
|
83
|
+
this.newline();
|
|
84
|
+
const body = this.#out.join(this.#newline);
|
|
85
|
+
return body.length > 0 ? `${body}${this.#newline}` : "";
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
function spaceBetween(prev, cur, inQualifiedName) {
|
|
89
|
+
if (prev === void 0) return false;
|
|
90
|
+
if (inQualifiedName) return false;
|
|
91
|
+
switch (cur) {
|
|
92
|
+
case "LParen":
|
|
93
|
+
case "LBracket":
|
|
94
|
+
case "RParen":
|
|
95
|
+
case "RBracket":
|
|
96
|
+
case "Comma":
|
|
97
|
+
case "Question":
|
|
98
|
+
case "Dot":
|
|
99
|
+
case "Colon": return false;
|
|
100
|
+
case "RBrace": return prev !== "LBrace";
|
|
101
|
+
default: break;
|
|
102
|
+
}
|
|
103
|
+
switch (prev) {
|
|
104
|
+
case "LParen":
|
|
105
|
+
case "LBracket":
|
|
106
|
+
case "Dot":
|
|
107
|
+
case "At":
|
|
108
|
+
case "DoubleAt": return false;
|
|
109
|
+
default: return true;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function streamNode(writer, node, padTo) {
|
|
113
|
+
let continuation = 0;
|
|
114
|
+
let first = true;
|
|
115
|
+
let prevQualified = false;
|
|
116
|
+
const walk = (parent, qualified) => {
|
|
117
|
+
for (const child of parent.children()) {
|
|
118
|
+
if (child instanceof SyntaxNode) {
|
|
119
|
+
walk(child, qualified || child.kind === "QualifiedName");
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (child.kind === "Whitespace" || child.kind === "Newline") continue;
|
|
123
|
+
if (child.kind === "Comment") {
|
|
124
|
+
writer.comment(child.text);
|
|
125
|
+
writer.indent();
|
|
126
|
+
continuation += 1;
|
|
127
|
+
prevQualified = false;
|
|
128
|
+
first = false;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const pad = first ? padTo : void 0;
|
|
132
|
+
const space = spaceBetween(writer.prevKind(), child.kind, qualified && prevQualified);
|
|
133
|
+
writer.write(child, space, writer.lineOpen() ? pad : void 0);
|
|
134
|
+
prevQualified = qualified;
|
|
135
|
+
first = false;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
walk(node, false);
|
|
139
|
+
return continuation;
|
|
140
|
+
}
|
|
141
|
+
function closeContinuation(writer, count) {
|
|
142
|
+
for (let i = 0; i < count; i++) writer.unindent();
|
|
143
|
+
}
|
|
144
|
+
function emitField(writer, field, columns) {
|
|
145
|
+
return streamRow(writer, field.syntax, columns);
|
|
146
|
+
}
|
|
147
|
+
function emitNamedType(writer, decl) {
|
|
148
|
+
return streamRow(writer, decl.syntax, void 0);
|
|
149
|
+
}
|
|
150
|
+
function streamRow(writer, row, columns) {
|
|
151
|
+
let continuation = 0;
|
|
152
|
+
let sawAttribute = false;
|
|
153
|
+
for (const child of row.children()) {
|
|
154
|
+
if (child instanceof SyntaxNode) {
|
|
155
|
+
let padTo;
|
|
156
|
+
if (child.kind === "TypeAnnotation" && continuation === 0) padTo = columns?.typeColumn;
|
|
157
|
+
else if (child.kind === "FieldAttribute") {
|
|
158
|
+
if (continuation > 0) writer.newline();
|
|
159
|
+
else if (!sawAttribute) padTo = columns?.attributeColumn;
|
|
160
|
+
sawAttribute = true;
|
|
161
|
+
}
|
|
162
|
+
continuation += streamNode(writer, child, padTo);
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (child.kind === "Whitespace" || child.kind === "Newline") continue;
|
|
166
|
+
if (child.kind === "Comment") {
|
|
167
|
+
writer.comment(child.text);
|
|
168
|
+
writer.indent();
|
|
169
|
+
continuation += 1;
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
const space = spaceBetween(writer.prevKind(), child.kind, false);
|
|
173
|
+
writer.write(child, space);
|
|
174
|
+
}
|
|
175
|
+
return continuation;
|
|
176
|
+
}
|
|
177
|
+
function emitBlockAttribute(writer, attribute) {
|
|
178
|
+
return streamNode(writer, attribute.syntax);
|
|
179
|
+
}
|
|
180
|
+
function emitKeyValue(writer, pair) {
|
|
181
|
+
return streamNode(writer, pair.syntax);
|
|
182
|
+
}
|
|
183
|
+
function leafMember(writer, category, print) {
|
|
184
|
+
return {
|
|
185
|
+
category,
|
|
186
|
+
emit(trailing) {
|
|
187
|
+
const continuation = print();
|
|
188
|
+
if (trailing !== void 0) writer.comment(trailing);
|
|
189
|
+
else writer.newline();
|
|
190
|
+
return continuation;
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function emitModel(writer, model, trailing) {
|
|
195
|
+
const columns = alignmentMap(model.syntax);
|
|
196
|
+
emitBlockBody(writer, model.syntax, trailing, (node) => {
|
|
197
|
+
const field = FieldDeclarationAst.cast(node);
|
|
198
|
+
if (field) return leafMember(writer, "regular", () => emitField(writer, field, columns));
|
|
199
|
+
const attribute = ModelAttributeAst.cast(node);
|
|
200
|
+
if (attribute) return leafMember(writer, "blockAttribute", () => emitBlockAttribute(writer, attribute));
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
function emitCompositeType(writer, composite, trailing) {
|
|
204
|
+
const columns = alignmentMap(composite.syntax);
|
|
205
|
+
emitBlockBody(writer, composite.syntax, trailing, (node) => {
|
|
206
|
+
const field = FieldDeclarationAst.cast(node);
|
|
207
|
+
if (field) return leafMember(writer, "regular", () => emitField(writer, field, columns));
|
|
208
|
+
const attribute = ModelAttributeAst.cast(node);
|
|
209
|
+
if (attribute) return leafMember(writer, "blockAttribute", () => emitBlockAttribute(writer, attribute));
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
function emitGenericBlock(writer, block, trailing) {
|
|
213
|
+
emitBlockBody(writer, block.syntax, trailing, (node) => {
|
|
214
|
+
const entry = KeyValuePairAst.cast(node);
|
|
215
|
+
if (entry) return leafMember(writer, "regular", () => emitKeyValue(writer, entry));
|
|
216
|
+
const attribute = ModelAttributeAst.cast(node);
|
|
217
|
+
if (attribute) return leafMember(writer, "blockAttribute", () => emitBlockAttribute(writer, attribute));
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
function emitNamespace(writer, namespace, trailing) {
|
|
221
|
+
emitBlockBody(writer, namespace.syntax, trailing, (node) => {
|
|
222
|
+
const declaration = castBlockDeclaration(node);
|
|
223
|
+
if (declaration) return nestedBlockMember(writer, declaration);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
function emitTypesBlock(writer, block, trailing) {
|
|
227
|
+
emitBlockBody(writer, block.syntax, trailing, (node) => {
|
|
228
|
+
const named = NamedTypeDeclarationAst.cast(node);
|
|
229
|
+
if (named) return leafMember(writer, "regular", () => emitNamedType(writer, named));
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
function emitTopLevel(writer, document) {
|
|
233
|
+
walkRegion(writer, Array.from(document.syntax.children()), void 0, (node) => {
|
|
234
|
+
const declaration = castTopLevelDeclaration(node);
|
|
235
|
+
if (declaration) return nestedBlockMember(writer, declaration);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
function nestedBlockMember(writer, block) {
|
|
239
|
+
return {
|
|
240
|
+
category: "nestedBlock",
|
|
241
|
+
emit(trailing) {
|
|
242
|
+
block(writer, trailing);
|
|
243
|
+
return 0;
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function castBlockDeclaration(node) {
|
|
248
|
+
const model = ModelDeclarationAst.cast(node);
|
|
249
|
+
if (model) return (writer, trailing) => emitModel(writer, model, trailing);
|
|
250
|
+
const composite = CompositeTypeDeclarationAst.cast(node);
|
|
251
|
+
if (composite) return (writer, trailing) => emitCompositeType(writer, composite, trailing);
|
|
252
|
+
const generic = GenericBlockDeclarationAst.cast(node);
|
|
253
|
+
if (generic) return (writer, trailing) => emitGenericBlock(writer, generic, trailing);
|
|
254
|
+
}
|
|
255
|
+
function castTopLevelDeclaration(node) {
|
|
256
|
+
const block = castBlockDeclaration(node);
|
|
257
|
+
if (block) return block;
|
|
258
|
+
const namespace = NamespaceDeclarationAst.cast(node);
|
|
259
|
+
if (namespace) return (writer, trailing) => emitNamespace(writer, namespace, trailing);
|
|
260
|
+
const types = TypesBlockAst.cast(node);
|
|
261
|
+
if (types) return (writer, trailing) => emitTypesBlock(writer, types, trailing);
|
|
262
|
+
}
|
|
263
|
+
function emitBlockBody(writer, node, closingTrailing, classify) {
|
|
264
|
+
const children = Array.from(node.children());
|
|
265
|
+
const openIndex = children.findIndex((el) => !(el instanceof SyntaxNode) && el.kind === "LBrace");
|
|
266
|
+
streamHeader(writer, node);
|
|
267
|
+
const headerComment = sameLineCommentAfter(children, openIndex);
|
|
268
|
+
if (headerComment !== void 0) writer.comment(headerComment);
|
|
269
|
+
else writer.newline();
|
|
270
|
+
writer.indent();
|
|
271
|
+
walkRegion(writer, children, "RBrace", classify);
|
|
272
|
+
writer.unindent();
|
|
273
|
+
writer.writeRaw("}");
|
|
274
|
+
if (closingTrailing !== void 0) writer.comment(closingTrailing);
|
|
275
|
+
else writer.newline();
|
|
276
|
+
}
|
|
277
|
+
function streamHeader(writer, node) {
|
|
278
|
+
let done = false;
|
|
279
|
+
const walk = (parent) => {
|
|
280
|
+
for (const child of parent.children()) {
|
|
281
|
+
if (done) return;
|
|
282
|
+
if (child instanceof SyntaxNode) {
|
|
283
|
+
walk(child);
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
if (child.kind === "Whitespace" || child.kind === "Newline" || child.kind === "Comment") continue;
|
|
287
|
+
const space = spaceBetween(writer.prevKind(), child.kind, false);
|
|
288
|
+
writer.write(child, space);
|
|
289
|
+
if (child.kind === "LBrace") {
|
|
290
|
+
done = true;
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
walk(node);
|
|
296
|
+
}
|
|
297
|
+
function walkRegion(writer, elements, closeKind, classify) {
|
|
298
|
+
let sawOpenBrace = closeKind === void 0;
|
|
299
|
+
let sawContent = false;
|
|
300
|
+
let lastWasRegular = false;
|
|
301
|
+
let ledByComment = false;
|
|
302
|
+
let newlines = 0;
|
|
303
|
+
for (let i = 0; i < elements.length; i++) {
|
|
304
|
+
const element = elements[i];
|
|
305
|
+
if (element === void 0) continue;
|
|
306
|
+
if (element instanceof SyntaxNode) {
|
|
307
|
+
if (!sawOpenBrace) continue;
|
|
308
|
+
const member = classify(element);
|
|
309
|
+
if (member === void 0) continue;
|
|
310
|
+
if (!ledByComment) {
|
|
311
|
+
if (newlines >= 2 && sawContent && !writer.lastIsBlank()) writer.blank();
|
|
312
|
+
else if (separationBlankWanted(writer, member.category, sawContent, lastWasRegular)) writer.blank();
|
|
313
|
+
}
|
|
314
|
+
const trailing = sameLineTrailingComment(elements, i);
|
|
315
|
+
closeContinuation(writer, member.emit(trailing.text));
|
|
316
|
+
if (trailing.index !== void 0) i = trailing.index;
|
|
317
|
+
sawContent = true;
|
|
318
|
+
lastWasRegular = member.category !== "blockAttribute";
|
|
319
|
+
ledByComment = false;
|
|
320
|
+
newlines = 0;
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
if (element.kind === "LBrace" && closeKind === "RBrace" && !sawOpenBrace) {
|
|
324
|
+
sawOpenBrace = true;
|
|
325
|
+
newlines = 0;
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
if (!sawOpenBrace) continue;
|
|
329
|
+
if (closeKind === "RBrace" && element.kind === "RBrace") break;
|
|
330
|
+
if (element.kind === "Whitespace") continue;
|
|
331
|
+
if (element.kind === "Newline") {
|
|
332
|
+
newlines += 1;
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
if (element.kind === "Comment") {
|
|
336
|
+
if (closeKind === "RBrace" && newlines === 0 && !sawContent) continue;
|
|
337
|
+
if (newlines >= 2 && sawContent && !writer.lastIsBlank()) writer.blank();
|
|
338
|
+
else if (!ledByComment) {
|
|
339
|
+
const led = leadingMemberAfter(elements, i, classify);
|
|
340
|
+
if (led && separationBlankWanted(writer, led, sawContent, lastWasRegular)) writer.blank();
|
|
341
|
+
}
|
|
342
|
+
writer.writeRaw(element.text);
|
|
343
|
+
writer.newline();
|
|
344
|
+
sawContent = true;
|
|
345
|
+
ledByComment = true;
|
|
346
|
+
newlines = 0;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
function separationBlankWanted(writer, category, sawContent, lastWasRegular) {
|
|
351
|
+
if (!sawContent || writer.lastIsBlank()) return false;
|
|
352
|
+
if (category === "nestedBlock") return true;
|
|
353
|
+
return category === "blockAttribute" && lastWasRegular;
|
|
354
|
+
}
|
|
355
|
+
function leadingMemberAfter(elements, commentIndex, classify) {
|
|
356
|
+
for (let i = commentIndex + 1; i < elements.length; i++) {
|
|
357
|
+
const element = elements[i];
|
|
358
|
+
if (element === void 0) continue;
|
|
359
|
+
if (element instanceof SyntaxNode) return classify(element)?.category;
|
|
360
|
+
if (element.kind === "RBrace") return void 0;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
function sameLineTrailingComment(elements, memberIndex) {
|
|
364
|
+
for (let i = memberIndex + 1; i < elements.length; i++) {
|
|
365
|
+
const element = elements[i];
|
|
366
|
+
if (element === void 0) continue;
|
|
367
|
+
if (element instanceof SyntaxNode) break;
|
|
368
|
+
if (element.kind === "Whitespace") continue;
|
|
369
|
+
if (element.kind === "Comment") return {
|
|
370
|
+
text: element.text,
|
|
371
|
+
index: i
|
|
372
|
+
};
|
|
373
|
+
break;
|
|
374
|
+
}
|
|
375
|
+
return {
|
|
376
|
+
text: void 0,
|
|
377
|
+
index: void 0
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
function sameLineCommentAfter(children, openIndex) {
|
|
381
|
+
for (let i = openIndex + 1; i < children.length; i++) {
|
|
382
|
+
const child = children[i];
|
|
383
|
+
if (child === void 0) continue;
|
|
384
|
+
if (child instanceof SyntaxNode) return void 0;
|
|
385
|
+
if (child.kind === "Whitespace") continue;
|
|
386
|
+
if (child.kind === "Comment") return child.text;
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
function alignmentMap(block) {
|
|
391
|
+
const fields = [];
|
|
392
|
+
for (const element of block.children()) {
|
|
393
|
+
if (!(element instanceof SyntaxNode)) continue;
|
|
394
|
+
if (FieldDeclarationAst.cast(element) === void 0) continue;
|
|
395
|
+
if (hasInteriorComment(element)) continue;
|
|
396
|
+
fields.push(element);
|
|
397
|
+
}
|
|
398
|
+
if (fields.length === 0) return void 0;
|
|
399
|
+
return alignmentColumns(fields);
|
|
400
|
+
}
|
|
401
|
+
function alignmentColumns(rows) {
|
|
402
|
+
let nameWidth = 0;
|
|
403
|
+
for (const row of rows) {
|
|
404
|
+
const field = FieldDeclarationAst.cast(row);
|
|
405
|
+
if (!field) continue;
|
|
406
|
+
nameWidth = Math.max(nameWidth, renderTokens(field.name()?.syntax).length);
|
|
407
|
+
}
|
|
408
|
+
const typeColumn = nameWidth + 1;
|
|
409
|
+
let cellEnd = 0;
|
|
410
|
+
for (const row of rows) {
|
|
411
|
+
const field = FieldDeclarationAst.cast(row);
|
|
412
|
+
if (!field) continue;
|
|
413
|
+
const name = renderTokens(field.name()?.syntax);
|
|
414
|
+
const type = renderTokens(field.typeAnnotation()?.syntax);
|
|
415
|
+
cellEnd = Math.max(cellEnd, type.length > 0 ? typeColumn + type.length : name.length);
|
|
416
|
+
}
|
|
417
|
+
return {
|
|
418
|
+
typeColumn,
|
|
419
|
+
attributeColumn: cellEnd + 1
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
function hasInteriorComment(node) {
|
|
423
|
+
for (const token of node.tokens()) if (token.kind === "Comment") return true;
|
|
424
|
+
return false;
|
|
425
|
+
}
|
|
426
|
+
function renderTokens(node) {
|
|
427
|
+
if (!node) return "";
|
|
428
|
+
let out = "";
|
|
429
|
+
let prev;
|
|
430
|
+
let prevQualified = false;
|
|
431
|
+
const walk = (parent, qualified) => {
|
|
432
|
+
for (const child of parent.children()) {
|
|
433
|
+
if (child instanceof SyntaxNode) {
|
|
434
|
+
walk(child, qualified || child.kind === "QualifiedName");
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
if (child.kind === "Whitespace" || child.kind === "Newline" || child.kind === "Comment") continue;
|
|
438
|
+
if (spaceBetween(prev, child.kind, qualified && prevQualified)) out += " ";
|
|
439
|
+
out += child.text;
|
|
440
|
+
prev = child.kind;
|
|
441
|
+
prevQualified = qualified;
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
walk(node, false);
|
|
445
|
+
return out;
|
|
446
|
+
}
|
|
447
|
+
//#endregion
|
|
448
|
+
//#region src/format/options.ts
|
|
449
|
+
function resolveFormatOptions(options) {
|
|
450
|
+
const indent = options?.indent ?? 2;
|
|
451
|
+
if (indent !== "tab" && (typeof indent !== "number" || !Number.isInteger(indent) || indent < 1)) throw new TypeError(`Invalid format options: indent must be a positive integer or 'tab', got ${String(indent)}`);
|
|
452
|
+
const newline = options?.newline ?? "LF";
|
|
453
|
+
if (newline !== "LF" && newline !== "CRLF") throw new TypeError(`Invalid format options: newline must be 'LF' or 'CRLF', got ${String(newline)}`);
|
|
454
|
+
return {
|
|
455
|
+
indentUnit: indent === "tab" ? " " : " ".repeat(indent),
|
|
456
|
+
newline: newline === "CRLF" ? "\r\n" : "\n"
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
//#endregion
|
|
460
|
+
//#region src/format/format.ts
|
|
461
|
+
function format(source, options) {
|
|
462
|
+
const resolved = resolveFormatOptions(options);
|
|
463
|
+
const { document, diagnostics } = parse(source);
|
|
464
|
+
if (diagnostics.length > 0) throw new PslFormatError(diagnostics);
|
|
465
|
+
return emitDocument(document, resolved.indentUnit, resolved.newline);
|
|
466
|
+
}
|
|
467
|
+
//#endregion
|
|
468
|
+
export { PslFormatError, format };
|
|
469
|
+
|
|
470
|
+
//# sourceMappingURL=format.mjs.map
|