@cratis/screenplay-language 4.259.0 → 5.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/dist/bundles/compiler/Authoring/QuickFixes.js +6 -2
- package/dist/bundles/compiler/Authoring/QuickFixes.js.map +1 -1
- package/dist/bundles/compiler/Authoring/StructuredValueQuickFix.js +3 -0
- package/dist/bundles/compiler/Authoring/StructuredValueQuickFix.js.map +1 -0
- package/dist/bundles/compiler/Dependencies/SliceReferences.js +1 -1
- package/dist/bundles/compiler/Dependencies/SliceReferences.js.map +1 -1
- package/dist/bundles/compiler/Diagnostics/DiagnosticCodes.js +1 -1
- package/dist/bundles/compiler/Diagnostics/DiagnosticCodes.js.map +1 -1
- package/dist/bundles/compiler/Files/PlayFolderMerge.js +1 -1
- package/dist/bundles/compiler/Files/PlayFolderMerge.js.map +1 -1
- package/dist/bundles/compiler/Parsing/CaptureParser.js +1 -1
- package/dist/bundles/compiler/Parsing/CaptureParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/CompositionParser.js +1 -1
- package/dist/bundles/compiler/Parsing/CompositionParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/ExpressionParser.js +1 -1
- package/dist/bundles/compiler/Parsing/ExpressionParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/OperationParser.js +1 -1
- package/dist/bundles/compiler/Parsing/OperationParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/ProducesParser.js +1 -1
- package/dist/bundles/compiler/Parsing/ProducesParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/ProjectionParser.js +1 -1
- package/dist/bundles/compiler/Parsing/ProjectionParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/ReactionParser.js +1 -1
- package/dist/bundles/compiler/Parsing/ReactionParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/ScreenParser.js +1 -1
- package/dist/bundles/compiler/Parsing/ScreenParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/ScreenplayParser.js +1 -1
- package/dist/bundles/compiler/Parsing/ScreenplayParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/SeedParser.js +1 -1
- package/dist/bundles/compiler/Parsing/SeedParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationCaseParser.js +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationCaseParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationExampleParser.js +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationExampleParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationParser.js +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationResponseParser.js +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationResponseParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/StateMachineParser.js +2 -0
- package/dist/bundles/compiler/Parsing/StateMachineParser.js.map +1 -0
- package/dist/bundles/compiler/Parsing/StructuredBlockParser.js +2 -0
- package/dist/bundles/compiler/Parsing/StructuredBlockParser.js.map +1 -0
- package/dist/bundles/compiler/Parsing/UiBindingParser.js +1 -1
- package/dist/bundles/compiler/Parsing/UiBindingParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/WorkflowParser.js +2 -0
- package/dist/bundles/compiler/Parsing/WorkflowParser.js.map +1 -0
- package/dist/bundles/compiler/Syntax/ScreenplaySyntaxWalker.js +1 -1
- package/dist/bundles/compiler/Syntax/ScreenplaySyntaxWalker.js.map +1 -1
- package/dist/bundles/compiler/Syntax/Structure.js.map +1 -1
- package/dist/bundles/compiler/Syntax/SyntaxCollections.js +1 -1
- package/dist/bundles/compiler/Syntax/SyntaxCollections.js.map +1 -1
- package/dist/bundles/completion-items.js +22 -16
- package/dist/bundles/completion-items.js.map +1 -1
- package/dist/bundles/completion-planner.js +2 -2
- package/dist/bundles/completion-planner.js.map +1 -1
- package/dist/bundles/example-analysis.js +1 -1
- package/dist/bundles/example-analysis.js.map +1 -1
- package/dist/bundles/keyword-docs.js +1 -1
- package/dist/bundles/keyword-docs.js.map +1 -1
- package/dist/bundles/language.js +1 -1
- package/dist/bundles/language.js.map +1 -1
- package/dist/bundles/tokens.js +1 -1
- package/dist/bundles/tokens.js.map +1 -1
- package/dist/completion-items.d.ts +3 -0
- package/dist/completion-items.d.ts.map +1 -1
- package/dist/completion-planner.d.ts.map +1 -1
- package/dist/keyword-docs.d.ts.map +1 -1
- package/dist/language.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CompositionParser.js","names":["component","stringBodyPattern","exposureHeader","pattern","instanceHeader","exposedProperty","setPattern","itemsPattern","itemPattern","itemValuePattern","operations","match","group","unescapeString","text","entry","header","context","DiagnosticCodes","locationOf","properties","line","property","contributions","contribution","granted","unknown","operation","set","parseMappingSource","items","parsed","child","item","values","value"],"sources":["../../../../../../Compiler/Parsing/CompositionParser.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { ContributedItemSyntax, ContributedItemValueSyntax, ExposedPropertySyntax, ExposureSyntax, InstanceContributionSyntax, InstanceContributionsSyntax } from '../Syntax/CompositionSyntax';\nimport { stringBodyPattern, unescapeString } from '../Text/StringLiteral';\nimport { pattern } from '../Text/patterns';\nimport { parseMappingSource } from './ExpressionParser';\nimport { ParserContext } from './ParserContext';\nimport { locationOf, SourceLine } from './SourceLine';\n\nconst component = `(?:([A-Za-z_]\\\\w*)|\"(${stringBodyPattern})\")\\\\.(\\\\w+(?:\\\\.\\\\w+)*)`;\nconst exposureHeader = pattern('^exposure\\\\s+for\\\\s+([A-Za-z_]\\\\w*)$');\nconst instanceHeader = pattern('^instance\\\\s+([A-Za-z_]\\\\w*)$');\nconst exposedProperty = pattern(`^property\\\\s+${component}(?:\\\\s+label\\\\s+\"(${stringBodyPattern})\")?(?:\\\\s+operations\\\\s+([\\\\w-]+(?:\\\\s*,\\\\s*[\\\\w-]+)*))?(?:\\\\s+fields\\\\s+(\\\\w+(?:\\\\s*,\\\\s*\\\\w+)*))?(?:\\\\s+reexposes\\\\s+([A-Za-z_]\\\\w*))?$`);\nconst setPattern = pattern(`^set\\\\s+${component}\\\\s*=\\\\s*(.+)$`);\nconst itemsPattern = pattern(`^items\\\\s+${component}$`);\nconst itemPattern = pattern(`^item\\\\s+(?:([A-Za-z_][\\\\w-]*)|\"(${stringBodyPattern})\")$`);\nconst itemValuePattern = pattern('^([A-Za-z_]\\\\w*)\\\\s*=\\\\s*(.+)$');\nconst operations = ['add', 'remove', 'reorder', 'edit-fields'];\nconst exposedPropertyShape = '\\'property <component>.<path> [label \"<text>\"] [operations <add|remove|reorder|edit-fields>, ...] [fields <field>, ...] [reexposes <Owner>]\\'';\n\nconst reference = (match: RegExpExecArray, group: number): string => match[group] ?? unescapeString(match[group + 1]);\nconst list = (text: string): string[] => text.trim() === 'none' ? [] : text.split(',').map(entry => entry.trim()).filter(entry => entry.length > 0);\n\n// 'exposure for <Owner>' - the port of the C# CompositionParser.ParseExposure.\nexport function parseExposure(context: ParserContext, header: SourceLine): ExposureSyntax {\n const match = exposureHeader.exec(header.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidExposureDeclaration, `Invalid exposure declaration '${header.content}' - expected 'exposure for <Owner>'`, locationOf(header));\n }\n const properties: ExposedPropertySyntax[] = [];\n for (let line = context.peekChild(header.indent); line !== undefined; line = context.peekChild(header.indent)) {\n context.reader.takeSignificant();\n const property = parseExposedProperty(context, line);\n if (property !== undefined) properties.push(property);\n }\n return { kind: 'ExposureSyntax', owner: match?.[1] ?? header.content, properties, location: locationOf(header) };\n}\n\n// 'instance <Instance>' - the port of the C# CompositionParser.ParseInstance.\nexport function parseInstance(context: ParserContext, header: SourceLine): InstanceContributionsSyntax {\n const match = instanceHeader.exec(header.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidInstanceContribution, `Invalid instance declaration '${header.content}' - expected 'instance <Screen or Template>'`, locationOf(header));\n }\n const contributions: InstanceContributionSyntax[] = [];\n for (let line = context.peekChild(header.indent); line !== undefined; line = context.peekChild(header.indent)) {\n context.reader.takeSignificant();\n const contribution = parseContribution(context, line);\n if (contribution !== undefined) contributions.push(contribution);\n }\n return { kind: 'InstanceContributionsSyntax', instance: match?.[1] ?? header.content, contributions, location: locationOf(header) };\n}\n\nfunction parseExposedProperty(context: ParserContext, line: SourceLine): ExposedPropertySyntax | undefined {\n const match = exposedProperty.exec(line.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidExposureDeclaration, `Invalid exposed property '${line.content}' - expected ${exposedPropertyShape}`, locationOf(line));\n return undefined;\n }\n const granted = match[5] === undefined ? [] : list(match[5]);\n const unknown = granted.find(operation => !operations.includes(operation));\n if (unknown !== undefined) {\n context.error(DiagnosticCodes.InvalidExposureDeclaration, `Unknown collection operation '${unknown}' - expected add, remove, reorder, edit-fields or none`, locationOf(line));\n return undefined;\n }\n return {\n kind: 'ExposedPropertySyntax',\n component: reference(match, 1),\n path: match[3],\n label: match[4] === undefined ? null : unescapeString(match[4]),\n isCollection: match[5] !== undefined,\n operations: granted,\n restrictsFields: match[6] !== undefined,\n editableFields: match[6] === undefined ? [] : list(match[6]),\n reExposes: match[7] ?? null,\n location: locationOf(line)\n };\n}\n\nfunction parseContribution(context: ParserContext, line: SourceLine): InstanceContributionSyntax | undefined {\n const set = setPattern.exec(line.content);\n if (set !== null) {\n context.skipBlock(line.indent);\n return { kind: 'InstanceContributionSyntax', component: reference(set, 1), path: set[3], value: parseMappingSource(set[4], locationOf(line), context), items: [], location: locationOf(line) };\n }\n const items = itemsPattern.exec(line.content);\n if (items !== null) {\n const parsed: ContributedItemSyntax[] = [];\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n const item = parseItem(context, child);\n if (item !== undefined) parsed.push(item);\n }\n return { kind: 'InstanceContributionSyntax', component: reference(items, 1), path: items[3], value: null, items: parsed, location: locationOf(line) };\n }\n context.error(DiagnosticCodes.InvalidInstanceContribution, `Invalid instance contribution '${line.content}' - expected 'set <component>.<path> = <value>' or 'items <component>.<path>'`, locationOf(line));\n context.skipBlock(line.indent);\n return undefined;\n}\n\nfunction parseItem(context: ParserContext, line: SourceLine): ContributedItemSyntax | undefined {\n const match = itemPattern.exec(line.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidInstanceContribution, `Invalid contributed item '${line.content}' - expected 'item <id>'`, locationOf(line));\n context.skipBlock(line.indent);\n return undefined;\n }\n const values: ContributedItemValueSyntax[] = [];\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n const value = itemValuePattern.exec(child.content);\n if (value === null) {\n context.error(DiagnosticCodes.InvalidInstanceContribution, `Invalid item value '${child.content}' - expected '<field> = <value>'`, locationOf(child));\n context.skipBlock(child.indent);\n continue;\n }\n values.push({ kind: 'ContributedItemValueSyntax', field: value[1], value: parseMappingSource(value[2], locationOf(child), context), location: locationOf(child) });\n }\n return { kind: 'ContributedItemSyntax', id: reference(match, 1), values, location: locationOf(line) };\n}\n"],"mappings":"gWAWA,MAAMA,EAAY,wBAAwBC,EAAkB,0BACtDC,EAAiBC,EAAQ,sCAAsC,EAC/DC,EAAiBD,EAAQ,+BAA+B,EACxDE,EAAkBF,EAAQ,gBAAgBH,EAAU,oBAAoBC,EAAkB,2IAA2I,EACrOK,EAAaH,EAAQ,WAAWH,EAAU,eAAe,EACzDO,EAAeJ,EAAQ,aAAaH,EAAU,EAAE,EAChDQ,EAAcL,EAAQ,oCAAoCF,EAAkB,KAAK,EACjFQ,EAAmBN,EAAQ,gCAAgC,EAC3DO,EAAa,CAAC,MAAO,SAAU,UAAW,aAAa,EAGvD,WAAa,EAAwB,IAA0BC,EAAMC,IAAUC,EAAeF,EAAMC,EAAQ,EAAE,EAC9G,KAAQ,GAA2BE,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,EAAmBM,EAAM,GAAIhB,EAAWa,CAAK,EAAGf,CAAO,EAAG,SAAUE,EAAWa,CAAK,CAAE,CAAC,CACrK,CACA,MAAO,CAAE,KAAM,wBAAyB,GAAI,UAAUrB,EAAO,CAAC,EAAG,SAAQ,SAAUQ,EAAWE,CAAI,CAAE,CACxG"}
|
|
1
|
+
{"version":3,"file":"CompositionParser.js","names":["component","stringBodyPattern","exposureHeader","pattern","instanceHeader","exposedProperty","setPattern","setBlockPattern","itemsPattern","itemPattern","itemValuePattern","operations","match","group","unescapeString","text","entry","header","context","DiagnosticCodes","locationOf","properties","line","property","contributions","contribution","granted","unknown","operation","set","parseMappingSource","setBlock","parseStructuredValue","items","parsed","child","item","values","value","structured","tryParseStructuredMapping"],"sources":["../../../../../../Compiler/Parsing/CompositionParser.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { ContributedItemSyntax, ContributedItemValueSyntax, ExposedPropertySyntax, ExposureSyntax, InstanceContributionSyntax, InstanceContributionsSyntax } from '../Syntax/CompositionSyntax';\nimport { stringBodyPattern, unescapeString } from '../Text/StringLiteral';\nimport { pattern } from '../Text/patterns';\nimport { parseMappingSource } from './ExpressionParser';\nimport { ParserContext } from './ParserContext';\nimport { locationOf, SourceLine } from './SourceLine';\nimport { parseStructuredValue, StructuredMarker, tryParseStructuredMapping } from './StructuredBlockParser';\n\nconst component = `(?:([A-Za-z_]\\\\w*)|\"(${stringBodyPattern})\")\\\\.(\\\\w+(?:\\\\.\\\\w+)*)`;\nconst exposureHeader = pattern('^exposure\\\\s+for\\\\s+([A-Za-z_]\\\\w*)$');\nconst instanceHeader = pattern('^instance\\\\s+([A-Za-z_]\\\\w*)$');\nconst exposedProperty = pattern(`^property\\\\s+${component}(?:\\\\s+label\\\\s+\"(${stringBodyPattern})\")?(?:\\\\s+operations\\\\s+([\\\\w-]+(?:\\\\s*,\\\\s*[\\\\w-]+)*))?(?:\\\\s+fields\\\\s+(\\\\w+(?:\\\\s*,\\\\s*\\\\w+)*))?(?:\\\\s+reexposes\\\\s+([A-Za-z_]\\\\w*))?$`);\nconst setPattern = pattern(`^set\\\\s+${component}\\\\s*=\\\\s*(.+)$`);\nconst setBlockPattern = pattern(`^set\\\\s+${component}(?:\\\\s+(none|empty))?$`);\nconst itemsPattern = pattern(`^items\\\\s+${component}$`);\nconst itemPattern = pattern(`^item\\\\s+(?:([A-Za-z_][\\\\w-]*)|\"(${stringBodyPattern})\")$`);\nconst itemValuePattern = pattern('^([A-Za-z_]\\\\w*)\\\\s*=\\\\s*(.+)$');\nconst operations = ['add', 'remove', 'reorder', 'edit-fields'];\nconst exposedPropertyShape = '\\'property <component>.<path> [label \"<text>\"] [operations <add|remove|reorder|edit-fields>, ...] [fields <field>, ...] [reexposes <Owner>]\\'';\n\nconst reference = (match: RegExpExecArray, group: number): string => match[group] ?? unescapeString(match[group + 1]);\nconst list = (text: string): string[] => text.trim() === 'none' ? [] : text.split(',').map(entry => entry.trim()).filter(entry => entry.length > 0);\n\n// 'exposure for <Owner>' - the port of the C# CompositionParser.ParseExposure.\nexport function parseExposure(context: ParserContext, header: SourceLine): ExposureSyntax {\n const match = exposureHeader.exec(header.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidExposureDeclaration, `Invalid exposure declaration '${header.content}' - expected 'exposure for <Owner>'`, locationOf(header));\n }\n const properties: ExposedPropertySyntax[] = [];\n for (let line = context.peekChild(header.indent); line !== undefined; line = context.peekChild(header.indent)) {\n context.reader.takeSignificant();\n const property = parseExposedProperty(context, line);\n if (property !== undefined) properties.push(property);\n }\n return { kind: 'ExposureSyntax', owner: match?.[1] ?? header.content, properties, location: locationOf(header) };\n}\n\n// 'instance <Instance>' - the port of the C# CompositionParser.ParseInstance.\nexport function parseInstance(context: ParserContext, header: SourceLine): InstanceContributionsSyntax {\n const match = instanceHeader.exec(header.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidInstanceContribution, `Invalid instance declaration '${header.content}' - expected 'instance <Screen or Template>'`, locationOf(header));\n }\n const contributions: InstanceContributionSyntax[] = [];\n for (let line = context.peekChild(header.indent); line !== undefined; line = context.peekChild(header.indent)) {\n context.reader.takeSignificant();\n const contribution = parseContribution(context, line);\n if (contribution !== undefined) contributions.push(contribution);\n }\n return { kind: 'InstanceContributionsSyntax', instance: match?.[1] ?? header.content, contributions, location: locationOf(header) };\n}\n\nfunction parseExposedProperty(context: ParserContext, line: SourceLine): ExposedPropertySyntax | undefined {\n const match = exposedProperty.exec(line.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidExposureDeclaration, `Invalid exposed property '${line.content}' - expected ${exposedPropertyShape}`, locationOf(line));\n return undefined;\n }\n const granted = match[5] === undefined ? [] : list(match[5]);\n const unknown = granted.find(operation => !operations.includes(operation));\n if (unknown !== undefined) {\n context.error(DiagnosticCodes.InvalidExposureDeclaration, `Unknown collection operation '${unknown}' - expected add, remove, reorder, edit-fields or none`, locationOf(line));\n return undefined;\n }\n return {\n kind: 'ExposedPropertySyntax',\n component: reference(match, 1),\n path: match[3],\n label: match[4] === undefined ? null : unescapeString(match[4]),\n isCollection: match[5] !== undefined,\n operations: granted,\n restrictsFields: match[6] !== undefined,\n editableFields: match[6] === undefined ? [] : list(match[6]),\n reExposes: match[7] ?? null,\n location: locationOf(line)\n };\n}\n\nfunction parseContribution(context: ParserContext, line: SourceLine): InstanceContributionSyntax | undefined {\n const set = setPattern.exec(line.content);\n if (set !== null) {\n context.skipBlock(line.indent);\n return { kind: 'InstanceContributionSyntax', component: reference(set, 1), path: set[3], value: parseMappingSource(set[4], locationOf(line), context), items: [], location: locationOf(line) };\n }\n const setBlock = setBlockPattern.exec(line.content);\n if (setBlock !== null) {\n return { kind: 'InstanceContributionSyntax', component: reference(setBlock, 1), path: setBlock[3], value: parseStructuredValue(context, line, setBlock[4]?.trim() as StructuredMarker), items: [], location: locationOf(line) };\n }\n const items = itemsPattern.exec(line.content);\n if (items !== null) {\n const parsed: ContributedItemSyntax[] = [];\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n const item = parseItem(context, child);\n if (item !== undefined) parsed.push(item);\n }\n return { kind: 'InstanceContributionSyntax', component: reference(items, 1), path: items[3], value: null, items: parsed, location: locationOf(line) };\n }\n context.error(DiagnosticCodes.InvalidInstanceContribution, `Invalid instance contribution '${line.content}' - expected 'set <component>.<path> = <value>' or 'items <component>.<path>'`, locationOf(line));\n context.skipBlock(line.indent);\n return undefined;\n}\n\nfunction parseItem(context: ParserContext, line: SourceLine): ContributedItemSyntax | undefined {\n const match = itemPattern.exec(line.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidInstanceContribution, `Invalid contributed item '${line.content}' - expected 'item <id>'`, locationOf(line));\n context.skipBlock(line.indent);\n return undefined;\n }\n const values: ContributedItemValueSyntax[] = [];\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n const value = itemValuePattern.exec(child.content);\n const structured = value === null ? tryParseStructuredMapping(context, child) : undefined;\n if (structured !== undefined) {\n values.push({ kind: 'ContributedItemValueSyntax', field: structured.property, value: structured.source, location: locationOf(child) });\n continue;\n }\n if (value === null) {\n context.error(DiagnosticCodes.InvalidInstanceContribution, `Invalid item value '${child.content}' - expected '<field> = <value>'`, locationOf(child));\n context.skipBlock(child.indent);\n continue;\n }\n values.push({ kind: 'ContributedItemValueSyntax', field: value[1], value: parseMappingSource(value[2], locationOf(child), context), location: locationOf(child) });\n }\n return { kind: 'ContributedItemSyntax', id: reference(match, 1), values, location: locationOf(line) };\n}\n"],"mappings":"icAYA,MAAMA,EAAY,wBAAwBC,EAAkB,0BACtDC,EAAiBC,EAAQ,sCAAsC,EAC/DC,EAAiBD,EAAQ,+BAA+B,EACxDE,EAAkBF,EAAQ,gBAAgBH,EAAU,oBAAoBC,EAAkB,2IAA2I,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,EAAK,OAAO,EAC3C,GAAIV,IAAU,KAAM,CAChBM,EAAQ,MAAMC,EAAgB,4BAA6B,6BAA6BG,EAAK,QAAQ,0BAA2BF,EAAWE,CAAI,CAAC,EAChJJ,EAAQ,UAAUI,EAAK,MAAM,EAC7B,MACJ,CACA,IAAMe,EAAuC,CAAC,EAC9C,IAAK,IAAIF,EAAQjB,EAAQ,UAAUI,EAAK,MAAM,EAAGa,IAAU,IAAA,GAAW,EAAQjB,EAAQ,UAAUI,EAAK,MAAM,EAAG,CAC1GJ,EAAQ,OAAO,gBAAgB,EAC/B,IAAMoB,EAAQ5B,EAAiB,KAAKyB,EAAM,OAAO,EAC3CI,EAAaD,IAAU,KAAOE,EAA0BtB,EAASiB,CAAK,EAAI,IAAA,GAC5EI,IAAe,IAAA,GAIfD,IAAU,MACVpB,EAAQ,MAAMC,EAAgB,4BAA6B,uBAAuBgB,EAAM,QAAQ,kCAAmCf,EAAWe,CAAK,CAAC,EACpJjB,EAAQ,UAAUiB,EAAM,MAAM,GAGlCE,EAAO,KAAK,CAAE,KAAM,6BAA8B,MAAOC,EAAM,GAAI,MAAOR,EAAmBQ,EAAM,GAAIlB,EAAWe,CAAK,EAAGjB,CAAO,EAAG,SAAUE,EAAWe,CAAK,CAAE,CAAC,EAR7JE,EAAO,KAAK,CAAE,KAAM,6BAA8B,MAAOE,EAAW,SAAU,MAAOA,EAAW,OAAQ,SAAUnB,EAAWe,CAAK,CAAE,CAAC,CAS7I,CACA,MAAO,CAAE,KAAM,wBAAyB,GAAI,UAAUvB,EAAO,CAAC,EAAG,SAAQ,SAAUQ,EAAWE,CAAI,CAAE,CACxG"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{unescapeString as t}from"../Text/StringLiteral.js";import{nativePattern as n,pattern as r}from"../Text/patterns.js";import{isExactNumberToken as i,parseExactNumber as a}from"../Syntax/ExactNumber.js";import{InvalidStructuredValue as o,StructuredValueParser as s}from"./StructuredValueParser.js";const c=r(`^@?[A-Za-z_]\\w*(\\.@?[A-Za-z_$]\\w*)*$`),l=n(`^@?[A-Za-z_]\\w*(\\.@?[A-Za-z_$]\\w*)*$`),u=r(`^-?\\d+(\\.\\d+)?$`),d=[`command`,`arguments`,`tenant`,`causedBy`,`causation`,`occurred`,`identity`],f=[`subject`,`name`,`userName`],p=[`id`,`name`,`userName`,`isAuthenticated`,`roles`,`claims`]
|
|
1
|
+
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{unescapeString as t}from"../Text/StringLiteral.js";import{nativePattern as n,pattern as r}from"../Text/patterns.js";import{isExactNumberToken as i,parseExactNumber as a}from"../Syntax/ExactNumber.js";import{InvalidStructuredValue as o,StructuredValueParser as s}from"./StructuredValueParser.js";const c=r(`^@?[A-Za-z_]\\w*(\\.@?[A-Za-z_$]\\w*)*$`),l=n(`^@?[A-Za-z_]\\w*(\\.@?[A-Za-z_$]\\w*)*$`),u=r(`^-?\\d+(\\.\\d+)?$`),d=[`command`,`arguments`,`tenant`,`causedBy`,`causation`,`occurred`,`identity`],f=[`subject`,`name`,`userName`],p=[`id`,`name`,`userName`,`isAuthenticated`,`roles`,`claims`],m=`Screenplay has no JSON values - write the object or list as an indented block: one 'member = value' line per member, one 'item' line per list element, and '<name> none' for an empty list`;function parseModeledMappingSource(e,t,n){return parseMappingSource(e,t,n,!0)}function parseMappingSource(t,n,r,i=!1){if(t=t.trim(),t===`$refusal`||t.startsWith(`$refusal.`))return{kind:`RefusalExpressionSyntax`,member:t===`$refusal`?``:t.substring(9),location:n};if(t===`$eventSourceId`)return{kind:`EventSourceIdExpressionSyntax`,location:n};if(t===`$eventContext.eventSourceId`)return{kind:`EventContextExpressionSyntax`,path:`eventSourceId`,location:n};if(t===`$identity`||t===`$identity.`)return r?.error(e.InvalidExpression,`Invalid expression '${t}'`,n),{kind:`RawExpressionSyntax`,text:t,location:n};if(t.startsWith(`$identity.`)){let e=t.substring(10);return r?.deferIdentityValidation!==!0&&warnOnUnknownIdentityProperty(e.split(`.`)[0],`$identity`,n,r),{kind:`IdentityExpressionSyntax`,path:e,location:n}}if(t.startsWith(`$context.`)){let e=t.substring(9);return warnOnUnknownContextPath(e,n,r),{kind:`ContextExpressionSyntax`,path:e,location:n}}if(t.startsWith(`$env.`))return{kind:`EnvironmentExpressionSyntax`,name:t.substring(5),location:n};if(t.startsWith(`$strings.`))return{kind:`StringsExpressionSyntax`,key:t.substring(9),location:n};if(t.startsWith(`$.`))return{kind:`SourceItemExpressionSyntax`,path:t.substring(2),location:n};if(t.startsWith(`{`)||t.startsWith(`[`)){r?.error(e.InlineJsonValue,m,n);try{return new s(t,n,r).parse()}catch(i){if(!(i instanceof o))throw i;return r?.error(e.InvalidStructuredValue,`Invalid inline structured value: ${i.message}`,n),{kind:`RawExpressionSyntax`,text:t,location:n}}}let a=r===void 0?parseLiteral(t,n):parseLiteral(t,n,r);return a===void 0?(i||r?.sourceOptions.numericMode===`exact`?l:c).test(t)?{kind:`PathExpressionSyntax`,path:t,location:n}:{kind:`RawExpressionSyntax`,text:t,location:n}:a}function warnOnUnknownContextPath(t,n,r){let[i,a]=t.split(`.`);d.includes(i)?a!==void 0&&i===`causedBy`&&!f.includes(a)?r?.warning(e.UnknownContextCausedByProperty,`Unknown $context.causedBy property '${a}' - expected ${f.join(`, `)}`,n):a!==void 0&&i===`identity`&&warnOnUnknownIdentityProperty(a,`$context.identity`,n,r):r?.warning(e.UnknownContextPath,`Unknown $context path '${t}' - expected one of ${d.join(`, `)}`,n)}function warnOnUnknownIdentityProperty(t,n,r,i){p.includes(t)||i?.warning(e.UnknownContextIdentityProperty,`Unknown ${n} property '${t}' - expected ${p.join(`, `)}`,r)}function parseLiteral(n,r,o){let literal=e=>({kind:`LiteralExpressionSyntax`,value:e,location:r});switch(n){case`true`:return literal(!0);case`false`:return literal(!1);case`null`:return literal(null)}if(n.length>=2&&(n.startsWith(`"`)&&n.endsWith(`"`)||n.startsWith(`'`)&&n.endsWith(`'`)))return literal(t(n.substring(1,n.length-1)));if(o?.sourceOptions.numericMode===`exact`){if(!i(n))return;let t=a(n);return t===void 0?(o.error(e.InexactNumericLiteral,`Numeric literal is not exactly representable in the bounded Decimal domain.`,r),{kind:`RawExpressionSyntax`,text:n,location:r}):literal(t)}if(u.test(n)&&!Number.isNaN(Number(n)))return literal(Number(n))}export{p as identityProperties,m as inlineJsonMessage,parseLiteral,parseMappingSource,parseModeledMappingSource};
|
|
2
2
|
//# sourceMappingURL=ExpressionParser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpressionParser.js","names":["pathPattern","pattern","nativePathPattern","nativePattern","numberPattern","contextRoots","causedByProperties","identityProperties","text","location","context","DiagnosticCodes","path","StructuredValueParser","error","InvalidStructuredValue","literal","nativeIdentifiers","root","member","unescapeString","isExactNumberToken","number","parseExactNumber"],"sources":["../../../../../../Compiler/Parsing/ExpressionParser.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { SourceLocation } from '../Diagnostics/SourceLocation';\nimport { ExpressionSyntax, LiteralExpressionSyntax } from '../Syntax/Expressions';\nimport { ExactNumber, isExactNumberToken, parseExactNumber } from '../Syntax/ExactNumber';\nimport { nativePattern, pattern } from '../Text/patterns';\nimport { unescapeString } from '../Text/StringLiteral';\nimport { ParserContext } from './ParserContext';\nimport { InvalidStructuredValue, StructuredValueParser } from './StructuredValueParser';\n\nconst pathPattern = pattern('^@?[A-Za-z_]\\\\w*(\\\\.@?[A-Za-z_$]\\\\w*)*$');\nconst nativePathPattern = nativePattern('^@?[A-Za-z_]\\\\w*(\\\\.@?[A-Za-z_$]\\\\w*)*$');\nconst numberPattern = pattern('^-?\\\\d+(\\\\.\\\\d+)?$');\nconst contextRoots = ['command', 'arguments', 'tenant', 'causedBy', 'causation', 'occurred', 'identity'];\nconst causedByProperties = ['subject', 'name', 'userName'];\nexport const identityProperties = ['id', 'name', 'userName', 'isAuthenticated', 'roles', 'claims'];\n\n// Reads the right-hand side of a mapping or a rule operand - the port of the C# ExpressionParser's\n// ParseMappingSource. With a context it also reports what the C# compiler reports while reading one: an\n// unknown $context path, and an inline structured value that is not valid JSON.\nexport function parseModeledMappingSource(text: string, location: SourceLocation, context: ParserContext): ExpressionSyntax {\n return parseMappingSource(text, location, context, true);\n}\n\nexport function parseMappingSource(text: string, location: SourceLocation, context?: ParserContext, nativeIdentifiers = false): ExpressionSyntax {\n text = text.trim();\n if (text === '$refusal' || text.startsWith('$refusal.')) {\n return { kind: 'RefusalExpressionSyntax', member: text === '$refusal' ? '' : text.substring('$refusal.'.length), location };\n }\n if (text === '$eventSourceId') {\n return { kind: 'EventSourceIdExpressionSyntax', location };\n }\n if (text === '$eventContext.eventSourceId') {\n return { kind: 'EventContextExpressionSyntax', path: 'eventSourceId', location };\n }\n if (text === '$identity' || text === '$identity.') {\n context?.error(DiagnosticCodes.InvalidExpression, `Invalid expression '${text}'`, location);\n return { kind: 'RawExpressionSyntax', text, location };\n }\n if (text.startsWith('$identity.')) {\n const path = text.substring('$identity.'.length);\n if (context?.deferIdentityValidation !== true) warnOnUnknownIdentityProperty(path.split('.')[0], '$identity', location, context);\n return { kind: 'IdentityExpressionSyntax', path, location };\n }\n if (text.startsWith('$context.')) {\n const path = text.substring('$context.'.length);\n warnOnUnknownContextPath(path, location, context);\n return { kind: 'ContextExpressionSyntax', path, location };\n }\n if (text.startsWith('$env.')) {\n return { kind: 'EnvironmentExpressionSyntax', name: text.substring('$env.'.length), location };\n }\n if (text.startsWith('$strings.')) {\n return { kind: 'StringsExpressionSyntax', key: text.substring('$strings.'.length), location };\n }\n if (text.startsWith('$.')) {\n return { kind: 'SourceItemExpressionSyntax', path: text.substring('$.'.length), location };\n }\n if (text.startsWith('{') || text.startsWith('[')) {\n try {\n return new StructuredValueParser(text, location, context).parse();\n } catch (error) {\n if (!(error instanceof InvalidStructuredValue)) {\n throw error;\n }\n context?.error(DiagnosticCodes.InvalidStructuredValue, `Invalid inline structured value: ${error.message}`, location);\n return { kind: 'RawExpressionSyntax', text, location };\n }\n }\n const literal = context === undefined ? parseLiteral(text, location) : parseLiteral(text, location, context);\n if (literal !== undefined) {\n return literal;\n }\n if ((nativeIdentifiers || context?.sourceOptions.numericMode === 'exact' ? nativePathPattern : pathPattern).test(text)) {\n return { kind: 'PathExpressionSyntax', path: text, location };\n }\n return { kind: 'RawExpressionSyntax', text, location };\n}\n\nfunction warnOnUnknownContextPath(path: string, location: SourceLocation, context: ParserContext | undefined): void {\n const [root, member] = path.split('.');\n if (!contextRoots.includes(root)) {\n context?.warning(DiagnosticCodes.UnknownContextPath, `Unknown $context path '${path}' - expected one of ${contextRoots.join(', ')}`, location);\n } else if (member !== undefined && root === 'causedBy' && !causedByProperties.includes(member)) {\n context?.warning(DiagnosticCodes.UnknownContextCausedByProperty,\n `Unknown $context.causedBy property '${member}' - expected ${causedByProperties.join(', ')}`, location);\n } else if (member !== undefined && root === 'identity') {\n warnOnUnknownIdentityProperty(member, '$context.identity', location, context);\n }\n}\n\nfunction warnOnUnknownIdentityProperty(member: string, root: string, location: SourceLocation, context: ParserContext | undefined): void {\n if (!identityProperties.includes(member)) {\n context?.warning(DiagnosticCodes.UnknownContextIdentityProperty,\n `Unknown ${root} property '${member}' - expected ${identityProperties.join(', ')}`, location);\n }\n}\n\nexport function parseLiteral(text: string, location: SourceLocation): LiteralExpressionSyntax | undefined;\nexport function parseLiteral(text: string, location: SourceLocation, context: ParserContext): ExpressionSyntax | undefined;\nexport function parseLiteral(text: string, location: SourceLocation, context?: ParserContext): ExpressionSyntax | undefined {\n const literal = (value: string | number | boolean | null | ExactNumber): LiteralExpressionSyntax => ({ kind: 'LiteralExpressionSyntax', value, location });\n switch (text) {\n case 'true':\n return literal(true);\n case 'false':\n return literal(false);\n case 'null':\n return literal(null);\n }\n const quoted = text.length >= 2 && ((text.startsWith('\"') && text.endsWith('\"')) || (text.startsWith('\\'') && text.endsWith('\\'')));\n if (quoted) {\n return literal(unescapeString(text.substring(1, text.length - 1)));\n }\n if (context?.sourceOptions.numericMode === 'exact') {\n if (!isExactNumberToken(text)) return undefined;\n const number = parseExactNumber(text);\n if (number !== undefined) return literal(number);\n context.error(DiagnosticCodes.InexactNumericLiteral, 'Numeric literal is not exactly representable in the bounded Decimal domain.', location);\n return { kind: 'RawExpressionSyntax', text, location };\n }\n // .NET also parses digits from other scripts; JavaScript's Number does not, so such a number is left to\n // be read as raw text - a divergence no real document is expected to meet.\n if (numberPattern.test(text) && !Number.isNaN(Number(text))) {\n return literal(Number(text));\n }\n return undefined;\n}\n"],"mappings":"uaAYA,MAAMA,EAAcC,EAAQ,yCAAyC,EAC/DC,EAAoBC,EAAc,yCAAyC,EAC3EC,EAAgBH,EAAQ,oBAAoB,EAC5CI,EAAe,CAAC,UAAW,YAAa,SAAU,WAAY,YAAa,WAAY,UAAU,EACjGC,EAAqB,CAAC,UAAW,OAAQ,UAAU,EAC5CC,EAAqB,CAAC,KAAM,OAAQ,WAAY,kBAAmB,QAAS,QAAQ,EAKjG,SAAgB,0BAA0B,EAAc,EAA0B,EAA0C,CACxH,OAAO,mBAAmBC,EAAMC,EAAUC,EAAS,EAAI,CAC3D,CAEA,SAAgB,mBAAmB,EAAc,EAA0B,EAAyB,EAAoB,GAAyB,CAE7I,GADA,EAAOF,EAAK,KAAK,EACbA,IAAS,YAAcA,EAAK,WAAW,WAAW,EAClD,MAAO,CAAE,KAAM,0BAA2B,OAAQA,IAAS,WAAa,GAAKA,EAAK,UAAU,CAAkB,EAAG,UAAS,EAE9H,GAAIA,IAAS,iBACT,MAAO,CAAE,KAAM,gCAAiC,UAAS,EAE7D,GAAIA,IAAS,8BACT,MAAO,CAAE,KAAM,+BAAgC,KAAM,gBAAiB,UAAS,EAEnF,G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QY,EAAeZ,EAAK,UAAU,EAAGA,EAAK,OAAS,CAAC,CAAC,CAAC,EAErE,GAAIE,GAAS,cAAc,cAAgB,QAAS,CAChD,GAAI,CAACW,EAAmBb,CAAI,EAAG,OAC/B,IAAMc,EAASC,EAAiBf,CAAI,EAGpC,OAFIc,IAAW,IAAA,IACfZ,EAAQ,MAAMC,EAAgB,sBAAuB,8EAA+EF,CAAQ,EACrI,CAAE,KAAM,sBAAuB,OAAM,UAAS,GAFpB,QAAQa,CAAM,CAGnD,CAGA,GAAIlB,EAAc,KAAKI,CAAI,GAAK,CAAC,OAAO,MAAM,OAAOA,CAAI,CAAC,EACtD,OAAO,QAAQ,OAAOA,CAAI,CAAC,CAGnC"}
|
|
1
|
+
{"version":3,"file":"ExpressionParser.js","names":["pathPattern","pattern","nativePathPattern","nativePattern","numberPattern","contextRoots","causedByProperties","identityProperties","inlineJsonMessage","text","location","context","DiagnosticCodes","path","StructuredValueParser","error","InvalidStructuredValue","literal","nativeIdentifiers","root","member","unescapeString","isExactNumberToken","number","parseExactNumber"],"sources":["../../../../../../Compiler/Parsing/ExpressionParser.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { SourceLocation } from '../Diagnostics/SourceLocation';\nimport { ExpressionSyntax, LiteralExpressionSyntax } from '../Syntax/Expressions';\nimport { ExactNumber, isExactNumberToken, parseExactNumber } from '../Syntax/ExactNumber';\nimport { nativePattern, pattern } from '../Text/patterns';\nimport { unescapeString } from '../Text/StringLiteral';\nimport { ParserContext } from './ParserContext';\nimport { InvalidStructuredValue, StructuredValueParser } from './StructuredValueParser';\n\nconst pathPattern = pattern('^@?[A-Za-z_]\\\\w*(\\\\.@?[A-Za-z_$]\\\\w*)*$');\nconst nativePathPattern = nativePattern('^@?[A-Za-z_]\\\\w*(\\\\.@?[A-Za-z_$]\\\\w*)*$');\nconst numberPattern = pattern('^-?\\\\d+(\\\\.\\\\d+)?$');\nconst contextRoots = ['command', 'arguments', 'tenant', 'causedBy', 'causation', 'occurred', 'identity'];\nconst causedByProperties = ['subject', 'name', 'userName'];\nexport const identityProperties = ['id', 'name', 'userName', 'isAuthenticated', 'roles', 'claims'];\n\n// Reads the right-hand side of a mapping or a rule operand - the port of the C# ExpressionParser's\n// ParseMappingSource. With a context it also reports what the C# compiler reports while reading one: an\n// unknown $context path, and an inline structured value that is not valid JSON.\nexport const inlineJsonMessage = \"Screenplay has no JSON values - write the object or list as an indented block: one 'member = value' line per member, one 'item' line per list element, and '<name> none' for an empty list\";\n\nexport function parseModeledMappingSource(text: string, location: SourceLocation, context: ParserContext): ExpressionSyntax {\n return parseMappingSource(text, location, context, true);\n}\n\nexport function parseMappingSource(text: string, location: SourceLocation, context?: ParserContext, nativeIdentifiers = false): ExpressionSyntax {\n text = text.trim();\n if (text === '$refusal' || text.startsWith('$refusal.')) {\n return { kind: 'RefusalExpressionSyntax', member: text === '$refusal' ? '' : text.substring('$refusal.'.length), location };\n }\n if (text === '$eventSourceId') {\n return { kind: 'EventSourceIdExpressionSyntax', location };\n }\n if (text === '$eventContext.eventSourceId') {\n return { kind: 'EventContextExpressionSyntax', path: 'eventSourceId', location };\n }\n if (text === '$identity' || text === '$identity.') {\n context?.error(DiagnosticCodes.InvalidExpression, `Invalid expression '${text}'`, location);\n return { kind: 'RawExpressionSyntax', text, location };\n }\n if (text.startsWith('$identity.')) {\n const path = text.substring('$identity.'.length);\n if (context?.deferIdentityValidation !== true) warnOnUnknownIdentityProperty(path.split('.')[0], '$identity', location, context);\n return { kind: 'IdentityExpressionSyntax', path, location };\n }\n if (text.startsWith('$context.')) {\n const path = text.substring('$context.'.length);\n warnOnUnknownContextPath(path, location, context);\n return { kind: 'ContextExpressionSyntax', path, location };\n }\n if (text.startsWith('$env.')) {\n return { kind: 'EnvironmentExpressionSyntax', name: text.substring('$env.'.length), location };\n }\n if (text.startsWith('$strings.')) {\n return { kind: 'StringsExpressionSyntax', key: text.substring('$strings.'.length), location };\n }\n if (text.startsWith('$.')) {\n return { kind: 'SourceItemExpressionSyntax', path: text.substring('$.'.length), location };\n }\n if (text.startsWith('{') || text.startsWith('[')) {\n // Screenplay has no JSON. The value is still read so the tree stays whole and printing it writes the block form.\n context?.error(DiagnosticCodes.InlineJsonValue, inlineJsonMessage, location);\n try {\n return new StructuredValueParser(text, location, context).parse();\n } catch (error) {\n if (!(error instanceof InvalidStructuredValue)) {\n throw error;\n }\n context?.error(DiagnosticCodes.InvalidStructuredValue, `Invalid inline structured value: ${error.message}`, location);\n return { kind: 'RawExpressionSyntax', text, location };\n }\n }\n const literal = context === undefined ? parseLiteral(text, location) : parseLiteral(text, location, context);\n if (literal !== undefined) {\n return literal;\n }\n if ((nativeIdentifiers || context?.sourceOptions.numericMode === 'exact' ? nativePathPattern : pathPattern).test(text)) {\n return { kind: 'PathExpressionSyntax', path: text, location };\n }\n return { kind: 'RawExpressionSyntax', text, location };\n}\n\nfunction warnOnUnknownContextPath(path: string, location: SourceLocation, context: ParserContext | undefined): void {\n const [root, member] = path.split('.');\n if (!contextRoots.includes(root)) {\n context?.warning(DiagnosticCodes.UnknownContextPath, `Unknown $context path '${path}' - expected one of ${contextRoots.join(', ')}`, location);\n } else if (member !== undefined && root === 'causedBy' && !causedByProperties.includes(member)) {\n context?.warning(DiagnosticCodes.UnknownContextCausedByProperty,\n `Unknown $context.causedBy property '${member}' - expected ${causedByProperties.join(', ')}`, location);\n } else if (member !== undefined && root === 'identity') {\n warnOnUnknownIdentityProperty(member, '$context.identity', location, context);\n }\n}\n\nfunction warnOnUnknownIdentityProperty(member: string, root: string, location: SourceLocation, context: ParserContext | undefined): void {\n if (!identityProperties.includes(member)) {\n context?.warning(DiagnosticCodes.UnknownContextIdentityProperty,\n `Unknown ${root} property '${member}' - expected ${identityProperties.join(', ')}`, location);\n }\n}\n\nexport function parseLiteral(text: string, location: SourceLocation): LiteralExpressionSyntax | undefined;\nexport function parseLiteral(text: string, location: SourceLocation, context: ParserContext): ExpressionSyntax | undefined;\nexport function parseLiteral(text: string, location: SourceLocation, context?: ParserContext): ExpressionSyntax | undefined {\n const literal = (value: string | number | boolean | null | ExactNumber): LiteralExpressionSyntax => ({ kind: 'LiteralExpressionSyntax', value, location });\n switch (text) {\n case 'true':\n return literal(true);\n case 'false':\n return literal(false);\n case 'null':\n return literal(null);\n }\n const quoted = text.length >= 2 && ((text.startsWith('\"') && text.endsWith('\"')) || (text.startsWith('\\'') && text.endsWith('\\'')));\n if (quoted) {\n return literal(unescapeString(text.substring(1, text.length - 1)));\n }\n if (context?.sourceOptions.numericMode === 'exact') {\n if (!isExactNumberToken(text)) return undefined;\n const number = parseExactNumber(text);\n if (number !== undefined) return literal(number);\n context.error(DiagnosticCodes.InexactNumericLiteral, 'Numeric literal is not exactly representable in the bounded Decimal domain.', location);\n return { kind: 'RawExpressionSyntax', text, location };\n }\n // .NET also parses digits from other scripts; JavaScript's Number does not, so such a number is left to\n // be read as raw text - a divergence no real document is expected to meet.\n if (numberPattern.test(text) && !Number.isNaN(Number(text))) {\n return literal(Number(text));\n }\n return undefined;\n}\n"],"mappings":"uaAYA,MAAMA,EAAcC,EAAQ,yCAAyC,EAC/DC,EAAoBC,EAAc,yCAAyC,EAC3EC,EAAgBH,EAAQ,oBAAoB,EAC5CI,EAAe,CAAC,UAAW,YAAa,SAAU,WAAY,YAAa,WAAY,UAAU,EACjGC,EAAqB,CAAC,UAAW,OAAQ,UAAU,EAC5CC,EAAqB,CAAC,KAAM,OAAQ,WAAY,kBAAmB,QAAS,QAAQ,EAKpFC,EAAoB,6LAEjC,SAAgB,0BAA0B,EAAc,EAA0B,EAA0C,CACxH,OAAO,mBAAmBC,EAAMC,EAAUC,EAAS,EAAI,CAC3D,CAEA,SAAgB,mBAAmB,EAAc,EAA0B,EAAyB,EAAoB,GAAyB,CAE7I,GADA,EAAOF,EAAK,KAAK,EACbA,IAAS,YAAcA,EAAK,WAAW,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BAA2B,QAAO,UAAS,GACxJ,OAAQD,EAAR,CACI,IAAK,OACD,OAAO,QAAQ,EAAI,EACvB,IAAK,QACD,OAAO,QAAQ,EAAK,EACxB,IAAK,OACD,OAAO,QAAQ,IAAI,CAC3B,CAEA,GADeA,EAAK,QAAU,IAAOA,EAAK,WAAW,GAAG,GAAKA,EAAK,SAAS,GAAG,GAAOA,EAAK,WAAW,GAAI,GAAKA,EAAK,SAAS,GAAI,GAE5H,OAAO,QAAQY,EAAeZ,EAAK,UAAU,EAAGA,EAAK,OAAS,CAAC,CAAC,CAAC,EAErE,GAAIE,GAAS,cAAc,cAAgB,QAAS,CAChD,GAAI,CAACW,EAAmBb,CAAI,EAAG,OAC/B,IAAMc,EAASC,EAAiBf,CAAI,EAGpC,OAFIc,IAAW,IAAA,IACfZ,EAAQ,MAAMC,EAAgB,sBAAuB,8EAA+EF,CAAQ,EACrI,CAAE,KAAM,sBAAuB,OAAM,UAAS,GAFpB,QAAQa,CAAM,CAGnD,CAGA,GAAInB,EAAc,KAAKK,CAAI,GAAK,CAAC,OAAO,MAAM,OAAOA,CAAI,CAAC,EACtD,OAAO,QAAQ,OAAOA,CAAI,CAAC,CAGnC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{pattern as t}from"../Text/patterns.js";import{locationOf as n}from"./SourceLine.js";import{parseMappingSource as r}from"./ExpressionParser.js";import{firstWord as i}from"./LineText.js";import{parseProperty as a,tryParseProperty as o}from"./PropertyLineParser.js";import{
|
|
1
|
+
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{pattern as t}from"../Text/patterns.js";import{locationOf as n}from"./SourceLine.js";import{parseMappingSource as r}from"./ExpressionParser.js";import{firstWord as i}from"./LineText.js";import{parseProperty as a,tryParseProperty as o}from"./PropertyLineParser.js";import{parseStructuredValue as s,trailingMarker as c}from"./StructuredBlockParser.js";import{parseDescription as l}from"./DescriptionParser.js";import{isFileDirective as u}from"./FileReferences.js";import{parseCode as d,parseFile as f,parseImplementationWrapper as p}from"./ImplementationParser.js";const m=t(`^system\\s+([A-Za-z_]\\w*)$`),h=t(`^operation\\s+([A-Za-z_]\\w*)$`),g=t(`^produces\\s+operation\\s+([A-Za-z_]\\w*)$`),_=t(`^uses\\s+([A-Za-z_]\\w*)$`),v=t(`^(.+?)\\s*=(?!=|>)\\s*(.+)$`),y=/* @__PURE__ */ new Set([`for`,`tag`,`generation`,`origin`,`documentation`,`namespace`,`sequence`,`correlation`,`causation`,`causedBy`,`occurred`]);function rejectOperationChildren(e,t,r,i){let a=e.peekChild(t.indent);a!==void 0&&(e.error(r,i,n(a)),e.skipBlock(t.indent))}function parseSystem(t,r){let a=m.exec(r.content);a===null&&t.error(e.InvalidSystemDeclaration,`Expected 'system <Name>'.`,n(r));let o=null;for(let s=t.peekChild(r.indent);s!==void 0;s=t.peekChild(r.indent))t.reader.takeSignificant(),i(s.content)===`description`?o=l(t,s,o,`System '${a?.[1]??``}'`):(t.error(e.InvalidSystemDeclaration,`A system accepts only a description; abilities are not supported.`,n(s)),t.skipBlock(s.indent));return{kind:`SystemSyntax`,name:a?.[1]??``,description:o,location:n(r)}}function parseOperation(t,u,d=!1){let f=(d?g:h).exec(u.content),p=f?.[1]??``;f===null&&t.error(e.InvalidOperationDeclaration,`Expected an operation declaration with one name.`,n(u));let m=null,b=null,x=n(u),S=null,C=null,w=[],T=[],E=/* @__PURE__ */ new Set;for(let f=t.peekChild(u.indent);f!==void 0;f=t.peekChild(u.indent)){t.reader.takeSignificant();let u=v.exec(f.content),h=d&&u===null?c(f.content):void 0,g=f;d&&u!==null?g={...f,content:u[1].trimEnd()}:h!==void 0&&(g={...f,content:f.content.substring(0,f.content.length-h.length-1)});let D=d&&u===null&&(h!==void 0||t.peekChild(f.indent)!==void 0);if(u===null&&y.has(i(f.content)))t.error(e.InvalidOperationDeclaration,`Operations cannot declare event routing or metadata; escape a keyword-named input with @.`,n(f)),t.skipBlock(f.indent);else if(!_.test(f.content)&&o(g)!==void 0){let i=a(t,g);d&&u===null&&!D&&t.error(e.InvalidOperationMapping,`An inline operation input requires '<property> <Type> = <source>'.`,n(f)),i.isSubject&&t.error(e.InvalidSubjectOwner,`The subject modifier is only valid on event properties, not operation inputs (decision 0008: one data subject per event).`,n(f)),(i.isIdentifier||i.isGenerated)&&t.error(e.InvalidOperationDeclaration,`Operation inputs cannot be identifier or generated properties.`,n(f)),E.has(i.name)&&t.error(e.DuplicateDeclaration,`Operation '${p}' already declares input '${i.name}'.`,n(f)),E.add(i.name),w.push(i),d&&u!==null&&T.push({kind:`PropertyMappingSyntax`,property:i.name,source:r(u[2],{...n(f),column:f.indent+f.content.length-u[2].length+1},t),location:n(f)}),D&&T.push({kind:`PropertyMappingSyntax`,property:i.name,source:s(t,f,h),location:n(f)}),rejectOperationChildren(t,f,e.InvalidOperationDeclaration,`An operation input cannot have children.`)}else if(i(f.content)===`description`)m=l(t,f,m,`Operation '${p}'`);else if(_.test(f.content))b===null?(b=_.exec(f.content)[1],x={...n(f),column:n(f).column+f.content.indexOf(b,4)}):t.error(e.InvalidSystemReference,`An operation declares exactly one 'uses <System>'.`,n(f)),rejectOperationChildren(t,f,e.InvalidSystemReference,`A system reference cannot have children.`);else if(f.content===`execute`||f.content===`compensate`){let r=parseOperationPhase(t,f);f.content===`execute`?S===null?S=r:t.error(e.InvalidOperationDeclaration,`An operation declares execute at most once.`,n(f)):C===null?C=r:t.error(e.InvalidOperationDeclaration,`An operation declares compensate at most once.`,n(f))}else t.error(e.InvalidOperationDeclaration,`Unexpected '${f.content}' in operation - expected uses, an input, description, execute or compensate.`,n(f)),t.skipBlock(f.indent)}return b===null&&t.error(e.InvalidSystemReference,`An operation requires exactly one 'uses <System>'.`,n(u)),{operation:{kind:`OperationSyntax`,name:p,uses:b??``,usesLocation:x,inputs:w,description:m,execute:S,compensate:C,location:n(u)},mappings:T}}function parseOperationPhase(t,r){let a=null,o=null,s=null,c=null,m=!1;for(let h=t.peekChild(r.indent);h!==void 0;h=t.peekChild(r.indent))if(t.reader.takeSignificant(),i(h.content)===`description`)a=l(t,h,a,`Operation phase '${r.content}'`);else if(i(h.content)===`implementation`){m&&t.error(e.ConflictingImplementationSources,`A phase cannot mix wrapped and direct sources or repeat its wrapper.`,n(h));let r=p(t,h);m||(o=r.file,s=r.code,c=r.implementation),m=!0}else if(u(h)||h.content.startsWith("```")){m&&t.error(e.ConflictingImplementationSources,`A phase has at most one file or inline payload.`,n(h));let r=u(h)?f(t,h):null,i=r===null?d(t,h):null;m||(o=r,s=i),m=!0,r!==null&&rejectOperationChildren(t,h,e.InvalidImplementationBlock,`A file directive cannot have children.`)}else t.error(e.InvalidOperationDeclaration,`A phase accepts description, file, a tagged fence or implementation.`,n(h)),t.skipBlock(h.indent);return{kind:`OperationPhaseSyntax`,description:a,file:o,code:s,implementation:c,location:n(r)}}export{parseOperation,parseSystem,rejectOperationChildren};
|
|
2
2
|
//# sourceMappingURL=OperationParser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OperationParser.js","names":["systemHeader","pattern","operationHeader","inlineHeader","usesPattern","typedMapping","eventMetadata","child","context","line","code","message","locationOf","match","header","DiagnosticCodes","description","firstWord","parseDescription","inline","name","uses","usesLocation","execute","compensate","inputs","mappings","names","typed","propertyLine","tryParseProperty","property","parseProperty","parseMappingSource","phase","file","implementation","sourceSelected","source","parseImplementationWrapper","isFileDirective","parsedFile","parseFile","parsedCode","parseCode"],"sources":["../../../../../../Compiler/Parsing/OperationParser.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { PropertySyntax } from '../Syntax/Declarations';\nimport { pattern } from '../Text/patterns';\nimport { PropertyMappingSyntax } from '../Syntax/Expressions';\nimport { OperationPhaseSyntax, OperationSyntax, SystemSyntax } from '../Syntax/Operations';\nimport { parseDescription } from './DescriptionParser';\nimport { parseMappingSource } from './ExpressionParser';\nimport { isFileDirective } from './FileReferences';\nimport { parseCode, parseFile, parseImplementationWrapper } from './ImplementationParser';\nimport { firstWord } from './LineText';\nimport { ParserContext } from './ParserContext';\nimport { parseProperty, tryParseProperty } from './PropertyLineParser';\nimport { locationOf, SourceLine } from './SourceLine';\n\nconst systemHeader = pattern('^system\\\\s+([A-Za-z_]\\\\w*)$');\nconst operationHeader = pattern('^operation\\\\s+([A-Za-z_]\\\\w*)$');\nconst inlineHeader = pattern('^produces\\\\s+operation\\\\s+([A-Za-z_]\\\\w*)$');\nconst usesPattern = pattern('^uses\\\\s+([A-Za-z_]\\\\w*)$');\nconst typedMapping = pattern('^(.+?)\\\\s*=(?!=|>)\\\\s*(.+)$');\nconst eventMetadata = new Set(['for', 'tag', 'generation', 'origin', 'documentation', 'namespace', 'sequence', 'correlation', 'causation', 'causedBy', 'occurred']);\n\nexport function rejectOperationChildren(context: ParserContext, line: SourceLine, code: string, message: string): void {\n const child = context.peekChild(line.indent);\n if (child === undefined) return;\n context.error(code, message, locationOf(child));\n context.skipBlock(line.indent);\n}\n\nexport function parseSystem(context: ParserContext, header: SourceLine): SystemSyntax {\n const match = systemHeader.exec(header.content);\n if (match === null) context.error(DiagnosticCodes.InvalidSystemDeclaration, \"Expected 'system <Name>'.\", locationOf(header));\n let description: string | null = null;\n for (let child = context.peekChild(header.indent); child !== undefined; child = context.peekChild(header.indent)) {\n context.reader.takeSignificant();\n if (firstWord(child.content) === 'description') description = parseDescription(context, child, description, `System '${match?.[1] ?? ''}'`);\n else {\n context.error(DiagnosticCodes.InvalidSystemDeclaration, 'A system accepts only a description; abilities are not supported.', locationOf(child));\n context.skipBlock(child.indent);\n }\n }\n return { kind: 'SystemSyntax', name: match?.[1] ?? '', description, location: locationOf(header) };\n}\n\nexport function parseOperation(context: ParserContext, header: SourceLine, inline = false): { operation: OperationSyntax; mappings: PropertyMappingSyntax[] } {\n const match = (inline ? inlineHeader : operationHeader).exec(header.content);\n const name = match?.[1] ?? '';\n if (match === null) context.error(DiagnosticCodes.InvalidOperationDeclaration, 'Expected an operation declaration with one name.', locationOf(header));\n let description: string | null = null;\n let uses: string | null = null;\n let usesLocation = locationOf(header);\n let execute: OperationPhaseSyntax | null = null;\n let compensate: OperationPhaseSyntax | null = null;\n const inputs: PropertySyntax[] = [];\n const mappings: PropertyMappingSyntax[] = [];\n const names = new Set<string>();\n for (let line = context.peekChild(header.indent); line !== undefined; line = context.peekChild(header.indent)) {\n context.reader.takeSignificant();\n const typed = typedMapping.exec(line.content);\n const propertyLine = inline && typed !== null ? { ...line, content: typed[1].trimEnd() } : line;\n if (typed === null && eventMetadata.has(firstWord(line.content))) {\n context.error(DiagnosticCodes.InvalidOperationDeclaration, 'Operations cannot declare event routing or metadata; escape a keyword-named input with @.', locationOf(line));\n context.skipBlock(line.indent);\n continue;\n }\n if (!usesPattern.test(line.content) && tryParseProperty(propertyLine) !== undefined) {\n const property = parseProperty(context, propertyLine)!;\n if (inline && typed === null) context.error(DiagnosticCodes.InvalidOperationMapping, \"An inline operation input requires '<property> <Type> = <source>'.\", locationOf(line));\n if (property.isSubject) context.error(DiagnosticCodes.InvalidSubjectOwner, 'The subject modifier is only valid on event properties, not operation inputs (decision 0008: one data subject per event).', locationOf(line));\n if (property.isIdentifier || property.isGenerated) context.error(DiagnosticCodes.InvalidOperationDeclaration, 'Operation inputs cannot be identifier or generated properties.', locationOf(line));\n if (names.has(property.name)) context.error(DiagnosticCodes.DuplicateDeclaration, `Operation '${name}' already declares input '${property.name}'.`, locationOf(line));\n names.add(property.name);\n inputs.push(property);\n if (inline && typed !== null) mappings.push({ kind: 'PropertyMappingSyntax', property: property.name, source: parseMappingSource(typed[2], { ...locationOf(line), column: line.indent + line.content.length - typed[2].length + 1 }, context), location: locationOf(line) });\n rejectOperationChildren(context, line, DiagnosticCodes.InvalidOperationDeclaration, 'An operation input cannot have children.');\n } else if (firstWord(line.content) === 'description') description = parseDescription(context, line, description, `Operation '${name}'`);\n else if (usesPattern.test(line.content)) {\n if (uses !== null) context.error(DiagnosticCodes.InvalidSystemReference, \"An operation declares exactly one 'uses <System>'.\", locationOf(line));\n else {\n uses = usesPattern.exec(line.content)![1];\n usesLocation = { ...locationOf(line), column: locationOf(line).column + line.content.indexOf(uses, 4) };\n }\n rejectOperationChildren(context, line, DiagnosticCodes.InvalidSystemReference, 'A system reference cannot have children.');\n } else if (line.content === 'execute' || line.content === 'compensate') {\n const phase = parseOperationPhase(context, line);\n if (line.content === 'execute') {\n if (execute !== null) context.error(DiagnosticCodes.InvalidOperationDeclaration, 'An operation declares execute at most once.', locationOf(line));\n else execute = phase;\n } else {\n if (compensate !== null) context.error(DiagnosticCodes.InvalidOperationDeclaration, 'An operation declares compensate at most once.', locationOf(line));\n else compensate = phase;\n }\n } else {\n context.error(DiagnosticCodes.InvalidOperationDeclaration, `Unexpected '${line.content}' in operation - expected uses, an input, description, execute or compensate.`, locationOf(line));\n context.skipBlock(line.indent);\n }\n }\n if (uses === null) context.error(DiagnosticCodes.InvalidSystemReference, \"An operation requires exactly one 'uses <System>'.\", locationOf(header));\n return { operation: { kind: 'OperationSyntax', name, uses: uses ?? '', usesLocation, inputs, description, execute, compensate, location: locationOf(header) }, mappings };\n}\n\nfunction parseOperationPhase(context: ParserContext, header: SourceLine): OperationPhaseSyntax {\n let description: string | null = null;\n let file: OperationPhaseSyntax['file'] = null;\n let code: OperationPhaseSyntax['code'] = null;\n let implementation: OperationPhaseSyntax['implementation'] = null;\n let sourceSelected = false;\n for (let line = context.peekChild(header.indent); line !== undefined; line = context.peekChild(header.indent)) {\n context.reader.takeSignificant();\n if (firstWord(line.content) === 'description') {\n description = parseDescription(context, line, description, `Operation phase '${header.content}'`);\n continue;\n }\n if (firstWord(line.content) === 'implementation') {\n if (sourceSelected) context.error(DiagnosticCodes.ConflictingImplementationSources, 'A phase cannot mix wrapped and direct sources or repeat its wrapper.', locationOf(line));\n const source = parseImplementationWrapper(context, line);\n if (!sourceSelected) { file = source.file; code = source.code; implementation = source.implementation; }\n sourceSelected = true;\n } else if (isFileDirective(line) || line.content.startsWith('```')) {\n if (sourceSelected) context.error(DiagnosticCodes.ConflictingImplementationSources, 'A phase has at most one file or inline payload.', locationOf(line));\n const parsedFile = isFileDirective(line) ? parseFile(context, line) : null;\n const parsedCode = parsedFile === null ? parseCode(context, line) : null;\n if (!sourceSelected) { file = parsedFile; code = parsedCode; }\n sourceSelected = true;\n if (parsedFile !== null) rejectOperationChildren(context, line, DiagnosticCodes.InvalidImplementationBlock, 'A file directive cannot have children.');\n } else {\n context.error(DiagnosticCodes.InvalidOperationDeclaration, 'A phase accepts description, file, a tagged fence or implementation.', locationOf(line));\n context.skipBlock(line.indent);\n }\n }\n return { kind: 'OperationPhaseSyntax', description, file, code, implementation, location: locationOf(header) };\n}\n"],"mappings":"4lBAiBA,MAAMA,EAAeC,EAAQ,6BAA6B,EACpDC,EAAkBD,EAAQ,gCAAgC,EAC1DE,EAAeF,EAAQ,4CAA4C,EACnEG,EAAcH,EAAQ,2BAA2B,EACjDI,EAAeJ,EAAQ,6BAA6B,EACpDK,kBAAgB,IAAI,IAAI,CAAC,MAAO,MAAO,aAAc,SAAU,gBAAiB,YAAa,WAAY,cAAe,YAAa,WAAY,UAAU,CAAC,EAElK,SAAgB,wBAAwB,EAAwB,EAAkB,EAAc,EAAuB,CACnH,IAAMC,EAAQC,EAAQ,UAAUC,EAAK,MAAM,EACvCF,IAAU,IAAA,KACdC,EAAQ,MAAME,EAAMC,EAASC,EAAWL,CAAK,CAAC,EAC9CC,EAAQ,UAAUC,EAAK,MAAM,EACjC,CAEA,SAAgB,YAAY,EAAwB,EAAkC,CAClF,IAAMI,EAAQb,EAAa,KAAKc,EAAO,OAAO,EAC1CD,IAAU,MAAML,EAAQ,MAAMO,EAAgB,yBAA0B,4BAA6BH,EAAWE,CAAM,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QAAQ,EAAE,OAGpG,GAAIG,EAAUR,EAAK,OAAO,IAAM,iBAAkB,CAC1C4B,GAAgB7B,EAAQ,MAAMO,EAAgB,iCAAkC,uEAAwEH,EAAWH,CAAI,CAAC,EAC5K,IAAM6B,EAASC,EAA2B/B,EAASC,CAAI,EAClD4B,IAAkB,EAAOC,EAAO,KAAM,EAAOA,EAAO,KAAM,EAAiBA,EAAO,gBACvF,EAAiB,EACrB,MAAO,GAAIE,EAAgB/B,CAAI,GAAKA,EAAK,QAAQ,WAAW,KAAK,EAAG,CAC5D4B,GAAgB7B,EAAQ,MAAMO,EAAgB,iCAAkC,kDAAmDH,EAAWH,CAAI,CAAC,EACvJ,IAAMgC,EAAaD,EAAgB/B,CAAI,EAAIiC,EAAUlC,EAASC,CAAI,EAAI,KAChEkC,EAAaF,IAAe,KAAOG,EAAUpC,EAASC,CAAI,EAAI,KAC/D4B,IAAkB,EAAOI,EAAY,EAAOE,GACjD,EAAiB,GACbF,IAAe,MAAM,wBAAwBjC,EAASC,EAAMM,EAAgB,2BAA4B,wCAAwC,CACxJ,MACIP,EAAQ,MAAMO,EAAgB,4BAA6B,uEAAwEH,EAAWH,CAAI,CAAC,EACnJD,EAAQ,UAAUC,EAAK,MAAM,EAGrC,MAAO,CAAE,KAAM,uBAAwB,cAAa,OAAM,OAAM,iBAAgB,SAAUG,EAAWE,CAAM,CAAE,CACjH"}
|
|
1
|
+
{"version":3,"file":"OperationParser.js","names":["systemHeader","pattern","operationHeader","inlineHeader","usesPattern","typedMapping","eventMetadata","child","context","line","code","message","locationOf","match","header","DiagnosticCodes","description","firstWord","parseDescription","inline","name","uses","usesLocation","execute","compensate","inputs","mappings","names","typed","marker","trailingMarker","propertyLine","structured","tryParseProperty","property","parseProperty","parseMappingSource","parseStructuredValue","phase","file","implementation","sourceSelected","source","parseImplementationWrapper","isFileDirective","parsedFile","parseFile","parsedCode","parseCode"],"sources":["../../../../../../Compiler/Parsing/OperationParser.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { PropertySyntax } from '../Syntax/Declarations';\nimport { pattern } from '../Text/patterns';\nimport { PropertyMappingSyntax } from '../Syntax/Expressions';\nimport { OperationPhaseSyntax, OperationSyntax, SystemSyntax } from '../Syntax/Operations';\nimport { parseDescription } from './DescriptionParser';\nimport { parseMappingSource } from './ExpressionParser';\nimport { isFileDirective } from './FileReferences';\nimport { parseCode, parseFile, parseImplementationWrapper } from './ImplementationParser';\nimport { firstWord } from './LineText';\nimport { ParserContext } from './ParserContext';\nimport { parseProperty, tryParseProperty } from './PropertyLineParser';\nimport { locationOf, SourceLine } from './SourceLine';\nimport { parseStructuredValue, trailingMarker } from './StructuredBlockParser';\n\nconst systemHeader = pattern('^system\\\\s+([A-Za-z_]\\\\w*)$');\nconst operationHeader = pattern('^operation\\\\s+([A-Za-z_]\\\\w*)$');\nconst inlineHeader = pattern('^produces\\\\s+operation\\\\s+([A-Za-z_]\\\\w*)$');\nconst usesPattern = pattern('^uses\\\\s+([A-Za-z_]\\\\w*)$');\nconst typedMapping = pattern('^(.+?)\\\\s*=(?!=|>)\\\\s*(.+)$');\nconst eventMetadata = new Set(['for', 'tag', 'generation', 'origin', 'documentation', 'namespace', 'sequence', 'correlation', 'causation', 'causedBy', 'occurred']);\n\nexport function rejectOperationChildren(context: ParserContext, line: SourceLine, code: string, message: string): void {\n const child = context.peekChild(line.indent);\n if (child === undefined) return;\n context.error(code, message, locationOf(child));\n context.skipBlock(line.indent);\n}\n\nexport function parseSystem(context: ParserContext, header: SourceLine): SystemSyntax {\n const match = systemHeader.exec(header.content);\n if (match === null) context.error(DiagnosticCodes.InvalidSystemDeclaration, \"Expected 'system <Name>'.\", locationOf(header));\n let description: string | null = null;\n for (let child = context.peekChild(header.indent); child !== undefined; child = context.peekChild(header.indent)) {\n context.reader.takeSignificant();\n if (firstWord(child.content) === 'description') description = parseDescription(context, child, description, `System '${match?.[1] ?? ''}'`);\n else {\n context.error(DiagnosticCodes.InvalidSystemDeclaration, 'A system accepts only a description; abilities are not supported.', locationOf(child));\n context.skipBlock(child.indent);\n }\n }\n return { kind: 'SystemSyntax', name: match?.[1] ?? '', description, location: locationOf(header) };\n}\n\nexport function parseOperation(context: ParserContext, header: SourceLine, inline = false): { operation: OperationSyntax; mappings: PropertyMappingSyntax[] } {\n const match = (inline ? inlineHeader : operationHeader).exec(header.content);\n const name = match?.[1] ?? '';\n if (match === null) context.error(DiagnosticCodes.InvalidOperationDeclaration, 'Expected an operation declaration with one name.', locationOf(header));\n let description: string | null = null;\n let uses: string | null = null;\n let usesLocation = locationOf(header);\n let execute: OperationPhaseSyntax | null = null;\n let compensate: OperationPhaseSyntax | null = null;\n const inputs: PropertySyntax[] = [];\n const mappings: PropertyMappingSyntax[] = [];\n const names = new Set<string>();\n for (let line = context.peekChild(header.indent); line !== undefined; line = context.peekChild(header.indent)) {\n context.reader.takeSignificant();\n const typed = typedMapping.exec(line.content);\n const marker = inline && typed === null ? trailingMarker(line.content) : undefined;\n let propertyLine = line;\n if (inline && typed !== null) propertyLine = { ...line, content: typed[1].trimEnd() };\n else if (marker !== undefined) propertyLine = { ...line, content: line.content.substring(0, line.content.length - marker.length - 1) };\n const structured = inline && typed === null && (marker !== undefined || context.peekChild(line.indent) !== undefined);\n if (typed === null && eventMetadata.has(firstWord(line.content))) {\n context.error(DiagnosticCodes.InvalidOperationDeclaration, 'Operations cannot declare event routing or metadata; escape a keyword-named input with @.', locationOf(line));\n context.skipBlock(line.indent);\n continue;\n }\n if (!usesPattern.test(line.content) && tryParseProperty(propertyLine) !== undefined) {\n const property = parseProperty(context, propertyLine)!;\n if (inline && typed === null && !structured) context.error(DiagnosticCodes.InvalidOperationMapping, \"An inline operation input requires '<property> <Type> = <source>'.\", locationOf(line));\n if (property.isSubject) context.error(DiagnosticCodes.InvalidSubjectOwner, 'The subject modifier is only valid on event properties, not operation inputs (decision 0008: one data subject per event).', locationOf(line));\n if (property.isIdentifier || property.isGenerated) context.error(DiagnosticCodes.InvalidOperationDeclaration, 'Operation inputs cannot be identifier or generated properties.', locationOf(line));\n if (names.has(property.name)) context.error(DiagnosticCodes.DuplicateDeclaration, `Operation '${name}' already declares input '${property.name}'.`, locationOf(line));\n names.add(property.name);\n inputs.push(property);\n if (inline && typed !== null) mappings.push({ kind: 'PropertyMappingSyntax', property: property.name, source: parseMappingSource(typed[2], { ...locationOf(line), column: line.indent + line.content.length - typed[2].length + 1 }, context), location: locationOf(line) });\n if (structured) mappings.push({ kind: 'PropertyMappingSyntax', property: property.name, source: parseStructuredValue(context, line, marker), location: locationOf(line) });\n rejectOperationChildren(context, line, DiagnosticCodes.InvalidOperationDeclaration, 'An operation input cannot have children.');\n } else if (firstWord(line.content) === 'description') description = parseDescription(context, line, description, `Operation '${name}'`);\n else if (usesPattern.test(line.content)) {\n if (uses !== null) context.error(DiagnosticCodes.InvalidSystemReference, \"An operation declares exactly one 'uses <System>'.\", locationOf(line));\n else {\n uses = usesPattern.exec(line.content)![1];\n usesLocation = { ...locationOf(line), column: locationOf(line).column + line.content.indexOf(uses, 4) };\n }\n rejectOperationChildren(context, line, DiagnosticCodes.InvalidSystemReference, 'A system reference cannot have children.');\n } else if (line.content === 'execute' || line.content === 'compensate') {\n const phase = parseOperationPhase(context, line);\n if (line.content === 'execute') {\n if (execute !== null) context.error(DiagnosticCodes.InvalidOperationDeclaration, 'An operation declares execute at most once.', locationOf(line));\n else execute = phase;\n } else {\n if (compensate !== null) context.error(DiagnosticCodes.InvalidOperationDeclaration, 'An operation declares compensate at most once.', locationOf(line));\n else compensate = phase;\n }\n } else {\n context.error(DiagnosticCodes.InvalidOperationDeclaration, `Unexpected '${line.content}' in operation - expected uses, an input, description, execute or compensate.`, locationOf(line));\n context.skipBlock(line.indent);\n }\n }\n if (uses === null) context.error(DiagnosticCodes.InvalidSystemReference, \"An operation requires exactly one 'uses <System>'.\", locationOf(header));\n return { operation: { kind: 'OperationSyntax', name, uses: uses ?? '', usesLocation, inputs, description, execute, compensate, location: locationOf(header) }, mappings };\n}\n\nfunction parseOperationPhase(context: ParserContext, header: SourceLine): OperationPhaseSyntax {\n let description: string | null = null;\n let file: OperationPhaseSyntax['file'] = null;\n let code: OperationPhaseSyntax['code'] = null;\n let implementation: OperationPhaseSyntax['implementation'] = null;\n let sourceSelected = false;\n for (let line = context.peekChild(header.indent); line !== undefined; line = context.peekChild(header.indent)) {\n context.reader.takeSignificant();\n if (firstWord(line.content) === 'description') {\n description = parseDescription(context, line, description, `Operation phase '${header.content}'`);\n continue;\n }\n if (firstWord(line.content) === 'implementation') {\n if (sourceSelected) context.error(DiagnosticCodes.ConflictingImplementationSources, 'A phase cannot mix wrapped and direct sources or repeat its wrapper.', locationOf(line));\n const source = parseImplementationWrapper(context, line);\n if (!sourceSelected) { file = source.file; code = source.code; implementation = source.implementation; }\n sourceSelected = true;\n } else if (isFileDirective(line) || line.content.startsWith('```')) {\n if (sourceSelected) context.error(DiagnosticCodes.ConflictingImplementationSources, 'A phase has at most one file or inline payload.', locationOf(line));\n const parsedFile = isFileDirective(line) ? parseFile(context, line) : null;\n const parsedCode = parsedFile === null ? parseCode(context, line) : null;\n if (!sourceSelected) { file = parsedFile; code = parsedCode; }\n sourceSelected = true;\n if (parsedFile !== null) rejectOperationChildren(context, line, DiagnosticCodes.InvalidImplementationBlock, 'A file directive cannot have children.');\n } else {\n context.error(DiagnosticCodes.InvalidOperationDeclaration, 'A phase accepts description, file, a tagged fence or implementation.', locationOf(line));\n context.skipBlock(line.indent);\n }\n }\n return { kind: 'OperationPhaseSyntax', description, file, code, implementation, location: locationOf(header) };\n}\n"],"mappings":"krBAkBA,MAAMA,EAAeC,EAAQ,6BAA6B,EACpDC,EAAkBD,EAAQ,gCAAgC,EAC1DE,EAAeF,EAAQ,4CAA4C,EACnEG,EAAcH,EAAQ,2BAA2B,EACjDI,EAAeJ,EAAQ,6BAA6B,EACpDK,kB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,QAAQ,WAAW,KAAK,EAAG,CAC5DgC,GAAgBjC,EAAQ,MAAMO,EAAgB,iCAAkC,kDAAmDH,EAAWH,CAAI,CAAC,EACvJ,IAAMoC,EAAaD,EAAgBnC,CAAI,EAAIqC,EAAUtC,EAASC,CAAI,EAAI,KAChEsC,EAAaF,IAAe,KAAOG,EAAUxC,EAASC,CAAI,EAAI,KAC/DgC,IAAkB,EAAOI,EAAY,EAAOE,GACjD,EAAiB,GACbF,IAAe,MAAM,wBAAwBrC,EAASC,EAAMM,EAAgB,2BAA4B,wCAAwC,CACxJ,MACIP,EAAQ,MAAMO,EAAgB,4BAA6B,uEAAwEH,EAAWH,CAAI,CAAC,EACnJD,EAAQ,UAAUC,EAAK,MAAM,EAGrC,MAAO,CAAE,KAAM,uBAAwB,cAAa,OAAM,OAAM,iBAAgB,SAAUG,EAAWE,CAAM,CAAE,CACjH"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{pattern as t}from"../Text/patterns.js";import{locationOf as n}from"./SourceLine.js";import{parseMappingSource as r}from"./ExpressionParser.js";import{diagnosticText as i}from"../Diagnostics/DiagnosticArgument.js";import{firstWord as a,unescapeIdentifier as o}from"./LineText.js";import{parseProperty as s}from"./PropertyLineParser.js";import{
|
|
1
|
+
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{pattern as t}from"../Text/patterns.js";import{locationOf as n}from"./SourceLine.js";import{parseMappingSource as r}from"./ExpressionParser.js";import{diagnosticText as i}from"../Diagnostics/DiagnosticArgument.js";import{firstWord as a,unescapeIdentifier as o}from"./LineText.js";import{parseProperty as s}from"./PropertyLineParser.js";import{parseStructuredValue as c,trailingMarker as l,tryParseStructuredMapping as u}from"./StructuredBlockParser.js";import{parseCondition as d}from"./ConditionParser.js";import{sourceStreamPattern as f}from"../Text/SourceStreamNames.js";import{parseCommandStream as p}from"./EventSourceParser.js";import{EventMetadataParser as m}from"./EventMetadataParser.js";import{parseTag as h}from"./DeclarationParsers.js";import{parseOperation as g}from"./OperationParser.js";const _=t(`^produces\\s+operation(?:\\s|$)`),v=t(`^produces\\s+event\\s+([A-Za-z_]\\w*)(?:\\s+(generation)(?:\\s+.*)?)?$`),y=t(`^produces\\s+([A-Z]\\w*(?:\\.[A-Za-z_]\\w*)*)$`),b=t(`^produces\\s+when\\s+(.+)$`),x=t(`^[A-Z]\\w*(?:\\.[A-Za-z_]\\w*)*$`),S=t(`^for\\s+(\\S.*)$`),C=t(`^(@?[\\w.]+)\\s*=(?!=|>)\\s*(.+)$`),w=t(`^(.+?)\\s*=(?!=|>)\\s*(.+)$`),T=/* @__PURE__ */ new Set([`namespace`,`sequence`,`correlation`,`causation`,`causedBy`,`occurred`]);function parseProduces(t,E,D=!1){if(_.test(E.content)){if(!D){t.error(e.OperationOutsideCommand,`Operations can only be produced by commands.`,n(E)),t.skipOpaqueBlock(E.indent);return}let r=g(t,E,!0);return{kind:`ProducesSyntax`,when:null,event:r.operation.name,targetLocation:{...n(E),column:E.indent+E.content.match(/^produces\s+operation(?:\s+|$)/)[0].length+1},inlineEvent:null,inlineOperation:r.operation,mappings:r.mappings,for:null,tags:[],location:n(E)}}let O=v.exec(E.content),k=E,A=null,j,M;if(O!==null){if(!D){t.error(e.InlineEventOutsideCommand,`Inline events can only be declared inside commands`,n(E)),t.skipOpaqueBlock(E.indent);return}O[2]!==void 0&&t.error(e.InlineEventGeneration,`Inline events are generation 1 - extract the event before declaring generations`,n(E)),j=O[1],M=E.indent+E.content.match(/^produces\s+event\s+/)[0].length+1}else if(b.test(E.content)){A=d(t,b.exec(E.content)[1],n(E));let r=t.peekChild(E.indent);if(r===void 0||!x.test(r.content)){t.error(e.ProducesWhenWithoutEvent,`Expected an event name on the line after 'produces when'`,n(E)),t.skipOpaqueBlock(E.indent);return}t.reader.takeSignificant(),k=r,j=r.content,M=r.indent+1}else{let r=y.exec(E.content);if(r===null){t.error(e.InvalidProducesDeclaration,`Invalid produces declaration '${E.content}' - expected 'produces <EventType>' or 'produces when <condition>'`,n(E)),t.skipOpaqueBlock(E.indent);return}j=r[1],M=E.indent+E.content.match(/^produces\s+/)[0].length+1}let N=[],P=/* @__PURE__ */ new Set,F=[],I=[],L=new m(j),R=null,z=null;for(let d=t.peekChild(k.indent);d!==void 0;d=t.peekChild(k.indent)){t.reader.takeSignificant();let m=a(d.content),g=n(d);if(T.has(m)){t.error(e.ReservedProductionMetadata,`'${m}' is system-assigned production metadata and cannot be supplied here`,g),t.skipOpaqueBlock(d.indent);continue}if(O!==null&&(m===`generation`||m===`origin`)){t.error(m===`generation`?e.InlineEventGeneration:e.ReservedProductionMetadata,m===`generation`?`Inline events are generation 1 - extract the event before declaring generations`:`An inline event is local to its command and cannot declare origin`,g),t.skipOpaqueBlock(d.indent);continue}if(m===`stream`&&!d.content.includes(`=`)){let n=f(`^stream\\s+([A-Za-z_]\\w*\\.[A-Za-z_]\\w*)$`).exec(d.content);if(!D)t.error(e.ProductionRouteOutsideCommand,`Only command event productions can declare a stream route.`,g),t.skipBlock(d.indent);else if(z!==null)t.error(e.InvalidCommandStream,`A production can declare at most one stream route.`,g),t.skipBlock(d.indent);else if(n===null)t.error(e.InvalidCommandStream,`Expected 'stream <Source>.<Stream>'.`,g),t.skipBlock(d.indent);else{let e={...g,column:d.indent+d.content.indexOf(n[1])+1},r={kind:`PropertySyntax`,name:`stream`,type:{kind:`TypeRefSyntax`,name:n[1],isCollection:!1,isOptional:!1,location:e},isIdentifier:!1,location:g};z=p(t,d,r,!1)}continue}if(m===`tag`){let e=h(t,d,!1);e!==void 0&&I.push(e);continue}let _=S.exec(d.content);if(_!==null){R===null?R=r(_[1],g,t):t.error(e.DuplicateProducesTarget,`'${k.content}' already declares where it lands - an event is appended to one event source`,g);continue}let v=(O===null?C:w).exec(d.content);if(v===null&&O===null){let e=u(t,d);if(e!==void 0){F.push(e);continue}}let y=l(d.content),b=v===null&&O!==null&&!d.content.includes(`=`)&&![`id`,`description`,`documentation`].includes(m)&&d.content.includes(` `)&&(y!==void 0||t.peekChild(d.indent)!==void 0),x=b?y===void 0?d.content:d.content.substring(0,d.content.length-y.length-1):v?.[1].trimEnd(),E=x===void 0||O===null?void 0:s(t,{...d,content:x});if((v!==null||b)&&(O===null||E!==void 0)){if(E!==void 0){E.isIdentifier&&(t.error(e.IdentifierOnEventProperty,`Property '${E.name}' of event '${j}' cannot be marked identifier - an event never carries its event source id`,g),E={...E,isIdentifier:!1});let n=E.name;P.has(n)&&t.error(e.DuplicateDeclaration,`Event '${j}' already declares property '${E.name}'`,g),P.add(n),N.push(E)}F.push(v===null?{kind:`PropertyMappingSyntax`,property:E.name,source:c(t,d,y),location:g}:{kind:`PropertyMappingSyntax`,property:E?.name??o(v[1]),source:r(v[2],{...g,column:d.indent+d.content.length-v[2].length+1},t),location:g})}else(O===null||!L.tryParse(t,d))&&t.error(e.InvalidPropertyMapping,`Invalid ${O===null?``:`inline `}property mapping '${d.content}' - expected '<property>${O===null?``:` <Type>`} = <source>'`,g,i(`text`,d.content))}return k!==E&&t.skipBlock(E.indent),{kind:`ProducesSyntax`,when:A,event:j,stream:z,targetLocation:{...n(k),column:M},inlineOperation:null,mappings:F,for:R,tags:O===null?I:[],location:n(E),inlineEvent:O===null?null:{kind:`EventSyntax`,name:j,properties:N,tags:I,generation:1,hasGenerationMarker:!1,...L.value,location:n(E)}}}export{parseProduces};
|
|
2
2
|
//# sourceMappingURL=ProducesParser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProducesParser.js","names":["inlineOperationPrefix","pattern","inlineHeader","plainHeader","conditional","eventName","targetPattern","mappingPattern","typedMappingPattern","reserved","header","inCommand","context","DiagnosticCodes","locationOf","parsed","parseOperation","inline","parent","when","name","targetColumn","parseCondition","child","plain","properties","propertyNames","mappings","tags","metadata","EventMetadataParser","target","stream","line","keyword","firstWord","location","route","sourceStreamPattern","typeLocation","candidate","parseCommandStream","tag","parseTag","forMatch","parseMappingSource","match","property","parseProperty","propertyName","unescapeIdentifier","diagnosticText"],"sources":["../../../../../../Compiler/Parsing/ProducesParser.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { diagnosticText } from '../Diagnostics/DiagnosticArgument';\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { CommandStreamSyntax } from '../Syntax/CommandStreamSyntax';\nimport { sourceStreamPattern } from '../Text/SourceStreamNames';\nimport { parseCommandStream } from './EventSourceParser';\nimport { ConditionSyntax } from '../Syntax/Conditions';\nimport { parseCondition } from './ConditionParser';\nimport { PropertySyntax, TagSyntax } from '../Syntax/Declarations';\nimport { ExpressionSyntax, PropertyMappingSyntax } from '../Syntax/Expressions';\nimport { ProducesSyntax } from '../Syntax/Reactions';\nimport { pattern } from '../Text/patterns';\nimport { parseTag } from './DeclarationParsers';\nimport { EventMetadataParser } from './EventMetadataParser';\nimport { parseMappingSource } from './ExpressionParser';\nimport { firstWord, unescapeIdentifier } from './LineText';\nimport { ParserContext } from './ParserContext';\nimport { parseOperation } from './OperationParser';\nimport { parseProperty } from './PropertyLineParser';\nimport { locationOf, SourceLine } from './SourceLine';\n\nconst inlineOperationPrefix = pattern('^produces\\\\s+operation(?:\\\\s|$)');\nconst inlineHeader = pattern('^produces\\\\s+event\\\\s+([A-Za-z_]\\\\w*)(?:\\\\s+(generation)(?:\\\\s+.*)?)?$');\nconst plainHeader = pattern('^produces\\\\s+([A-Z]\\\\w*(?:\\\\.[A-Za-z_]\\\\w*)*)$');\nconst conditional = pattern('^produces\\\\s+when\\\\s+(.+)$');\nconst eventName = pattern('^[A-Z]\\\\w*(?:\\\\.[A-Za-z_]\\\\w*)*$');\nconst targetPattern = pattern('^for\\\\s+(\\\\S.*)$');\nconst mappingPattern = pattern('^(@?[\\\\w.]+)\\\\s*=(?!=|>)\\\\s*(.+)$');\nconst typedMappingPattern = pattern('^(.+?)\\\\s*=(?!=|>)\\\\s*(.+)$');\nconst reserved = new Set(['namespace', 'sequence', 'correlation', 'causation', 'causedBy', 'occurred']);\n\nexport function parseProduces(context: ParserContext, header: SourceLine, inCommand = false): ProducesSyntax | undefined {\n if (inlineOperationPrefix.test(header.content)) {\n if (!inCommand) {\n context.error(DiagnosticCodes.OperationOutsideCommand, 'Operations can only be produced by commands.', locationOf(header));\n context.skipOpaqueBlock(header.indent);\n return undefined;\n }\n const parsed = parseOperation(context, header, true);\n return { kind: 'ProducesSyntax', when: null, event: parsed.operation.name, targetLocation: { ...locationOf(header), column: header.indent + header.content.match(/^produces\\s+operation(?:\\s+|$)/)![0].length + 1 }, inlineEvent: null, inlineOperation: parsed.operation, mappings: parsed.mappings, for: null, tags: [], location: locationOf(header) };\n }\n const inline = inlineHeader.exec(header.content);\n let parent = header;\n let when: ConditionSyntax | null = null;\n let name: string;\n let targetColumn: number;\n if (inline !== null) {\n if (!inCommand) {\n context.error(DiagnosticCodes.InlineEventOutsideCommand, 'Inline events can only be declared inside commands', locationOf(header));\n context.skipOpaqueBlock(header.indent);\n return undefined;\n }\n if (inline[2] !== undefined) {\n context.error(DiagnosticCodes.InlineEventGeneration, 'Inline events are generation 1 - extract the event before declaring generations', locationOf(header));\n }\n name = inline[1];\n targetColumn = header.indent + header.content.match(/^produces\\s+event\\s+/)![0].length + 1;\n } else if (conditional.test(header.content)) {\n when = parseCondition(context, conditional.exec(header.content)![1], locationOf(header));\n const child = context.peekChild(header.indent);\n if (child === undefined || !eventName.test(child.content)) {\n context.error(DiagnosticCodes.ProducesWhenWithoutEvent, \"Expected an event name on the line after 'produces when'\", locationOf(header));\n context.skipOpaqueBlock(header.indent);\n return undefined;\n }\n context.reader.takeSignificant();\n parent = child;\n name = child.content;\n targetColumn = child.indent + 1;\n } else {\n const plain = plainHeader.exec(header.content);\n if (plain === null) {\n context.error(DiagnosticCodes.InvalidProducesDeclaration, `Invalid produces declaration '${header.content}' - expected 'produces <EventType>' or 'produces when <condition>'`, locationOf(header));\n context.skipOpaqueBlock(header.indent);\n return undefined;\n }\n name = plain[1];\n targetColumn = header.indent + header.content.match(/^produces\\s+/)![0].length + 1;\n }\n const properties: PropertySyntax[] = [];\n const propertyNames = new Set<string>();\n const mappings: PropertyMappingSyntax[] = [];\n const tags: TagSyntax[] = [];\n const metadata = new EventMetadataParser(name);\n let target: ExpressionSyntax | null = null;\n let stream: CommandStreamSyntax | null = null;\n for (let line = context.peekChild(parent.indent); line !== undefined; line = context.peekChild(parent.indent)) {\n context.reader.takeSignificant();\n const keyword = firstWord(line.content);\n const location = locationOf(line);\n if (reserved.has(keyword)) {\n context.error(DiagnosticCodes.ReservedProductionMetadata, `'${keyword}' is system-assigned production metadata and cannot be supplied here`, location);\n context.skipOpaqueBlock(line.indent);\n continue;\n }\n if (inline !== null && (keyword === 'generation' || keyword === 'origin')) {\n context.error(keyword === 'generation' ? DiagnosticCodes.InlineEventGeneration : DiagnosticCodes.ReservedProductionMetadata,\n keyword === 'generation' ? 'Inline events are generation 1 - extract the event before declaring generations' : 'An inline event is local to its command and cannot declare origin', location);\n context.skipOpaqueBlock(line.indent);\n continue;\n }\n if (keyword === 'stream' && !line.content.includes('=')) {\n const route = sourceStreamPattern('^stream\\\\s+([A-Za-z_]\\\\w*\\\\.[A-Za-z_]\\\\w*)$').exec(line.content);\n if (!inCommand) {\n context.error(DiagnosticCodes.ProductionRouteOutsideCommand, 'Only command event productions can declare a stream route.', location);\n context.skipBlock(line.indent);\n } else if (stream !== null) {\n context.error(DiagnosticCodes.InvalidCommandStream, 'A production can declare at most one stream route.', location);\n context.skipBlock(line.indent);\n } else if (route === null) {\n context.error(DiagnosticCodes.InvalidCommandStream, \"Expected 'stream <Source>.<Stream>'.\", location);\n context.skipBlock(line.indent);\n } else {\n const typeLocation = { ...location, column: line.indent + line.content.indexOf(route[1]) + 1 };\n const candidate: PropertySyntax = { kind: 'PropertySyntax', name: 'stream', type: { kind: 'TypeRefSyntax', name: route[1], isCollection: false, isOptional: false, location: typeLocation }, isIdentifier: false, location };\n stream = parseCommandStream(context, line, candidate, false);\n }\n continue;\n }\n if (keyword === 'tag') {\n const tag = parseTag(context, line, false);\n if (tag !== undefined) tags.push(tag);\n continue;\n }\n const forMatch = targetPattern.exec(line.content);\n if (forMatch !== null) {\n if (target !== null) {\n context.error(DiagnosticCodes.DuplicateProducesTarget, `'${parent.content}' already declares where it lands - an event is appended to one event source`, location);\n } else {\n target = parseMappingSource(forMatch[1], location, context);\n }\n continue;\n }\n const match = (inline === null ? mappingPattern : typedMappingPattern).exec(line.content);\n let property = match === null || inline === null ? undefined : parseProperty(context, { ...line, content: match[1].trimEnd() });\n if (match !== null && (inline === null || property !== undefined)) {\n if (property !== undefined) {\n if (property.isIdentifier) {\n context.error(DiagnosticCodes.IdentifierOnEventProperty, `Property '${property.name}' of event '${name}' cannot be marked identifier - an event never carries its event source id`, location);\n property = { ...property, isIdentifier: false };\n }\n const propertyName = property.name;\n if (propertyNames.has(propertyName)) {\n context.error(DiagnosticCodes.DuplicateDeclaration, `Event '${name}' already declares property '${property.name}'`, location);\n }\n propertyNames.add(propertyName);\n properties.push(property);\n }\n mappings.push({ kind: 'PropertyMappingSyntax', property: property?.name ?? unescapeIdentifier(match[1]), source: parseMappingSource(match[2], { ...location, column: line.indent + line.content.length - match[2].length + 1 }, context), location });\n } else if (inline === null || !metadata.tryParse(context, line)) {\n context.error(DiagnosticCodes.InvalidPropertyMapping, `Invalid ${inline === null ? '' : 'inline '}property mapping '${line.content}' - expected '<property>${inline === null ? '' : ' <Type>'} = <source>'`, location, diagnosticText('text', line.content));\n }\n }\n if (parent !== header) context.skipBlock(header.indent);\n return {\n kind: 'ProducesSyntax', when, event: name, stream, targetLocation: { ...locationOf(parent), column: targetColumn }, inlineOperation: null, mappings, for: target, tags: inline === null ? tags : [], location: locationOf(header),\n inlineEvent: inline === null ? null : { kind: 'EventSyntax', name, properties, tags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,EAAK,OAASA,EAAK,QAAQ,OAASa,EAAM,EAAE,CAAC,OAAS,CAAE,EAAGlC,CAAO,EAAG,UAAS,CAAC,CACxP,MAAWK,IAAW,MAAQ,CAACY,EAAS,SAASjB,EAASqB,CAAI,IAC1DrB,EAAQ,MAAMC,EAAgB,uBAAwB,WAAWI,IAAW,KAAO,GAAK,UAAU,oBAAoBgB,EAAK,QAAQ,0BAA0BhB,IAAW,KAAO,GAAK,UAAU,cAAemB,EAAUe,EAAe,OAAQlB,EAAK,OAAO,CAAC,CAEnQ,CAEA,OADIf,IAAWR,GAAQE,EAAQ,UAAUF,EAAO,MAAM,EAC/C,CACH,KAAM,iBAAkB,OAAM,MAAOU,EAAM,SAAQ,eAAgB,CAAE,GAAGN,EAAWI,CAAM,EAAG,OAAQG,CAAa,EAAG,gBAAiB,KAAM,WAAU,IAAKU,EAAQ,KAAMd,IAAW,KAAOW,EAAO,CAAC,EAAG,SAAUd,EAAWJ,CAAM,EAChO,YAAaO,IAAW,KAAO,KAAO,CAAE,KAAM,cAAe,OAAM,aAAY,OAAM,WAAY,EAAG,oBAAqB,GAAO,GAAGY,EAAS,MAAO,SAAUf,EAAWJ,CAAM,CAAE,CACpL,CACJ"}
|
|
1
|
+
{"version":3,"file":"ProducesParser.js","names":["inlineOperationPrefix","pattern","inlineHeader","plainHeader","conditional","eventName","targetPattern","mappingPattern","typedMappingPattern","reserved","header","inCommand","context","DiagnosticCodes","locationOf","parsed","parseOperation","inline","parent","when","name","targetColumn","parseCondition","child","plain","properties","propertyNames","mappings","tags","metadata","EventMetadataParser","target","stream","line","keyword","firstWord","location","route","sourceStreamPattern","typeLocation","candidate","parseCommandStream","tag","parseTag","forMatch","parseMappingSource","match","structured","tryParseStructuredMapping","marker","trailingMarker","declaration","property","parseProperty","propertyName","parseStructuredValue","unescapeIdentifier","diagnosticText"],"sources":["../../../../../../Compiler/Parsing/ProducesParser.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { diagnosticText } from '../Diagnostics/DiagnosticArgument';\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { CommandStreamSyntax } from '../Syntax/CommandStreamSyntax';\nimport { sourceStreamPattern } from '../Text/SourceStreamNames';\nimport { parseCommandStream } from './EventSourceParser';\nimport { ConditionSyntax } from '../Syntax/Conditions';\nimport { parseCondition } from './ConditionParser';\nimport { PropertySyntax, TagSyntax } from '../Syntax/Declarations';\nimport { ExpressionSyntax, PropertyMappingSyntax } from '../Syntax/Expressions';\nimport { ProducesSyntax } from '../Syntax/Reactions';\nimport { pattern } from '../Text/patterns';\nimport { parseTag } from './DeclarationParsers';\nimport { EventMetadataParser } from './EventMetadataParser';\nimport { parseMappingSource } from './ExpressionParser';\nimport { firstWord, unescapeIdentifier } from './LineText';\nimport { ParserContext } from './ParserContext';\nimport { parseOperation } from './OperationParser';\nimport { parseProperty } from './PropertyLineParser';\nimport { locationOf, SourceLine } from './SourceLine';\nimport { parseStructuredValue, trailingMarker, tryParseStructuredMapping } from './StructuredBlockParser';\n\nconst inlineOperationPrefix = pattern('^produces\\\\s+operation(?:\\\\s|$)');\nconst inlineHeader = pattern('^produces\\\\s+event\\\\s+([A-Za-z_]\\\\w*)(?:\\\\s+(generation)(?:\\\\s+.*)?)?$');\nconst plainHeader = pattern('^produces\\\\s+([A-Z]\\\\w*(?:\\\\.[A-Za-z_]\\\\w*)*)$');\nconst conditional = pattern('^produces\\\\s+when\\\\s+(.+)$');\nconst eventName = pattern('^[A-Z]\\\\w*(?:\\\\.[A-Za-z_]\\\\w*)*$');\nconst targetPattern = pattern('^for\\\\s+(\\\\S.*)$');\nconst mappingPattern = pattern('^(@?[\\\\w.]+)\\\\s*=(?!=|>)\\\\s*(.+)$');\nconst typedMappingPattern = pattern('^(.+?)\\\\s*=(?!=|>)\\\\s*(.+)$');\nconst reserved = new Set(['namespace', 'sequence', 'correlation', 'causation', 'causedBy', 'occurred']);\n\nexport function parseProduces(context: ParserContext, header: SourceLine, inCommand = false): ProducesSyntax | undefined {\n if (inlineOperationPrefix.test(header.content)) {\n if (!inCommand) {\n context.error(DiagnosticCodes.OperationOutsideCommand, 'Operations can only be produced by commands.', locationOf(header));\n context.skipOpaqueBlock(header.indent);\n return undefined;\n }\n const parsed = parseOperation(context, header, true);\n return { kind: 'ProducesSyntax', when: null, event: parsed.operation.name, targetLocation: { ...locationOf(header), column: header.indent + header.content.match(/^produces\\s+operation(?:\\s+|$)/)![0].length + 1 }, inlineEvent: null, inlineOperation: parsed.operation, mappings: parsed.mappings, for: null, tags: [], location: locationOf(header) };\n }\n const inline = inlineHeader.exec(header.content);\n let parent = header;\n let when: ConditionSyntax | null = null;\n let name: string;\n let targetColumn: number;\n if (inline !== null) {\n if (!inCommand) {\n context.error(DiagnosticCodes.InlineEventOutsideCommand, 'Inline events can only be declared inside commands', locationOf(header));\n context.skipOpaqueBlock(header.indent);\n return undefined;\n }\n if (inline[2] !== undefined) {\n context.error(DiagnosticCodes.InlineEventGeneration, 'Inline events are generation 1 - extract the event before declaring generations', locationOf(header));\n }\n name = inline[1];\n targetColumn = header.indent + header.content.match(/^produces\\s+event\\s+/)![0].length + 1;\n } else if (conditional.test(header.content)) {\n when = parseCondition(context, conditional.exec(header.content)![1], locationOf(header));\n const child = context.peekChild(header.indent);\n if (child === undefined || !eventName.test(child.content)) {\n context.error(DiagnosticCodes.ProducesWhenWithoutEvent, \"Expected an event name on the line after 'produces when'\", locationOf(header));\n context.skipOpaqueBlock(header.indent);\n return undefined;\n }\n context.reader.takeSignificant();\n parent = child;\n name = child.content;\n targetColumn = child.indent + 1;\n } else {\n const plain = plainHeader.exec(header.content);\n if (plain === null) {\n context.error(DiagnosticCodes.InvalidProducesDeclaration, `Invalid produces declaration '${header.content}' - expected 'produces <EventType>' or 'produces when <condition>'`, locationOf(header));\n context.skipOpaqueBlock(header.indent);\n return undefined;\n }\n name = plain[1];\n targetColumn = header.indent + header.content.match(/^produces\\s+/)![0].length + 1;\n }\n const properties: PropertySyntax[] = [];\n const propertyNames = new Set<string>();\n const mappings: PropertyMappingSyntax[] = [];\n const tags: TagSyntax[] = [];\n const metadata = new EventMetadataParser(name);\n let target: ExpressionSyntax | null = null;\n let stream: CommandStreamSyntax | null = null;\n for (let line = context.peekChild(parent.indent); line !== undefined; line = context.peekChild(parent.indent)) {\n context.reader.takeSignificant();\n const keyword = firstWord(line.content);\n const location = locationOf(line);\n if (reserved.has(keyword)) {\n context.error(DiagnosticCodes.ReservedProductionMetadata, `'${keyword}' is system-assigned production metadata and cannot be supplied here`, location);\n context.skipOpaqueBlock(line.indent);\n continue;\n }\n if (inline !== null && (keyword === 'generation' || keyword === 'origin')) {\n context.error(keyword === 'generation' ? DiagnosticCodes.InlineEventGeneration : DiagnosticCodes.ReservedProductionMetadata,\n keyword === 'generation' ? 'Inline events are generation 1 - extract the event before declaring generations' : 'An inline event is local to its command and cannot declare origin', location);\n context.skipOpaqueBlock(line.indent);\n continue;\n }\n if (keyword === 'stream' && !line.content.includes('=')) {\n const route = sourceStreamPattern('^stream\\\\s+([A-Za-z_]\\\\w*\\\\.[A-Za-z_]\\\\w*)$').exec(line.content);\n if (!inCommand) {\n context.error(DiagnosticCodes.ProductionRouteOutsideCommand, 'Only command event productions can declare a stream route.', location);\n context.skipBlock(line.indent);\n } else if (stream !== null) {\n context.error(DiagnosticCodes.InvalidCommandStream, 'A production can declare at most one stream route.', location);\n context.skipBlock(line.indent);\n } else if (route === null) {\n context.error(DiagnosticCodes.InvalidCommandStream, \"Expected 'stream <Source>.<Stream>'.\", location);\n context.skipBlock(line.indent);\n } else {\n const typeLocation = { ...location, column: line.indent + line.content.indexOf(route[1]) + 1 };\n const candidate: PropertySyntax = { kind: 'PropertySyntax', name: 'stream', type: { kind: 'TypeRefSyntax', name: route[1], isCollection: false, isOptional: false, location: typeLocation }, isIdentifier: false, location };\n stream = parseCommandStream(context, line, candidate, false);\n }\n continue;\n }\n if (keyword === 'tag') {\n const tag = parseTag(context, line, false);\n if (tag !== undefined) tags.push(tag);\n continue;\n }\n const forMatch = targetPattern.exec(line.content);\n if (forMatch !== null) {\n if (target !== null) {\n context.error(DiagnosticCodes.DuplicateProducesTarget, `'${parent.content}' already declares where it lands - an event is appended to one event source`, location);\n } else {\n target = parseMappingSource(forMatch[1], location, context);\n }\n continue;\n }\n const match = (inline === null ? mappingPattern : typedMappingPattern).exec(line.content);\n if (match === null && inline === null) {\n const structured = tryParseStructuredMapping(context, line);\n if (structured !== undefined) {\n mappings.push(structured);\n continue;\n }\n }\n const marker = trailingMarker(line.content);\n const structured = match === null && inline !== null && !line.content.includes('=') && !['id', 'description', 'documentation'].includes(keyword) && line.content.includes(' ') && (marker !== undefined || context.peekChild(line.indent) !== undefined);\n const declaration = structured ? (marker === undefined ? line.content : line.content.substring(0, line.content.length - marker.length - 1)) : match?.[1].trimEnd();\n let property = declaration === undefined || inline === null ? undefined : parseProperty(context, { ...line, content: declaration });\n if ((match !== null || structured) && (inline === null || property !== undefined)) {\n if (property !== undefined) {\n if (property.isIdentifier) {\n context.error(DiagnosticCodes.IdentifierOnEventProperty, `Property '${property.name}' of event '${name}' cannot be marked identifier - an event never carries its event source id`, location);\n property = { ...property, isIdentifier: false };\n }\n const propertyName = property.name;\n if (propertyNames.has(propertyName)) {\n context.error(DiagnosticCodes.DuplicateDeclaration, `Event '${name}' already declares property '${property.name}'`, location);\n }\n propertyNames.add(propertyName);\n properties.push(property);\n }\n mappings.push(match === null\n ? { kind: 'PropertyMappingSyntax', property: property!.name, source: parseStructuredValue(context, line, marker), location }\n : { kind: 'PropertyMappingSyntax', property: property?.name ?? unescapeIdentifier(match[1]), source: parseMappingSource(match[2], { ...location, column: line.indent + line.content.length - match[2].length + 1 }, context), location });\n } else if (inline === null || !metadata.tryParse(context, line)) {\n context.error(DiagnosticCodes.InvalidPropertyMapping, `Invalid ${inline === null ? '' : 'inline '}property mapping '${line.content}' - expected '<property>${inline === null ? '' : ' <Type>'} = <source>'`, location, diagnosticText('text', line.content));\n }\n }\n if (parent !== header) context.skipBlock(header.indent);\n return {\n kind: 'ProducesSyntax', when, event: name, stream, targetLocation: { ...locationOf(parent), column: targetColumn }, inlineOperation: null, mappings, for: target, tags: inline === null ? tags : [], location: locationOf(header),\n inlineEvent: inline === null ? null : { kind: 'EventSyntax', name, properties, tags, generation: 1, hasGenerationMarker: false, ...metadata.value, location: locationOf(header) },\n };\n}\n"],"mappings":"i6BAwBA,MAAMA,EAAwBC,EAAQ,iCAAiC,EACjEC,EAAeD,EAAQ,wEAAwE,EAC/FE,EAAcF,EAAQ,gDAAgD,EACtEG,EAAcH,EAAQ,4BAA4B,EAClDI,EAAYJ,EAAQ,kCAAkC,EACtDK,EAAgBL,EAAQ,kBAAkB,EAC1CM,EAAiBN,EAAQ,mCAAmC,EAC5DO,EAAsBP,EAAQ,6BAA6B,EAC3DQ,kBAAW,IAAI,IAAI,CAAC,YAAa,WAAY,cAAe,YAAa,WAAY,UAAU,CAAC,EAEtG,SAAgB,cAAc,EAAwB,EAAoB,EAAY,GAAmC,CACrH,GAAIT,EAAsB,KAAKU,EAAO,OAAO,EAAG,CAC5C,GAAI,CAACC,EAAW,CACZC,EAAQ,MAAMC,EAAgB,wBAAyB,+CAAgDC,EAAWJ,CAAM,CAAC,EACzHE,EAAQ,gBAAgBF,EAAO,MAAM,EACrC,MACJ,CACA,IAAMK,EAASC,EAAeJ,EAASF,EAAQ,EAAI,EACnD,MAAO,CAAE,KAAM,iBAAkB,KAAM,KAAM,MAAOK,EAAO,UAAU,KAAM,eAAgB,CAAE,GAAGD,EAAWJ,CAAM,EAAG,OAAQA,EAAO,OAASA,EAAO,QAAQ,MAAM,gCAAgC,CAAC,CAAE,EAAE,CAAC,OAAS,CAAE,EAAG,YAAa,KAAM,gBAAiBK,EAAO,UAAW,SAAUA,EAAO,SAAU,IAAK,KAAM,KAAM,CAAC,EAAG,SAAUD,EAAWJ,CAAM,CAAE,CAC5V,CACA,IAAMO,EAASf,EA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CAAC,CAEnQ,CAEA,OADIf,IAAWR,GAAQE,EAAQ,UAAUF,EAAO,MAAM,EAC/C,CACH,KAAM,iBAAkB,OAAM,MAAOU,EAAM,SAAQ,eAAgB,CAAE,GAAGN,EAAWI,CAAM,EAAG,OAAQG,CAAa,EAAG,gBAAiB,KAAM,WAAU,IAAKU,EAAQ,KAAMd,IAAW,KAAOW,EAAO,CAAC,EAAG,SAAUd,EAAWJ,CAAM,EAChO,YAAaO,IAAW,KAAO,KAAO,CAAE,KAAM,cAAe,OAAM,aAAY,OAAM,WAAY,EAAG,oBAAqB,GAAO,GAAGY,EAAS,MAAO,SAAUf,EAAWJ,CAAM,CAAE,CACpL,CACJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{pattern as t}from"../Text/patterns.js";import{locationOf as n}from"./SourceLine.js";import{diagnosticText as r}from"../Diagnostics/DiagnosticArgument.js";import{firstWord as i,splitTopLevel as a,unescapeIdentifier as o}from"./LineText.js";import{parseDescription as s}from"./DescriptionParser.js";import{isFileDirective as c}from"./FileReferences.js";import{parseProjectionExpression as l}from"./ProjectionExpressionParser.js";import{validateProjectionEventScopes as u}from"./ProjectionEventScopeValidator.js";const d=t(`^projection\\s+(@?[\\w.]+)\\s*(?:=>\\s*([\\w.]+))?$`),f=t(`^(@?[\\w.]+)(?:\\s+key\\s+(.+))?$`),p=t(`^join\\s+(@?[\\w.]+)\\s+on\\s+(@?[\\w.]+)$`),m=t(`^with\\s+(@?[\\w.]+)$`),h=t(`^children\\s+(@?[\\w.]+)\\s+identified\\s+by\\s+(.+)$`),g=t(`^nested\\s+(@?[\\w.]+)$`),_=t(`^remove\\s+with\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$`),v=t(`^remove\\s+via\\s+join\\s+on\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$`),y=t(`^clear\\s+with\\s+(@?[\\w.]+)$`),b=t(`^variant\\s+(@?[\\w.]+)\\s*$`),x=t(`^enters\\s+on\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$`),S=t(`^(increment|decrement|count|clear)\\s+(@?[$\\w.]+)$`),C=t(`^(add|subtract)\\s+(@?[$\\w.]+)\\s+by\\s+(.+?)(?:\\s+\\*\\s+(.+))?$`),w=t(`^set\\s+(@?[$\\w.]+)\\s+(?:=|to)\\s+(.+)$`),T=t(`^(@?[$\\w.@]+)\\s*=(?!=|>)\\s*(.+)$`),E={increment:`IncrementMappingSyntax`,decrement:`DecrementMappingSyntax`,clear:`ClearMappingSyntax`,count:`CountMappingSyntax`};function parseProjection(t,r){let a=d.exec(r.content);if(a===null)return t.error(e.InvalidProjectionDeclaration,`Invalid projection declaration '${r.content}' - expected 'projection <Name> [=> <ReadModel>]'`,n(r)),t.skipBlock(r.indent),{kind:`ProjectionSyntax`,sourceOptions:t.sourceOptions,name:i(r.content),readModel:null,sequence:null,autoMap:`Inherit`,blocks:[],location:n(r)};let o=a[1],l=null,f=null,p=`Inherit`,m=null,h=[];for(let e=t.peekChild(r.indent);e!==void 0;e=t.peekChild(r.indent)){if(t.reader.takeSignificant(),c(e))continue;let n=i(e.content);if(n===`description`)f=s(t,e,f,`Projection '${o}'`);else if(n===`sequence`)l=e.content.substring(8).trim();else if(n===`automap`)p=`Enabled`;else if(e.content===`no automap`)p=`Disabled`;else if(n===`key`)m=parseKey(t,e);else if(n===`variant`)h.push(parseVariant(t,e));else{let n=parseBlock(t,e,!1);n!==void 0&&h.push(n)}}return reportVariantConflicts(t,h,o),u(t,o,h),h.length===0&&t.error(e.EmptyProjection,`Projection '${o}' must contain at least one directive`,n(r)),{kind:`ProjectionSyntax`,sourceOptions:t.sourceOptions,name:o,readModel:a[2]??null,sequence:l,autoMap:p,key:m,blocks:h,description:f,location:n(r)}}function reportVariantConflicts(t,n,r){let i=n.filter(e=>e.kind===`ProjectionVariantSyntax`),a=/* @__PURE__ */ new Map;i.forEach(e=>a.set(e.name,[...a.get(e.name)??[],e]));for(let n of[...a.values()].flatMap(e=>e.slice(1)))t.error(e.DuplicateProjectionVariant,`Duplicate variant '${n.name}' - a variant name is declared once`,n.location);let o=/* @__PURE__ */ new Set;for(let i of n.flatMap(e=>e.kind===`ProjectionVariantSyntax`?e.entersOn:[]))i.event.length>0&&o.has(i.event)&&t.error(e.DuplicateVariantEnteringEvent,`Entering event '${i.event}' is claimed more than once in projection '${r}'`,i.location),o.add(i.event)}function parseBlock(t,r,a){let o=n(r);switch(i(r.content)){case`from`:return parseFrom(t,r);case`every`:{let e=!0,{autoMap:n,mappings:i}=parseMappingBlock(t,r,t=>t.content===`exclude children`&&(e=!1,!0));return{kind:`EverySyntax`,includeChildren:e,autoMap:n,mappings:i,location:o}}case`all`:{let{autoMap:e,mappings:n}=parseMappingBlock(t,r);return{kind:`AllSyntax`,autoMap:e,mappings:n,location:o}}case`join`:return parseJoin(t,r);case`children`:return parseChildren(t,r);case`nested`:return parseNested(t,r);case`remove`:return parseRemove(t,r);case`clear`:return a||t.error(e.ClearWithOutsideNestedBlock,`'clear with' is only valid inside a nested block`,o),parseClearWith(t,r);default:t.error(e.UnknownProjectionDirective,`Unexpected '${i(r.content)}' in projection body`,o),t.skipBlock(r.indent);return}}function parseFrom(t,r){let s=[];for(let i of a(r.content.substring(4),`,`)){let a=i.trim();if(a.length===0){t.error(e.FromWithoutEvent,`Expected an event type after 'from'`,n(r));continue}let c=f.exec(a);c===null?t.error(e.InvalidEventReference,`Invalid event reference '${a}'`,n(r)):s.push({kind:`EventSpecSyntax`,event:o(c[1]),key:c[2]===void 0?null:l(c[2],n(r),t),location:n(r)})}let c=[],u=null,d=null;for(let e=t.peekChild(r.indent);e!==void 0;e=t.peekChild(r.indent)){t.reader.takeSignificant();let r=i(e.content);r===`key`?u=parseKey(t,e):r===`parent`?d=l(e.content.substring(6),n(e),t):pushMapping(t,e,c)}return{kind:`FromSyntax`,events:s,key:u,parentKey:d,mappings:c,location:n(r)}}function parseJoin(t,r){let i=p.exec(r.content);if(i===null)return t.error(e.InvalidJoinDeclaration,`Invalid join declaration '${r.content}' - expected 'join <property> on <key>'`,n(r)),t.skipBlock(r.indent),{kind:`JoinSyntax`,property:``,on:``,events:[],location:n(r)};let a=[];for(let i=t.peekChild(r.indent);i!==void 0;i=t.peekChild(r.indent)){t.reader.takeSignificant();let r=m.exec(i.content);if(r===null){t.error(e.JoinWithoutEvent,`Expected 'with <EventType>' in join block, got '${i.content}'`,n(i)),t.skipBlock(i.indent);continue}let{autoMap:s,mappings:c}=parseMappingBlock(t,i);a.push({kind:`JoinEventSyntax`,event:o(r[1]),autoMap:s,mappings:c,location:n(i)})}return{kind:`JoinSyntax`,property:o(i[1]),on:o(i[2]),events:a,location:n(r)}}function parseChildren(t,r){let i=h.exec(r.content);if(i===null)return t.error(e.InvalidChildrenDeclaration,`Invalid children declaration '${r.content}' - expected 'children <collection> identified by <key>'`,n(r)),t.skipBlock(r.indent),{kind:`ChildrenSyntax`,property:``,autoMap:`Inherit`,blocks:[],location:n(r)};let{autoMap:a,blocks:s}=parseChildBlocks(t,r);return{kind:`ChildrenSyntax`,property:o(i[1]),identifiedBy:l(i[2],n(r),t),autoMap:a,blocks:s,location:n(r)}}function parseNested(t,r){let i=g.exec(r.content);if(i===null)return t.error(e.InvalidNestedDeclaration,`Invalid nested declaration '${r.content}' - expected 'nested <property>'`,n(r)),t.skipBlock(r.indent),{kind:`NestedSyntax`,property:``,autoMap:`Inherit`,blocks:[],location:n(r)};let a=o(i[1]),{autoMap:s,blocks:c}=parseChildBlocks(t,r);return c.some(e=>e.kind===`FromSyntax`)||t.error(e.NestedBlockWithoutFrom,`Nested block '${a}' must contain at least one 'from' directive`,n(r)),{kind:`NestedSyntax`,property:a,autoMap:s,blocks:c,location:n(r)}}function parseChildBlocks(e,t){let n=[],r=`Inherit`;for(let i=e.peekChild(t.indent);i!==void 0;i=e.peekChild(t.indent)){if(e.reader.takeSignificant(),i.content===`automap`){r=`Enabled`;continue}if(i.content===`no automap`){r=`Disabled`;continue}let t=parseBlock(e,i,!0);t!==void 0&&n.push(t)}return{autoMap:r,blocks:n}}function parseRemove(t,r){let a=v.exec(r.content);if(a!==null)return{kind:`RemoveViaJoinSyntax`,event:o(a[1]),key:a[2]===void 0?null:l(a[2],n(r),t),location:n(r)};let s=_.exec(r.content);if(s===null){t.error(e.InvalidRemoveDeclaration,`Invalid remove declaration '${r.content}' - expected 'remove with <EventType>' or 'remove via join on <EventType>'`,n(r)),t.skipBlock(r.indent);return}let c=s[2]===void 0?null:l(s[2],n(r),t),u=null,d=null;for(let a=t.peekChild(r.indent);a!==void 0;a=t.peekChild(r.indent))if(t.reader.takeSignificant(),i(a.content)===`parent`)d=l(a.content.substring(6),n(a),t);else if(i(a.content)===`key`){(c!==null||u!==null)&&t.error(e.InvalidReadModelKeyLookup,`A removal can only declare one key.`,n(a));let r=parseKey(t,a);r.kind===`CompositeKeySyntax`?u=r:c=r.expression}else t.error(e.UnknownRemoveDirective,`Unexpected '${a.content}' in remove block - only 'parent' or 'key' is allowed`,n(a));return{kind:`RemoveWithSyntax`,event:o(s[1]),key:c,...u===null?{}:{partsKey:u},parentKey:d,location:n(r)}}function parseClearWith(t,r){let i=y.exec(r.content);return i===null?(t.error(e.InvalidClearDeclaration,`Invalid clear declaration '${r.content}' - expected 'clear with <EventType>'`,n(r)),{kind:`ClearWithSyntax`,event:``,location:n(r)}):{kind:`ClearWithSyntax`,event:o(i[1]),location:n(r)}}function parseVariant(t,r){let a=b.exec(r.content);if(a===null)return t.error(e.InvalidProjectionVariantDeclaration,`Invalid variant declaration '${r.content}' - expected 'variant <Name>'`,n(r)),t.skipBlock(r.indent),{kind:`ProjectionVariantSyntax`,name:i(r.content),entersOn:[],blocks:[],location:n(r)};let s=o(a[1]),c=[],l=[];for(let a=t.peekChild(r.indent);a!==void 0;a=t.peekChild(r.indent)){t.reader.takeSignificant();let r=i(a.content);if(r===`enters`)c.push(parseEntersOn(t,a));else if(r===`variant`)t.error(e.NestedProjectionVariantNotAllowed,`A variant cannot be declared inside another variant`,n(a)),t.skipBlock(a.indent);else{let e=parseBlock(t,a,!1);e!==void 0&&l.push(e)}}return c.length===0&&t.error(e.VariantRequiresEnteringEvent,`Variant '${s}' must declare at least one 'enters on' event`,n(r)),{kind:`ProjectionVariantSyntax`,name:s,entersOn:c,blocks:l,location:n(r)}}function parseEntersOn(t,r){let i=x.exec(r.content);return i===null?(t.error(e.InvalidEntersOnDeclaration,`Invalid 'enters on' declaration '${r.content}' - expected 'enters on <EventType> [key <expression>]'`,n(r)),t.skipBlock(r.indent),{kind:`ProjectionEntersOnSyntax`,event:``,key:null,location:n(r)}):{kind:`ProjectionEntersOnSyntax`,event:o(i[1]),key:i[2]===void 0?null:l(i[2],n(r),t),location:n(r)}}function parseKey(t,r){let i=r.content.substring(3).trim();if(t.peekChild(r.indent)===void 0)return{kind:`ExpressionKeySyntax`,expression:l(i,n(r),t),location:n(r)};i.endsWith(`{`)&&t.information(e.RedundantCompositeKeyBraces,`Write the composite key without braces; the indented parts already belong to the key.`,n(r));let a=[];for(let s=t.peekChild(r.indent);s!==void 0;s=t.peekChild(r.indent)){if(t.reader.takeSignificant(),s.content===`}`)continue;let r=T.exec(s.content);if(r===null){t.sourceOptions.numericMode===`exact`&&t.error(e.InvalidCompositeKeyPart,`Invalid composite key part '${s.content}' - expected '<property> = <expression>'`,n(s));continue}let c=l(r[2],n(s),t);t.sourceOptions.numericMode===`exact`&&i.replace(/\{$/,``).trim().length>0&&c.kind===`TemplateExpressionSyntax`&&t.error(e.TemplateInCompositeKey,`Template expressions are not allowed in composite keys`,n(s)),a.push({kind:`KeyPartSyntax`,property:o(r[1]),expression:c,location:n(s)})}let s=t.reader.peekSignificant();return s!==void 0&&s.indent===r.indent&&s.content===`}`&&t.reader.takeSignificant(),t.sourceOptions.numericMode===`exact`&&a.length===0&&t.error(e.EmptyCompositeKey,`Composite keys must contain at least one part`,n(r)),{kind:`CompositeKeySyntax`,type:i.replace(/\{$/,``).trim(),parts:a,location:n(r)}}function parseMappingBlock(e,t,n=()=>!1){let r=`Inherit`,i=[];for(let a=e.peekChild(t.indent);a!==void 0;a=e.peekChild(t.indent))e.reader.takeSignificant(),a.content===`automap`?r=`Enabled`:a.content===`no automap`?r=`Disabled`:n(a)||pushMapping(e,a,i);return{autoMap:r,mappings:i}}function pushMapping(t,i,a){let s=n(i),c=S.exec(i.content);if(c!==null){c[1]!==`clear`||c[2]!==`with`?a.push({kind:E[c[1]],property:o(c[2]),location:s}):t.sourceOptions.numericMode===`exact`&&t.error(e.InvalidProjectionMapping,`Invalid mapping '${i.content}' - 'clear with' is a block directive and needs an event type; to clear a property named 'with', write 'clear @with'`,s,r(`text`,i.content));return}let u=C.exec(i.content);if(u!==null){a.push({kind:u[1]===`add`?`AddMappingSyntax`:`SubtractMappingSyntax`,property:o(u[2]),value:l(u[3],s,t),...u[4]===void 0?{}:{factor:l(u[4],s,t)},location:s});return}let d=w.exec(i.content)??T.exec(i.content);d===null?t.sourceOptions.numericMode===`exact`&&t.error(e.InvalidProjectionMapping,`Invalid mapping '${i.content}'`,s,r(`text`,i.content)):a.push({kind:`SetMappingSyntax`,property:o(d[1]),source:l(d[2],s,t),location:s})}export{parseProjection};
|
|
1
|
+
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{pattern as t}from"../Text/patterns.js";import{locationOf as n}from"./SourceLine.js";import{diagnosticText as r}from"../Diagnostics/DiagnosticArgument.js";import{firstWord as i,splitTopLevel as a,unescapeIdentifier as o}from"./LineText.js";import{tryParseStructuredMapping as s}from"./StructuredBlockParser.js";import{parseDescription as c}from"./DescriptionParser.js";import{isFileDirective as l}from"./FileReferences.js";import{parseProjectionExpression as u}from"./ProjectionExpressionParser.js";import{validateProjectionEventScopes as d}from"./ProjectionEventScopeValidator.js";const f=t(`^projection\\s+(@?[\\w.]+)\\s*(?:=>\\s*([\\w.]+))?$`),p=t(`^(@?[\\w.]+)(?:\\s+key\\s+(.+))?$`),m=t(`^join\\s+(@?[\\w.]+)\\s+on\\s+(@?[\\w.]+)$`),h=t(`^with\\s+(@?[\\w.]+)$`),g=t(`^children\\s+(@?[\\w.]+)\\s+identified\\s+by\\s+(.+)$`),_=t(`^nested\\s+(@?[\\w.]+)$`),v=t(`^remove\\s+with\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$`),y=t(`^remove\\s+via\\s+join\\s+on\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$`),b=t(`^clear\\s+with\\s+(@?[\\w.]+)$`),x=t(`^variant\\s+(@?[\\w.]+)\\s*$`),S=t(`^enters\\s+on\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$`),C=t(`^(increment|decrement|count|clear)\\s+(@?[$\\w.]+)$`),w=t(`^(add|subtract)\\s+(@?[$\\w.]+)\\s+by\\s+(.+?)(?:\\s+\\*\\s+(.+))?$`),T=t(`^set\\s+(@?[$\\w.]+)\\s+(?:=|to)\\s+(.+)$`),E=t(`^(@?[$\\w.@]+)\\s*=(?!=|>)\\s*(.+)$`),D={increment:`IncrementMappingSyntax`,decrement:`DecrementMappingSyntax`,clear:`ClearMappingSyntax`,count:`CountMappingSyntax`};function parseProjection(t,r){let a=f.exec(r.content);if(a===null)return t.error(e.InvalidProjectionDeclaration,`Invalid projection declaration '${r.content}' - expected 'projection <Name> [=> <ReadModel>]'`,n(r)),t.skipBlock(r.indent),{kind:`ProjectionSyntax`,sourceOptions:t.sourceOptions,name:i(r.content),readModel:null,sequence:null,autoMap:`Inherit`,blocks:[],location:n(r)};let o=a[1],s=null,u=null,p=`Inherit`,m=null,h=[];for(let e=t.peekChild(r.indent);e!==void 0;e=t.peekChild(r.indent)){if(t.reader.takeSignificant(),l(e))continue;let n=i(e.content);if(n===`description`)u=c(t,e,u,`Projection '${o}'`);else if(n===`sequence`)s=e.content.substring(8).trim();else if(n===`automap`)p=`Enabled`;else if(e.content===`no automap`)p=`Disabled`;else if(n===`key`)m=parseKey(t,e);else if(n===`variant`)h.push(parseVariant(t,e));else{let n=parseBlock(t,e,!1);n!==void 0&&h.push(n)}}return reportVariantConflicts(t,h,o),d(t,o,h),h.length===0&&t.error(e.EmptyProjection,`Projection '${o}' must contain at least one directive`,n(r)),{kind:`ProjectionSyntax`,sourceOptions:t.sourceOptions,name:o,readModel:a[2]??null,sequence:s,autoMap:p,key:m,blocks:h,description:u,location:n(r)}}function reportVariantConflicts(t,n,r){let i=n.filter(e=>e.kind===`ProjectionVariantSyntax`),a=/* @__PURE__ */ new Map;i.forEach(e=>a.set(e.name,[...a.get(e.name)??[],e]));for(let n of[...a.values()].flatMap(e=>e.slice(1)))t.error(e.DuplicateProjectionVariant,`Duplicate variant '${n.name}' - a variant name is declared once`,n.location);let o=/* @__PURE__ */ new Set;for(let i of n.flatMap(e=>e.kind===`ProjectionVariantSyntax`?e.entersOn:[]))i.event.length>0&&o.has(i.event)&&t.error(e.DuplicateVariantEnteringEvent,`Entering event '${i.event}' is claimed more than once in projection '${r}'`,i.location),o.add(i.event)}function parseBlock(t,r,a){let o=n(r);switch(i(r.content)){case`from`:return parseFrom(t,r);case`every`:{let e=!0,{autoMap:n,mappings:i}=parseMappingBlock(t,r,t=>t.content===`exclude children`&&(e=!1,!0));return{kind:`EverySyntax`,includeChildren:e,autoMap:n,mappings:i,location:o}}case`all`:{let{autoMap:e,mappings:n}=parseMappingBlock(t,r);return{kind:`AllSyntax`,autoMap:e,mappings:n,location:o}}case`join`:return parseJoin(t,r);case`children`:return parseChildren(t,r);case`nested`:return parseNested(t,r);case`remove`:return parseRemove(t,r);case`clear`:return a||t.error(e.ClearWithOutsideNestedBlock,`'clear with' is only valid inside a nested block`,o),parseClearWith(t,r);default:t.error(e.UnknownProjectionDirective,`Unexpected '${i(r.content)}' in projection body`,o),t.skipBlock(r.indent);return}}function parseFrom(t,r){let s=[];for(let i of a(r.content.substring(4),`,`)){let a=i.trim();if(a.length===0){t.error(e.FromWithoutEvent,`Expected an event type after 'from'`,n(r));continue}let c=p.exec(a);c===null?t.error(e.InvalidEventReference,`Invalid event reference '${a}'`,n(r)):s.push({kind:`EventSpecSyntax`,event:o(c[1]),key:c[2]===void 0?null:u(c[2],n(r),t),location:n(r)})}let c=[],l=null,d=null;for(let e=t.peekChild(r.indent);e!==void 0;e=t.peekChild(r.indent)){t.reader.takeSignificant();let r=i(e.content);r===`key`?l=parseKey(t,e):r===`parent`?d=u(e.content.substring(6),n(e),t):pushMapping(t,e,c)}return{kind:`FromSyntax`,events:s,key:l,parentKey:d,mappings:c,location:n(r)}}function parseJoin(t,r){let i=m.exec(r.content);if(i===null)return t.error(e.InvalidJoinDeclaration,`Invalid join declaration '${r.content}' - expected 'join <property> on <key>'`,n(r)),t.skipBlock(r.indent),{kind:`JoinSyntax`,property:``,on:``,events:[],location:n(r)};let a=[];for(let i=t.peekChild(r.indent);i!==void 0;i=t.peekChild(r.indent)){t.reader.takeSignificant();let r=h.exec(i.content);if(r===null){t.error(e.JoinWithoutEvent,`Expected 'with <EventType>' in join block, got '${i.content}'`,n(i)),t.skipBlock(i.indent);continue}let{autoMap:s,mappings:c}=parseMappingBlock(t,i);a.push({kind:`JoinEventSyntax`,event:o(r[1]),autoMap:s,mappings:c,location:n(i)})}return{kind:`JoinSyntax`,property:o(i[1]),on:o(i[2]),events:a,location:n(r)}}function parseChildren(t,r){let i=g.exec(r.content);if(i===null)return t.error(e.InvalidChildrenDeclaration,`Invalid children declaration '${r.content}' - expected 'children <collection> identified by <key>'`,n(r)),t.skipBlock(r.indent),{kind:`ChildrenSyntax`,property:``,autoMap:`Inherit`,blocks:[],location:n(r)};let{autoMap:a,blocks:s}=parseChildBlocks(t,r);return{kind:`ChildrenSyntax`,property:o(i[1]),identifiedBy:u(i[2],n(r),t),autoMap:a,blocks:s,location:n(r)}}function parseNested(t,r){let i=_.exec(r.content);if(i===null)return t.error(e.InvalidNestedDeclaration,`Invalid nested declaration '${r.content}' - expected 'nested <property>'`,n(r)),t.skipBlock(r.indent),{kind:`NestedSyntax`,property:``,autoMap:`Inherit`,blocks:[],location:n(r)};let a=o(i[1]),{autoMap:s,blocks:c}=parseChildBlocks(t,r);return c.some(e=>e.kind===`FromSyntax`)||t.error(e.NestedBlockWithoutFrom,`Nested block '${a}' must contain at least one 'from' directive`,n(r)),{kind:`NestedSyntax`,property:a,autoMap:s,blocks:c,location:n(r)}}function parseChildBlocks(e,t){let n=[],r=`Inherit`;for(let i=e.peekChild(t.indent);i!==void 0;i=e.peekChild(t.indent)){if(e.reader.takeSignificant(),i.content===`automap`){r=`Enabled`;continue}if(i.content===`no automap`){r=`Disabled`;continue}let t=parseBlock(e,i,!0);t!==void 0&&n.push(t)}return{autoMap:r,blocks:n}}function parseRemove(t,r){let a=y.exec(r.content);if(a!==null)return{kind:`RemoveViaJoinSyntax`,event:o(a[1]),key:a[2]===void 0?null:u(a[2],n(r),t),location:n(r)};let s=v.exec(r.content);if(s===null){t.error(e.InvalidRemoveDeclaration,`Invalid remove declaration '${r.content}' - expected 'remove with <EventType>' or 'remove via join on <EventType>'`,n(r)),t.skipBlock(r.indent);return}let c=s[2]===void 0?null:u(s[2],n(r),t),l=null,d=null;for(let a=t.peekChild(r.indent);a!==void 0;a=t.peekChild(r.indent))if(t.reader.takeSignificant(),i(a.content)===`parent`)d=u(a.content.substring(6),n(a),t);else if(i(a.content)===`key`){(c!==null||l!==null)&&t.error(e.InvalidReadModelKeyLookup,`A removal can only declare one key.`,n(a));let r=parseKey(t,a);r.kind===`CompositeKeySyntax`?l=r:c=r.expression}else t.error(e.UnknownRemoveDirective,`Unexpected '${a.content}' in remove block - only 'parent' or 'key' is allowed`,n(a));return{kind:`RemoveWithSyntax`,event:o(s[1]),key:c,...l===null?{}:{partsKey:l},parentKey:d,location:n(r)}}function parseClearWith(t,r){let i=b.exec(r.content);return i===null?(t.error(e.InvalidClearDeclaration,`Invalid clear declaration '${r.content}' - expected 'clear with <EventType>'`,n(r)),{kind:`ClearWithSyntax`,event:``,location:n(r)}):{kind:`ClearWithSyntax`,event:o(i[1]),location:n(r)}}function parseVariant(t,r){let a=x.exec(r.content);if(a===null)return t.error(e.InvalidProjectionVariantDeclaration,`Invalid variant declaration '${r.content}' - expected 'variant <Name>'`,n(r)),t.skipBlock(r.indent),{kind:`ProjectionVariantSyntax`,name:i(r.content),entersOn:[],blocks:[],location:n(r)};let s=o(a[1]),c=[],l=[];for(let a=t.peekChild(r.indent);a!==void 0;a=t.peekChild(r.indent)){t.reader.takeSignificant();let r=i(a.content);if(r===`enters`)c.push(parseEntersOn(t,a));else if(r===`variant`)t.error(e.NestedProjectionVariantNotAllowed,`A variant cannot be declared inside another variant`,n(a)),t.skipBlock(a.indent);else{let e=parseBlock(t,a,!1);e!==void 0&&l.push(e)}}return c.length===0&&t.error(e.VariantRequiresEnteringEvent,`Variant '${s}' must declare at least one 'enters on' event`,n(r)),{kind:`ProjectionVariantSyntax`,name:s,entersOn:c,blocks:l,location:n(r)}}function parseEntersOn(t,r){let i=S.exec(r.content);return i===null?(t.error(e.InvalidEntersOnDeclaration,`Invalid 'enters on' declaration '${r.content}' - expected 'enters on <EventType> [key <expression>]'`,n(r)),t.skipBlock(r.indent),{kind:`ProjectionEntersOnSyntax`,event:``,key:null,location:n(r)}):{kind:`ProjectionEntersOnSyntax`,event:o(i[1]),key:i[2]===void 0?null:u(i[2],n(r),t),location:n(r)}}function parseKey(t,r){let i=r.content.substring(3).trim();if(t.peekChild(r.indent)===void 0)return{kind:`ExpressionKeySyntax`,expression:u(i,n(r),t),location:n(r)};i.endsWith(`{`)&&t.information(e.RedundantCompositeKeyBraces,`Write the composite key without braces; the indented parts already belong to the key.`,n(r));let a=[];for(let s=t.peekChild(r.indent);s!==void 0;s=t.peekChild(r.indent)){if(t.reader.takeSignificant(),s.content===`}`)continue;let r=E.exec(s.content);if(r===null){t.sourceOptions.numericMode===`exact`&&t.error(e.InvalidCompositeKeyPart,`Invalid composite key part '${s.content}' - expected '<property> = <expression>'`,n(s));continue}let c=u(r[2],n(s),t);t.sourceOptions.numericMode===`exact`&&i.replace(/\{$/,``).trim().length>0&&c.kind===`TemplateExpressionSyntax`&&t.error(e.TemplateInCompositeKey,`Template expressions are not allowed in composite keys`,n(s)),a.push({kind:`KeyPartSyntax`,property:o(r[1]),expression:c,location:n(s)})}let s=t.reader.peekSignificant();return s!==void 0&&s.indent===r.indent&&s.content===`}`&&t.reader.takeSignificant(),t.sourceOptions.numericMode===`exact`&&a.length===0&&t.error(e.EmptyCompositeKey,`Composite keys must contain at least one part`,n(r)),{kind:`CompositeKeySyntax`,type:i.replace(/\{$/,``).trim(),parts:a,location:n(r)}}function parseMappingBlock(e,t,n=()=>!1){let r=`Inherit`,i=[];for(let a=e.peekChild(t.indent);a!==void 0;a=e.peekChild(t.indent))e.reader.takeSignificant(),a.content===`automap`?r=`Enabled`:a.content===`no automap`?r=`Disabled`:n(a)||pushMapping(e,a,i);return{autoMap:r,mappings:i}}function pushMapping(t,i,a){let c=n(i),l=C.exec(i.content);if(l!==null){l[1]!==`clear`||l[2]!==`with`?a.push({kind:D[l[1]],property:o(l[2]),location:c}):t.sourceOptions.numericMode===`exact`&&t.error(e.InvalidProjectionMapping,`Invalid mapping '${i.content}' - 'clear with' is a block directive and needs an event type; to clear a property named 'with', write 'clear @with'`,c,r(`text`,i.content));return}let d=w.exec(i.content);if(d!==null){a.push({kind:d[1]===`add`?`AddMappingSyntax`:`SubtractMappingSyntax`,property:o(d[2]),value:u(d[3],c,t),...d[4]===void 0?{}:{factor:u(d[4],c,t)},location:c});return}let f=T.exec(i.content)??E.exec(i.content);if(f!==null){a.push({kind:`SetMappingSyntax`,property:o(f[1]),source:u(f[2],c,t),location:c});return}let p=t.sourceOptions.numericMode===`exact`?s(t,i):void 0;p===void 0?t.sourceOptions.numericMode===`exact`&&t.error(e.InvalidProjectionMapping,`Invalid mapping '${i.content}'`,c,r(`text`,i.content)):a.push({kind:`SetMappingSyntax`,property:p.property,source:p.source,location:c})}export{parseProjection};
|
|
2
2
|
//# sourceMappingURL=ProjectionParser.js.map
|