@cratis/screenplay-language 5.3.2 → 5.4.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.
@@ -1 +1 @@
1
- {"version":3,"file":"ScreenplayParser.js","names":["domainPattern","pattern","timeZonePattern","stringBodyPattern","importPattern","conceptPattern","enumValuePattern","personaPattern","personaPolicyPattern","personaGoalPattern","stickyNotePattern","stickyNoteColourPattern","tabIndentPattern","primitiveTypes","opaqueTopLevel","bodyKeywords","documentPlacement","context","lines","moduleBody","placement","ModuleBody","featureBody","FeatureBody","placedBody","identity","applicationContext","reactionProductionMode","sawReactionBatches","commandReadMode","timeZone","sawTimeZone","sawCommandReads","domain","imports","fileImports","concepts","types","systems","stateMachines","workflows","eventSources","modules","personas","stickyNotes","policies","purposes","seeds","examples","declaredTriggers","exposures","instanceContributions","sawOtherConstruct","line","keyword","firstWord","isDocumentPlacement","DiagnosticCodes","locationOf","match","unescapeString","misplacedReactionIdentity","isFileImport","parseFileImport","origin","isBlankPublicEventOrigin","parseExample","parseEventSource","parseSystem","parseStateMachine","parseWorkflow","parseType","parseModule","stickyNote","parseSeed","parsePurpose","parseApplicationContext","parseIdentity","policy","parsePolicy","previous","parseExposure","parseInstance","data","parseTriggerDeclaration","name","collectInputUses","parseUiProfile","root","recordAuthoredDocument","modulePattern","describePlacement","word","hint","expected","moduleBodyExpected","featureBodyExpected","feature","innermost","index","start","existing","inFence","startOf","type","attributeText","attributes","parseComplianceMarkers","values","members","EnumerationMembers","generation","declaredGeneration","description","validations","child","memberName","parseDescription","isFileDirective","parsed","parseValidate","parseGeneration","parseComplianceDirective","unescapeIdentifier","valueNumbers","goals","position","size","goal","parseCanvasPair","canvasMatch","text","colour"],"sources":["../../../../../../Compiler/Parsing/ScreenplayParser.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 { CommandReadMode } from '../Syntax/CommandReadMode';\nimport { ReactionProductionMode } from '../Syntax/ReactionProductionMode';\nimport { EnumerationMembers } from './EnumerationMembers';\nimport { GenerationSyntax } from '../Syntax/GenerationSyntax';\nimport { parseGeneration } from './GenerationParser';\nimport { IdentitySyntax } from '../Syntax/IdentitySyntax';\nimport { parseIdentity } from './IdentityParser';\nimport { parseApplicationContext } from './ApplicationContextParser';\nimport { misplacedReactionIdentity } from './ReactionIdentityParser';\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { recordAuthoredDocument } from '../Syntax/SourceOptions';\nimport { SourceLocation } from '../Diagnostics/SourceLocation';\nimport { describePlacement, documentPlacement, isDocumentPlacement, PlayPlacement } from '../Files/PlayPlacement';\nimport { PersonaSyntax, StickyNoteSyntax } from '../Syntax/Authorization';\nimport { ConceptSyntax, DomainSyntax, ImportSyntax, TypeSyntax } from '../Syntax/Declarations';\nimport { SpecificationExampleSyntax } from '../Syntax/Specifications';\nimport { TimeZoneSyntax } from '../Syntax/Calendar';\nimport { ApplicationContextSyntax, ApplicationSyntax, FeatureSyntax, FileImportSyntax, ModuleSyntax } from '../Syntax/Structure';\nimport { parseTriggerDeclaration } from './TriggerDataParser';\nimport { pattern } from '../Text/patterns';\nimport { parseComplianceDirective, parseComplianceMarkers } from './ConceptComplianceParser';\nimport { parseType } from './DeclarationParsers';\nimport { ValidateSyntax } from '../Syntax/Commands';\nimport { parseValidate } from './CommandParser';\nimport { parseDescription } from './DescriptionParser';\nimport { FeatureBody, featureBodyExpected } from './FeatureBody';\nimport { isFileImport, parseFileImport } from './FileImportParser';\nimport { isFileDirective } from './FileReferences';\nimport { collectInputUses } from './InputUses';\nimport { firstWord, unescapeIdentifier } from './LineText';\nimport { ModuleBody, moduleBodyExpected, modulePattern, parseModule } from './ModuleBody';\nimport { ParserContext } from './ParserContext';\nimport { PolicySyntax } from '../Syntax/Policies';\nimport { parsePolicy } from './PolicyParser';\nimport { PurposeSyntax } from '../Syntax/Purposes';\nimport { parsePurpose } from './PurposeParser';\nimport { SeedSyntax } from '../Syntax/Seeds';\nimport { parseSeed } from './SeedParser';\nimport { parseSystem } from './OperationParser';\nimport { parseStateMachine } from './StateMachineParser';\nimport { parseWorkflow } from './WorkflowParser';\nimport { StateMachineSyntax, WorkflowSyntax } from '../Syntax/Lifecycles';\nimport { EventVisibility } from '../Syntax/EventVisibility';\nimport { isBlankPublicEventOrigin } from '../Syntax/PublicEventInvariants';\nimport { stringBodyPattern, unescapeString } from '../Text/StringLiteral';\nimport { SystemSyntax } from '../Syntax/Operations';\nimport { EventSourceSyntax } from '../Syntax/EventSources';\nimport { parseCanvasPair } from './CanvasPlacement';\nimport { parseEventSource } from './EventSourceParser';\nimport { parseExposure, parseInstance } from './CompositionParser';\nimport { ExposureSyntax, InstanceContributionsSyntax } from '../Syntax/CompositionSyntax';\nimport { parseExample } from './SpecificationExampleParser';\nimport { parseUiProfile } from './UiProfileLegacyLayout';\nimport { locationOf, SourceLine, startOf } from './SourceLine';\n\nconst domainPattern = pattern('^domain\\\\s+([A-Za-z_]\\\\w*(?:\\\\.[A-Za-z_]\\\\w*)*)$');\nconst timeZonePattern = pattern(`^time\\\\s+zone\\\\s+(configurable\\\\s+default\\\\s+)?\"(${stringBodyPattern})\"$`);\nconst importPattern = pattern(`^import\\\\s+([\\\\w.]+)(?:\\\\s+from\\\\s+\"(?<origin>${stringBodyPattern})\")?$`);\nconst conceptPattern = pattern('^concept\\\\s+(\\\\w+)\\\\s*:\\\\s*(\\\\w+)((?:\\\\s+@?\\\\w+)*)$');\nconst enumValuePattern = pattern('^@?[a-z_]\\\\w*$');\nconst personaPattern = pattern('^persona\\\\s+([A-Za-z_]\\\\w*)$');\nconst personaPolicyPattern = pattern('^policy\\\\s+([A-Za-z_]\\\\w*)$');\nconst personaGoalPattern = pattern(`^goal\\\\s+\"(${stringBodyPattern})\"$`);\nconst stickyNotePattern = pattern('^sticky\\\\s+note\\\\s+on\\\\s+(personas|eventsources|givencontexts|seeddata)$');\nconst stickyNoteColourPattern = pattern('^colour\\\\s+(yellow|pink|green|blue)$');\nconst tabIndentPattern = /^[ ]*\\t/;\nconst primitiveTypes = ['Uuid', 'String', 'Int', 'Decimal', 'Bool', 'Date', 'DateTime'];\n\n// Top-level, module and feature constructs the C# compiler knows that this compiler does not model. They\n// are skipped whole, not reported.\nconst opaqueTopLevel = new Set(['policy', 'authentication', 'onboarding', 'seed', 'ui', 'theme', 'trigger', 'layout', 'behavior', 'sample']);\n\n// What belongs in a module or feature body; at the top level of a whole document it gets a hint saying so.\nconst bodyKeywords = new Set(['slice', 'feature', 'description', 'documentation', 'authorize', 'screen', 'dialog', 'form', 'contribute', 'on', 'uses']);\n\n// Parses one document into its application syntax - the port of the C# ScreenplayParser. The placement says\n// where the document's top level belongs: the application, unless an import placed it in a module or feature.\nexport function parseApplication(context: ParserContext, lines: readonly SourceLine[], placement: PlayPlacement = documentPlacement): ApplicationSyntax {\n context.deferIdentityValidation = true;\n warnOnTabIndentation(context, lines);\n const moduleBody = placement.length === 1 ? new ModuleBody(placement[0]) : undefined;\n const featureBody = placement.length > 1 ? new FeatureBody(placement[placement.length - 1]) : undefined;\n const placedBody = moduleBody ?? featureBody;\n let identity: IdentitySyntax | null = null;\n let applicationContext: ApplicationContextSyntax | null = null;\n let reactionProductionMode: ReactionProductionMode | null = null;\n let sawReactionBatches = false;\n let commandReadMode: CommandReadMode | null = null;\n let timeZone: TimeZoneSyntax | null = null;\n let sawTimeZone = false;\n let sawCommandReads = false;\n let domain: DomainSyntax | null = null;\n const imports: ImportSyntax[] = [];\n const fileImports: FileImportSyntax[] = [];\n const concepts: ConceptSyntax[] = [];\n const types: TypeSyntax[] = [];\n const systems: SystemSyntax[] = [];\n const stateMachines: StateMachineSyntax[] = [];\n const workflows: WorkflowSyntax[] = [];\n const eventSources: EventSourceSyntax[] = [];\n const modules: ModuleSyntax[] = [];\n const personas: PersonaSyntax[] = [];\n const stickyNotes: StickyNoteSyntax[] = [];\n const policies: PolicySyntax[] = [];\n const purposes: PurposeSyntax[] = [];\n const seeds: SeedSyntax[] = [];\n const examples: SpecificationExampleSyntax[] = [];\n const declaredTriggers: NonNullable<ApplicationSyntax['declaredTriggers']>[number][] = [];\n const exposures: ExposureSyntax[] = [];\n const instanceContributions: InstanceContributionsSyntax[] = [];\n let sawOtherConstruct = false;\n for (let line = context.reader.peekSignificant(); line !== undefined; line = context.reader.peekSignificant()) {\n context.reader.takeSignificant();\n const keyword = firstWord(line.content);\n if (keyword === 'command' && /^command\\s+reads(?:\\s|$)/.test(line.content)) {\n if (sawCommandReads || !isDocumentPlacement(placement) || !/^command\\s+reads\\s+protected$/.test(line.content)) {\n context.error(DiagnosticCodes.InvalidCommandReadsDeclaration, \"Declare 'command reads protected' once at the application root.\", locationOf(line));\n } else {\n commandReadMode = CommandReadMode.Protected;\n }\n sawCommandReads = true;\n continue;\n }\n if (keyword === 'time' && /^time\\s+zone(?:\\s|$)/.test(line.content)) {\n const match = timeZonePattern.exec(line.content);\n context.skipBlock(line.indent);\n if (sawTimeZone || !isDocumentPlacement(placement) || match === null) {\n context.error(DiagnosticCodes.InvalidTimeZoneDeclaration, \"Declare 'time zone \\\"<id>\\\"' or 'time zone configurable default \\\"<id>\\\"' once at the application root.\", locationOf(line));\n } else {\n timeZone = { kind: 'TimeZoneSyntax', id: unescapeString(match[2]), configurable: match[1] !== undefined, location: locationOf(line) };\n }\n sawTimeZone = true;\n continue;\n }\n if (keyword === 'reaction') {\n if (sawReactionBatches || !isDocumentPlacement(placement) || !/^reaction\\s+batches\\s+atomic$/.test(line.content)) {\n context.error(DiagnosticCodes.InvalidReactionBatchesDeclaration, \"Declare 'reaction batches atomic' once at the application root.\", locationOf(line));\n } else {\n reactionProductionMode = ReactionProductionMode.Atomic;\n }\n sawReactionBatches = true;\n continue;\n }\n if (keyword === 'runs') {\n misplacedReactionIdentity(context, line);\n continue;\n }\n if (keyword === 'domain') {\n context.authoredDeclarations = true;\n domain = parseDomain(context, line, domain, sawOtherConstruct);\n continue;\n }\n // The C# parser asks whether anything was declared before the domain, so an import it rejected,\n // a file import and an unknown construct do not count.\n sawOtherConstruct ||= declaresConstruct(keyword, line, placement);\n context.authoredDeclarations ||= keyword !== 'import' && declaresConstruct(keyword, line, placement);\n if (keyword === 'import' && isFileImport(line.content)) {\n // A top level import belongs to whatever the document's top level is - the application, or the\n // module or feature the document was itself imported into.\n if (placedBody !== undefined) {\n placedBody.tryParse(context, line);\n } else {\n parseFileImport(context, line, fileImports);\n }\n } else if (keyword === 'import') {\n const match = importPattern.exec(line.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidImportDeclaration, `Invalid import '${line.content}' - expected 'import <Qualified.Name> [from \"<origin>\"]'`, locationOf(line));\n } else {\n const origin = match.groups?.origin === undefined ? null : unescapeString(match.groups.origin);\n if (origin !== null && isBlankPublicEventOrigin(origin)) {\n context.error(DiagnosticCodes.InvalidImportDeclaration, 'An import origin must be a nonblank quoted string', locationOf(line));\n }\n imports.push({ kind: 'ImportSyntax', qualifiedName: match[1], origin, visibility: origin === null ? EventVisibility.Private : EventVisibility.Public, location: locationOf(line) });\n }\n } else if (keyword === 'example') {\n if (placedBody !== undefined) placedBody.tryParse(context, line);\n else examples.push(parseExample(context, line));\n } else if (keyword === 'eventsource') {\n eventSources.push(parseEventSource(context, line));\n } else if (keyword === 'system') {\n systems.push(parseSystem(context, line));\n } else if (keyword === 'statemachine') {\n stateMachines.push(parseStateMachine(context, line));\n } else if (keyword === 'workflow') {\n workflows.push(parseWorkflow(context, line));\n } else if (keyword === 'concept') {\n concepts.push(parseConcept(context, line));\n } else if (keyword === 'type') {\n types.push(parseType(context, line));\n } else if (keyword === 'module' && !isDocumentPlacement(placement)) {\n parseModuleInPlacedFile(context, line, placement, moduleBody);\n } else if (keyword === 'module') {\n modules.push(parseModule(context, line));\n } else if (keyword === 'persona') {\n personas.push(parsePersona(context, line));\n } else if (keyword === 'sticky') {\n const stickyNote = parseStickyNote(context, line);\n if (stickyNote !== null) stickyNotes.push(stickyNote);\n } else if (keyword === 'seed') {\n seeds.push(parseSeed(context.valueContext, line));\n } else if (keyword === 'purpose' && placedBody !== undefined) {\n placedBody.tryParse(context, line);\n } else if (keyword === 'purpose') {\n purposes.push(parsePurpose(context, line));\n } else if (keyword === 'context') {\n applicationContext = parseApplicationContext(context, line, applicationContext, placement);\n } else if (keyword === 'identity') {\n identity = parseIdentity(context, line, identity);\n } else if (keyword === 'policy') {\n const policy = parsePolicy(context, line);\n if (policies.some(previous => previous.name === policy.name)) {\n context.error(DiagnosticCodes.DuplicateDeclaration, `Duplicate declaration of policy '${policy.name}' - policy names must be unique`, policy.location);\n }\n policies.push(policy);\n } else if (keyword === 'exposure') {\n exposures.push(parseExposure(context, line));\n } else if (keyword === 'instance') {\n instanceContributions.push(parseInstance(context, line));\n } else if (keyword === 'trigger') {\n const data = parseTriggerDeclaration(context, line);\n const name = /^trigger\\s+([A-Za-z_]\\w*)$/.exec(line.content)?.[1];\n if (name !== undefined) declaredTriggers.push({ name, data });\n } else if (opaqueTopLevel.has(keyword)) {\n if (keyword === 'behavior' || keyword === 'layout') collectInputUses(context, line);\n else if (keyword === 'ui') parseUiProfile(context, line);\n else context.skipOpaqueBlock(line.indent);\n } else if (placedBody?.tryParse(context, line) !== true) {\n reportUnexpectedTopLevel(context, line, placement);\n }\n }\n if (moduleBody !== undefined) {\n modules.unshift(moduleBody.build(context.start, true));\n } else if (featureBody !== undefined) {\n modules.unshift(place(placement, featureBody.build(context.start, true), context.start));\n }\n const root: ApplicationSyntax = { kind: 'ApplicationSyntax', ...(commandReadMode === null ? {} : { commandReadMode }), ...(timeZone === null ? {} : { timeZone }), ...(applicationContext === null ? {} : { context: applicationContext }), ...(reactionProductionMode === null ? {} : { reactionProductionMode }), ...(identity === null ? {} : { identity }), sourceOptions: context.sourceOptions, domain, imports, concepts, types, systems, ...(stateMachines.length > 0 ? { stateMachines } : {}), ...(workflows.length > 0 ? { workflows } : {}), eventSources, examples, modules, personas, policies, purposes, seeds, declaredTriggers, fileImports, ...(exposures.length > 0 ? { exposures } : {}), ...(stickyNotes.length > 0 ? { stickyNotes } : {}), ...(instanceContributions.length > 0 ? { instanceContributions } : {}), location: context.start };\n if (context.authoredDeclarations) recordAuthoredDocument(root);\n return root;\n}\n\nfunction declaresConstruct(keyword: string, line: SourceLine, placement: PlayPlacement): boolean {\n if (keyword === 'import') {\n return importPattern.test(line.content);\n }\n if (keyword === 'module') {\n return isDocumentPlacement(placement);\n }\n if (keyword === 'identity') return line.content === 'identity';\n if (keyword === 'context') return line.content === 'context';\n return keyword === 'purpose' || keyword === 'example' || keyword === 'exposure' || keyword === 'instance' || keyword === 'eventsource' || keyword === 'system' || keyword === 'statemachine' || keyword === 'workflow' || keyword === 'concept' || keyword === 'type' || keyword === 'persona' || keyword === 'sticky' || opaqueTopLevel.has(keyword);\n}\n\nfunction parseModuleInPlacedFile(context: ParserContext, line: SourceLine, placement: PlayPlacement, moduleBody: ModuleBody | undefined): void {\n const name = modulePattern.exec(line.content)?.[1] ?? '';\n\n // Restating the module a file is placed in says nothing new, so its body simply joins the placement.\n if (moduleBody !== undefined && name === placement[0]) {\n context.authoredDeclarations = true;\n moduleBody.parseChildren(context, line);\n return;\n }\n context.error(DiagnosticCodes.ModuleInPlacedFile,\n `This file is imported into ${describePlacement(placement)}, so it cannot declare module '${name}' - import it at the top level of a document instead`, locationOf(line));\n context.skipBlock(line.indent);\n}\n\nfunction reportUnexpectedTopLevel(context: ParserContext, line: SourceLine, placement: PlayPlacement): void {\n const word = firstWord(line.content);\n if (!isDocumentPlacement(placement)) {\n const expected = placement.length === 1 ? moduleBodyExpected : featureBodyExpected;\n context.error(DiagnosticCodes.UnexpectedInPlacedFile,\n `Unexpected '${word}' in a file imported into ${describePlacement(placement)} - expected an application declaration or ${expected}`, locationOf(line));\n } else {\n const hint = bodyKeywords.has(word)\n ? ` - '${word}' belongs in a module or feature; wrap it in one, or import this file from inside one`\n : ' - expected domain, import, concept, type, policy, persona, sticky note, authentication, onboarding, identity, context, module, seed, trigger, behavior, ui profile, theme, sample data or layout';\n context.error(DiagnosticCodes.UnknownTopLevelConstruct, `Unexpected '${word}' at the top level${hint}`, locationOf(line));\n }\n context.skipBlock(line.indent);\n}\n\n// Wraps the feature a file is placed in in the features and module around it, each marked as a placement.\nfunction place(placement: PlayPlacement, innermost: FeatureSyntax, start: SourceLocation): ModuleSyntax {\n let feature = innermost;\n for (let index = placement.length - 2; index >= 1; index--) {\n feature = {\n kind: 'FeatureSyntax', name: placement[index], description: null, authorize: null,\n features: [feature], slices: [], fileImports: [], isPlacement: true, location: start,\n };\n }\n return {\n kind: 'ModuleSyntax', name: placement[0], description: null, authorize: null,\n features: [feature], fileImports: [], isPlacement: true, location: start,\n };\n}\n\nfunction parseDomain(context: ParserContext, line: SourceLine, existing: DomainSyntax | null, sawOtherConstruct: boolean): DomainSyntax | null {\n const match = domainPattern.exec(line.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidDomainDeclaration, `Invalid domain declaration '${line.content}' - expected 'domain <Qualified.Name>'`, locationOf(line));\n return existing;\n }\n if (existing !== null) {\n context.error(DiagnosticCodes.DuplicateDomain, 'The document already declares a domain - a document can have at most one', locationOf(line));\n return existing;\n }\n if (sawOtherConstruct) {\n context.error(DiagnosticCodes.DomainNotFirst, '\\'domain\\' must be declared before any other construct', locationOf(line));\n }\n return { kind: 'DomainSyntax', name: match[1], location: locationOf(line) };\n}\n\nfunction warnOnTabIndentation(context: ParserContext, lines: readonly SourceLine[]): void {\n let inFence = false;\n for (const line of lines) {\n if (line.raw.trimStart().startsWith('```')) {\n inFence = !inFence;\n continue;\n }\n if (!inFence && tabIndentPattern.test(line.raw)) {\n context.warning(DiagnosticCodes.TabIndentation, 'Screenplay is indentation based - use spaces, not tabs', startOf(line));\n }\n }\n}\n\nfunction parseConcept(context: ParserContext, line: SourceLine): ConceptSyntax {\n const match = conceptPattern.exec(line.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidConceptDeclaration, `Invalid concept declaration '${line.content}' - expected 'concept <Name> : <Type>'`, locationOf(line));\n context.skipBlock(line.indent);\n return { kind: 'ConceptSyntax', name: firstWord(line.content), type: '', attributes: [], values: [], location: locationOf(line) };\n }\n const [, name, type, attributeText] = match;\n const attributes = parseComplianceMarkers(context, line, name, attributeText);\n if (type !== 'Enum' && !primitiveTypes.includes(type)) {\n context.error(DiagnosticCodes.UnknownPrimitiveType, `Unknown primitive type '${type}' - expected ${primitiveTypes.join(', ')} or Enum`, locationOf(line));\n }\n const values: string[] = [];\n const members = new EnumerationMembers();\n let generation: GenerationSyntax | null = null;\n let declaredGeneration = false;\n let description: string | null = null;\n const validations: ValidateSyntax[] = [];\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n const memberName = type === 'Enum' ? members.tryNumbered(context, child) : undefined;\n if (memberName !== undefined) {\n values.push(memberName);\n } else if (firstWord(child.content) === 'description' && (type !== 'Enum' || child.content !== 'description' || context.peekChild(child.indent)?.content.startsWith('```') === true)) {\n description = parseDescription(context, child, description, `Concept '${name}'`);\n } else if (isFileDirective(child)) {\n continue;\n } else if (firstWord(child.content) === 'validate') {\n if (type === 'Enum' && child.content === 'validate' && context.peekChild(child.indent) === undefined) {\n context.warning(DiagnosticCodes.ValidateReadAsEnumerationBlock,\n `'validate' in enumeration concept '${name}' declares an empty validate block, not a value named 'validate' - write '@validate' for the value`,\n locationOf(child));\n }\n const parsed = parseValidate(context, child, 'concept', name);\n if (parsed !== undefined) validations.push(parsed);\n } else if (firstWord(child.content) === 'generate' && !(type === 'Enum' && child.content === 'generate')) {\n if (declaredGeneration) context.error(DiagnosticCodes.DuplicateGeneration, `Concept '${name}' declares generation more than once.`, locationOf(child));\n const parsed = parseGeneration(context, child, type);\n if (!declaredGeneration) generation = parsed;\n declaredGeneration = true;\n } else if (parseComplianceDirective(context, child, name, attributes)) {\n // Compliance directives are modeled by their original concept marker.\n } else if (type === 'Enum' && enumValuePattern.test(child.content)) {\n values.push(unescapeIdentifier(child.content));\n } else if (type === 'Enum') {\n context.error(DiagnosticCodes.InvalidEnumerationValue, `Invalid enum value '${child.content}' - expected an identifier`, locationOf(child));\n } else {\n context.error(DiagnosticCodes.UnknownConceptDirective, `Unexpected '${child.content}' in concept body - expected validate, generate, 'file <path>' or '<attribute> reason \"<text>\"'`, locationOf(child));\n context.skipBlock(child.indent);\n }\n }\n const valueNumbers = members.finish(context, line, values.length);\n return { kind: 'ConceptSyntax', name, type, attributes, values, validations, description, ...(generation === null ? {} : { generation }), ...(valueNumbers === undefined ? {} : { valueNumbers }), location: locationOf(line) };\n}\n\n// 'persona <Name>' with an optional description and the policies it holds - the port of the C# ParsePersona.\nfunction parsePersona(context: ParserContext, line: SourceLine): PersonaSyntax {\n const name = personaPattern.exec(line.content)?.[1] ?? '';\n if (name === '') {\n context.error(DiagnosticCodes.InvalidPersonaDeclaration, `Invalid persona declaration '${line.content}' - expected 'persona <Name>'`, locationOf(line));\n }\n let description: string | null = null;\n const policies: string[] = [];\n const goals: string[] = [];\n let position: readonly [number, number] | null = null;\n let size: readonly [number, number] | null = null;\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n const keyword = firstWord(child.content);\n if (keyword === 'description') {\n description = parseDescription(context, child, description, `Persona '${name}'`);\n } else if (keyword === 'goal') {\n const goal = personaGoalPattern.exec(child.content);\n if (goal === null) {\n context.error(DiagnosticCodes.InvalidPersonaDeclaration, `Invalid goal '${child.content}' - expected 'goal \"<text>\"'`, locationOf(child));\n } else {\n goals.push(unescapeString(goal[1]));\n }\n } else if (keyword === 'position') {\n position = parseCanvasPair(context, child, 'position', 'x', 'y', position, true) ?? position;\n } else if (keyword === 'size') {\n size = parseCanvasPair(context, child, 'size', 'width', 'height', size, false) ?? size;\n } else if (keyword === 'policy') {\n const policy = personaPolicyPattern.exec(child.content);\n if (policy === null) {\n context.error(DiagnosticCodes.InvalidPersonaPolicyReference, `Invalid policy reference '${child.content}' - expected 'policy <Name>'`, locationOf(child));\n } else {\n policies.push(policy[1]);\n }\n } else {\n context.error(DiagnosticCodes.UnknownPersonaDirective, `Unexpected '${keyword}' in persona body - expected description, goal, policy, position or size`, locationOf(child));\n context.skipBlock(child.indent);\n }\n }\n return {\n kind: 'PersonaSyntax', name, description, policies,\n ...(goals.length > 0 ? { goals } : {}),\n ...(position === null ? {} : { x: position[0], y: position[1] }),\n ...(size === null ? {} : { width: size[0], height: size[1] }),\n location: locationOf(line),\n };\n}\n\n// 'sticky note on <canvas>' with the text it carries, an optional colour and where it sits on that canvas - the port of the C# ParseStickyNote.\nfunction parseStickyNote(context: ParserContext, line: SourceLine): StickyNoteSyntax | null {\n const canvasMatch = stickyNotePattern.exec(line.content);\n if (canvasMatch === null) {\n context.error(DiagnosticCodes.InvalidPersonaDeclaration, `Invalid sticky note declaration '${line.content}' - expected 'sticky note on personas', 'sticky note on eventsources', 'sticky note on givencontexts' or 'sticky note on seeddata'`, locationOf(line));\n context.skipBlock(line.indent);\n return null;\n }\n let text: string | null = null;\n let colour: string | null = null;\n let position: readonly [number, number] | null = null;\n let size: readonly [number, number] | null = null;\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n const keyword = firstWord(child.content);\n if (keyword === 'description') {\n text = parseDescription(context, child, text, 'A sticky note');\n } else if (keyword === 'colour') {\n const match = stickyNoteColourPattern.exec(child.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidPersonaDeclaration, `Invalid colour '${child.content}' - expected 'colour yellow', 'colour pink', 'colour green' or 'colour blue'`, locationOf(child));\n } else {\n colour = match[1];\n }\n } else if (keyword === 'position') {\n position = parseCanvasPair(context, child, 'position', 'x', 'y', position, true) ?? position;\n } else if (keyword === 'size') {\n size = parseCanvasPair(context, child, 'size', 'width', 'height', size, false) ?? size;\n } else {\n context.error(DiagnosticCodes.UnknownPersonaDirective, `Unexpected '${keyword}' in sticky note body - expected description, colour, position or size`, locationOf(child));\n context.skipBlock(child.indent);\n }\n }\n if (text === null || position === null) {\n context.error(DiagnosticCodes.InvalidPersonaDeclaration, 'A sticky note needs a description (the text on it) and a position', locationOf(line));\n return null;\n }\n return { kind: 'StickyNoteSyntax', canvas: canvasMatch[1] as StickyNoteSyntax['canvas'], text, colour, x: position[0], y: position[1], width: size === null ? null : size[0], height: size === null ? null : size[1], location: locationOf(line) };\n}\n\n"],"mappings":"A,0sEA0DA,MAAMA,EAAgBC,EAAQ,kDAAkD,EAC1EC,GAAkBD,EAAQ,oDAAoDE,EAAkB,IAAI,EACpGC,EAAgBH,EAAQ,iDAAiDE,EAAkB,MAAM,EACjGE,EAAiBJ,EAAQ,qDAAqD,EAC9EK,EAAmBL,EAAQ,gBAAgB,EAC3CM,EAAiBN,EAAQ,8BAA8B,EACvDO,EAAuBP,EAAQ,6BAA6B,EAC5DQ,EAAqBR,EAAQ,cAAcE,EAAkB,IAAI,EACjEO,EAAoBT,EAAQ,0EAA0E,EACtGU,EAA0BV,EAAQ,sCAAsC,EACxEW,EAAmB,UACnBC,EAAiB,CAAC,OAAQ,SAAU,MAAO,UAAW,OAAQ,OAAQ,UAAU,EAIhFC,kBAAiB,IAAI,IAAI,CAAC,SAAU,iBAAkB,aAAc,OAAQ,KAAM,QAAS,UAAW,SAAU,WAAY,QAAQ,CAAC,EAGrIC,kBAAe,IAAI,IAAI,CAAC,QAAS,UAAW,cAAe,gBAAiB,YAAa,SAAU,SAAU,OAAQ,aAAc,KAAM,MAAM,CAAC,EAItJ,SAAgB,iBAAiB,EAAwB,EAA8B,EAA2BC,EAAsC,CACpJ,EAAQ,wBAA0B,GAClC,qBAAqBC,EAASC,CAAK,EACnC,IAAMC,EAAaC,EAAU,SAAW,EAAI,IAAIC,GAAWD,EAAU,EAAE,EAAI,IAAA,GACrEE,EAAcF,EAAU,OAAS,EAAI,IAAIG,EAAYH,EAAUA,EAAU,OAAS,EAAE,EAAI,IAAA,GACxFI,EAAaL,GAAcG,EAC7BG,EAAkC,KAClCC,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AOC,IAAS,KAAO,KAAOA,EAAK,GAAI,OAAQA,IAAS,KAAO,KAAOA,EAAK,GAAI,SAAUrE,EAAWL,CAAI,CAAE,CACrP,C"}
1
+ {"version":3,"file":"ScreenplayParser.js","names":["domainPattern","pattern","timeZonePattern","stringBodyPattern","importPattern","conceptPattern","enumValuePattern","personaPattern","personaPolicyPattern","personaGoalPattern","stickyNotePattern","stickyNoteColourPattern","tabIndentPattern","primitiveTypes","opaqueTopLevel","bodyKeywords","documentPlacement","context","lines","moduleBody","placement","ModuleBody","featureBody","FeatureBody","placedBody","identity","applicationContext","reactionProductionMode","sawReactionBatches","commandReadMode","timeZone","sawTimeZone","sawCommandReads","domain","imports","fileImports","concepts","types","systems","stateMachines","workflows","eventSources","modules","personas","stickyNotes","policies","purposes","seeds","examples","declaredTriggers","exposures","instanceContributions","sawOtherConstruct","line","keyword","firstWord","isDocumentPlacement","DiagnosticCodes","locationOf","match","unescapeString","misplacedReactionIdentity","isFileImport","parseFileImport","origin","isBlankPublicEventOrigin","parseExample","parseEventSource","parseSystem","parseStateMachine","parseWorkflow","parseType","parseModule","stickyNote","parseSeed","parsePurpose","parseApplicationContext","parseIdentity","policy","parsePolicy","previous","parseExposure","parseInstance","data","parseTriggerDeclaration","name","collectInputUses","parseUiProfile","root","recordAuthoredDocument","modulePattern","describePlacement","word","hint","expected","moduleBodyExpected","featureBodyExpected","feature","innermost","index","start","existing","inFence","startOf","type","attributeText","attributes","parseComplianceMarkers","values","members","EnumerationMembers","generation","declaredGeneration","description","validations","child","memberName","parseDescription","isFileDirective","parsed","parseValidate","parseGeneration","parseComplianceDirective","unescapeIdentifier","misplacedRuleHintForConcept","valueNumbers","goals","position","size","goal","parseCanvasPair","canvasMatch","text","colour"],"sources":["../../../../../../Compiler/Parsing/ScreenplayParser.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 { CommandReadMode } from '../Syntax/CommandReadMode';\nimport { ReactionProductionMode } from '../Syntax/ReactionProductionMode';\nimport { EnumerationMembers } from './EnumerationMembers';\nimport { GenerationSyntax } from '../Syntax/GenerationSyntax';\nimport { misplacedRuleHintForConcept } from './MisplacedRuleHint';\nimport { parseGeneration } from './GenerationParser';\nimport { IdentitySyntax } from '../Syntax/IdentitySyntax';\nimport { parseIdentity } from './IdentityParser';\nimport { parseApplicationContext } from './ApplicationContextParser';\nimport { misplacedReactionIdentity } from './ReactionIdentityParser';\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { recordAuthoredDocument } from '../Syntax/SourceOptions';\nimport { SourceLocation } from '../Diagnostics/SourceLocation';\nimport { describePlacement, documentPlacement, isDocumentPlacement, PlayPlacement } from '../Files/PlayPlacement';\nimport { PersonaSyntax, StickyNoteSyntax } from '../Syntax/Authorization';\nimport { ConceptSyntax, DomainSyntax, ImportSyntax, TypeSyntax } from '../Syntax/Declarations';\nimport { SpecificationExampleSyntax } from '../Syntax/Specifications';\nimport { TimeZoneSyntax } from '../Syntax/Calendar';\nimport { ApplicationContextSyntax, ApplicationSyntax, FeatureSyntax, FileImportSyntax, ModuleSyntax } from '../Syntax/Structure';\nimport { parseTriggerDeclaration } from './TriggerDataParser';\nimport { pattern } from '../Text/patterns';\nimport { parseComplianceDirective, parseComplianceMarkers } from './ConceptComplianceParser';\nimport { parseType } from './DeclarationParsers';\nimport { ValidateSyntax } from '../Syntax/Commands';\nimport { parseValidate } from './CommandParser';\nimport { parseDescription } from './DescriptionParser';\nimport { FeatureBody, featureBodyExpected } from './FeatureBody';\nimport { isFileImport, parseFileImport } from './FileImportParser';\nimport { isFileDirective } from './FileReferences';\nimport { collectInputUses } from './InputUses';\nimport { firstWord, unescapeIdentifier } from './LineText';\nimport { ModuleBody, moduleBodyExpected, modulePattern, parseModule } from './ModuleBody';\nimport { ParserContext } from './ParserContext';\nimport { PolicySyntax } from '../Syntax/Policies';\nimport { parsePolicy } from './PolicyParser';\nimport { PurposeSyntax } from '../Syntax/Purposes';\nimport { parsePurpose } from './PurposeParser';\nimport { SeedSyntax } from '../Syntax/Seeds';\nimport { parseSeed } from './SeedParser';\nimport { parseSystem } from './OperationParser';\nimport { parseStateMachine } from './StateMachineParser';\nimport { parseWorkflow } from './WorkflowParser';\nimport { StateMachineSyntax, WorkflowSyntax } from '../Syntax/Lifecycles';\nimport { EventVisibility } from '../Syntax/EventVisibility';\nimport { isBlankPublicEventOrigin } from '../Syntax/PublicEventInvariants';\nimport { stringBodyPattern, unescapeString } from '../Text/StringLiteral';\nimport { SystemSyntax } from '../Syntax/Operations';\nimport { EventSourceSyntax } from '../Syntax/EventSources';\nimport { parseCanvasPair } from './CanvasPlacement';\nimport { parseEventSource } from './EventSourceParser';\nimport { parseExposure, parseInstance } from './CompositionParser';\nimport { ExposureSyntax, InstanceContributionsSyntax } from '../Syntax/CompositionSyntax';\nimport { parseExample } from './SpecificationExampleParser';\nimport { parseUiProfile } from './UiProfileLegacyLayout';\nimport { locationOf, SourceLine, startOf } from './SourceLine';\n\nconst domainPattern = pattern('^domain\\\\s+([A-Za-z_]\\\\w*(?:\\\\.[A-Za-z_]\\\\w*)*)$');\nconst timeZonePattern = pattern(`^time\\\\s+zone\\\\s+(configurable\\\\s+default\\\\s+)?\"(${stringBodyPattern})\"$`);\nconst importPattern = pattern(`^import\\\\s+([\\\\w.]+)(?:\\\\s+from\\\\s+\"(?<origin>${stringBodyPattern})\")?$`);\nconst conceptPattern = pattern('^concept\\\\s+(\\\\w+)\\\\s*:\\\\s*(\\\\w+)((?:\\\\s+@?\\\\w+)*)$');\nconst enumValuePattern = pattern('^@?[a-z_]\\\\w*$');\nconst personaPattern = pattern('^persona\\\\s+([A-Za-z_]\\\\w*)$');\nconst personaPolicyPattern = pattern('^policy\\\\s+([A-Za-z_]\\\\w*)$');\nconst personaGoalPattern = pattern(`^goal\\\\s+\"(${stringBodyPattern})\"$`);\nconst stickyNotePattern = pattern('^sticky\\\\s+note\\\\s+on\\\\s+(personas|eventsources|givencontexts|seeddata)$');\nconst stickyNoteColourPattern = pattern('^colour\\\\s+(yellow|pink|green|blue)$');\nconst tabIndentPattern = /^[ ]*\\t/;\nconst primitiveTypes = ['Uuid', 'String', 'Int', 'Decimal', 'Bool', 'Date', 'DateTime'];\n\n// Top-level, module and feature constructs the C# compiler knows that this compiler does not model. They\n// are skipped whole, not reported.\nconst opaqueTopLevel = new Set(['policy', 'authentication', 'onboarding', 'seed', 'ui', 'theme', 'trigger', 'layout', 'behavior', 'sample']);\n\n// What belongs in a module or feature body; at the top level of a whole document it gets a hint saying so.\nconst bodyKeywords = new Set(['slice', 'feature', 'description', 'documentation', 'authorize', 'screen', 'dialog', 'form', 'contribute', 'on', 'uses']);\n\n// Parses one document into its application syntax - the port of the C# ScreenplayParser. The placement says\n// where the document's top level belongs: the application, unless an import placed it in a module or feature.\nexport function parseApplication(context: ParserContext, lines: readonly SourceLine[], placement: PlayPlacement = documentPlacement): ApplicationSyntax {\n context.deferIdentityValidation = true;\n warnOnTabIndentation(context, lines);\n const moduleBody = placement.length === 1 ? new ModuleBody(placement[0]) : undefined;\n const featureBody = placement.length > 1 ? new FeatureBody(placement[placement.length - 1]) : undefined;\n const placedBody = moduleBody ?? featureBody;\n let identity: IdentitySyntax | null = null;\n let applicationContext: ApplicationContextSyntax | null = null;\n let reactionProductionMode: ReactionProductionMode | null = null;\n let sawReactionBatches = false;\n let commandReadMode: CommandReadMode | null = null;\n let timeZone: TimeZoneSyntax | null = null;\n let sawTimeZone = false;\n let sawCommandReads = false;\n let domain: DomainSyntax | null = null;\n const imports: ImportSyntax[] = [];\n const fileImports: FileImportSyntax[] = [];\n const concepts: ConceptSyntax[] = [];\n const types: TypeSyntax[] = [];\n const systems: SystemSyntax[] = [];\n const stateMachines: StateMachineSyntax[] = [];\n const workflows: WorkflowSyntax[] = [];\n const eventSources: EventSourceSyntax[] = [];\n const modules: ModuleSyntax[] = [];\n const personas: PersonaSyntax[] = [];\n const stickyNotes: StickyNoteSyntax[] = [];\n const policies: PolicySyntax[] = [];\n const purposes: PurposeSyntax[] = [];\n const seeds: SeedSyntax[] = [];\n const examples: SpecificationExampleSyntax[] = [];\n const declaredTriggers: NonNullable<ApplicationSyntax['declaredTriggers']>[number][] = [];\n const exposures: ExposureSyntax[] = [];\n const instanceContributions: InstanceContributionsSyntax[] = [];\n let sawOtherConstruct = false;\n for (let line = context.reader.peekSignificant(); line !== undefined; line = context.reader.peekSignificant()) {\n context.reader.takeSignificant();\n const keyword = firstWord(line.content);\n if (keyword === 'command' && /^command\\s+reads(?:\\s|$)/.test(line.content)) {\n if (sawCommandReads || !isDocumentPlacement(placement) || !/^command\\s+reads\\s+protected$/.test(line.content)) {\n context.error(DiagnosticCodes.InvalidCommandReadsDeclaration, \"Declare 'command reads protected' once at the application root.\", locationOf(line));\n } else {\n commandReadMode = CommandReadMode.Protected;\n }\n sawCommandReads = true;\n continue;\n }\n if (keyword === 'time' && /^time\\s+zone(?:\\s|$)/.test(line.content)) {\n const match = timeZonePattern.exec(line.content);\n context.skipBlock(line.indent);\n if (sawTimeZone || !isDocumentPlacement(placement) || match === null) {\n context.error(DiagnosticCodes.InvalidTimeZoneDeclaration, \"Declare 'time zone \\\"<id>\\\"' or 'time zone configurable default \\\"<id>\\\"' once at the application root.\", locationOf(line));\n } else {\n timeZone = { kind: 'TimeZoneSyntax', id: unescapeString(match[2]), configurable: match[1] !== undefined, location: locationOf(line) };\n }\n sawTimeZone = true;\n continue;\n }\n if (keyword === 'reaction') {\n if (sawReactionBatches || !isDocumentPlacement(placement) || !/^reaction\\s+batches\\s+atomic$/.test(line.content)) {\n context.error(DiagnosticCodes.InvalidReactionBatchesDeclaration, \"Declare 'reaction batches atomic' once at the application root.\", locationOf(line));\n } else {\n reactionProductionMode = ReactionProductionMode.Atomic;\n }\n sawReactionBatches = true;\n continue;\n }\n if (keyword === 'runs') {\n misplacedReactionIdentity(context, line);\n continue;\n }\n if (keyword === 'domain') {\n context.authoredDeclarations = true;\n domain = parseDomain(context, line, domain, sawOtherConstruct);\n continue;\n }\n // The C# parser asks whether anything was declared before the domain, so an import it rejected,\n // a file import and an unknown construct do not count.\n sawOtherConstruct ||= declaresConstruct(keyword, line, placement);\n context.authoredDeclarations ||= keyword !== 'import' && declaresConstruct(keyword, line, placement);\n if (keyword === 'import' && isFileImport(line.content)) {\n // A top level import belongs to whatever the document's top level is - the application, or the\n // module or feature the document was itself imported into.\n if (placedBody !== undefined) {\n placedBody.tryParse(context, line);\n } else {\n parseFileImport(context, line, fileImports);\n }\n } else if (keyword === 'import') {\n const match = importPattern.exec(line.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidImportDeclaration, `Invalid import '${line.content}' - expected 'import <Qualified.Name> [from \"<origin>\"]'`, locationOf(line));\n } else {\n const origin = match.groups?.origin === undefined ? null : unescapeString(match.groups.origin);\n if (origin !== null && isBlankPublicEventOrigin(origin)) {\n context.error(DiagnosticCodes.InvalidImportDeclaration, 'An import origin must be a nonblank quoted string', locationOf(line));\n }\n imports.push({ kind: 'ImportSyntax', qualifiedName: match[1], origin, visibility: origin === null ? EventVisibility.Private : EventVisibility.Public, location: locationOf(line) });\n }\n } else if (keyword === 'example') {\n if (placedBody !== undefined) placedBody.tryParse(context, line);\n else examples.push(parseExample(context, line));\n } else if (keyword === 'eventsource') {\n eventSources.push(parseEventSource(context, line));\n } else if (keyword === 'system') {\n systems.push(parseSystem(context, line));\n } else if (keyword === 'statemachine') {\n stateMachines.push(parseStateMachine(context, line));\n } else if (keyword === 'workflow') {\n workflows.push(parseWorkflow(context, line));\n } else if (keyword === 'concept') {\n concepts.push(parseConcept(context, line));\n } else if (keyword === 'type') {\n types.push(parseType(context, line));\n } else if (keyword === 'module' && !isDocumentPlacement(placement)) {\n parseModuleInPlacedFile(context, line, placement, moduleBody);\n } else if (keyword === 'module') {\n modules.push(parseModule(context, line));\n } else if (keyword === 'persona') {\n personas.push(parsePersona(context, line));\n } else if (keyword === 'sticky') {\n const stickyNote = parseStickyNote(context, line);\n if (stickyNote !== null) stickyNotes.push(stickyNote);\n } else if (keyword === 'seed') {\n seeds.push(parseSeed(context.valueContext, line));\n } else if (keyword === 'purpose' && placedBody !== undefined) {\n placedBody.tryParse(context, line);\n } else if (keyword === 'purpose') {\n purposes.push(parsePurpose(context, line));\n } else if (keyword === 'context') {\n applicationContext = parseApplicationContext(context, line, applicationContext, placement);\n } else if (keyword === 'identity') {\n identity = parseIdentity(context, line, identity);\n } else if (keyword === 'policy') {\n const policy = parsePolicy(context, line);\n if (policies.some(previous => previous.name === policy.name)) {\n context.error(DiagnosticCodes.DuplicateDeclaration, `Duplicate declaration of policy '${policy.name}' - policy names must be unique`, policy.location);\n }\n policies.push(policy);\n } else if (keyword === 'exposure') {\n exposures.push(parseExposure(context, line));\n } else if (keyword === 'instance') {\n instanceContributions.push(parseInstance(context, line));\n } else if (keyword === 'trigger') {\n const data = parseTriggerDeclaration(context, line);\n const name = /^trigger\\s+([A-Za-z_]\\w*)$/.exec(line.content)?.[1];\n if (name !== undefined) declaredTriggers.push({ name, data });\n } else if (opaqueTopLevel.has(keyword)) {\n if (keyword === 'behavior' || keyword === 'layout') collectInputUses(context, line);\n else if (keyword === 'ui') parseUiProfile(context, line);\n else context.skipOpaqueBlock(line.indent);\n } else if (placedBody?.tryParse(context, line) !== true) {\n reportUnexpectedTopLevel(context, line, placement);\n }\n }\n if (moduleBody !== undefined) {\n modules.unshift(moduleBody.build(context.start, true));\n } else if (featureBody !== undefined) {\n modules.unshift(place(placement, featureBody.build(context.start, true), context.start));\n }\n const root: ApplicationSyntax = { kind: 'ApplicationSyntax', ...(commandReadMode === null ? {} : { commandReadMode }), ...(timeZone === null ? {} : { timeZone }), ...(applicationContext === null ? {} : { context: applicationContext }), ...(reactionProductionMode === null ? {} : { reactionProductionMode }), ...(identity === null ? {} : { identity }), sourceOptions: context.sourceOptions, domain, imports, concepts, types, systems, ...(stateMachines.length > 0 ? { stateMachines } : {}), ...(workflows.length > 0 ? { workflows } : {}), eventSources, examples, modules, personas, policies, purposes, seeds, declaredTriggers, fileImports, ...(exposures.length > 0 ? { exposures } : {}), ...(stickyNotes.length > 0 ? { stickyNotes } : {}), ...(instanceContributions.length > 0 ? { instanceContributions } : {}), location: context.start };\n if (context.authoredDeclarations) recordAuthoredDocument(root);\n return root;\n}\n\nfunction declaresConstruct(keyword: string, line: SourceLine, placement: PlayPlacement): boolean {\n if (keyword === 'import') {\n return importPattern.test(line.content);\n }\n if (keyword === 'module') {\n return isDocumentPlacement(placement);\n }\n if (keyword === 'identity') return line.content === 'identity';\n if (keyword === 'context') return line.content === 'context';\n return keyword === 'purpose' || keyword === 'example' || keyword === 'exposure' || keyword === 'instance' || keyword === 'eventsource' || keyword === 'system' || keyword === 'statemachine' || keyword === 'workflow' || keyword === 'concept' || keyword === 'type' || keyword === 'persona' || keyword === 'sticky' || opaqueTopLevel.has(keyword);\n}\n\nfunction parseModuleInPlacedFile(context: ParserContext, line: SourceLine, placement: PlayPlacement, moduleBody: ModuleBody | undefined): void {\n const name = modulePattern.exec(line.content)?.[1] ?? '';\n\n // Restating the module a file is placed in says nothing new, so its body simply joins the placement.\n if (moduleBody !== undefined && name === placement[0]) {\n context.authoredDeclarations = true;\n moduleBody.parseChildren(context, line);\n return;\n }\n context.error(DiagnosticCodes.ModuleInPlacedFile,\n `This file is imported into ${describePlacement(placement)}, so it cannot declare module '${name}' - import it at the top level of a document instead`, locationOf(line));\n context.skipBlock(line.indent);\n}\n\nfunction reportUnexpectedTopLevel(context: ParserContext, line: SourceLine, placement: PlayPlacement): void {\n const word = firstWord(line.content);\n if (!isDocumentPlacement(placement)) {\n const expected = placement.length === 1 ? moduleBodyExpected : featureBodyExpected;\n context.error(DiagnosticCodes.UnexpectedInPlacedFile,\n `Unexpected '${word}' in a file imported into ${describePlacement(placement)} - expected an application declaration or ${expected}`, locationOf(line));\n } else {\n const hint = bodyKeywords.has(word)\n ? ` - '${word}' belongs in a module or feature; wrap it in one, or import this file from inside one`\n : ' - expected domain, import, concept, type, policy, persona, sticky note, authentication, onboarding, identity, context, module, seed, trigger, behavior, ui profile, theme, sample data or layout';\n context.error(DiagnosticCodes.UnknownTopLevelConstruct, `Unexpected '${word}' at the top level${hint}`, locationOf(line));\n }\n context.skipBlock(line.indent);\n}\n\n// Wraps the feature a file is placed in in the features and module around it, each marked as a placement.\nfunction place(placement: PlayPlacement, innermost: FeatureSyntax, start: SourceLocation): ModuleSyntax {\n let feature = innermost;\n for (let index = placement.length - 2; index >= 1; index--) {\n feature = {\n kind: 'FeatureSyntax', name: placement[index], description: null, authorize: null,\n features: [feature], slices: [], fileImports: [], isPlacement: true, location: start,\n };\n }\n return {\n kind: 'ModuleSyntax', name: placement[0], description: null, authorize: null,\n features: [feature], fileImports: [], isPlacement: true, location: start,\n };\n}\n\nfunction parseDomain(context: ParserContext, line: SourceLine, existing: DomainSyntax | null, sawOtherConstruct: boolean): DomainSyntax | null {\n const match = domainPattern.exec(line.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidDomainDeclaration, `Invalid domain declaration '${line.content}' - expected 'domain <Qualified.Name>'`, locationOf(line));\n return existing;\n }\n if (existing !== null) {\n context.error(DiagnosticCodes.DuplicateDomain, 'The document already declares a domain - a document can have at most one', locationOf(line));\n return existing;\n }\n if (sawOtherConstruct) {\n context.error(DiagnosticCodes.DomainNotFirst, '\\'domain\\' must be declared before any other construct', locationOf(line));\n }\n return { kind: 'DomainSyntax', name: match[1], location: locationOf(line) };\n}\n\nfunction warnOnTabIndentation(context: ParserContext, lines: readonly SourceLine[]): void {\n let inFence = false;\n for (const line of lines) {\n if (line.raw.trimStart().startsWith('```')) {\n inFence = !inFence;\n continue;\n }\n if (!inFence && tabIndentPattern.test(line.raw)) {\n context.warning(DiagnosticCodes.TabIndentation, 'Screenplay is indentation based - use spaces, not tabs', startOf(line));\n }\n }\n}\n\nfunction parseConcept(context: ParserContext, line: SourceLine): ConceptSyntax {\n const match = conceptPattern.exec(line.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidConceptDeclaration, `Invalid concept declaration '${line.content}' - expected 'concept <Name> : <Type>'`, locationOf(line));\n context.skipBlock(line.indent);\n return { kind: 'ConceptSyntax', name: firstWord(line.content), type: '', attributes: [], values: [], location: locationOf(line) };\n }\n const [, name, type, attributeText] = match;\n const attributes = parseComplianceMarkers(context, line, name, attributeText);\n if (type !== 'Enum' && !primitiveTypes.includes(type)) {\n context.error(DiagnosticCodes.UnknownPrimitiveType, `Unknown primitive type '${type}' - expected ${primitiveTypes.join(', ')} or Enum`, locationOf(line));\n }\n const values: string[] = [];\n const members = new EnumerationMembers();\n let generation: GenerationSyntax | null = null;\n let declaredGeneration = false;\n let description: string | null = null;\n const validations: ValidateSyntax[] = [];\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n const memberName = type === 'Enum' ? members.tryNumbered(context, child) : undefined;\n if (memberName !== undefined) {\n values.push(memberName);\n } else if (firstWord(child.content) === 'description' && (type !== 'Enum' || child.content !== 'description' || context.peekChild(child.indent)?.content.startsWith('```') === true)) {\n description = parseDescription(context, child, description, `Concept '${name}'`);\n } else if (isFileDirective(child)) {\n continue;\n } else if (firstWord(child.content) === 'validate') {\n if (type === 'Enum' && child.content === 'validate' && context.peekChild(child.indent) === undefined) {\n context.warning(DiagnosticCodes.ValidateReadAsEnumerationBlock,\n `'validate' in enumeration concept '${name}' declares an empty validate block, not a value named 'validate' - write '@validate' for the value`,\n locationOf(child));\n }\n const parsed = parseValidate(context, child, 'concept', name);\n if (parsed !== undefined) validations.push(parsed);\n } else if (firstWord(child.content) === 'generate' && !(type === 'Enum' && child.content === 'generate')) {\n if (declaredGeneration) context.error(DiagnosticCodes.DuplicateGeneration, `Concept '${name}' declares generation more than once.`, locationOf(child));\n const parsed = parseGeneration(context, child, type);\n if (!declaredGeneration) generation = parsed;\n declaredGeneration = true;\n } else if (parseComplianceDirective(context, child, name, attributes)) {\n // Compliance directives are modeled by their original concept marker.\n } else if (type === 'Enum' && enumValuePattern.test(child.content)) {\n values.push(unescapeIdentifier(child.content));\n } else if (type === 'Enum') {\n context.error(DiagnosticCodes.InvalidEnumerationValue, `Invalid enum value '${child.content}' - expected an identifier`, locationOf(child));\n } else {\n context.error(DiagnosticCodes.UnknownConceptDirective, `Unexpected '${child.content}' in concept body - expected validate, generate, 'file <path>' or '<attribute> reason \"<text>\"'${misplacedRuleHintForConcept(child.content)}`, locationOf(child));\n context.skipBlock(child.indent);\n }\n }\n const valueNumbers = members.finish(context, line, values.length);\n return { kind: 'ConceptSyntax', name, type, attributes, values, validations, description, ...(generation === null ? {} : { generation }), ...(valueNumbers === undefined ? {} : { valueNumbers }), location: locationOf(line) };\n}\n\n// 'persona <Name>' with an optional description and the policies it holds - the port of the C# ParsePersona.\nfunction parsePersona(context: ParserContext, line: SourceLine): PersonaSyntax {\n const name = personaPattern.exec(line.content)?.[1] ?? '';\n if (name === '') {\n context.error(DiagnosticCodes.InvalidPersonaDeclaration, `Invalid persona declaration '${line.content}' - expected 'persona <Name>'`, locationOf(line));\n }\n let description: string | null = null;\n const policies: string[] = [];\n const goals: string[] = [];\n let position: readonly [number, number] | null = null;\n let size: readonly [number, number] | null = null;\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n const keyword = firstWord(child.content);\n if (keyword === 'description') {\n description = parseDescription(context, child, description, `Persona '${name}'`);\n } else if (keyword === 'goal') {\n const goal = personaGoalPattern.exec(child.content);\n if (goal === null) {\n context.error(DiagnosticCodes.InvalidPersonaDeclaration, `Invalid goal '${child.content}' - expected 'goal \"<text>\"'`, locationOf(child));\n } else {\n goals.push(unescapeString(goal[1]));\n }\n } else if (keyword === 'position') {\n position = parseCanvasPair(context, child, 'position', 'x', 'y', position, true) ?? position;\n } else if (keyword === 'size') {\n size = parseCanvasPair(context, child, 'size', 'width', 'height', size, false) ?? size;\n } else if (keyword === 'policy') {\n const policy = personaPolicyPattern.exec(child.content);\n if (policy === null) {\n context.error(DiagnosticCodes.InvalidPersonaPolicyReference, `Invalid policy reference '${child.content}' - expected 'policy <Name>'`, locationOf(child));\n } else {\n policies.push(policy[1]);\n }\n } else {\n context.error(DiagnosticCodes.UnknownPersonaDirective, `Unexpected '${keyword}' in persona body - expected description, goal, policy, position or size`, locationOf(child));\n context.skipBlock(child.indent);\n }\n }\n return {\n kind: 'PersonaSyntax', name, description, policies,\n ...(goals.length > 0 ? { goals } : {}),\n ...(position === null ? {} : { x: position[0], y: position[1] }),\n ...(size === null ? {} : { width: size[0], height: size[1] }),\n location: locationOf(line),\n };\n}\n\n// 'sticky note on <canvas>' with the text it carries, an optional colour and where it sits on that canvas - the port of the C# ParseStickyNote.\nfunction parseStickyNote(context: ParserContext, line: SourceLine): StickyNoteSyntax | null {\n const canvasMatch = stickyNotePattern.exec(line.content);\n if (canvasMatch === null) {\n context.error(DiagnosticCodes.InvalidPersonaDeclaration, `Invalid sticky note declaration '${line.content}' - expected 'sticky note on personas', 'sticky note on eventsources', 'sticky note on givencontexts' or 'sticky note on seeddata'`, locationOf(line));\n context.skipBlock(line.indent);\n return null;\n }\n let text: string | null = null;\n let colour: string | null = null;\n let position: readonly [number, number] | null = null;\n let size: readonly [number, number] | null = null;\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n const keyword = firstWord(child.content);\n if (keyword === 'description') {\n text = parseDescription(context, child, text, 'A sticky note');\n } else if (keyword === 'colour') {\n const match = stickyNoteColourPattern.exec(child.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidPersonaDeclaration, `Invalid colour '${child.content}' - expected 'colour yellow', 'colour pink', 'colour green' or 'colour blue'`, locationOf(child));\n } else {\n colour = match[1];\n }\n } else if (keyword === 'position') {\n position = parseCanvasPair(context, child, 'position', 'x', 'y', position, true) ?? position;\n } else if (keyword === 'size') {\n size = parseCanvasPair(context, child, 'size', 'width', 'height', size, false) ?? size;\n } else {\n context.error(DiagnosticCodes.UnknownPersonaDirective, `Unexpected '${keyword}' in sticky note body - expected description, colour, position or size`, locationOf(child));\n context.skipBlock(child.indent);\n }\n }\n if (text === null || position === null) {\n context.error(DiagnosticCodes.InvalidPersonaDeclaration, 'A sticky note needs a description (the text on it) and a position', locationOf(line));\n return null;\n }\n return { kind: 'StickyNoteSyntax', canvas: canvasMatch[1] as StickyNoteSyntax['canvas'], text, colour, x: position[0], y: position[1], width: size === null ? null : size[0], height: size === null ? null : size[1], location: locationOf(line) };\n}\n\n"],"mappings":"A,gxEA2DA,MAAMA,EAAgBC,EAAQ,kDAAkD,EAC1EC,EAAkBD,EAAQ,oDAAoDE,EAAkB,IAAI,EACpGC,EAAgBH,EAAQ,iDAAiDE,EAAkB,MAAM,EACjGE,EAAiBJ,EAAQ,qDAAqD,EAC9EK,EAAmBL,EAAQ,gBAAgB,EAC3CM,EAAiBN,EAAQ,8BAA8B,EACvDO,EAAuBP,EAAQ,6BAA6B,EAC5DQ,EAAqBR,EAAQ,cAAcE,EAAkB,IAAI,EACjEO,EAAoBT,EAAQ,0EAA0E,EACtGU,EAA0BV,EAAQ,sCAAsC,EACxEW,EAAmB,UACnBC,EAAiB,CAAC,OAAQ,SAAU,MAAO,UAAW,OAAQ,OAAQ,UAAU,EAIhFC,kBAAiB,IAAI,IAAI,CAAC,SAAU,iBAAkB,aAAc,OAAQ,KAAM,QAAS,UAAW,SAAU,WAAY,QAAQ,CAAC,EAGrIC,kBAAe,IAAI,IAAI,CAAC,QAAS,UAAW,cAAe,gBAAiB,YAAa,SAAU,SAAU,OAAQ,aAAc,KAAM,MAAM,CAAC,EAItJ,SAAgB,iBAAiB,EAAwB,EAA8B,EAA2BC,EAAsC,CACpJ,EAAQ,wBAA0B,GAClC,qBAAqBC,EAASC,CAAK,EACnC,IAAMC,EAAaC,EAAU,SAAW,EAAI,IAAIC,GAAWD,EAAU,EAAE,EAAI,IAAA,GACrEE,EAAcF,EAAU,OAAS,EAAI,IAAIG,EAAYH,EAAUA,EAAU,OAA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M,mBAAoB,OAAQ8E,EAAY,GAAkC,OAAM,SAAQ,EAAGJ,EAAS,GAAI,EAAGA,EAAS,GAAI,MAAOC,IAAS,KAAO,KAAOA,EAAK,GAAI,OAAQA,IAAS,KAAO,KAAOA,EAAK,GAAI,SAAUtE,EAAWL,CAAI,CAAE,CACrP,C"}
@@ -1,2 +1,2 @@
1
- import"../../_virtual/_virtual/_rolldown/runtime.js";import{parseRouteParts as e}from"./EventSourceParser.js";import{diagnosticText as t}from"../Diagnostics/DiagnosticArgument.js";import{DiagnosticCodes as n}from"../Diagnostics/DiagnosticCodes.js";import{dotNetWhitespace as r,nativePattern as i,pattern as a}from"../Text/patterns.js";import{sourceStreamPattern as o}from"../Text/SourceStreamNames.js";import{stringBodyPattern as s,unescapeString as c}from"../Text/StringLiteral.js";import{containsCaseReference as l,parseCase as u,parseParameter as d,parseSpecificationValue as f,validateTable as p}from"./SpecificationCaseParser.js";import{parseDescription as m}from"./DescriptionParser.js";import{isFileDirective as ee}from"./FileReferences.js";import{firstWord as h}from"./LineText.js";import{addFixtureValue as g,addInlineValue as _}from"./SpecificationExampleParser.js";import{rejectOperationChildren as v}from"./OperationParser.js";import{generatedFixturePattern as y,generatedFixturePrefix as b,parseConcrete as te,parseConcreteMapping as x,parseReturn as S,thenReturnsPrefix as C}from"./SpecificationResponseParser.js";import{locationOf as w}from"./SourceLine.js";import{sourceLocation as T}from"../Diagnostics/SourceLocation.js";import{parseStructuredValue as E,tryParseStructuredMapping as D}from"./StructuredBlockParser.js";const ne=a(`^(?:given\\s+operation|then\\s+(?:operation|compensated))(?:\\s|$)`),re=a(`^(given operation|then operation|then compensated)\\s+([A-Za-z_]\\w*(?:\\.[A-Za-z_]\\w*)*)(\\s+fails)?$`),O=a(`^specification\\s+([A-Za-z_]\\w*)$`),k=O,A=a(`^given caller as ([A-Za-z_]\\w*)$`),stepPattern=(e,t=``)=>i(`^${e}\\s+([A-Z]\\w*(?:\\.\\w+)*)${t}(?:\\s+(?<property>[\\w.]+)\\s*=(?!=|>)\\s*(?<value>.+))?$`.replaceAll(`\\s`,r)),j=stepPattern(`given`),M=stepPattern(`when\\s+append`),N=stepPattern(`when`),P=stepPattern(`then`),F=a(`^then\\s+query\\b`),I=a(`^(?:given|then)\\s+readmodel\\b`),L=stepPattern(`given\\s+readmodel`),R=stepPattern(`then\\s+readmodel`,`(?<exactly>\\s+exactly)?`),z=a(`^then\\s+no\\b`),B=a(`^then\\s+error\\s+"(${s})"$`),V=a(`^([\\w.]+)\\s*=(?!=|>)\\s*(.+)$`),H=i(`^([\\w.]+)\\s*=(?!=|>)\\s*(.+)$`),U=a(`^given\\s+time\\s+zone\\b`),W=a(`^given\\s+time\\s+zone\\s+"(${s})"$`),G=a(`^given\\s+clock\\b`),K=a(`^given\\s+capture\\b`),q=a(`^then\\s+invokes\\b`),J=a(`^then\\s+invokes\\s+([A-Za-z_]\\w*(?:\\.[A-Za-z_]\\w*)*)$`),Y=a(`^given\\s+generated\\b`),X=a(`^given\\s+generated\\s+([A-Z]\\w*)\\.([a-z_]\\w*)\\s*=(?!=|>)\\s*(.+)$`),ie=a(`^given\\s+generated\\s+([A-Z]\\w*)\\.([a-z_]\\w*)(?:\\s+(none|empty))?$`),ae=a(`^when\\s+clock\\b`),oe=a(`^when\\s+trigger\\b`),se=a(`^when\\s+capture\\b`),ce=a(`^when\\s+query\\b`),le=a(`^then\\s+result\\b`),ue=a(`^then\\s+no\\s+result\\b`),de=i(`^when\\s+redelivered\\b`),fe=i(`^when\\s+redelivered\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)\\s+to\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)$`),pe=a(`^then\\s+no\\s+events\\b`),me=a(`^(given|when)\\s+clock\\s+"(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d+)?)?(?:Z|[+-]\\d{2}:\\d{2}))"$`),he=a(`^when\\s+trigger\\s+([A-Za-z_]\\w*)$`),ge=a(`^(?:given|when)\\s+capture\\s+([A-Za-z_]\\w*)$`),_e=a(`^when\\s+query\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)$`),ve=a(`^then\\s+result(\\s+exactly)?$`),Z=i(`^then\\s+no\\s+readmodel\\s+([A-Z]\\w*)\\s+for(?:\\s+(.+))?$`),ye=i(`^(?:"${s}"|'(?:[^'\\\\]|\\\\.)*')$`),be=i(`^then\\s+query\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)(\\s+exactly)?$`);function parseSpecification(e,t){let r=O.exec(t.content)?.[1]??``;r===``&&e.error(n.InvalidSpecificationDeclaration,`Invalid specification declaration '${t.content}' - expected 'specification <Name>'`,w(t));let i=null,a=[],o=[],s={givenOperationFailures:[],thenOperations:[],thenCompensated:[],thenAbsentReadModels:[],thenQueries:[],given:[],givenReadModels:[],when:null,whenAppended:null,whenRedelivered:null,whenDeclared:!1,thenEvents:[],thenEventsInAnyOrder:!1,thenNoEvents:!1,thenReadModels:[],thenErrors:[],givenClock:null,givenTimeZone:null,givenCaptures:[],whenClock:null,whenTrigger:null,whenCapture:null,whenQuery:null,thenResults:[],thenNoResult:null,thenDenied:null,givenCaller:null,thenReturns:null};for(let c=e.peekChild(t.indent);c!==void 0;c=e.peekChild(t.indent)){if(e.reader.takeSignificant(),ee(c)||parseOperationStep(e,c,s))continue;let t=z.test(c.content)?`then`:h(c.content);if(t===`parameter`){let t=d(e,c);t!==null&&a.push(t)}else if(t===`case`){let t=u(e,c);t!==null&&o.push(t)}else t===`description`?i=m(e,c,i,`Specification '${r}'`):t===`given`?parseGiven(e,c,s):t===`when`?parseWhen(e,c,s,r):t===`then`?parseThen(e,c,s):(e.error(n.UnknownSpecificationDirective,`Unexpected '${h(c.content)}' in specification body`,w(c)),e.skipBlock(c.indent))}s.noEventsLine!==void 0&&(s.thenEvents.length>0||s.thenEventsInAnyOrder||s.thenErrors.length>0||s.thenDenied!==null)&&e.error(n.InvalidNoEventsExpectation,`'then no events' cannot accompany event, event-order, error or denial expectations.`,w(s.noEventsLine)),validateQueryRejection(e,t,s);let{whenDeclared:c,noEventsLine:l,...f}=s,g={kind:`SpecificationSyntax`,sourceOptions:e.sourceOptions,name:r,description:i,...f,...a.length===0?{}:{parameters:a},...o.length===0?{}:{cases:o},location:w(t)};return p(g,e),g}function validateQueryRejection(e,t,r){isQueryRejectionCandidate(r)&&!isWellFormedQueryRejection(r)&&e.error(n.MismatchedSpecificationQueryResult,`A query rejection requires exactly one query and one 'then error', no action, and no other outcomes`,w(t))}function isQueryRejectionCandidate(e){return e.thenErrors.length>0&&queriedCallCount(e)>0&&(e.whenQuery!==null||!hasAction(e))}function isWellFormedQueryRejection(e){return!hasAction(e)&&hasOneQueryAndOneError(e)&&!hasOtherOutcome(e)}function hasOneQueryAndOneError(e){return queriedCallCount(e)===1&&e.thenErrors.length===1}function hasAction(e){return[e.when,e.whenAppended,e.whenClock,e.whenTrigger,e.whenCapture,e.whenRedelivered].some(e=>e!==null)}function queriedCallCount(e){return e.thenQueries.length+(e.whenQuery===null?0:1)}function hasOtherOutcome(e){return[e.thenResults.length>0,e.thenNoResult!==null,e.thenDenied!==null,e.thenEvents.length>0,e.thenNoEvents,e.thenEventsInAnyOrder,e.thenReadModels.length>0,e.thenAbsentReadModels.length>0,e.thenReturns!==null,e.thenQueries.some(e=>e.results.length>0)].some(e=>e)}function parseOperationStep(e,t,r){if(!ne.test(t.content))return!1;let i=re.exec(t.content);if(i===null||i[1]===`given operation`!=(i[3]!==void 0))e.error(n.InvalidOperationSpecification,`Expected 'given operation <Name> fails', 'then operation <Name>' or 'then compensated <Name>'.`,w(t)),skipBody(e,t.indent);else if(i[1]===`then operation`){let a=[];for(let r=e.peekChild(t.indent);r!==void 0;r=e.peekChild(t.indent)){e.reader.takeSignificant();let t=x(e,r,V,n.InvalidOperationSpecification);t!==null&&a.push(t)}r.thenOperations.push({kind:`SpecificationOperationSyntax`,operation:i[2],values:a,location:w(t)})}else v(e,t,n.InvalidOperationSpecification,`Failure and compensation assertions cannot have children.`),i[1]===`given operation`?r.givenOperationFailures.push({kind:`SpecificationOperationFailureSyntax`,operation:i[2],location:w(t)}):r.thenCompensated.push({kind:`SpecificationCompensatedSyntax`,operation:i[2],location:w(t)});return!0}function parseGiven(e,t,r){if(G.test(t.content))r.givenClock===null?r.givenClock=parseClock(e,t,`given`):(e.error(n.InvalidSpecificationClock,`A specification states its clock at most once.`,w(t)),skipBody(e,t.indent));else if(U.test(t.content)){let i=W.exec(t.content);skipBody(e,t.indent),r.givenTimeZone!==null||i===null?e.error(n.InvalidSpecificationTimeZone,`A specification states its time zone at most once, as 'given time zone "<id>"'.`,w(t)):r.givenTimeZone={kind:`SpecificationTimeZoneSyntax`,id:c(i[1]),location:w(t)}}else if(Y.test(t.content)){let n=parseGivenGenerated(e,t);n!==null&&(r.givenGenerated??=[]).push(n)}else if(K.test(t.content)){let n=parseCapture(e,t,`given`);n!==null&&r.givenCaptures.push(n)}else if(t.content.startsWith(`given caller`)){if(r.givenCaller!==null||r.givenCallerPersona!==void 0)e.error(n.DuplicateSpecificationCallerOrDenied,`A specification has at most one 'given caller' block.`,w(t)),e.skipBlock(t.indent);else if(t.content.startsWith(`given caller as`)){let i=A.exec(t.content);i===null&&e.error(n.InvalidSpecificationCallerPersona,`Expected 'given caller as <Persona>'.`,w(t));let a=e.peekChild(t.indent);a!==void 0&&e.error(n.InvalidSpecificationCallerPersona,`'given caller as <Persona>' has no body; use an explicit 'given caller' for refinements.`,w(a)),skipBody(e,t.indent),i!==null&&(r.givenCallerPersona={kind:`SpecificationCallerPersonaSyntax`,name:i[1],location:w(t)})}else r.givenCaller=parseCaller(e,t)}else if(I.test(t.content)){let n=parseReadModelStep(e,t,L,`given`);n!==void 0&&r.givenReadModels.push(n)}else{let n=parseEventStep(e,t,j,`given`);n!==void 0&&r.given.push(n)}}const xe=a(`^role${r}+"(${s})"$`),Se=a(`^claim${r}+"(${s})"${r}*=${r}*"(${s})"$`);function parseCaller(e,t){if(t.content!==`given caller`)return e.error(n.InvalidSpecificationCaller,`Expected exactly 'given caller'.`,w(t)),e.skipBlock(t.indent),null;let r=!1,i=[],a=[];for(let o=e.peekChild(t.indent);o!==void 0;o=e.peekChild(t.indent)){e.reader.takeSignificant();let t=xe.exec(o.content),s=Se.exec(o.content);o.content===`authenticated`&&!r?r=!0:t===null?s===null?e.error(l(o.content)?n.InvalidSpecificationCaseReference:n.InvalidSpecificationCaller,`Invalid caller fixture '${o.content}' - expected authenticated, role "...", or claim "..." = "...".`,w(o)):a.push({kind:`SpecificationCallerClaimSyntax`,type:c(s[1]),value:c(s[2]),location:w(o)}):i.push(c(t[1]))}return{kind:`SpecificationCallerSyntax`,authenticated:r,roles:i,claims:a,location:w(t)}}function parseWhen(e,t,r,i){let a=t.content.startsWith(`when append`);if(r.whenDeclared){let o=r.whenAppended!==null||a?n.ConflictingSpecificationActions:n.DuplicateSpecificationWhen;e.error(o,`Specification '${i}' already declares a 'when' - a specification can have at most one`,w(t)),skipBody(e,t.indent);return}if(r.whenDeclared=!0,a){r.whenAppended=parseEventStep(e,t,M,`when append`)??null;return}if(de.test(t.content)){let i=fe.exec(t.content);i===null?(e.error(n.UnmatchedRedeliveredOccurrence,`Expected 'when redelivered <Event> to <Reaction>'.`,w(t)),skipBody(e,t.indent)):r.whenRedelivered={kind:`SpecificationRedeliverySyntax`,eventType:i[1],reaction:i[2],...parseValuesWithEventSource(e,t,void 0,void 0,`when redelivered`),location:w(t)};return}if(ae.test(t.content)){r.whenClock=parseClock(e,t,`when`);return}if(oe.test(t.content)){r.whenTrigger=parseNamedStep(e,t,he,n.InvalidSpecificationTrigger,`when trigger`,`when trigger <Trigger>`,(e,n)=>({kind:`SpecificationTriggerSyntax`,trigger:e,values:n,location:w(t)}));return}if(se.test(t.content)){r.whenCapture=parseCapture(e,t,`when`);return}if(ce.test(t.content)){r.whenQuery=parseNamedStep(e,t,_e,n.InvalidSpecificationQueryAction,`when query`,`when query <Query>`,(e,n)=>({kind:`SpecificationWhenQuerySyntax`,query:e,arguments:n,location:w(t)}),!0);return}let o=N.exec(t.content);if(o===null){e.error(n.InvalidSpecificationWhen,`Invalid 'when' declaration '${t.content}' - expected 'when <CommandType>' or 'when append <EventType>'`,w(t)),skipBody(e,t.indent);return}let s=[],c=parseValuesWithEventSource(e,t,s,o);r.when={kind:`SpecificationCommandSyntax`,commandType:o[1],...c,generatedValues:s,inlineProperty:o.groups?.property??null,location:w(t)}}function parseThen(e,t,r){if(pe.test(t.content)){t.content!==`then no events`||r.thenNoEvents?e.error(n.InvalidNoEventsExpectation,`Expected one 'then no events' directive.`,w(t)):(r.thenNoEvents=!0,r.noEventsLine=t);let i=e.peekChild(t.indent);i!==void 0&&e.error(n.InvalidNoEventsExpectation,`'then no events' cannot have child mappings.`,w(i)),skipBody(e,t.indent);return}if(C.test(t.content)){let i=S(e,t);r.thenReturns===null?r.thenReturns=i:e.error(n.InvalidReturnExpectation,`A specification declares at most one return expectation.`,w(t));return}if(t.content.startsWith(`then events`)){t.content!==`then events in any order`||r.thenEventsInAnyOrder?e.error(n.InvalidSpecificationEventOrder,`Expected one 'then events in any order' directive.`,w(t)):r.thenEventsInAnyOrder=!0,skipBody(e,t.indent);return}if(le.test(t.content)){parseResult(e,t,r);return}if(ue.test(t.content)){t.content!==`then no result`||r.thenNoResult!==null?e.error(n.InvalidSpecificationQueryAction,`Expected one 'then no result' directive.`,w(t)):r.thenNoResult={kind:`SpecificationNoResultSyntax`,location:w(t)},skipBody(e,t.indent);return}if(q.test(t.content)){let i=parseNamedStep(e,t,J,n.InvalidSpecificationInvocation,`then invokes`,`then invokes <Command>`,(e,n)=>({kind:`SpecificationInvocationSyntax`,command:e,values:n,location:w(t)}));i!==null&&(r.thenInvocations??=[]).push(i);return}if(t.content.startsWith(`then denied`)){t.content===`then denied`?r.thenDenied===null?r.thenDenied={kind:`SpecificationDeniedSyntax`,location:w(t)}:e.error(n.DuplicateSpecificationCallerOrDenied,`A specification has at most one 'then denied' outcome.`,w(t)):(e.error(n.InvalidSpecificationDenied,`Expected exactly 'then denied'.`,w(t)),skipBody(e,t.indent));return}if(t.content===`then error`){r.thenErrors.push({kind:`SpecificationErrorSyntax`,name:null,location:w(t)});return}if(t.content.startsWith(`then error case.`)){let n=f(t.content.substring(11),{...w(t),column:w(t).column+11},e);n.kind===`CaseValueExpressionSyntax`&&r.thenErrors.push({kind:`SpecificationErrorSyntax`,name:null,caseValue:n,location:w(t)});return}let i=B.exec(t.content);if(i!==null){r.thenErrors.push({kind:`SpecificationErrorSyntax`,name:c(i[1]),location:w(t)});return}if(h(t.content.substring(4).trim())===`error`){e.error(n.InvalidThenError,`Invalid 'then error' declaration '${t.content}' - expected 'then error' or 'then error "<reason>"'`,w(t)),skipBody(e,t.indent);return}if(z.test(t.content)){if(e.sourceOptions.numericMode===`exact`){let n=parseAbsentReadModel(e,t);n!==null&&r.thenAbsentReadModels.push(n);return}let n=Z.exec(t.content);if(n!==null&&n[2]===void 0&&e.peekChild(t.indent)!==void 0){r.thenAbsentReadModels.push({kind:`SpecificationAbsentReadModelSyntax`,name:n[1],key:E(e.valueContext,t,void 0),location:w(t)});return}if(n!==null&&n[2]!==void 0&&!n[2].endsWith(` exactly`)){let i=f(n[2].trim(),w(t),e.valueContext);(i.kind===`LiteralExpressionSyntax`||i.kind===`ObjectExpressionSyntax`||i.kind===`CaseValueExpressionSyntax`)&&r.thenAbsentReadModels.push({kind:`SpecificationAbsentReadModelSyntax`,name:n[1],key:i,location:w(t)})}e.skipOpaqueBlock(t.indent);return}if(F.test(t.content)){let i=e.sourceOptions.numericMode===`exact`,reject=(t,n,r)=>{if(!i)return e.skipOpaqueBlock(r.indent);e.error(t,n,w(r)),e.skipBlock(r.indent)},a=be.exec(t.content);if(a===null)return reject(n.InvalidSpecificationQuery,`Invalid 'then query' declaration '${t.content}' - expected 'then query <Query> [exactly]'`,t);let o=[],s=[],c=!1;for(let r=e.peekChild(t.indent);r!==void 0;r=e.peekChild(t.indent))e.reader.takeSignificant(),r.content===`arguments`&&!c?o.push(...parseValues(e.valueContext,r,!0,void 0,e)):r.content===`arguments`?reject(n.DuplicateSpecificationQueryArguments,`Query assertion '${a[1]}' already declares arguments`,r):r.content===`result`?s.push({kind:`SpecificationQueryResultSyntax`,properties:parseValues(e.valueContext,r,!0),exactly:!1,location:w(r)}):reject(n.UnknownSpecificationQueryDirective,`Unexpected '${h(r.content)}' in 'then query' body - expected arguments or result`,r),c||=r.content===`arguments`;r.thenQueries.push({kind:`SpecificationQuerySyntax`,query:a[1],arguments:o,results:s,exactly:a[2]!==void 0,location:w(t)});return}if(I.test(t.content)){let n=parseReadModelStep(e,t,R,`then`);n!==void 0&&r.thenReadModels.push(n);return}let a=parseEventStep(e,t,P,`then`);a!==void 0&&r.thenEvents.push(a)}function parseAbsentReadModel(e,t){let r=Z.exec(t.content);if(r!==null&&r[2]===void 0&&e.peekChild(t.indent)!==void 0)return{kind:`SpecificationAbsentReadModelSyntax`,name:r[1],key:E(e,t,void 0),location:w(t)};if(r===null||r[2]===void 0||r[2].endsWith(` exactly`))return e.error(n.InvalidAbsentReadModelStep,`Invalid absence assertion '${t.content}' - expected 'then no readmodel <ReadModelType> for <key>'`,w(t)),skipBody(e,t.indent),null;let i=r[2].trim(),a=!(i.startsWith(`"`)||i.startsWith(`'`))||ye.test(i)?f(i,w(t),e.valueContext):null,o=a!==null&&(a.kind===`LiteralExpressionSyntax`||a.kind===`ObjectExpressionSyntax`||a.kind===`CaseValueExpressionSyntax`);o||e.error(n.InvalidAbsentReadModelStep,`Invalid absence key '${i}' - expected exactly one concrete value.`,w(t));let s=!1;for(let r=e.peekChild(t.indent);r!==void 0;r=e.peekChild(t.indent))e.reader.takeSignificant(),e.error(n.InvalidAbsentReadModelStep,`An absent read model assertion cannot have child mappings.`,w(r)),s=!0;return s||!o?null:{kind:`SpecificationAbsentReadModelSyntax`,name:r[1],key:a,location:w(t)}}function skipBody(e,t){if(e.sourceOptions.numericMode!==`exact`)return e.skipBlock(t);e.skipOpaqueBlock(t)}function parseClock(e,t,r){let i=me.exec(t.content);return skipBody(e,t.indent),i===null||i[1]!==r?(e.error(l(t.content)?n.InvalidSpecificationCaseReference:n.InvalidSpecificationClock,`Invalid '${r} clock' - expected '${r} clock "<ISO 8601 instant>"', such as '${r} clock "2026-10-05T08:00:00Z"'`,w(t)),null):{kind:`SpecificationClockSyntax`,instant:i[2],location:w(t)}}function parseGivenGenerated(e,t){let r=X.exec(t.content),i=r===null?ie.exec(t.content):null;if(i!==null)return{kind:`SpecificationGeneratedValueSyntax`,command:i[1],property:i[2],source:E(e,t,i[3]),location:w(t)};if(r===null)return e.error(n.InvalidGeneratedFixture,`Expected 'given generated <Command>.<property> = <value>' with exactly one concrete value.`,w(t)),e.skipBlock(t.indent),null;let a=w(t),o=te(e,r[3],{...a,column:a.column+t.content.indexOf(r[3],t.content.indexOf(`=`)+1)},n.InvalidGeneratedFixture),s=e.peekChild(t.indent);return s!==void 0&&(e.error(n.InvalidGeneratedFixture,`A pinned generated value cannot have child directives.`,w(s)),e.skipBlock(t.indent)),o===null?null:{kind:`SpecificationGeneratedValueSyntax`,command:r[1],property:r[2],source:o,location:a}}function parseCapture(e,t,r){return parseNamedStep(e,t,ge,n.InvalidSpecificationCapture,`${r} capture`,`${r} capture <Capture>`,(e,n)=>({kind:`SpecificationCaptureSyntax`,capture:e,record:n,location:w(t)}))}function parseNamedStep(e,t,n,r,i,a,o,s=!1){let c=n.exec(t.content);return c===null?(e.error(r,`Invalid '${i}' declaration '${t.content}' - expected '${a}'`,w(t)),skipBody(e,t.indent),null):o(c[1],parseValues(e,t,!1,void 0,s?e:void 0))}function parseResult(e,t,r){let i=ve.exec(t.content);i===null?(e.error(n.InvalidSpecificationQueryAction,`Invalid 'then result' declaration '${t.content}' - expected 'then result [exactly]'`,w(t)),skipBody(e,t.indent)):r.thenResults.push({kind:`SpecificationQueryResultSyntax`,properties:parseValues(e,t),exactly:i[1]!==void 0,location:w(t)})}function parseReadModelStep(e,t,r,i){let a=r.exec(t.content);if(a===null)e.error(n.InvalidReadModelStep,`Invalid '${i} readmodel' declaration '${t.content}' - expected '${i} readmodel <ReadModelType>'`,w(t)),skipBody(e,t.indent);else return{kind:`SpecificationReadModelSyntax`,name:a[1],properties:parseValues(e,t,!1,a),exactly:i===`then`&&a.groups?.exactly!==void 0,inlineProperty:a.groups?.property??null,location:w(t)}}function parseEventStep(e,t,r,i){let a=r.exec(t.content);if(a===null)e.error(n.InvalidEventStep,`Invalid '${i}' declaration '${t.content}' - expected '${i} <EventType>'`,w(t)),skipBody(e,t.indent);else return{kind:`SpecificationEventSyntax`,eventType:a[1],...parseValuesWithEventSource(e,t,void 0,a,i),inlineProperty:a.groups?.property??null,location:w(t)}}const Q=o(`^stream\\s+([A-Za-z_]\\w*)\\.([A-Za-z_]\\w*)$`),Ce=a(`^streamId\\s*=(?!=|>)\\s*(.+)$`);function parseValuesWithEventSource(e,r,i,a,o){let s=[];_(e,r,a,s);let c=null,l,u,d=!1;for(let a=e.peekChild(r.indent);a!==void 0;a=e.peekChild(r.indent)){e.reader.takeSignificant();let r;if(i!==void 0&&b.test(a.content)){let t=x(e,a,y,n.InvalidGeneratedFixture);t!==null&&i.push(t);continue}let p=V.exec(a.content);if(p!==null)g(e,s,mappingOf(e,a,p));else if(h(a.content)===`stream`||a.content.startsWith(`no stream`)){if(o===void 0){e.error(n.SpecificationStreamOnCommand,`A command occurrence cannot declare a route; assert it on a then event.`,w(a)),e.skipBlock(a.indent);continue}if(d){e.error(n.InvalidSpecificationStream,`An event occurrence declares at most one stream or no stream directive.`,w(a)),e.skipBlock(a.indent);continue}let t=Q.exec(a.content);a.content===`no stream`&&(o===`then`||o===`when redelivered`)?(u={kind:`SpecificationNoStreamSyntax`,location:w(a)},d=!0,rejectSpecificationRouteChildren(e,a)):t===null?(e.error(n.InvalidSpecificationStream,`Expected 'stream Source.Stream', or 'no stream' on a then event.`,w(a)),e.skipBlock(a.indent)):(l=parseSpecificationStream(e,a,t),d=!0)}else if(h(a.content)===`for`){let t=a.content.substring(3).trim();t.length===0?e.error(n.InvalidSpecificationEventSource,`Invalid event-source assertion 'for' - expected 'for <value>'`,w(a)):c===null?c=f(t,w(a),e):e.error(n.DuplicateSpecificationEventSource,`A specification step can declare its event-source assertion only once`,w(a))}else(r=D(e,a))===void 0?e.error(n.InvalidSpecificationValue,`Invalid property mapping '${a.content}' - expected '<property> = <value>'`,w(a),t(`text`,a.content)):g(e,s,r)}return{values:s,for:c,...l===void 0?{}:{stream:l},...u===void 0?{}:{noStream:u}}}function parseSpecificationStream(t,r,i){let a=null,o=[],s=!1,c={};for(let i=t.peekChild(r.indent);i!==void 0;i=t.peekChild(r.indent)){if(t.reader.takeSignificant(),i.content===`streamId`){a!==null||s?(t.error(n.InvalidSpecificationStream,`Declare either one 'streamId = <literal>' mapping or one streamId part block.`,w(i)),t.skipBlock(i.indent)):(s=!0,c.streamId=w(i),o=e(t,i,n.InvalidSpecificationStream).map(e=>e.source.kind===`PathExpressionSyntax`&&e.source.path.startsWith(`case.`)?{...e,source:f(e.source.path,e.source.location,t)}:e));continue}let r=Ce.exec(i.content);if(r===null||a!==null||s){t.error(n.InvalidSpecificationStream,`Declare either one 'streamId = <literal>' mapping or one streamId part block.`,w(i)),t.skipBlock(i.indent);continue}let l={...w(i),column:i.indent+1+i.content.indexOf(r[1],i.content.indexOf(`=`)+1)};a={kind:`PropertyMappingSyntax`,property:`streamId`,source:f(r[1],l,t),location:w(i)},rejectSpecificationRouteChildren(t,i)}return{kind:`SpecificationStreamSyntax`,eventSource:i[1],stream:i[2],streamId:a,streamIdParts:o,directiveLocations:c,referenceLocation:{...w(r),column:r.indent+1+r.content.indexOf(i[1],6)},referenceLength:i[1].length+1+i[2].length,location:w(r)}}function rejectSpecificationRouteChildren(e,t){let r=e.peekChild(t.indent);r!==void 0&&(e.error(n.InvalidSpecificationStream,`This directive cannot have children.`,w(r)),e.skipBlock(t.indent))}function parseValues(e,r,i=!1,a,o){let s=[];_(e,r,a,s);for(let a=e.peekChild(r.indent);a!==void 0;a=e.peekChild(r.indent)){e.reader.takeSignificant();let r=(i||e.sourceOptions.numericMode===`exact`?H:V).exec(a.content),c=r===null?D(e,a):void 0;if(r===null&&c===void 0){e.error(n.InvalidSpecificationValue,`Invalid property mapping '${a.content}' - expected '<property> = <value>'`,w(a),t(`text`,a.content));continue}let l=c??mappingOf(e,a,r,i);o===void 0?g(e,s,l):(s.some(e=>e.property===l.property)&&o.error(n.UnknownSpecificationQueryArgument,`Query argument '${l.property}' is repeated.`,l.location,t(`argument`,l.property)),s.push(l))}return s}function mappingOf(e,t,n,r=!1){return{kind:`PropertyMappingSyntax`,property:n[1],source:f(n[2],w(t),e,r),location:w(t)}}const $=a(`^when\\s+start\\s+(.+)$`),we=a(`^outcome\\s+([A-Za-z_]\\w*)\\s+([A-Za-z_]\\w*)$`),Te=a(`^then\\s+(is|sends|starts|completes|fails\\s+at|waits\\s+at)(?:\\s+([A-Za-z_]\\w*))?$`);function lifecycleExpectation(e){let t=Te.exec(e.content);if(t===null)return;let n=t[1].replace(/\s+/g,` `),r=n===`is`?`State`:n===`sends`?`Sends`:n===`starts`?`Starts`:n===`completes`?`Completes`:n===`fails at`?`Fails`:`Waits`;if(t[2]!==void 0!=(r===`Completes`))return{kind:`LifecycleExpectationSyntax`,expectation:r,target:t[2]??null,location:w(e)}}function parseLifecycleSpecification(e,t,n){let r=k.exec(t.content);if(r===null)return e.error(n,`Invalid specification '${t.content}' - expected 'specification <Name>'.`,w(t)),skipBody(e,t.indent),{kind:`LifecycleSpecificationSyntax`,name:``,description:null,given:[],whenAppended:null,whenStarted:null,outcomes:[],then:[],location:w(t)};let i=r[1],a=null,o=[],s=null,c=null,l=!1,u=[],d=[],p={};for(let r=e.peekChild(t.indent);r!==void 0;r=e.peekChild(t.indent)){e.reader.takeSignificant();let t=h(r.content);if(t===`description`)a=m(e,r,a,`Specification '${i}'`),p.description??=w(r);else if(t===`given`){let t=parseEventStep(e,r,j,`given`);t!==void 0&&o.push(t)}else if(t===`when`){if(l){e.error(n,`Specification '${i}' already declares a 'when'.`,w(r)),skipBody(e,r.indent);continue}l=!0;let t=$.exec(r.content);if(t!==null){let n=r.content.indexOf(t[1],10);c=f(t[1].trim(),T(r.number,r.indent+(r.contentOffset??0)+1+n,r.path),e)}else r.content.startsWith(`when append`)?s=parseEventStep(e,r,M,`when append`)??null:(e.error(n,`Invalid '${r.content}' - expected 'when append <Event>' or 'when start <key>'.`,w(r)),skipBody(e,r.indent))}else if(t===`outcome`){let t=we.exec(r.content);t===null?e.error(n,`Invalid outcome '${r.content}' - expected 'outcome <Node> <outlet>'.`,w(r)):u.push({kind:`LifecycleOutcomeSyntax`,node:t[1],outlet:t[2],location:w(r)}),v(e,r,n,`An outcome cannot have children.`)}else if(t===`then`){let t=lifecycleExpectation(r);t===void 0?e.error(n,`Invalid '${r.content}' - expected 'then is <State>', 'then sends <Command>', 'then starts <Workflow>', 'then completes', 'then fails at <Node>' or 'then waits at <Node>'.`,w(r)):d.push(t),v(e,r,n,`A then line cannot have children.`)}else e.error(n,`Unexpected '${r.content}' in specification '${i}' - expected description, given, when, outcome or then.`,w(r)),e.skipBlock(r.indent)}return{kind:`LifecycleSpecificationSyntax`,name:i,description:a,given:o,whenAppended:s,whenStarted:c,outcomes:u,then:d,location:w(t),directiveLocations:p}}export{parseLifecycleSpecification,parseSpecification,parseSpecificationStream,rejectSpecificationRouteChildren,Q as specificationStream};
1
+ import"../../_virtual/_virtual/_rolldown/runtime.js";import{parseRouteParts as e}from"./EventSourceParser.js";import{diagnosticText as t}from"../Diagnostics/DiagnosticArgument.js";import{DiagnosticCodes as n}from"../Diagnostics/DiagnosticCodes.js";import{dotNetWhitespace as r,nativePattern as i,pattern as a}from"../Text/patterns.js";import{sourceStreamPattern as o}from"../Text/SourceStreamNames.js";import{stringBodyPattern as s,unescapeString as c}from"../Text/StringLiteral.js";import{containsCaseReference as l,parseCase as u,parseParameter as d,parseSpecificationValue as f,validateTable as p}from"./SpecificationCaseParser.js";import{parseDescription as m}from"./DescriptionParser.js";import{isFileDirective as ee}from"./FileReferences.js";import{firstWord as h}from"./LineText.js";import{addFixtureValue as g,addInlineValue as _}from"./SpecificationExampleParser.js";import{rejectOperationChildren as v}from"./OperationParser.js";import{generatedFixturePattern as y,generatedFixturePrefix as b,parseConcrete as te,parseConcreteMapping as x,parseReturn as S,thenReturnsPrefix as C}from"./SpecificationResponseParser.js";import{locationOf as w}from"./SourceLine.js";import{sourceLocation as T}from"../Diagnostics/SourceLocation.js";import{parseStructuredValue as E,tryParseStructuredMapping as D}from"./StructuredBlockParser.js";const ne=a(`^(?:given\\s+operation|then\\s+(?:operation|compensated))(?:\\s|$)`),re=a(`^(given operation|then operation|then compensated)\\s+([A-Za-z_]\\w*(?:\\.[A-Za-z_]\\w*)*)(\\s+fails)?$`),O=a(`^specification\\s+([A-Za-z_]\\w*)$`),k=O,A=a(`^given caller as ([A-Za-z_]\\w*)$`),stepPattern=(e,t=``)=>i(`^${e}\\s+([A-Z]\\w*(?:\\.\\w+)*)${t}(?:\\s+(?<property>[\\w.]+)\\s*=(?!=|>)\\s*(?<value>.+))?$`.replaceAll(`\\s`,r)),j=stepPattern(`given`),M=stepPattern(`when\\s+append`),N=stepPattern(`when`),P=stepPattern(`then`),F=a(`^then\\s+query\\b`),I=a(`^(?:given|then)\\s+readmodel\\b`),L=stepPattern(`given\\s+readmodel`),R=stepPattern(`then\\s+readmodel`,`(?<exactly>\\s+exactly)?`),z=a(`^then\\s+no\\b`),B=a(`^then\\s+error\\s+"(${s})"$`),V=a(`^([\\w.]+)\\s*=(?!=|>)\\s*(.+)$`),H=i(`^([\\w.]+)\\s*=(?!=|>)\\s*(.+)$`),U=a(`^given\\s+time\\s+zone\\b`),W=a(`^given\\s+time\\s+zone\\s+"(${s})"$`),G=a(`^given\\s+clock\\b`),K=a(`^given\\s+capture\\b`),q=a(`^then\\s+invokes\\b`),J=a(`^then\\s+invokes\\s+([A-Za-z_]\\w*(?:\\.[A-Za-z_]\\w*)*)$`),Y=a(`^given\\s+generated\\b`),X=a(`^given\\s+generated\\s+([A-Z]\\w*)\\.([a-z_]\\w*)\\s*=(?!=|>)\\s*(.+)$`),ie=a(`^given\\s+generated\\s+([A-Z]\\w*)\\.([a-z_]\\w*)(?:\\s+(none|empty))?$`),ae=a(`^when\\s+clock\\b`),oe=a(`^when\\s+trigger\\b`),se=a(`^when\\s+capture\\b`),ce=a(`^when\\s+query\\b`),le=a(`^then\\s+result\\b`),ue=a(`^then\\s+no\\s+result\\b`),de=i(`^when\\s+redelivered\\b`),fe=i(`^when\\s+redelivered\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)\\s+to\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)$`),pe=a(`^then\\s+no\\s+events\\b`),me=a(`^(given|when)\\s+clock\\s+"(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d+)?)?(?:Z|[+-]\\d{2}:\\d{2}))"$`),he=a(`^when\\s+trigger\\s+([A-Za-z_]\\w*)$`),ge=a(`^(?:given|when)\\s+capture\\s+([A-Za-z_]\\w*)$`),_e=a(`^when\\s+query\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)$`),ve=a(`^then\\s+result(\\s+exactly)?$`),Z=i(`^then\\s+no\\s+readmodel\\s+([A-Z]\\w*)\\s+for(?:\\s+(.+))?$`),ye=i(`^(?:"${s}"|'(?:[^'\\\\]|\\\\.)*')$`),be=i(`^then\\s+query\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)(\\s+exactly)?$`);function parseSpecification(e,t){let r=O.exec(t.content)?.[1]??``;r===``&&e.error(n.InvalidSpecificationDeclaration,`Invalid specification declaration '${t.content}' - expected 'specification <Name>'`,w(t));let i=null,a=[],o=[],s={givenOperationFailures:[],thenOperations:[],thenCompensated:[],thenAbsentReadModels:[],thenQueries:[],given:[],givenReadModels:[],when:null,whenAppended:null,whenRedelivered:null,whenDeclared:!1,thenEvents:[],thenEventsInAnyOrder:!1,thenNoEvents:!1,thenReadModels:[],thenErrors:[],givenClock:null,givenTimeZone:null,givenCaptures:[],whenClock:null,whenTrigger:null,whenCapture:null,whenQuery:null,thenResults:[],thenNoResult:null,thenDenied:null,givenCaller:null,thenReturns:null};for(let c=e.peekChild(t.indent);c!==void 0;c=e.peekChild(t.indent)){if(e.reader.takeSignificant(),ee(c)||parseOperationStep(e,c,s))continue;let t=z.test(c.content)?`then`:h(c.content);if(t===`parameter`){let t=d(e,c);t!==null&&a.push(t)}else if(t===`case`){let t=u(e,c);t!==null&&o.push(t)}else t===`description`?i=m(e,c,i,`Specification '${r}'`):t===`given`?parseGiven(e,c,s):t===`when`?parseWhen(e,c,s,r):t===`then`?parseThen(e,c,s):(e.error(n.UnknownSpecificationDirective,`Unexpected '${h(c.content)}' in specification body`,w(c)),e.skipBlock(c.indent))}s.noEventsLine!==void 0&&(s.thenEvents.length>0||s.thenEventsInAnyOrder||s.thenErrors.length>0||s.thenDenied!==null)&&e.error(n.InvalidNoEventsExpectation,`'then no events' cannot accompany event, event-order, error or denial expectations.`,w(s.noEventsLine)),validateQueryRejection(e,t,s);let{whenDeclared:c,noEventsLine:l,...f}=s,g={kind:`SpecificationSyntax`,sourceOptions:e.sourceOptions,name:r,description:i,...f,...a.length===0?{}:{parameters:a},...o.length===0?{}:{cases:o},location:w(t)};return p(g,e),g}function validateQueryRejection(e,t,r){isQueryRejectionCandidate(r)&&!isWellFormedQueryRejection(r)&&e.error(n.MismatchedSpecificationQueryResult,`A query rejection requires exactly one query and one 'then error', no action, and no other outcomes`,w(t))}function isQueryRejectionCandidate(e){return e.thenErrors.length>0&&queriedCallCount(e)>0&&(e.whenQuery!==null||!hasAction(e))}function isWellFormedQueryRejection(e){return!hasAction(e)&&hasOneQueryAndOneError(e)&&!hasOtherOutcome(e)}function hasOneQueryAndOneError(e){return queriedCallCount(e)===1&&e.thenErrors.length===1}function hasAction(e){return[e.when,e.whenAppended,e.whenClock,e.whenTrigger,e.whenCapture,e.whenRedelivered].some(e=>e!==null)}function queriedCallCount(e){return e.thenQueries.length+(e.whenQuery===null?0:1)}function hasOtherOutcome(e){return[e.thenResults.length>0,e.thenNoResult!==null,e.thenDenied!==null,e.thenEvents.length>0,e.thenNoEvents,e.thenEventsInAnyOrder,e.thenReadModels.length>0,e.thenAbsentReadModels.length>0,e.thenReturns!==null,e.thenQueries.some(e=>e.results.length>0)].some(e=>e)}function parseOperationStep(e,t,r){if(!ne.test(t.content))return!1;let i=re.exec(t.content);if(i===null||i[1]===`given operation`!=(i[3]!==void 0))e.error(n.InvalidOperationSpecification,`Expected 'given operation <Name> fails', 'then operation <Name>' or 'then compensated <Name>'.`,w(t)),skipBody(e,t.indent);else if(i[1]===`then operation`){let a=[];for(let r=e.peekChild(t.indent);r!==void 0;r=e.peekChild(t.indent)){e.reader.takeSignificant();let t=x(e,r,V,n.InvalidOperationSpecification);t!==null&&a.push(t)}r.thenOperations.push({kind:`SpecificationOperationSyntax`,operation:i[2],values:a,location:w(t)})}else v(e,t,n.InvalidOperationSpecification,`Failure and compensation assertions cannot have children.`),i[1]===`given operation`?r.givenOperationFailures.push({kind:`SpecificationOperationFailureSyntax`,operation:i[2],location:w(t)}):r.thenCompensated.push({kind:`SpecificationCompensatedSyntax`,operation:i[2],location:w(t)});return!0}const xe=[{matches:e=>G.test(e.content),parse:parseGivenClock},{matches:e=>U.test(e.content),parse:parseGivenTimeZone},{matches:e=>Y.test(e.content),parse:parseGivenGeneratedValue},{matches:e=>K.test(e.content),parse:parseGivenCapture},{matches:e=>e.content.startsWith(`given caller`),parse:parseGivenCaller},{matches:e=>I.test(e.content),parse:parseGivenReadModel},{matches:()=>!0,parse:parseGivenEvent}];function parseGiven(e,t,n){for(let r of xe)if(r.matches(t)){r.parse(e,t,n);return}}function parseGivenClock(e,t,r){r.givenClock===null?r.givenClock=parseClock(e,t,`given`):(e.error(n.InvalidSpecificationClock,`A specification states its clock at most once.`,w(t)),skipBody(e,t.indent))}function parseGivenTimeZone(e,t,r){let i=W.exec(t.content);skipBody(e,t.indent),r.givenTimeZone!==null||i===null?e.error(n.InvalidSpecificationTimeZone,`A specification states its time zone at most once, as 'given time zone "<id>"'.`,w(t)):r.givenTimeZone={kind:`SpecificationTimeZoneSyntax`,id:c(i[1]),location:w(t)}}function parseGivenGeneratedValue(e,t,n){let r=parseGivenGenerated(e,t);r!==null&&(n.givenGenerated??=[]).push(r)}function parseGivenCapture(e,t,n){let r=parseCapture(e,t,`given`);r!==null&&n.givenCaptures.push(r)}function parseGivenCaller(e,t,r){r.givenCaller!==null||r.givenCallerPersona!==void 0?(e.error(n.DuplicateSpecificationCallerOrDenied,`A specification has at most one 'given caller' block.`,w(t)),e.skipBlock(t.indent)):t.content.startsWith(`given caller as`)?parseGivenCallerPersona(e,t,r):r.givenCaller=parseCaller(e,t)}function parseGivenCallerPersona(e,t,r){let i=A.exec(t.content);i===null&&e.error(n.InvalidSpecificationCallerPersona,`Expected 'given caller as <Persona>'.`,w(t));let a=e.peekChild(t.indent);a!==void 0&&e.error(n.InvalidSpecificationCallerPersona,`'given caller as <Persona>' has no body; use an explicit 'given caller' for refinements.`,w(a)),skipBody(e,t.indent),i!==null&&(r.givenCallerPersona={kind:`SpecificationCallerPersonaSyntax`,name:i[1],location:w(t)})}function parseGivenReadModel(e,t,n){let r=parseReadModelStep(e,t,L,`given`);r!==void 0&&n.givenReadModels.push(r)}function parseGivenEvent(e,t,n){let r=parseEventStep(e,t,j,`given`);r!==void 0&&n.given.push(r)}const Se=a(`^role${r}+"(${s})"$`),Ce=a(`^claim${r}+"(${s})"${r}*=${r}*"(${s})"$`);function parseCaller(e,t){if(t.content!==`given caller`)return e.error(n.InvalidSpecificationCaller,`Expected exactly 'given caller'.`,w(t)),e.skipBlock(t.indent),null;let r=!1,i=[],a=[];for(let o=e.peekChild(t.indent);o!==void 0;o=e.peekChild(t.indent)){e.reader.takeSignificant();let t=Se.exec(o.content),s=Ce.exec(o.content);o.content===`authenticated`&&!r?r=!0:t===null?s===null?e.error(l(o.content)?n.InvalidSpecificationCaseReference:n.InvalidSpecificationCaller,`Invalid caller fixture '${o.content}' - expected authenticated, role "...", or claim "..." = "...".`,w(o)):a.push({kind:`SpecificationCallerClaimSyntax`,type:c(s[1]),value:c(s[2]),location:w(o)}):i.push(c(t[1]))}return{kind:`SpecificationCallerSyntax`,authenticated:r,roles:i,claims:a,location:w(t)}}function parseWhen(e,t,r,i){let a=t.content.startsWith(`when append`);if(r.whenDeclared){let o=r.whenAppended!==null||a?n.ConflictingSpecificationActions:n.DuplicateSpecificationWhen;e.error(o,`Specification '${i}' already declares a 'when' - a specification can have at most one`,w(t)),skipBody(e,t.indent);return}if(r.whenDeclared=!0,a){r.whenAppended=parseEventStep(e,t,M,`when append`)??null;return}if(de.test(t.content)){let i=fe.exec(t.content);i===null?(e.error(n.UnmatchedRedeliveredOccurrence,`Expected 'when redelivered <Event> to <Reaction>'.`,w(t)),skipBody(e,t.indent)):r.whenRedelivered={kind:`SpecificationRedeliverySyntax`,eventType:i[1],reaction:i[2],...parseValuesWithEventSource(e,t,void 0,void 0,`when redelivered`),location:w(t)};return}if(ae.test(t.content)){r.whenClock=parseClock(e,t,`when`);return}if(oe.test(t.content)){r.whenTrigger=parseNamedStep(e,t,he,n.InvalidSpecificationTrigger,`when trigger`,`when trigger <Trigger>`,(e,n)=>({kind:`SpecificationTriggerSyntax`,trigger:e,values:n,location:w(t)}));return}if(se.test(t.content)){r.whenCapture=parseCapture(e,t,`when`);return}if(ce.test(t.content)){r.whenQuery=parseNamedStep(e,t,_e,n.InvalidSpecificationQueryAction,`when query`,`when query <Query>`,(e,n)=>({kind:`SpecificationWhenQuerySyntax`,query:e,arguments:n,location:w(t)}),!0);return}let o=N.exec(t.content);if(o===null){e.error(n.InvalidSpecificationWhen,`Invalid 'when' declaration '${t.content}' - expected 'when <CommandType>' or 'when append <EventType>'`,w(t)),skipBody(e,t.indent);return}let s=[],c=parseValuesWithEventSource(e,t,s,o);r.when={kind:`SpecificationCommandSyntax`,commandType:o[1],...c,generatedValues:s,inlineProperty:o.groups?.property??null,location:w(t)}}function parseThen(e,t,r){if(pe.test(t.content)){t.content!==`then no events`||r.thenNoEvents?e.error(n.InvalidNoEventsExpectation,`Expected one 'then no events' directive.`,w(t)):(r.thenNoEvents=!0,r.noEventsLine=t);let i=e.peekChild(t.indent);i!==void 0&&e.error(n.InvalidNoEventsExpectation,`'then no events' cannot have child mappings.`,w(i)),skipBody(e,t.indent);return}if(C.test(t.content)){let i=S(e,t);r.thenReturns===null?r.thenReturns=i:e.error(n.InvalidReturnExpectation,`A specification declares at most one return expectation.`,w(t));return}if(t.content.startsWith(`then events`)){t.content!==`then events in any order`||r.thenEventsInAnyOrder?e.error(n.InvalidSpecificationEventOrder,`Expected one 'then events in any order' directive.`,w(t)):r.thenEventsInAnyOrder=!0,skipBody(e,t.indent);return}if(le.test(t.content)){parseResult(e,t,r);return}if(ue.test(t.content)){t.content!==`then no result`||r.thenNoResult!==null?e.error(n.InvalidSpecificationQueryAction,`Expected one 'then no result' directive.`,w(t)):r.thenNoResult={kind:`SpecificationNoResultSyntax`,location:w(t)},skipBody(e,t.indent);return}if(q.test(t.content)){let i=parseNamedStep(e,t,J,n.InvalidSpecificationInvocation,`then invokes`,`then invokes <Command>`,(e,n)=>({kind:`SpecificationInvocationSyntax`,command:e,values:n,location:w(t)}));i!==null&&(r.thenInvocations??=[]).push(i);return}if(t.content.startsWith(`then denied`)){t.content===`then denied`?r.thenDenied===null?r.thenDenied={kind:`SpecificationDeniedSyntax`,location:w(t)}:e.error(n.DuplicateSpecificationCallerOrDenied,`A specification has at most one 'then denied' outcome.`,w(t)):(e.error(n.InvalidSpecificationDenied,`Expected exactly 'then denied'.`,w(t)),skipBody(e,t.indent));return}if(t.content===`then error`){r.thenErrors.push({kind:`SpecificationErrorSyntax`,name:null,location:w(t)});return}if(t.content.startsWith(`then error case.`)){let n=f(t.content.substring(11),{...w(t),column:w(t).column+11},e);n.kind===`CaseValueExpressionSyntax`&&r.thenErrors.push({kind:`SpecificationErrorSyntax`,name:null,caseValue:n,location:w(t)});return}let i=B.exec(t.content);if(i!==null){r.thenErrors.push({kind:`SpecificationErrorSyntax`,name:c(i[1]),location:w(t)});return}if(h(t.content.substring(4).trim())===`error`){e.error(n.InvalidThenError,`Invalid 'then error' declaration '${t.content}' - expected 'then error' or 'then error "<reason>"'`,w(t)),skipBody(e,t.indent);return}if(z.test(t.content)){if(e.sourceOptions.numericMode===`exact`){let n=parseAbsentReadModel(e,t);n!==null&&r.thenAbsentReadModels.push(n);return}let n=Z.exec(t.content);if(n!==null&&n[2]===void 0&&e.peekChild(t.indent)!==void 0){r.thenAbsentReadModels.push({kind:`SpecificationAbsentReadModelSyntax`,name:n[1],key:E(e.valueContext,t,void 0),location:w(t)});return}if(n!==null&&n[2]!==void 0&&!n[2].endsWith(` exactly`)){let i=f(n[2].trim(),w(t),e.valueContext);(i.kind===`LiteralExpressionSyntax`||i.kind===`ObjectExpressionSyntax`||i.kind===`CaseValueExpressionSyntax`)&&r.thenAbsentReadModels.push({kind:`SpecificationAbsentReadModelSyntax`,name:n[1],key:i,location:w(t)})}e.skipOpaqueBlock(t.indent);return}if(F.test(t.content)){let i=e.sourceOptions.numericMode===`exact`,reject=(t,n,r)=>{if(!i)return e.skipOpaqueBlock(r.indent);e.error(t,n,w(r)),e.skipBlock(r.indent)},a=be.exec(t.content);if(a===null)return reject(n.InvalidSpecificationQuery,`Invalid 'then query' declaration '${t.content}' - expected 'then query <Query> [exactly]'`,t);let o=[],s=[],c=!1;for(let r=e.peekChild(t.indent);r!==void 0;r=e.peekChild(t.indent))e.reader.takeSignificant(),r.content===`arguments`&&!c?o.push(...parseValues(e.valueContext,r,!0,void 0,e)):r.content===`arguments`?reject(n.DuplicateSpecificationQueryArguments,`Query assertion '${a[1]}' already declares arguments`,r):r.content===`result`?s.push({kind:`SpecificationQueryResultSyntax`,properties:parseValues(e.valueContext,r,!0),exactly:!1,location:w(r)}):reject(n.UnknownSpecificationQueryDirective,`Unexpected '${h(r.content)}' in 'then query' body - expected arguments or result`,r),c||=r.content===`arguments`;r.thenQueries.push({kind:`SpecificationQuerySyntax`,query:a[1],arguments:o,results:s,exactly:a[2]!==void 0,location:w(t)});return}if(I.test(t.content)){let n=parseReadModelStep(e,t,R,`then`);n!==void 0&&r.thenReadModels.push(n);return}let a=parseEventStep(e,t,P,`then`);a!==void 0&&r.thenEvents.push(a)}function parseAbsentReadModel(e,t){let r=Z.exec(t.content);if(r!==null&&r[2]===void 0&&e.peekChild(t.indent)!==void 0)return{kind:`SpecificationAbsentReadModelSyntax`,name:r[1],key:E(e,t,void 0),location:w(t)};if(r===null||r[2]===void 0||r[2].endsWith(` exactly`))return e.error(n.InvalidAbsentReadModelStep,`Invalid absence assertion '${t.content}' - expected 'then no readmodel <ReadModelType> for <key>'`,w(t)),skipBody(e,t.indent),null;let i=r[2].trim(),a=!(i.startsWith(`"`)||i.startsWith(`'`))||ye.test(i)?f(i,w(t),e.valueContext):null,o=a!==null&&(a.kind===`LiteralExpressionSyntax`||a.kind===`ObjectExpressionSyntax`||a.kind===`CaseValueExpressionSyntax`);o||e.error(n.InvalidAbsentReadModelStep,`Invalid absence key '${i}' - expected exactly one concrete value.`,w(t));let s=!1;for(let r=e.peekChild(t.indent);r!==void 0;r=e.peekChild(t.indent))e.reader.takeSignificant(),e.error(n.InvalidAbsentReadModelStep,`An absent read model assertion cannot have child mappings.`,w(r)),s=!0;return s||!o?null:{kind:`SpecificationAbsentReadModelSyntax`,name:r[1],key:a,location:w(t)}}function skipBody(e,t){if(e.sourceOptions.numericMode!==`exact`)return e.skipBlock(t);e.skipOpaqueBlock(t)}function parseClock(e,t,r){let i=me.exec(t.content);return skipBody(e,t.indent),i===null||i[1]!==r?(e.error(l(t.content)?n.InvalidSpecificationCaseReference:n.InvalidSpecificationClock,`Invalid '${r} clock' - expected '${r} clock "<ISO 8601 instant>"', such as '${r} clock "2026-10-05T08:00:00Z"'`,w(t)),null):{kind:`SpecificationClockSyntax`,instant:i[2],location:w(t)}}function parseGivenGenerated(e,t){let r=X.exec(t.content),i=r===null?ie.exec(t.content):null;if(i!==null)return{kind:`SpecificationGeneratedValueSyntax`,command:i[1],property:i[2],source:E(e,t,i[3]),location:w(t)};if(r===null)return e.error(n.InvalidGeneratedFixture,`Expected 'given generated <Command>.<property> = <value>' with exactly one concrete value.`,w(t)),e.skipBlock(t.indent),null;let a=w(t),o=te(e,r[3],{...a,column:a.column+t.content.indexOf(r[3],t.content.indexOf(`=`)+1)},n.InvalidGeneratedFixture),s=e.peekChild(t.indent);return s!==void 0&&(e.error(n.InvalidGeneratedFixture,`A pinned generated value cannot have child directives.`,w(s)),e.skipBlock(t.indent)),o===null?null:{kind:`SpecificationGeneratedValueSyntax`,command:r[1],property:r[2],source:o,location:a}}function parseCapture(e,t,r){return parseNamedStep(e,t,ge,n.InvalidSpecificationCapture,`${r} capture`,`${r} capture <Capture>`,(e,n)=>({kind:`SpecificationCaptureSyntax`,capture:e,record:n,location:w(t)}))}function parseNamedStep(e,t,n,r,i,a,o,s=!1){let c=n.exec(t.content);return c===null?(e.error(r,`Invalid '${i}' declaration '${t.content}' - expected '${a}'`,w(t)),skipBody(e,t.indent),null):o(c[1],parseValues(e,t,!1,void 0,s?e:void 0))}function parseResult(e,t,r){let i=ve.exec(t.content);i===null?(e.error(n.InvalidSpecificationQueryAction,`Invalid 'then result' declaration '${t.content}' - expected 'then result [exactly]'`,w(t)),skipBody(e,t.indent)):r.thenResults.push({kind:`SpecificationQueryResultSyntax`,properties:parseValues(e,t),exactly:i[1]!==void 0,location:w(t)})}function parseReadModelStep(e,t,r,i){let a=r.exec(t.content);if(a===null)e.error(n.InvalidReadModelStep,`Invalid '${i} readmodel' declaration '${t.content}' - expected '${i} readmodel <ReadModelType>'`,w(t)),skipBody(e,t.indent);else return{kind:`SpecificationReadModelSyntax`,name:a[1],properties:parseValues(e,t,!1,a),exactly:i===`then`&&a.groups?.exactly!==void 0,inlineProperty:a.groups?.property??null,location:w(t)}}function parseEventStep(e,t,r,i){let a=r.exec(t.content);if(a===null)e.error(n.InvalidEventStep,`Invalid '${i}' declaration '${t.content}' - expected '${i} <EventType>'`,w(t)),skipBody(e,t.indent);else return{kind:`SpecificationEventSyntax`,eventType:a[1],...parseValuesWithEventSource(e,t,void 0,a,i),inlineProperty:a.groups?.property??null,location:w(t)}}const Q=o(`^stream\\s+([A-Za-z_]\\w*)\\.([A-Za-z_]\\w*)$`),$=a(`^streamId\\s*=(?!=|>)\\s*(.+)$`);function parseValuesWithEventSource(e,r,i,a,o){let s=[];_(e,r,a,s);let c=null,l,u,d=!1;for(let a=e.peekChild(r.indent);a!==void 0;a=e.peekChild(r.indent)){e.reader.takeSignificant();let r;if(i!==void 0&&b.test(a.content)){let t=x(e,a,y,n.InvalidGeneratedFixture);t!==null&&i.push(t);continue}let p=V.exec(a.content);if(p!==null)g(e,s,mappingOf(e,a,p));else if(h(a.content)===`stream`||a.content.startsWith(`no stream`)){if(o===void 0){e.error(n.SpecificationStreamOnCommand,`A command occurrence cannot declare a route; assert it on a then event.`,w(a)),e.skipBlock(a.indent);continue}if(d){e.error(n.InvalidSpecificationStream,`An event occurrence declares at most one stream or no stream directive.`,w(a)),e.skipBlock(a.indent);continue}let t=Q.exec(a.content);a.content===`no stream`&&(o===`then`||o===`when redelivered`)?(u={kind:`SpecificationNoStreamSyntax`,location:w(a)},d=!0,rejectSpecificationRouteChildren(e,a)):t===null?(e.error(n.InvalidSpecificationStream,`Expected 'stream Source.Stream', or 'no stream' on a then event.`,w(a)),e.skipBlock(a.indent)):(l=parseSpecificationStream(e,a,t),d=!0)}else if(h(a.content)===`for`){let t=a.content.substring(3).trim();t.length===0?e.error(n.InvalidSpecificationEventSource,`Invalid event-source assertion 'for' - expected 'for <value>'`,w(a)):c===null?c=f(t,w(a),e):e.error(n.DuplicateSpecificationEventSource,`A specification step can declare its event-source assertion only once`,w(a))}else(r=D(e,a))===void 0?e.error(n.InvalidSpecificationValue,`Invalid property mapping '${a.content}' - expected '<property> = <value>'`,w(a),t(`text`,a.content)):g(e,s,r)}return{values:s,for:c,...l===void 0?{}:{stream:l},...u===void 0?{}:{noStream:u}}}function parseSpecificationStream(t,r,i){let a=null,o=[],s=!1,c={};for(let i=t.peekChild(r.indent);i!==void 0;i=t.peekChild(r.indent)){if(t.reader.takeSignificant(),i.content===`streamId`){a!==null||s?(t.error(n.InvalidSpecificationStream,`Declare either one 'streamId = <literal>' mapping or one streamId part block.`,w(i)),t.skipBlock(i.indent)):(s=!0,c.streamId=w(i),o=e(t,i,n.InvalidSpecificationStream).map(e=>e.source.kind===`PathExpressionSyntax`&&e.source.path.startsWith(`case.`)?{...e,source:f(e.source.path,e.source.location,t)}:e));continue}let r=$.exec(i.content);if(r===null||a!==null||s){t.error(n.InvalidSpecificationStream,`Declare either one 'streamId = <literal>' mapping or one streamId part block.`,w(i)),t.skipBlock(i.indent);continue}let l={...w(i),column:i.indent+1+i.content.indexOf(r[1],i.content.indexOf(`=`)+1)};a={kind:`PropertyMappingSyntax`,property:`streamId`,source:f(r[1],l,t),location:w(i)},rejectSpecificationRouteChildren(t,i)}return{kind:`SpecificationStreamSyntax`,eventSource:i[1],stream:i[2],streamId:a,streamIdParts:o,directiveLocations:c,referenceLocation:{...w(r),column:r.indent+1+r.content.indexOf(i[1],6)},referenceLength:i[1].length+1+i[2].length,location:w(r)}}function rejectSpecificationRouteChildren(e,t){let r=e.peekChild(t.indent);r!==void 0&&(e.error(n.InvalidSpecificationStream,`This directive cannot have children.`,w(r)),e.skipBlock(t.indent))}function parseValues(e,r,i=!1,a,o){let s=[];_(e,r,a,s);for(let a=e.peekChild(r.indent);a!==void 0;a=e.peekChild(r.indent)){e.reader.takeSignificant();let r=(i||e.sourceOptions.numericMode===`exact`?H:V).exec(a.content),c=r===null?D(e,a):void 0;if(r===null&&c===void 0){e.error(n.InvalidSpecificationValue,`Invalid property mapping '${a.content}' - expected '<property> = <value>'`,w(a),t(`text`,a.content));continue}let l=c??mappingOf(e,a,r,i);o===void 0?g(e,s,l):(s.some(e=>e.property===l.property)&&o.error(n.UnknownSpecificationQueryArgument,`Query argument '${l.property}' is repeated.`,l.location,t(`argument`,l.property)),s.push(l))}return s}function mappingOf(e,t,n,r=!1){return{kind:`PropertyMappingSyntax`,property:n[1],source:f(n[2],w(t),e,r),location:w(t)}}const we=a(`^when\\s+start\\s+(.+)$`),Te=a(`^outcome\\s+([A-Za-z_]\\w*)\\s+([A-Za-z_]\\w*)$`),Ee=a(`^then\\s+(is|sends|starts|completes|fails\\s+at|waits\\s+at)(?:\\s+([A-Za-z_]\\w*))?$`);function lifecycleExpectation(e){let t=Ee.exec(e.content);if(t===null)return;let n=t[1].replace(/\s+/g,` `),r=n===`is`?`State`:n===`sends`?`Sends`:n===`starts`?`Starts`:n===`completes`?`Completes`:n===`fails at`?`Fails`:`Waits`;if(t[2]!==void 0!=(r===`Completes`))return{kind:`LifecycleExpectationSyntax`,expectation:r,target:t[2]??null,location:w(e)}}function parseLifecycleSpecification(e,t,n){let r=k.exec(t.content);if(r===null)return e.error(n,`Invalid specification '${t.content}' - expected 'specification <Name>'.`,w(t)),skipBody(e,t.indent),{kind:`LifecycleSpecificationSyntax`,name:``,description:null,given:[],whenAppended:null,whenStarted:null,outcomes:[],then:[],location:w(t)};let i=r[1],a=null,o=[],s=null,c=null,l=!1,u=[],d=[],p={};for(let r=e.peekChild(t.indent);r!==void 0;r=e.peekChild(t.indent)){e.reader.takeSignificant();let t=h(r.content);if(t===`description`)a=m(e,r,a,`Specification '${i}'`),p.description??=w(r);else if(t===`given`){let t=parseEventStep(e,r,j,`given`);t!==void 0&&o.push(t)}else if(t===`when`){if(l){e.error(n,`Specification '${i}' already declares a 'when'.`,w(r)),skipBody(e,r.indent);continue}l=!0;let t=we.exec(r.content);if(t!==null){let n=r.content.indexOf(t[1],10);c=f(t[1].trim(),T(r.number,r.indent+(r.contentOffset??0)+1+n,r.path),e)}else r.content.startsWith(`when append`)?s=parseEventStep(e,r,M,`when append`)??null:(e.error(n,`Invalid '${r.content}' - expected 'when append <Event>' or 'when start <key>'.`,w(r)),skipBody(e,r.indent))}else if(t===`outcome`){let t=Te.exec(r.content);t===null?e.error(n,`Invalid outcome '${r.content}' - expected 'outcome <Node> <outlet>'.`,w(r)):u.push({kind:`LifecycleOutcomeSyntax`,node:t[1],outlet:t[2],location:w(r)}),v(e,r,n,`An outcome cannot have children.`)}else if(t===`then`){let t=lifecycleExpectation(r);t===void 0?e.error(n,`Invalid '${r.content}' - expected 'then is <State>', 'then sends <Command>', 'then starts <Workflow>', 'then completes', 'then fails at <Node>' or 'then waits at <Node>'.`,w(r)):d.push(t),v(e,r,n,`A then line cannot have children.`)}else e.error(n,`Unexpected '${r.content}' in specification '${i}' - expected description, given, when, outcome or then.`,w(r)),e.skipBlock(r.indent)}return{kind:`LifecycleSpecificationSyntax`,name:i,description:a,given:o,whenAppended:s,whenStarted:c,outcomes:u,then:d,location:w(t),directiveLocations:p}}export{parseLifecycleSpecification,parseSpecification,parseSpecificationStream,rejectSpecificationRouteChildren,Q as specificationStream};
2
2
  //# sourceMappingURL=SpecificationParser.js.map