@cratis/screenplay-language 4.193.0 → 4.194.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundles/compiler/Diagnostics/DiagnosticArgument.js +2 -0
- package/dist/bundles/compiler/Diagnostics/DiagnosticArgument.js.map +1 -0
- package/dist/bundles/compiler/Parsing/CaptureParser.js +1 -1
- package/dist/bundles/compiler/Parsing/CaptureParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/ParserContext.js +1 -1
- package/dist/bundles/compiler/Parsing/ParserContext.js.map +1 -1
- package/dist/bundles/compiler/Parsing/ProducesParser.js +1 -1
- package/dist/bundles/compiler/Parsing/ProducesParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/ProjectionParser.js +1 -1
- package/dist/bundles/compiler/Parsing/ProjectionParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/ProjectionTargetValidator.js +1 -1
- package/dist/bundles/compiler/Parsing/ProjectionTargetValidator.js.map +1 -1
- package/dist/bundles/compiler/Parsing/ReactionParser.js +1 -1
- package/dist/bundles/compiler/Parsing/ReactionParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationCaseParser.js +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationCaseParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationCaseValidator.js +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationCaseValidator.js.map +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationCommandExamples.js +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationCommandExamples.js.map +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationExampleParser.js +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationExampleParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationParser.js +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationResponseParser.js +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationResponseParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationStreamValidator.js +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationStreamValidator.js.map +1 -1
- package/dist/bundles/compiler/index.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DiagnosticArgument.js","names":["name"],"sources":["../../../../../../Compiler/Diagnostics/DiagnosticArgument.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 { DiagnosticArgumentKind } from './DiagnosticArgumentKind';\n\nexport type DiagnosticArgument =\n | { readonly kind: DiagnosticArgumentKind.Text | DiagnosticArgumentKind.Keyword; readonly value: string }\n | { readonly kind: DiagnosticArgumentKind.Index; readonly value: number }\n | { readonly kind: DiagnosticArgumentKind.Declaration; readonly value: { readonly kind: string; readonly path: readonly string[] } };\n\nexport function diagnosticText(name: string, value: string): Readonly<Record<string, DiagnosticArgument>> {\n return { [name]: { kind: DiagnosticArgumentKind.Text, value } };\n}\n\nexport function diagnosticKeyword(name: string, value: string): Readonly<Record<string, DiagnosticArgument>> {\n return { [name]: { kind: DiagnosticArgumentKind.Keyword, value } };\n}\n"],"mappings":"qDAUA,SAAgB,eAAe,EAAc,EAA6D,CACtG,MAAO,EAAGA,GAAO,CAAE,KAAA,OAAmC,OAAM,CAAE,CAClE,CAEA,SAAgB,kBAAkB,EAAc,EAA6D,CACzG,MAAO,EAAGA,GAAO,CAAE,KAAA,UAAsC,OAAM,CAAE,CACrE"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{stringBodyPattern as t,unescapeString as n}from"../Text/StringLiteral.js";import{nativePattern as r,pattern as i}from"../Text/patterns.js";import{locationOf as a}from"./SourceLine.js";import{parseModeledMappingSource as o}from"./ExpressionParser.js";import{firstWord as
|
|
1
|
+
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{stringBodyPattern as t,unescapeString as n}from"../Text/StringLiteral.js";import{nativePattern as r,pattern as i}from"../Text/patterns.js";import{locationOf as a}from"./SourceLine.js";import{parseModeledMappingSource as o}from"./ExpressionParser.js";import{diagnosticText as s}from"../Diagnostics/DiagnosticArgument.js";import{firstWord as c,unescapeIdentifier as l}from"./LineText.js";import"../Syntax/CaptureEventsSource.js";import{parseTag as u}from"./DeclarationParsers.js";import{parseProjectionExpression as d}from"./ProjectionExpressionParser.js";const grammar=e=>({legacy:i(e),native:r(e)}),f=grammar(`^capture\\s+([A-Za-z_]\\w*)$`),p=/^[A-Za-z_][\w.]*$/,m=grammar(`^append\\s+([A-Z]\\w*)$`),h=grammar(`^children\\s+([a-z_]\\w*)\\s+identified\\s+by\\s+([\\w.]+)$`),g=grammar(`^nested\\s+([\\w.]+)$`),select=(e,t)=>e.sourceOptions.numericMode===`exact`?t.native:t.legacy,_=r(`^(@?[\\w.]+)\\s*=(?!=|>)\\s*(.+)$`),v=r(`^([a-z_]\\w*)\\s*=\\s*(.+)$`),y=r(`^"(${t})"\\s*=>\\s*(\\w+)$`),b=r(`^split\\s+(\\S+)\\s+by\\s+"(${t})"$`),x=new RegExp(r(`"${t}"|[\\w.]+`).source,`gu`),S=r(`^[\\w.]+$`);function parseCapture(t,n){let r=t;t=t.valueContext;let i=select(t,f).exec(n.content)?.[1]??``;i===``&&t.sourceOptions.numericMode===`exact`&&t.error(e.InvalidCaptureDeclaration,`Invalid capture declaration '${n.content}' - expected 'capture <Name>'`,a(n));let o=null,s=null,l=[],u=[],d=[],p=[];for(let i=t.peekChild(n.indent);i!==void 0;i=t.peekChild(n.indent))switch(t.reader.takeSignificant(),c(i.content)){case`source`:o=parseSource(t,i,r);break;case`key`:s=i.content.substring(3).trim();break;case`map`:l.push(...parseMap(t,i));break;case`append`:pushAppend(t,i,u);break;case`children`:{let n=select(t,h).exec(i.content);if(n===null){t.error(e.InvalidChildrenDeclaration,`Invalid children declaration '${i.content}' - expected 'children <collection> identified by <key>'`,a(i)),t.skipOpaqueBlock(i.indent);break}let r=mapAndAppends(t,i);n!==null&&d.push({kind:`CaptureChildrenSyntax`,property:n[1],identifiedBy:n[2],...r,location:a(i)});break}case`nested`:{let n=select(t,g).exec(i.content);if(n===null){t.error(e.InvalidNestedDeclaration,`Invalid nested declaration '${i.content}' - expected 'nested <Property>'`,a(i)),t.skipOpaqueBlock(i.indent);break}let r=mapAndAppends(t,i);n!==null&&p.push({kind:`CaptureNestedSyntax`,property:n[1],...r,location:a(i)});break}default:t.error(e.UnknownCaptureDirective,`Unexpected '${i.content}' in capture body`,a(i)),t.skipOpaqueBlock(i.indent)}return{kind:`CaptureSyntax`,sourceOptions:t.sourceOptions,name:i,source:o,key:s,map:l,appends:u,children:d,nested:p,location:a(n)}}function parseSource(e,t,n){let r=[];for(let n=e.peekChild(t.indent);n!==void 0;n=e.peekChild(t.indent)){e.reader.takeSignificant();let t=c(n.content);r.push({kind:`CaptureSourceSettingSyntax`,name:t,value:n.content.substring(t.length).trim(),location:a(n)})}let i=t.content.substring(6).trim();return i===`events`&&validateEventsSource(n,t,r),{kind:`CaptureSourceSyntax`,syntaxKind:i,settings:r,location:a(t)}}function validateEventsSource(t,n,r){r.length===0&&t.error(e.InvalidCaptureEventsSource,`'source events' needs at least one 'from <Event>' line naming a public event to consume`,a(n));let i=/* @__PURE__ */ new Set;for(let n of r)n.name===`from`?p.test(n.value)?i.has(n.value)?t.error(e.InvalidCaptureEventsSource,`Event '${n.value}' is already consumed by this 'source events'`,n.location):i.add(n.value):t.error(e.InvalidCaptureEventsSource,`Invalid event '${n.value}' - expected 'from <Event>', optionally qualified with dots`,n.location):t.error(e.InvalidCaptureEventsSource,`'source events' accepts only 'from <Event>' lines, got '${n.name}'`,n.location)}function parseMap(t,r){let i=[];for(let o=t.peekChild(r.indent);o!==void 0;o=t.peekChild(r.indent)){t.reader.takeSignificant();let r=a(o);if(c(o.content)===`split`){let s=b.exec(o.content);if(s===null){t.error(e.InvalidSplitDeclaration,`Invalid split operation '${o.content}' - expected 'split <property> by "<separator>"'`,r),t.skipOpaqueBlock(o.indent);continue}let c=[];for(let n=t.peekChild(o.indent);n!==void 0;n=t.peekChild(o.indent))t.reader.takeSignificant(),S.test(n.content)?c.push(n.content):t.error(e.InvalidSplitTarget,`Invalid split target '${n.content}' - expected a property path`,a(n));s!==null&&i.push({kind:`CaptureSplitSyntax`,source:d(s[1],r,t),separator:n(s[2]),targets:c,location:r});continue}let s=v.exec(o.content);if(s===null){t.error(e.InvalidMapEntry,`Invalid map entry '${o.content}' - expected '<property> = <source> [translate]'`,r),t.skipOpaqueBlock(o.indent);continue}let l=s[2].trim(),u=l.startsWith("`")?l.indexOf("`",1):-1,f=l.startsWith("`")?u>=0&&l.substring(u+1).trim()===`translate`:l.endsWith(` translate`),p=l.startsWith("`")&&u>=0&&(t.sourceOptions.numericMode!==`exact`||f||l.substring(u+1).trim()===``)?l.substring(0,u+1):f?l.substring(0,l.length-10).trimEnd():l,m=[];if(f)for(let r=t.peekChild(o.indent);r!==void 0;r=t.peekChild(o.indent)){t.reader.takeSignificant();let i=y.exec(r.content);i===null?t.error(e.InvalidTranslation,`Invalid translation '${r.content}' - expected '"<source>" => <target>'`,a(r)):m.push({kind:`CaptureTranslationSyntax`,from:n(i[1]),to:i[2],location:a(r)})}i.push({kind:`CaptureMapEntrySyntax`,property:s[1],source:d(p,r,t),translations:m,location:r})}return i}function mapAndAppends(t,n){let r=[],i=[];for(let o=t.peekChild(n.indent);o!==void 0;o=t.peekChild(n.indent))t.reader.takeSignificant(),c(o.content)===`map`?r=parseMap(t,o):c(o.content)===`append`?pushAppend(t,o,i):(t.error(e.UnknownCaptureBlockDirective,`Unexpected '${o.content}' in ${c(n.content)} block - expected 'map' or 'append <EventType>'`,a(o)),t.skipOpaqueBlock(o.indent));return{map:r,appends:i}}function pushAppend(t,n,r){let i=select(t,m).exec(n.content);if(i===null){t.error(e.InvalidAppendDeclaration,`Invalid append declaration '${n.content}' - expected 'append <EventType>'`,a(n)),t.skipOpaqueBlock(n.indent);return}let d=[],f=[],p=null,mapping=(n,r=!1)=>{let i=a(n);if(c(n.content)===`tag`){let e=u(t.valueContext,n,!1);e!==void 0&&f.push(e);return}let p=_.exec(n.content);p===null?t.error(r?e.InvalidPropertyMapping:e.UnknownAppendDirective,`Unexpected '${n.content}' in append body`,i,r?s(`text`,n.content):{}):d.push({kind:`PropertyMappingSyntax`,property:l(p[1]),source:o(p[2],i,t.valueContext),location:i})};for(let e=t.peekChild(n.indent);e!==void 0;e=t.peekChild(n.indent))if(t.reader.takeSignificant(),c(e.content)===`when`){p=parseWhen(t,e);for(let n=t.peekChild(e.indent);n!==void 0;n=t.peekChild(e.indent))t.reader.takeSignificant(),mapping(n,!0)}else mapping(e);r.push({kind:`CaptureAppendSyntax`,event:i[1],when:p,mappings:d,tags:f,location:a(n)})}function parseWhen(t,r){let i=r.content.substring(4).trim(),o=a(r),value=(e,t=[],n=null,r=null,i=null)=>({kind:`CaptureWhenSyntax`,syntaxKind:e,properties:t,fromValue:n,toValue:r,expression:i,location:o});if(i===`added`)return value(`Added`);if(i===`removed`)return value(`Removed`);if(i.startsWith("`"))return(!i.endsWith("`")||i.length<2)&&t.error(e.UnterminatedTemplateExpression,`Unterminated template expression in 'when' - expected a closing backtick`,o),value(`Expression`,[],null,null,i);if(i.length===0)return t.error(e.WhenWithoutTrigger,`Expected a trigger after 'when'`,o),null;let s=[...i.match(t.sourceOptions.numericMode===`exact`?/* @__PURE__ */ RegExp(`"(?:[^"\\\\]|\\\\.)*"|[^\\s]+`,`gu`):x)??[]],unquote=e=>e.startsWith(`"`)&&e.endsWith(`"`)?n(e.substring(1,e.length-1)):e;if(s.length===0)return t.error(e.InvalidWhenClause,`Invalid 'when' clause '${r.content}'`,o),null;if(s.length===1)return value(`PropertyChanged`,[unquote(s[0])]);if(s[1]===`from`)return s.length===5&&s[3]===`to`?value(`ValueTransition`,[unquote(s[0])],unquote(s[2]),unquote(s[4])):(t.error(e.InvalidWhenTransitionClause,`Invalid 'when ... from ... to ...' clause '${r.content}'`,o),null);if(s[1]!==`or`&&s[1]!==`and`)return t.error(e.InvalidWhenClause,`Invalid 'when' clause '${r.content}'`,o),null;if(s.length%2==0)return t.error(e.WhenCombinatorWithoutProperty,`Expected a property after '${s[1]}'`,o),null;let c=[unquote(s[0])];for(let n=1;n<s.length-1;n+=2){if(s[n]!==s[1])return t.error(e.MixedWhenCombinators,`Cannot mix 'and' and 'or' in a single 'when' clause '${r.content}'`,o),null;c.push(unquote(s[n+1]))}return value(s[1]===`or`?`LogicalOr`:`LogicalAnd`,c)}export{parseCapture};
|
|
2
2
|
//# sourceMappingURL=CaptureParser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CaptureParser.js","names":["legacyPattern","pattern","parseMappingSource","pattern","source","nativePattern","headerRules","eventNameRules","appendRules","childrenRules","nestedRules","context","rules","mappingPattern","mapEntryPattern","translationPattern","stringBodyPattern","splitPattern","whenTokens","splitTarget","owner","name","line","DiagnosticCodes","locationOf","key","map","appends","children","nested","child","firstWord","match","body","settings","settingName","syntaxKind","seen","setting","location","targets","target","parseProjectionExpression","unescapeString","raw","closing","translate","text","translations","entry","translated","mappings","tags","when","tag","parseTag","mapped","unescapeIdentifier","parseModeledMappingSource","value","trigger","from","to","tokens","properties","index"],"sources":["../../../../../../Compiler/Parsing/CaptureParser.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { CaptureAppendSyntax, CaptureChildrenSyntax, CaptureMapOperationSyntax, CaptureNestedSyntax, CaptureSourceSettingSyntax, CaptureSourceSyntax, CaptureSyntax, CaptureTranslationSyntax, CaptureWhenSyntax } from '../Syntax/Captures';\nimport { eventsSourceKind, fromSetting } from '../Syntax/CaptureEventsSource';\nimport { TagSyntax } from '../Syntax/Declarations';\nimport { PropertyMappingSyntax } from '../Syntax/Expressions';\nimport { nativePattern as pattern, pattern as legacyPattern } from '../Text/patterns';\nimport { stringBodyPattern, unescapeString } from '../Text/StringLiteral';\nimport { parseTag } from './DeclarationParsers';\nimport { parseModeledMappingSource as parseMappingSource } from './ExpressionParser';\nimport { firstWord, unescapeIdentifier } from './LineText';\nimport { ParserContext } from './ParserContext';\nimport { parseProjectionExpression } from './ProjectionExpressionParser';\nimport { locationOf, SourceLine } from './SourceLine';\n\n// The grammar Legacy already modeled keeps its original patterns; native patterns apply to Exact documents.\nconst grammar = (source: string): { legacy: RegExp; native: RegExp } => ({ legacy: legacyPattern(source), native: pattern(source) });\nconst headerRules = grammar('^capture\\\\s+([A-Za-z_]\\\\w*)$');\nconst eventNameRules = /^[A-Za-z_][\\w.]*$/;\nconst appendRules = grammar('^append\\\\s+([A-Z]\\\\w*)$');\nconst childrenRules = grammar('^children\\\\s+([a-z_]\\\\w*)\\\\s+identified\\\\s+by\\\\s+([\\\\w.]+)$');\nconst nestedRules = grammar('^nested\\\\s+([\\\\w.]+)$');\nconst select = (context: ParserContext, rules: { legacy: RegExp; native: RegExp }): RegExp => context.sourceOptions.numericMode === 'exact' ? rules.native : rules.legacy;\nconst mappingPattern = pattern('^(@?[\\\\w.]+)\\\\s*=(?!=|>)\\\\s*(.+)$');\nconst mapEntryPattern = pattern('^([a-z_]\\\\w*)\\\\s*=\\\\s*(.+)$');\nconst translationPattern = pattern(`^\"(${stringBodyPattern})\"\\\\s*=>\\\\s*(\\\\w+)$`);\nconst splitPattern = pattern(`^split\\\\s+(\\\\S+)\\\\s+by\\\\s+\"(${stringBodyPattern})\"$`);\nconst whenTokens = new RegExp(pattern(`\"${stringBodyPattern}\"|[\\\\w.]+`).source, 'gu');\nconst splitTarget = pattern('^[\\\\w.]+$');\n\n// A structural port of the existing capture grammar. Transition operands remain authored strings, as\n// C# models them; exact numeric mode is not admitted by any supported executable model (ESM) version yet (#285).\nexport function parseCapture(context: ParserContext, line: SourceLine): CaptureSyntax {\n // The events source is new grammar, so its violations reach the owning context rather than the quiet value context.\n const owner = context;\n context = context.valueContext;\n const name = select(context, headerRules).exec(line.content)?.[1] ?? '';\n if (name === '' && context.sourceOptions.numericMode === 'exact') context.error(DiagnosticCodes.InvalidCaptureDeclaration, `Invalid capture declaration '${line.content}' - expected 'capture <Name>'`, locationOf(line));\n let source: CaptureSourceSyntax | null = null;\n let key: string | null = null;\n const map: CaptureMapOperationSyntax[] = [];\n const appends: CaptureAppendSyntax[] = [];\n const children: CaptureChildrenSyntax[] = [];\n const nested: CaptureNestedSyntax[] = [];\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n switch (firstWord(child.content)) {\n case 'source': source = parseSource(context, child, owner); break;\n case 'key': key = child.content.substring('key'.length).trim(); break;\n case 'map': map.push(...parseMap(context, child)); break;\n case 'append': pushAppend(context, child, appends); break;\n case 'children': {\n const match = select(context, childrenRules).exec(child.content);\n if (match === null) { context.error(DiagnosticCodes.InvalidChildrenDeclaration, `Invalid children declaration '${child.content}' - expected 'children <collection> identified by <key>'`, locationOf(child)); context.skipOpaqueBlock(child.indent); break; }\n const body = mapAndAppends(context, child);\n if (match !== null) children.push({ kind: 'CaptureChildrenSyntax', property: match[1], identifiedBy: match[2], ...body, location: locationOf(child) });\n break;\n }\n case 'nested': {\n const match = select(context, nestedRules).exec(child.content);\n if (match === null) { context.error(DiagnosticCodes.InvalidNestedDeclaration, `Invalid nested declaration '${child.content}' - expected 'nested <Property>'`, locationOf(child)); context.skipOpaqueBlock(child.indent); break; }\n const body = mapAndAppends(context, child);\n if (match !== null) nested.push({ kind: 'CaptureNestedSyntax', property: match[1], ...body, location: locationOf(child) });\n break;\n }\n default:\n context.error(DiagnosticCodes.UnknownCaptureDirective, `Unexpected '${child.content}' in capture body`, locationOf(child));\n context.skipOpaqueBlock(child.indent);\n }\n }\n return { kind: 'CaptureSyntax', sourceOptions: context.sourceOptions, name, source, key, map, appends, children, nested, location: locationOf(line) };\n}\n\nfunction parseSource(context: ParserContext, line: SourceLine, owner: ParserContext): CaptureSourceSyntax {\n const settings: CaptureSourceSettingSyntax[] = [];\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n const settingName = firstWord(child.content);\n settings.push({ kind: 'CaptureSourceSettingSyntax', name: settingName, value: child.content.substring(settingName.length).trim(), location: locationOf(child) });\n }\n const syntaxKind = line.content.substring('source'.length).trim();\n if (syntaxKind === eventsSourceKind) validateEventsSource(owner, line, settings);\n return { kind: 'CaptureSourceSyntax', syntaxKind, settings, location: locationOf(line) };\n}\n\nfunction validateEventsSource(context: ParserContext, line: SourceLine, settings: readonly CaptureSourceSettingSyntax[]): void {\n if (settings.length === 0) context.error(DiagnosticCodes.InvalidCaptureEventsSource, \"'source events' needs at least one 'from <Event>' line naming a public event to consume\", locationOf(line));\n const seen = new Set<string>();\n for (const setting of settings) {\n if (setting.name !== fromSetting) context.error(DiagnosticCodes.InvalidCaptureEventsSource, `'source events' accepts only 'from <Event>' lines, got '${setting.name}'`, setting.location);\n else if (!eventNameRules.test(setting.value)) context.error(DiagnosticCodes.InvalidCaptureEventsSource, `Invalid event '${setting.value}' - expected 'from <Event>', optionally qualified with dots`, setting.location);\n else if (seen.has(setting.value)) context.error(DiagnosticCodes.InvalidCaptureEventsSource, `Event '${setting.value}' is already consumed by this 'source events'`, setting.location);\n else seen.add(setting.value);\n }\n}\n\nfunction parseMap(context: ParserContext, line: SourceLine): CaptureMapOperationSyntax[] {\n const map: CaptureMapOperationSyntax[] = [];\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n const location = locationOf(child);\n if (firstWord(child.content) === 'split') {\n const match = splitPattern.exec(child.content);\n if (match === null) { context.error(DiagnosticCodes.InvalidSplitDeclaration, `Invalid split operation '${child.content}' - expected 'split <property> by \"<separator>\"'`, location); context.skipOpaqueBlock(child.indent); continue; }\n const targets: string[] = [];\n for (let target = context.peekChild(child.indent); target !== undefined; target = context.peekChild(child.indent)) {\n context.reader.takeSignificant();\n if (splitTarget.test(target.content)) targets.push(target.content);\n else context.error(DiagnosticCodes.InvalidSplitTarget, `Invalid split target '${target.content}' - expected a property path`, locationOf(target));\n }\n if (match !== null) map.push({ kind: 'CaptureSplitSyntax', source: parseProjectionExpression(match[1], location, context), separator: unescapeString(match[2]), targets, location });\n continue;\n }\n const match = mapEntryPattern.exec(child.content);\n if (match === null) { context.error(DiagnosticCodes.InvalidMapEntry, `Invalid map entry '${child.content}' - expected '<property> = <source> [translate]'`, location); context.skipOpaqueBlock(child.indent); continue; }\n const raw = match[2].trim();\n const closing = raw.startsWith('`') ? raw.indexOf('`', 1) : -1;\n const translate = raw.startsWith('`') ? closing >= 0 && raw.substring(closing + 1).trim() === 'translate' : raw.endsWith(' translate');\n const text = raw.startsWith('`') && closing >= 0 && (context.sourceOptions.numericMode !== 'exact' || translate || raw.substring(closing + 1).trim() === '') ? raw.substring(0, closing + 1) : translate ? raw.substring(0, raw.length - ' translate'.length).trimEnd() : raw;\n const translations: CaptureTranslationSyntax[] = [];\n if (translate) {\n for (let entry = context.peekChild(child.indent); entry !== undefined; entry = context.peekChild(child.indent)) {\n context.reader.takeSignificant();\n const translated = translationPattern.exec(entry.content);\n if (translated !== null) translations.push({ kind: 'CaptureTranslationSyntax', from: unescapeString(translated[1]), to: translated[2], location: locationOf(entry) });\n else context.error(DiagnosticCodes.InvalidTranslation, `Invalid translation '${entry.content}' - expected '\"<source>\" => <target>'`, locationOf(entry));\n }\n }\n map.push({ kind: 'CaptureMapEntrySyntax', property: match[1], source: parseProjectionExpression(text, location, context), translations, location });\n }\n return map;\n}\n\nfunction mapAndAppends(context: ParserContext, line: SourceLine): { map: CaptureMapOperationSyntax[]; appends: CaptureAppendSyntax[] } {\n let map: CaptureMapOperationSyntax[] = [];\n const appends: CaptureAppendSyntax[] = [];\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n if (firstWord(child.content) === 'map') map = parseMap(context, child);\n else if (firstWord(child.content) === 'append') pushAppend(context, child, appends);\n else {\n context.error(DiagnosticCodes.UnknownCaptureBlockDirective, `Unexpected '${child.content}' in ${firstWord(line.content)} block - expected 'map' or 'append <EventType>'`, locationOf(child));\n context.skipOpaqueBlock(child.indent);\n }\n }\n return { map, appends };\n}\n\nfunction pushAppend(context: ParserContext, line: SourceLine, appends: CaptureAppendSyntax[]): void {\n const match = select(context, appendRules).exec(line.content);\n if (match === null) { context.error(DiagnosticCodes.InvalidAppendDeclaration, `Invalid append declaration '${line.content}' - expected 'append <EventType>'`, locationOf(line)); context.skipOpaqueBlock(line.indent); return; }\n const mappings: PropertyMappingSyntax[] = [];\n const tags: TagSyntax[] = [];\n let when: CaptureWhenSyntax | null = null;\n const mapping = (child: SourceLine, nested = false): void => {\n const location = locationOf(child);\n if (firstWord(child.content) === 'tag') {\n const tag = parseTag(context.valueContext, child, false);\n if (tag !== undefined) tags.push(tag);\n return;\n }\n const mapped = mappingPattern.exec(child.content);\n if (mapped !== null) mappings.push({ kind: 'PropertyMappingSyntax', property: unescapeIdentifier(mapped[1]), source: parseMappingSource(mapped[2], location, context.valueContext), location });\n else context.error(nested ? DiagnosticCodes.InvalidPropertyMapping : DiagnosticCodes.UnknownAppendDirective, `Unexpected '${child.content}' in append body`, location);\n };\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n if (firstWord(child.content) === 'when') {\n when = parseWhen(context, child);\n for (let value = context.peekChild(child.indent); value !== undefined; value = context.peekChild(child.indent)) {\n context.reader.takeSignificant();\n mapping(value, true);\n }\n } else mapping(child);\n }\n appends.push({ kind: 'CaptureAppendSyntax', event: match[1], when, mappings, tags, location: locationOf(line) });\n}\n\nfunction parseWhen(context: ParserContext, line: SourceLine): CaptureWhenSyntax | null {\n const trigger = line.content.substring('when'.length).trim();\n const location = locationOf(line);\n const value = (syntaxKind: CaptureWhenSyntax['syntaxKind'], properties: string[] = [], from: string | null = null, to: string | null = null, expression: string | null = null): CaptureWhenSyntax => ({ kind: 'CaptureWhenSyntax', syntaxKind, properties, fromValue: from, toValue: to, expression, location });\n if (trigger === 'added') return value('Added');\n if (trigger === 'removed') return value('Removed');\n if (trigger.startsWith('`')) {\n if (!trigger.endsWith('`') || trigger.length < 2) context.error(DiagnosticCodes.UnterminatedTemplateExpression, \"Unterminated template expression in 'when' - expected a closing backtick\", location);\n return value('Expression', [], null, null, trigger);\n }\n if (trigger.length === 0) { context.error(DiagnosticCodes.WhenWithoutTrigger, \"Expected a trigger after 'when'\", location); return null; }\n const tokens: string[] = [...(trigger.match(context.sourceOptions.numericMode === 'exact' ? new RegExp(`\"${stringBodyPattern}\"|[^\\\\s]+`, 'gu') : whenTokens) ?? [])];\n const unquote = (text: string): string => text.startsWith('\"') && text.endsWith('\"') ? unescapeString(text.substring(1, text.length - 1)) : text;\n if (tokens.length === 0) { context.error(DiagnosticCodes.InvalidWhenClause, `Invalid 'when' clause '${line.content}'`, location); return null; }\n if (tokens.length === 1) return value('PropertyChanged', [unquote(tokens[0])]);\n if (tokens[1] === 'from') {\n if (tokens.length === 5 && tokens[3] === 'to') return value('ValueTransition', [unquote(tokens[0])], unquote(tokens[2]), unquote(tokens[4]));\n context.error(DiagnosticCodes.InvalidWhenTransitionClause, `Invalid 'when ... from ... to ...' clause '${line.content}'`, location); return null;\n }\n if (tokens[1] !== 'or' && tokens[1] !== 'and') { context.error(DiagnosticCodes.InvalidWhenClause, `Invalid 'when' clause '${line.content}'`, location); return null; }\n if (tokens.length % 2 === 0) { context.error(DiagnosticCodes.WhenCombinatorWithoutProperty, `Expected a property after '${tokens[1]}'`, location); return null; }\n const properties = [unquote(tokens[0])];\n for (let index = 1; index < tokens.length - 1; index += 2) {\n if (tokens[index] !== tokens[1]) { context.error(DiagnosticCodes.MixedWhenCombinators, `Cannot mix 'and' and 'or' in a single 'when' clause '${line.content}'`, location); return null; }\n properties.push(unquote(tokens[index + 1]));\n }\n return value(tokens[1] === 'or' ? 'LogicalOr' : 'LogicalAnd', properties);\n}\n"],"mappings":"omBAkBA,MAAM,QAAW,IAAwD,CAAE,OAAQA,EAAcI,CAAM,EAAG,OAAQH,EAAQG,CAAM,CAAE,GAC5HE,EAAc,QAAQ,8BAA8B,EACpDC,EAAiB,oBACjBC,EAAc,QAAQ,yBAAyB,EAC/CC,EAAgB,QAAQ,6DAA6D,EACrFC,EAAc,QAAQ,uBAAuB,EAC7C,QAAU,EAAwB,IAAsDC,EAAQ,cAAc,cAAgB,QAAUC,EAAM,OAASA,EAAM,OAC7JC,EAAiBZ,EAAQ,mCAAmC,EAC5Da,EAAkBb,EAAQ,6BAA6B,EACvDc,EAAqBd,EAAQ,MAAMe,EAAkB,oBAAoB,EACzEC,EAAehB,EAAQ,+BAA+Be,EAAkB,IAAI,EAC5EE,EAAa,IAAI,OAAOjB,EAAQ,IAAIe,EAAkB,UAAU,CAAC,CAAC,OAAQ,IAAI,EAC9EG,EAAclB,EAAQ,WAAW,EAIvC,SAAgB,aAAa,EAAwB,EAAiC,CAElF,IAAMmB,EAAQT,EACd,EAAUA,EAAQ,aAClB,IAAMU,EAAO,OAAOV,EAASL,CAAW,CAAC,CAAC,KAAKgB,EAAK,OAAO,CAAC,GAAG,IAAM,GACjED,IAAS,IAAMV,EAAQ,cAAc,cAAgB,SAASA,EAAQ,MAAMY,EAAgB,0BAA2B,gCAAgCD,EAAK,QAAQ,+BAAgCE,EAAWF,CAAI,CAAC,EACxN,IAAIlB,EAAqC,KACrCqB,EAAqB,KACnBC,EAAmC,CAAC,EACpCC,EAAiC,CAAC,EAClCC,EAAoC,CAAC,EACrCC,EAAgC,CAAC,EACvC,IAAK,IAAIC,EAAQnB,EAAQ,UAAUW,EAAK,MAAM,EAAGQ,IAAU,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A+B,8BAA8BwC,EAAO,GAAG,GAAIxB,CAAQ,EAAU,KAC1J,IAAMyB,EAAa,CAAC,QAAQD,EAAO,EAAE,CAAC,EACtC,IAAK,IAAIE,EAAQ,EAAGA,EAAQF,EAAO,OAAS,EAAG,GAAS,EAAG,CACvD,GAAIA,EAAOE,KAAWF,EAAO,GAA8I,OAAxIpD,EAAQ,MAAMY,EAAgB,qBAAsB,wDAAwDD,EAAK,QAAQ,GAAIiB,CAAQ,EAAU,KAClLyB,EAAW,KAAK,QAAQD,EAAOE,EAAQ,EAAE,CAAC,CAC9C,CACA,OAAO,MAAMF,EAAO,KAAO,KAAO,YAAc,aAAcC,CAAU,CAC5E"}
|
|
1
|
+
{"version":3,"file":"CaptureParser.js","names":["legacyPattern","pattern","parseMappingSource","pattern","source","nativePattern","headerRules","eventNameRules","appendRules","childrenRules","nestedRules","context","rules","mappingPattern","mapEntryPattern","translationPattern","stringBodyPattern","splitPattern","whenTokens","splitTarget","owner","name","line","DiagnosticCodes","locationOf","key","map","appends","children","nested","child","firstWord","match","body","settings","settingName","syntaxKind","seen","setting","location","targets","target","parseProjectionExpression","unescapeString","raw","closing","translate","text","translations","entry","translated","mappings","tags","when","tag","parseTag","mapped","diagnosticText","unescapeIdentifier","parseModeledMappingSource","value","trigger","from","to","tokens","properties","index"],"sources":["../../../../../../Compiler/Parsing/CaptureParser.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { diagnosticText } from '../Diagnostics/DiagnosticArgument';\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { CaptureAppendSyntax, CaptureChildrenSyntax, CaptureMapOperationSyntax, CaptureNestedSyntax, CaptureSourceSettingSyntax, CaptureSourceSyntax, CaptureSyntax, CaptureTranslationSyntax, CaptureWhenSyntax } from '../Syntax/Captures';\nimport { eventsSourceKind, fromSetting } from '../Syntax/CaptureEventsSource';\nimport { TagSyntax } from '../Syntax/Declarations';\nimport { PropertyMappingSyntax } from '../Syntax/Expressions';\nimport { nativePattern as pattern, pattern as legacyPattern } from '../Text/patterns';\nimport { stringBodyPattern, unescapeString } from '../Text/StringLiteral';\nimport { parseTag } from './DeclarationParsers';\nimport { parseModeledMappingSource as parseMappingSource } from './ExpressionParser';\nimport { firstWord, unescapeIdentifier } from './LineText';\nimport { ParserContext } from './ParserContext';\nimport { parseProjectionExpression } from './ProjectionExpressionParser';\nimport { locationOf, SourceLine } from './SourceLine';\n\n// The grammar Legacy already modeled keeps its original patterns; native patterns apply to Exact documents.\nconst grammar = (source: string): { legacy: RegExp; native: RegExp } => ({ legacy: legacyPattern(source), native: pattern(source) });\nconst headerRules = grammar('^capture\\\\s+([A-Za-z_]\\\\w*)$');\nconst eventNameRules = /^[A-Za-z_][\\w.]*$/;\nconst appendRules = grammar('^append\\\\s+([A-Z]\\\\w*)$');\nconst childrenRules = grammar('^children\\\\s+([a-z_]\\\\w*)\\\\s+identified\\\\s+by\\\\s+([\\\\w.]+)$');\nconst nestedRules = grammar('^nested\\\\s+([\\\\w.]+)$');\nconst select = (context: ParserContext, rules: { legacy: RegExp; native: RegExp }): RegExp => context.sourceOptions.numericMode === 'exact' ? rules.native : rules.legacy;\nconst mappingPattern = pattern('^(@?[\\\\w.]+)\\\\s*=(?!=|>)\\\\s*(.+)$');\nconst mapEntryPattern = pattern('^([a-z_]\\\\w*)\\\\s*=\\\\s*(.+)$');\nconst translationPattern = pattern(`^\"(${stringBodyPattern})\"\\\\s*=>\\\\s*(\\\\w+)$`);\nconst splitPattern = pattern(`^split\\\\s+(\\\\S+)\\\\s+by\\\\s+\"(${stringBodyPattern})\"$`);\nconst whenTokens = new RegExp(pattern(`\"${stringBodyPattern}\"|[\\\\w.]+`).source, 'gu');\nconst splitTarget = pattern('^[\\\\w.]+$');\n\n// A structural port of the existing capture grammar. Transition operands remain authored strings, as\n// C# models them; exact numeric mode is not admitted by any supported executable model (ESM) version yet (#285).\nexport function parseCapture(context: ParserContext, line: SourceLine): CaptureSyntax {\n // The events source is new grammar, so its violations reach the owning context rather than the quiet value context.\n const owner = context;\n context = context.valueContext;\n const name = select(context, headerRules).exec(line.content)?.[1] ?? '';\n if (name === '' && context.sourceOptions.numericMode === 'exact') context.error(DiagnosticCodes.InvalidCaptureDeclaration, `Invalid capture declaration '${line.content}' - expected 'capture <Name>'`, locationOf(line));\n let source: CaptureSourceSyntax | null = null;\n let key: string | null = null;\n const map: CaptureMapOperationSyntax[] = [];\n const appends: CaptureAppendSyntax[] = [];\n const children: CaptureChildrenSyntax[] = [];\n const nested: CaptureNestedSyntax[] = [];\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n switch (firstWord(child.content)) {\n case 'source': source = parseSource(context, child, owner); break;\n case 'key': key = child.content.substring('key'.length).trim(); break;\n case 'map': map.push(...parseMap(context, child)); break;\n case 'append': pushAppend(context, child, appends); break;\n case 'children': {\n const match = select(context, childrenRules).exec(child.content);\n if (match === null) { context.error(DiagnosticCodes.InvalidChildrenDeclaration, `Invalid children declaration '${child.content}' - expected 'children <collection> identified by <key>'`, locationOf(child)); context.skipOpaqueBlock(child.indent); break; }\n const body = mapAndAppends(context, child);\n if (match !== null) children.push({ kind: 'CaptureChildrenSyntax', property: match[1], identifiedBy: match[2], ...body, location: locationOf(child) });\n break;\n }\n case 'nested': {\n const match = select(context, nestedRules).exec(child.content);\n if (match === null) { context.error(DiagnosticCodes.InvalidNestedDeclaration, `Invalid nested declaration '${child.content}' - expected 'nested <Property>'`, locationOf(child)); context.skipOpaqueBlock(child.indent); break; }\n const body = mapAndAppends(context, child);\n if (match !== null) nested.push({ kind: 'CaptureNestedSyntax', property: match[1], ...body, location: locationOf(child) });\n break;\n }\n default:\n context.error(DiagnosticCodes.UnknownCaptureDirective, `Unexpected '${child.content}' in capture body`, locationOf(child));\n context.skipOpaqueBlock(child.indent);\n }\n }\n return { kind: 'CaptureSyntax', sourceOptions: context.sourceOptions, name, source, key, map, appends, children, nested, location: locationOf(line) };\n}\n\nfunction parseSource(context: ParserContext, line: SourceLine, owner: ParserContext): CaptureSourceSyntax {\n const settings: CaptureSourceSettingSyntax[] = [];\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n const settingName = firstWord(child.content);\n settings.push({ kind: 'CaptureSourceSettingSyntax', name: settingName, value: child.content.substring(settingName.length).trim(), location: locationOf(child) });\n }\n const syntaxKind = line.content.substring('source'.length).trim();\n if (syntaxKind === eventsSourceKind) validateEventsSource(owner, line, settings);\n return { kind: 'CaptureSourceSyntax', syntaxKind, settings, location: locationOf(line) };\n}\n\nfunction validateEventsSource(context: ParserContext, line: SourceLine, settings: readonly CaptureSourceSettingSyntax[]): void {\n if (settings.length === 0) context.error(DiagnosticCodes.InvalidCaptureEventsSource, \"'source events' needs at least one 'from <Event>' line naming a public event to consume\", locationOf(line));\n const seen = new Set<string>();\n for (const setting of settings) {\n if (setting.name !== fromSetting) context.error(DiagnosticCodes.InvalidCaptureEventsSource, `'source events' accepts only 'from <Event>' lines, got '${setting.name}'`, setting.location);\n else if (!eventNameRules.test(setting.value)) context.error(DiagnosticCodes.InvalidCaptureEventsSource, `Invalid event '${setting.value}' - expected 'from <Event>', optionally qualified with dots`, setting.location);\n else if (seen.has(setting.value)) context.error(DiagnosticCodes.InvalidCaptureEventsSource, `Event '${setting.value}' is already consumed by this 'source events'`, setting.location);\n else seen.add(setting.value);\n }\n}\n\nfunction parseMap(context: ParserContext, line: SourceLine): CaptureMapOperationSyntax[] {\n const map: CaptureMapOperationSyntax[] = [];\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n const location = locationOf(child);\n if (firstWord(child.content) === 'split') {\n const match = splitPattern.exec(child.content);\n if (match === null) { context.error(DiagnosticCodes.InvalidSplitDeclaration, `Invalid split operation '${child.content}' - expected 'split <property> by \"<separator>\"'`, location); context.skipOpaqueBlock(child.indent); continue; }\n const targets: string[] = [];\n for (let target = context.peekChild(child.indent); target !== undefined; target = context.peekChild(child.indent)) {\n context.reader.takeSignificant();\n if (splitTarget.test(target.content)) targets.push(target.content);\n else context.error(DiagnosticCodes.InvalidSplitTarget, `Invalid split target '${target.content}' - expected a property path`, locationOf(target));\n }\n if (match !== null) map.push({ kind: 'CaptureSplitSyntax', source: parseProjectionExpression(match[1], location, context), separator: unescapeString(match[2]), targets, location });\n continue;\n }\n const match = mapEntryPattern.exec(child.content);\n if (match === null) { context.error(DiagnosticCodes.InvalidMapEntry, `Invalid map entry '${child.content}' - expected '<property> = <source> [translate]'`, location); context.skipOpaqueBlock(child.indent); continue; }\n const raw = match[2].trim();\n const closing = raw.startsWith('`') ? raw.indexOf('`', 1) : -1;\n const translate = raw.startsWith('`') ? closing >= 0 && raw.substring(closing + 1).trim() === 'translate' : raw.endsWith(' translate');\n const text = raw.startsWith('`') && closing >= 0 && (context.sourceOptions.numericMode !== 'exact' || translate || raw.substring(closing + 1).trim() === '') ? raw.substring(0, closing + 1) : translate ? raw.substring(0, raw.length - ' translate'.length).trimEnd() : raw;\n const translations: CaptureTranslationSyntax[] = [];\n if (translate) {\n for (let entry = context.peekChild(child.indent); entry !== undefined; entry = context.peekChild(child.indent)) {\n context.reader.takeSignificant();\n const translated = translationPattern.exec(entry.content);\n if (translated !== null) translations.push({ kind: 'CaptureTranslationSyntax', from: unescapeString(translated[1]), to: translated[2], location: locationOf(entry) });\n else context.error(DiagnosticCodes.InvalidTranslation, `Invalid translation '${entry.content}' - expected '\"<source>\" => <target>'`, locationOf(entry));\n }\n }\n map.push({ kind: 'CaptureMapEntrySyntax', property: match[1], source: parseProjectionExpression(text, location, context), translations, location });\n }\n return map;\n}\n\nfunction mapAndAppends(context: ParserContext, line: SourceLine): { map: CaptureMapOperationSyntax[]; appends: CaptureAppendSyntax[] } {\n let map: CaptureMapOperationSyntax[] = [];\n const appends: CaptureAppendSyntax[] = [];\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n if (firstWord(child.content) === 'map') map = parseMap(context, child);\n else if (firstWord(child.content) === 'append') pushAppend(context, child, appends);\n else {\n context.error(DiagnosticCodes.UnknownCaptureBlockDirective, `Unexpected '${child.content}' in ${firstWord(line.content)} block - expected 'map' or 'append <EventType>'`, locationOf(child));\n context.skipOpaqueBlock(child.indent);\n }\n }\n return { map, appends };\n}\n\nfunction pushAppend(context: ParserContext, line: SourceLine, appends: CaptureAppendSyntax[]): void {\n const match = select(context, appendRules).exec(line.content);\n if (match === null) { context.error(DiagnosticCodes.InvalidAppendDeclaration, `Invalid append declaration '${line.content}' - expected 'append <EventType>'`, locationOf(line)); context.skipOpaqueBlock(line.indent); return; }\n const mappings: PropertyMappingSyntax[] = [];\n const tags: TagSyntax[] = [];\n let when: CaptureWhenSyntax | null = null;\n const mapping = (child: SourceLine, nested = false): void => {\n const location = locationOf(child);\n if (firstWord(child.content) === 'tag') {\n const tag = parseTag(context.valueContext, child, false);\n if (tag !== undefined) tags.push(tag);\n return;\n }\n const mapped = mappingPattern.exec(child.content);\n if (mapped !== null) mappings.push({ kind: 'PropertyMappingSyntax', property: unescapeIdentifier(mapped[1]), source: parseMappingSource(mapped[2], location, context.valueContext), location });\n else context.error(nested ? DiagnosticCodes.InvalidPropertyMapping : DiagnosticCodes.UnknownAppendDirective, `Unexpected '${child.content}' in append body`, location, nested ? diagnosticText('text', child.content) : {});\n };\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n if (firstWord(child.content) === 'when') {\n when = parseWhen(context, child);\n for (let value = context.peekChild(child.indent); value !== undefined; value = context.peekChild(child.indent)) {\n context.reader.takeSignificant();\n mapping(value, true);\n }\n } else mapping(child);\n }\n appends.push({ kind: 'CaptureAppendSyntax', event: match[1], when, mappings, tags, location: locationOf(line) });\n}\n\nfunction parseWhen(context: ParserContext, line: SourceLine): CaptureWhenSyntax | null {\n const trigger = line.content.substring('when'.length).trim();\n const location = locationOf(line);\n const value = (syntaxKind: CaptureWhenSyntax['syntaxKind'], properties: string[] = [], from: string | null = null, to: string | null = null, expression: string | null = null): CaptureWhenSyntax => ({ kind: 'CaptureWhenSyntax', syntaxKind, properties, fromValue: from, toValue: to, expression, location });\n if (trigger === 'added') return value('Added');\n if (trigger === 'removed') return value('Removed');\n if (trigger.startsWith('`')) {\n if (!trigger.endsWith('`') || trigger.length < 2) context.error(DiagnosticCodes.UnterminatedTemplateExpression, \"Unterminated template expression in 'when' - expected a closing backtick\", location);\n return value('Expression', [], null, null, trigger);\n }\n if (trigger.length === 0) { context.error(DiagnosticCodes.WhenWithoutTrigger, \"Expected a trigger after 'when'\", location); return null; }\n const tokens: string[] = [...(trigger.match(context.sourceOptions.numericMode === 'exact' ? new RegExp(`\"${stringBodyPattern}\"|[^\\\\s]+`, 'gu') : whenTokens) ?? [])];\n const unquote = (text: string): string => text.startsWith('\"') && text.endsWith('\"') ? unescapeString(text.substring(1, text.length - 1)) : text;\n if (tokens.length === 0) { context.error(DiagnosticCodes.InvalidWhenClause, `Invalid 'when' clause '${line.content}'`, location); return null; }\n if (tokens.length === 1) return value('PropertyChanged', [unquote(tokens[0])]);\n if (tokens[1] === 'from') {\n if (tokens.length === 5 && tokens[3] === 'to') return value('ValueTransition', [unquote(tokens[0])], unquote(tokens[2]), unquote(tokens[4]));\n context.error(DiagnosticCodes.InvalidWhenTransitionClause, `Invalid 'when ... from ... to ...' clause '${line.content}'`, location); return null;\n }\n if (tokens[1] !== 'or' && tokens[1] !== 'and') { context.error(DiagnosticCodes.InvalidWhenClause, `Invalid 'when' clause '${line.content}'`, location); return null; }\n if (tokens.length % 2 === 0) { context.error(DiagnosticCodes.WhenCombinatorWithoutProperty, `Expected a property after '${tokens[1]}'`, location); return null; }\n const properties = [unquote(tokens[0])];\n for (let index = 1; index < tokens.length - 1; index += 2) {\n if (tokens[index] !== tokens[1]) { context.error(DiagnosticCodes.MixedWhenCombinators, `Cannot mix 'and' and 'or' in a single 'when' clause '${line.content}'`, location); return null; }\n properties.push(unquote(tokens[index + 1]));\n }\n return value(tokens[1] === 'or' ? 'LogicalOr' : 'LogicalAnd', properties);\n}\n"],"mappings":"0qBAmBA,MAAM,QAAW,IAAwD,CAAE,OAAQA,EAAcI,CAAM,EAAG,OAAQH,EAAQG,CAAM,CAAE,GAC5HE,EAAc,QAAQ,8BAA8B,EACpDC,EAAiB,oBACjBC,EAAc,QAAQ,yBAAyB,EAC/CC,EAAgB,QAAQ,6DAA6D,EACrFC,EAAc,QAAQ,uBAAuB,EAC7C,QAAU,EAAwB,IAAsDC,EAAQ,cAAc,cAAgB,QAAUC,EAAM,OAASA,EAAM,OAC7JC,EAAiBZ,EAAQ,mCAAmC,EAC5Da,EAAkBb,EAAQ,6BAA6B,EACvDc,EAAqBd,EAAQ,MAAMe,EAAkB,oBAAoB,EACzEC,EAAehB,EAAQ,+BAA+Be,EAAkB,IAAI,EAC5EE,EAAa,IAAI,OAAOjB,EAAQ,IAAIe,EAAkB,UAAU,CAAC,CAAC,OAAQ,IAAI,EAC9EG,EAAclB,EAAQ,WAAW,EAIvC,SAAgB,aAAa,EAAwB,EAAiC,CAElF,IAAMmB,EAAQT,EACd,EAAUA,EAAQ,aAClB,IAAMU,EAAO,OAAOV,EAASL,CAAW,CAAC,CAAC,KAAKgB,EAAK,OAAO,CAAC,GAAG,IAAM,GACjED,IAAS,IAAMV,EAAQ,cAAc,cAAgB,SAASA,EAAQ,MAAMY,EAAgB,0BAA2B,gCAAgCD,EAAK,QAAQ,+BAAgCE,EAAWF,CAAI,CAAC,EACxN,IAAIlB,EAAqC,KACrCqB,EAAqB,KACnBC,EAAmC,CAAC,EACpCC,EAAiC,CAAC,EAClCC,EAAoC,CAAC,EACrCC,EAAgC,CAAC,EACvC,IAAK,IAAIC,EAAQnB,EAAQ,UAAUW,EAAK,MAAM,EAAGQ,IAAU,IAAA,GAAW,EAAQnB,EAAQ,UAAUW,EA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MAAMY,EAAgB,8BAA+B,8BAA8ByC,EAAO,GAAG,GAAIzB,CAAQ,EAAU,KAC1J,IAAM0B,EAAa,CAAC,QAAQD,EAAO,EAAE,CAAC,EACtC,IAAK,IAAIE,EAAQ,EAAGA,EAAQF,EAAO,OAAS,EAAG,GAAS,EAAG,CACvD,GAAIA,EAAOE,KAAWF,EAAO,GAA8I,OAAxIrD,EAAQ,MAAMY,EAAgB,qBAAsB,wDAAwDD,EAAK,QAAQ,GAAIiB,CAAQ,EAAU,KAClL0B,EAAW,KAAK,QAAQD,EAAOE,EAAQ,EAAE,CAAC,CAC9C,CACA,OAAO,MAAMF,EAAO,KAAO,KAAO,YAAc,aAAcC,CAAU,CAC5E"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../../_virtual/_virtual/_rolldown/runtime.js";import{sourceLocation as e}from"../Diagnostics/SourceLocation.js";import{legacySourceOptions as t}from"../Syntax/SourceOptions.js";var n=class ParserContext{reader;path;#e=[];triggerData=[];inputUses=[];continuationValues=[];guardedInteractions=[];interactionAncestors=/* @__PURE__ */ new Map;scope=[];languages;sourceOptions=t;authoredDeclarations=!1;deferIdentityValidation=!1;streamCandidates;get valueContext(){if(this.sourceOptions.numericMode===`exact`)return this;let e=new ParserContext(this.reader,this.path,this.languages);return e.sourceOptions=this.sourceOptions,e}constructor(e,t,n=/* @__PURE__ */ new Set([`csharp`,`typescript`,`react`,`html`,`sql`])){this.reader=e,this.path=t,this.languages=n}get start(){return e(1,1,this.path)}get diagnostics(){return this.nestedNumericDirectives.size>0&&this.sourceOptions.numericMode!==`legacy`&&this.reader.atEnd&&(this.#e.push(...[...this.nestedNumericDirectives].sort((e,t)=>e[0]-t[0]).map(e=>e[1])),this.nestedNumericDirectives.clear()),this.#e}nestedNumericDirectives=/* @__PURE__ */ new Map;claimField(e){this.nestedNumericDirectives.delete(e.number)}information(e,t,n){this.#e.push({severity:`information`,code:e,message:t,location:n})}error(e,t,n){this.#e.push({severity:`error`,code:e,message:t,location:n})}warning(e,t,n){this.#e.push({severity:`warning`,code:e,message:t,location:n})}peekChild(e){let t=this.reader.peekSignificant();return t!==void 0&&t.indent>e?t:void 0}skipBlock(e){for(;this.peekChild(e)!==void 0;)this.reader.takeSignificant()}skipOpaqueBlock(e){let t=this.peekChild(e);for(;t!==void 0;)this.reader.takeSignificant(),t.content.startsWith("```")&&this.skipFencedBody(),t=this.peekChild(e)}skipFencedBody(){for(let e=this.reader.takeRaw();e!==void 0;e=this.reader.takeRaw())if(e.raw.trim()==="```")return}};export{n as ParserContext};
|
|
1
|
+
import"../../_virtual/_virtual/_rolldown/runtime.js";import{sourceLocation as e}from"../Diagnostics/SourceLocation.js";import{legacySourceOptions as t}from"../Syntax/SourceOptions.js";var n=class ParserContext{reader;path;#e=[];triggerData=[];inputUses=[];continuationValues=[];guardedInteractions=[];interactionAncestors=/* @__PURE__ */ new Map;scope=[];languages;sourceOptions=t;authoredDeclarations=!1;deferIdentityValidation=!1;streamCandidates;get valueContext(){if(this.sourceOptions.numericMode===`exact`)return this;let e=new ParserContext(this.reader,this.path,this.languages);return e.sourceOptions=this.sourceOptions,e}constructor(e,t,n=/* @__PURE__ */ new Set([`csharp`,`typescript`,`react`,`html`,`sql`])){this.reader=e,this.path=t,this.languages=n}get start(){return e(1,1,this.path)}get diagnostics(){return this.nestedNumericDirectives.size>0&&this.sourceOptions.numericMode!==`legacy`&&this.reader.atEnd&&(this.#e.push(...[...this.nestedNumericDirectives].sort((e,t)=>e[0]-t[0]).map(e=>e[1])),this.nestedNumericDirectives.clear()),this.#e}nestedNumericDirectives=/* @__PURE__ */ new Map;claimField(e){this.nestedNumericDirectives.delete(e.number)}information(e,t,n,r={}){this.#e.push({severity:`information`,code:e,message:t,location:n,arguments:r})}error(e,t,n,r={}){this.#e.push({severity:`error`,code:e,message:t,location:n,arguments:r})}warning(e,t,n,r={}){this.#e.push({severity:`warning`,code:e,message:t,location:n,arguments:r})}peekChild(e){let t=this.reader.peekSignificant();return t!==void 0&&t.indent>e?t:void 0}skipBlock(e){for(;this.peekChild(e)!==void 0;)this.reader.takeSignificant()}skipOpaqueBlock(e){let t=this.peekChild(e);for(;t!==void 0;)this.reader.takeSignificant(),t.content.startsWith("```")&&this.skipFencedBody(),t=this.peekChild(e)}skipFencedBody(){for(let e=this.reader.takeRaw();e!==void 0;e=this.reader.takeRaw())if(e.raw.trim()==="```")return}};export{n as ParserContext};
|
|
2
2
|
//# sourceMappingURL=ParserContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParserContext.js","names":["ParserContext","legacySourceOptions","context","reader","path","languages","sourceLocation","#diagnostics","first","second","entry","line","parentIndent","child"],"sources":["../../../../../../Compiler/Parsing/ParserContext.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 { Diagnostic } from '../Diagnostics/Diagnostic';\nimport { CommandStreamCandidates } from './CommandStreamCandidates';\nimport { SourceLocation, sourceLocation } from '../Diagnostics/SourceLocation';\nimport { PropertySyntax } from '../Syntax/Declarations';\nimport { legacySourceOptions, SourceOptions } from '../Syntax/SourceOptions';\nimport { InputUse } from './InputUses';\nimport { ContinuationValueUse } from './ContinuationValueUse';\nimport { GuardedInteractionBinding, InteractionAncestor } from './InteractionAlternatives';\nimport { LineReader } from './LineReader';\nimport { SourceLine } from './SourceLine';\n\n// What every parser shares while it reads one document: the line reader, the diagnostics found so far and\n// the file the document came from.\nexport class ParserContext {\n readonly #diagnostics: Diagnostic[] = [];\n // Authoring verification needs these committed values even though SyntaxJson omits them.\n readonly triggerData: PropertySyntax[] = [];\n readonly inputUses: InputUse[] = [];\n readonly continuationValues: ContinuationValueUse[] = [];\n readonly guardedInteractions: GuardedInteractionBinding[] = [];\n interactionAncestors: ReadonlyMap<number, readonly InteractionAncestor[]> = new Map();\n scope: readonly string[] = [];\n readonly languages: ReadonlySet<string>;\n sourceOptions: SourceOptions = legacySourceOptions;\n authoredDeclarations = false;\n deferIdentityValidation = false;\n streamCandidates?: CommandStreamCandidates;\n\n // Structural enrichment of formerly opaque Legacy fields must not add diagnostics. Exact operands\n // use the owning context so representability failures cannot turn into successful opaque syntax.\n get valueContext(): ParserContext {\n if (this.sourceOptions.numericMode === 'exact') return this;\n const context = new ParserContext(this.reader, this.path, this.languages);\n context.sourceOptions = this.sourceOptions;\n return context;\n }\n\n constructor(readonly reader: LineReader, readonly path?: string, languages: ReadonlySet<string> = new Set(['csharp', 'typescript', 'react', 'html', 'sql'])) {\n this.languages = languages;\n }\n\n get start(): SourceLocation {\n return sourceLocation(1, 1, this.path);\n }\n\n get diagnostics(): readonly Diagnostic[] {\n // Directive-shaped lines nobody claimed as a field are errors, wherever they sit.\n if (this.nestedNumericDirectives.size > 0 && this.sourceOptions.numericMode !== 'legacy' && this.reader.atEnd) {\n this.#diagnostics.push(...[...this.nestedNumericDirectives].sort((first, second) => first[0] - second[0]).map(entry => entry[1]));\n this.nestedNumericDirectives.clear();\n }\n return this.#diagnostics;\n }\n\n // Directive-shaped lines below the top level, keyed by line number, still unclaimed as a field.\n nestedNumericDirectives = new Map<number, Diagnostic>();\n\n claimField(line: SourceLine): void {\n this.nestedNumericDirectives.delete(line.number);\n }\n\n information(code: string, message: string, location: SourceLocation): void {\n this.#diagnostics.push({ severity: 'information', code, message, location });\n }\n\n error(code: string, message: string, location: SourceLocation): void {\n this.#diagnostics.push({ severity: 'error', code, message, location });\n }\n\n warning(code: string, message: string, location: SourceLocation): void {\n this.#diagnostics.push({ severity: 'warning', code, message, location });\n }\n\n // The next significant line when it is indented deeper than its parent - that is, when it belongs to\n // the parent's body under the offside rule.\n peekChild(parentIndent: number): SourceLine | undefined {\n const line = this.reader.peekSignificant();\n return line !== undefined && line.indent > parentIndent ? line : undefined;\n }\n\n // Skips the body of a construct, the way the C# parser does after reporting it.\n skipBlock(parentIndent: number): void {\n while (this.peekChild(parentIndent) !== undefined) {\n this.reader.takeSignificant();\n }\n }\n\n // Skips the body of a construct this compiler deliberately does not model. Unlike skipBlock it steps\n // over fenced code blocks whole, because a fenced line may be indented less than the block it is in -\n // reading it as significant would end the skip early and misread the code as Screenplay.\n skipOpaqueBlock(parentIndent: number): void {\n let child = this.peekChild(parentIndent);\n while (child !== undefined) {\n this.reader.takeSignificant();\n if (child.content.startsWith('```')) {\n this.skipFencedBody();\n }\n child = this.peekChild(parentIndent);\n }\n }\n\n // Takes the raw lines of a fenced block up to and including its closing fence.\n skipFencedBody(): void {\n for (let line = this.reader.takeRaw(); line !== undefined; line = this.reader.takeRaw()) {\n if (line.raw.trim() === '```') {\n return;\n }\n }\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ParserContext.js","names":["ParserContext","legacySourceOptions","context","reader","path","languages","sourceLocation","#diagnostics","first","second","entry","line","arguments_","parentIndent","child"],"sources":["../../../../../../Compiler/Parsing/ParserContext.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 { DiagnosticArgument } from '../Diagnostics/DiagnosticArgument';\nimport { Diagnostic } from '../Diagnostics/Diagnostic';\nimport { CommandStreamCandidates } from './CommandStreamCandidates';\nimport { SourceLocation, sourceLocation } from '../Diagnostics/SourceLocation';\nimport { PropertySyntax } from '../Syntax/Declarations';\nimport { legacySourceOptions, SourceOptions } from '../Syntax/SourceOptions';\nimport { InputUse } from './InputUses';\nimport { ContinuationValueUse } from './ContinuationValueUse';\nimport { GuardedInteractionBinding, InteractionAncestor } from './InteractionAlternatives';\nimport { LineReader } from './LineReader';\nimport { SourceLine } from './SourceLine';\n\n// What every parser shares while it reads one document: the line reader, the diagnostics found so far and\n// the file the document came from.\nexport class ParserContext {\n readonly #diagnostics: Diagnostic[] = [];\n // Authoring verification needs these committed values even though SyntaxJson omits them.\n readonly triggerData: PropertySyntax[] = [];\n readonly inputUses: InputUse[] = [];\n readonly continuationValues: ContinuationValueUse[] = [];\n readonly guardedInteractions: GuardedInteractionBinding[] = [];\n interactionAncestors: ReadonlyMap<number, readonly InteractionAncestor[]> = new Map();\n scope: readonly string[] = [];\n readonly languages: ReadonlySet<string>;\n sourceOptions: SourceOptions = legacySourceOptions;\n authoredDeclarations = false;\n deferIdentityValidation = false;\n streamCandidates?: CommandStreamCandidates;\n\n // Structural enrichment of formerly opaque Legacy fields must not add diagnostics. Exact operands\n // use the owning context so representability failures cannot turn into successful opaque syntax.\n get valueContext(): ParserContext {\n if (this.sourceOptions.numericMode === 'exact') return this;\n const context = new ParserContext(this.reader, this.path, this.languages);\n context.sourceOptions = this.sourceOptions;\n return context;\n }\n\n constructor(readonly reader: LineReader, readonly path?: string, languages: ReadonlySet<string> = new Set(['csharp', 'typescript', 'react', 'html', 'sql'])) {\n this.languages = languages;\n }\n\n get start(): SourceLocation {\n return sourceLocation(1, 1, this.path);\n }\n\n get diagnostics(): readonly Diagnostic[] {\n // Directive-shaped lines nobody claimed as a field are errors, wherever they sit.\n if (this.nestedNumericDirectives.size > 0 && this.sourceOptions.numericMode !== 'legacy' && this.reader.atEnd) {\n this.#diagnostics.push(...[...this.nestedNumericDirectives].sort((first, second) => first[0] - second[0]).map(entry => entry[1]));\n this.nestedNumericDirectives.clear();\n }\n return this.#diagnostics;\n }\n\n // Directive-shaped lines below the top level, keyed by line number, still unclaimed as a field.\n nestedNumericDirectives = new Map<number, Diagnostic>();\n\n claimField(line: SourceLine): void {\n this.nestedNumericDirectives.delete(line.number);\n }\n\n information(code: string, message: string, location: SourceLocation, arguments_: Readonly<Record<string, DiagnosticArgument>> = {}): void {\n this.#diagnostics.push({ severity: 'information', code, message, location, arguments: arguments_ });\n }\n\n error(code: string, message: string, location: SourceLocation, arguments_: Readonly<Record<string, DiagnosticArgument>> = {}): void {\n this.#diagnostics.push({ severity: 'error', code, message, location, arguments: arguments_ });\n }\n\n warning(code: string, message: string, location: SourceLocation, arguments_: Readonly<Record<string, DiagnosticArgument>> = {}): void {\n this.#diagnostics.push({ severity: 'warning', code, message, location, arguments: arguments_ });\n }\n\n // The next significant line when it is indented deeper than its parent - that is, when it belongs to\n // the parent's body under the offside rule.\n peekChild(parentIndent: number): SourceLine | undefined {\n const line = this.reader.peekSignificant();\n return line !== undefined && line.indent > parentIndent ? line : undefined;\n }\n\n // Skips the body of a construct, the way the C# parser does after reporting it.\n skipBlock(parentIndent: number): void {\n while (this.peekChild(parentIndent) !== undefined) {\n this.reader.takeSignificant();\n }\n }\n\n // Skips the body of a construct this compiler deliberately does not model. Unlike skipBlock it steps\n // over fenced code blocks whole, because a fenced line may be indented less than the block it is in -\n // reading it as significant would end the skip early and misread the code as Screenplay.\n skipOpaqueBlock(parentIndent: number): void {\n let child = this.peekChild(parentIndent);\n while (child !== undefined) {\n this.reader.takeSignificant();\n if (child.content.startsWith('```')) {\n this.skipFencedBody();\n }\n child = this.peekChild(parentIndent);\n }\n }\n\n // Takes the raw lines of a fenced block up to and including its closing fence.\n skipFencedBody(): void {\n for (let line = this.reader.takeRaw(); line !== undefined; line = this.reader.takeRaw()) {\n if (line.raw.trim() === '```') {\n return;\n }\n }\n }\n}\n"],"mappings":"wLAiBA,IAAaA,EAAb,MAAa,aAAc,CAwBF,OAA6B,KAvBlD,GAAsC,CAAC,EAEvC,YAAyC,CAAC,EAC1C,UAAiC,CAAC,EAClC,mBAAsD,CAAC,EACvD,oBAA4D,CAAC,EAC7D,qCAA4E,IAAI,IAChF,MAA2B,CAAC,EAC5B,UACA,cAA+BC,EAC/B,qBAAuB,GACvB,wBAA0B,GAC1B,iBAIA,IAAI,cAA8B,CAC9B,GAAI,KAAK,cAAc,cAAgB,QAAS,OAAO,KACvD,IAAMC,EAAU,IAAI,cAAc,KAAK,OAAQ,KAAK,KAAM,KAAK,SAAS,EAExE,MADA,GAAQ,cAAgB,KAAK,cACtBA,CACX,CAEA,YAAY,EAA6B,EAAwB,kBAAiC,IAAI,IAAI,CAAC,SAAU,aAAc,QAAS,OAAQ,KAAK,CAAC,EAAG,CAAxI,KAAA,OAAAC,EAA6B,KA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,OAAO,gBAAgB,EACxBA,EAAM,QAAQ,WAAW,KAAK,GAC9B,KAAK,eAAe,EAExB,EAAQ,KAAK,UAAUD,CAAY,CAE3C,CAGA,gBAAuB,CACnB,IAAK,IAAIF,EAAO,KAAK,OAAO,QAAQ,EAAGA,IAAS,IAAA,GAAW,EAAO,KAAK,OAAO,QAAQ,EAClF,GAAIA,EAAK,IAAI,KAAK,IAAM,MACpB,MAGZ,CACJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{pattern as t}from"../Text/patterns.js";import{locationOf as n}from"./SourceLine.js";import{parseMappingSource as r}from"./ExpressionParser.js";import{firstWord as
|
|
1
|
+
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{pattern as t}from"../Text/patterns.js";import{locationOf as n}from"./SourceLine.js";import{parseMappingSource as r}from"./ExpressionParser.js";import{diagnosticText as i}from"../Diagnostics/DiagnosticArgument.js";import{firstWord as a,unescapeIdentifier as o}from"./LineText.js";import{parseProperty as s}from"./PropertyLineParser.js";import{parseCondition as c}from"./ConditionParser.js";import{sourceStreamPattern as l}from"../Text/SourceStreamNames.js";import{parseCommandStream as u}from"./EventSourceParser.js";import{parseOperation as d}from"./OperationParser.js";import{EventMetadataParser as f}from"./EventMetadataParser.js";import{parseTag as p}from"./DeclarationParsers.js";const m=t(`^produces\\s+operation(?:\\s|$)`),h=t(`^produces\\s+event\\s+([A-Za-z_]\\w*)(?:\\s+(generation)(?:\\s+.*)?)?$`),g=t(`^produces\\s+([A-Z]\\w*(?:\\.[A-Za-z_]\\w*)*)$`),_=t(`^produces\\s+when\\s+(.+)$`),v=t(`^[A-Z]\\w*(?:\\.[A-Za-z_]\\w*)*$`),y=t(`^for\\s+(\\S.*)$`),b=t(`^(@?[\\w.]+)\\s*=(?!=|>)\\s*(.+)$`),x=t(`^(.+?)\\s*=(?!=|>)\\s*(.+)$`),S=/* @__PURE__ */ new Set([`namespace`,`sequence`,`correlation`,`causation`,`causedBy`,`occurred`]);function parseProduces(t,C,w=!1){if(m.test(C.content)){if(!w){t.error(e.OperationOutsideCommand,`Operations can only be produced by commands.`,n(C)),t.skipOpaqueBlock(C.indent);return}let r=d(t,C,!0);return{kind:`ProducesSyntax`,when:null,event:r.operation.name,targetLocation:{...n(C),column:C.indent+C.content.match(/^produces\s+operation(?:\s+|$)/)[0].length+1},inlineEvent:null,inlineOperation:r.operation,mappings:r.mappings,for:null,tags:[],location:n(C)}}let T=h.exec(C.content),E=C,D=null,O,k;if(T!==null){if(!w){t.error(e.InlineEventOutsideCommand,`Inline events can only be declared inside commands`,n(C)),t.skipOpaqueBlock(C.indent);return}T[2]!==void 0&&t.error(e.InlineEventGeneration,`Inline events are generation 1 - extract the event before declaring generations`,n(C)),O=T[1],k=C.indent+C.content.match(/^produces\s+event\s+/)[0].length+1}else if(_.test(C.content)){D=c(t,_.exec(C.content)[1],n(C));let r=t.peekChild(C.indent);if(r===void 0||!v.test(r.content)){t.error(e.ProducesWhenWithoutEvent,`Expected an event name on the line after 'produces when'`,n(C)),t.skipOpaqueBlock(C.indent);return}t.reader.takeSignificant(),E=r,O=r.content,k=r.indent+1}else{let r=g.exec(C.content);if(r===null){t.error(e.InvalidProducesDeclaration,`Invalid produces declaration '${C.content}' - expected 'produces <EventType>' or 'produces when <condition>'`,n(C)),t.skipOpaqueBlock(C.indent);return}O=r[1],k=C.indent+C.content.match(/^produces\s+/)[0].length+1}let A=[],j=/* @__PURE__ */ new Set,M=[],N=[],P=new f(O),F=null,I=null;for(let c=t.peekChild(E.indent);c!==void 0;c=t.peekChild(E.indent)){t.reader.takeSignificant();let d=a(c.content),f=n(c);if(S.has(d)){t.error(e.ReservedProductionMetadata,`'${d}' is system-assigned production metadata and cannot be supplied here`,f),t.skipOpaqueBlock(c.indent);continue}if(T!==null&&(d===`generation`||d===`origin`)){t.error(d===`generation`?e.InlineEventGeneration:e.ReservedProductionMetadata,d===`generation`?`Inline events are generation 1 - extract the event before declaring generations`:`An inline event is local to its command and cannot declare origin`,f),t.skipOpaqueBlock(c.indent);continue}if(d===`stream`&&!c.content.includes(`=`)){let n=l(`^stream\\s+([A-Za-z_]\\w*\\.[A-Za-z_]\\w*)$`).exec(c.content);if(!w)t.error(e.ProductionRouteOutsideCommand,`Only command event productions can declare a stream route.`,f),t.skipBlock(c.indent);else if(I!==null)t.error(e.InvalidCommandStream,`A production can declare at most one stream route.`,f),t.skipBlock(c.indent);else if(n===null)t.error(e.InvalidCommandStream,`Expected 'stream <Source>.<Stream>'.`,f),t.skipBlock(c.indent);else{let e={...f,column:c.indent+c.content.indexOf(n[1])+1},r={kind:`PropertySyntax`,name:`stream`,type:{kind:`TypeRefSyntax`,name:n[1],isCollection:!1,isOptional:!1,location:e},isIdentifier:!1,location:f};I=u(t,c,r,!1)}continue}if(d===`tag`){let e=p(t,c,!1);e!==void 0&&N.push(e);continue}let m=y.exec(c.content);if(m!==null){F===null?F=r(m[1],f,t):t.error(e.DuplicateProducesTarget,`'${E.content}' already declares where it lands - an event is appended to one event source`,f);continue}let h=(T===null?b:x).exec(c.content),g=h===null||T===null?void 0:s(t,{...c,content:h[1].trimEnd()});if(h!==null&&(T===null||g!==void 0)){if(g!==void 0){g.isIdentifier&&(t.error(e.IdentifierOnEventProperty,`Property '${g.name}' of event '${O}' cannot be marked identifier - an event never carries its event source id`,f),g={...g,isIdentifier:!1});let n=g.name;j.has(n)&&t.error(e.DuplicateDeclaration,`Event '${O}' already declares property '${g.name}'`,f),j.add(n),A.push(g)}M.push({kind:`PropertyMappingSyntax`,property:g?.name??o(h[1]),source:r(h[2],{...f,column:c.indent+c.content.length-h[2].length+1},t),location:f})}else(T===null||!P.tryParse(t,c))&&t.error(e.InvalidPropertyMapping,`Invalid ${T===null?``:`inline `}property mapping '${c.content}' - expected '<property>${T===null?``:` <Type>`} = <source>'`,f,i(`text`,c.content))}return E!==C&&t.skipBlock(C.indent),{kind:`ProducesSyntax`,when:D,event:O,stream:I,targetLocation:{...n(E),column:k},inlineOperation:null,mappings:M,for:F,tags:T===null?N:[],location:n(C),inlineEvent:T===null?null:{kind:`EventSyntax`,name:O,properties:A,tags:N,generation:1,hasGenerationMarker:!1,...P.value,location:n(C)}}}export{parseProduces};
|
|
2
2
|
//# sourceMappingURL=ProducesParser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProducesParser.js","names":["inlineOperationPrefix","pattern","inlineHeader","plainHeader","conditional","eventName","targetPattern","mappingPattern","typedMappingPattern","reserved","header","inCommand","context","DiagnosticCodes","locationOf","parsed","parseOperation","inline","parent","when","name","targetColumn","parseCondition","child","plain","properties","propertyNames","mappings","tags","metadata","EventMetadataParser","target","stream","line","keyword","firstWord","location","route","sourceStreamPattern","typeLocation","candidate","parseCommandStream","tag","parseTag","forMatch","parseMappingSource","match","property","parseProperty","propertyName","unescapeIdentifier"],"sources":["../../../../../../Compiler/Parsing/ProducesParser.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { CommandStreamSyntax } from '../Syntax/CommandStreamSyntax';\nimport { sourceStreamPattern } from '../Text/SourceStreamNames';\nimport { parseCommandStream } from './EventSourceParser';\nimport { ConditionSyntax } from '../Syntax/Conditions';\nimport { parseCondition } from './ConditionParser';\nimport { PropertySyntax, TagSyntax } from '../Syntax/Declarations';\nimport { ExpressionSyntax, PropertyMappingSyntax } from '../Syntax/Expressions';\nimport { ProducesSyntax } from '../Syntax/Reactions';\nimport { pattern } from '../Text/patterns';\nimport { parseTag } from './DeclarationParsers';\nimport { EventMetadataParser } from './EventMetadataParser';\nimport { parseMappingSource } from './ExpressionParser';\nimport { firstWord, unescapeIdentifier } from './LineText';\nimport { ParserContext } from './ParserContext';\nimport { parseOperation } from './OperationParser';\nimport { parseProperty } from './PropertyLineParser';\nimport { locationOf, SourceLine } from './SourceLine';\n\nconst inlineOperationPrefix = pattern('^produces\\\\s+operation(?:\\\\s|$)');\nconst inlineHeader = pattern('^produces\\\\s+event\\\\s+([A-Za-z_]\\\\w*)(?:\\\\s+(generation)(?:\\\\s+.*)?)?$');\nconst plainHeader = pattern('^produces\\\\s+([A-Z]\\\\w*(?:\\\\.[A-Za-z_]\\\\w*)*)$');\nconst conditional = pattern('^produces\\\\s+when\\\\s+(.+)$');\nconst eventName = pattern('^[A-Z]\\\\w*(?:\\\\.[A-Za-z_]\\\\w*)*$');\nconst targetPattern = pattern('^for\\\\s+(\\\\S.*)$');\nconst mappingPattern = pattern('^(@?[\\\\w.]+)\\\\s*=(?!=|>)\\\\s*(.+)$');\nconst typedMappingPattern = pattern('^(.+?)\\\\s*=(?!=|>)\\\\s*(.+)$');\nconst reserved = new Set(['namespace', 'sequence', 'correlation', 'causation', 'causedBy', 'occurred']);\n\nexport function parseProduces(context: ParserContext, header: SourceLine, inCommand = false): ProducesSyntax | undefined {\n if (inlineOperationPrefix.test(header.content)) {\n if (!inCommand) {\n context.error(DiagnosticCodes.OperationOutsideCommand, 'Operations can only be produced by commands.', locationOf(header));\n context.skipOpaqueBlock(header.indent);\n return undefined;\n }\n const parsed = parseOperation(context, header, true);\n return { kind: 'ProducesSyntax', when: null, event: parsed.operation.name, targetLocation: { ...locationOf(header), column: header.indent + header.content.match(/^produces\\s+operation(?:\\s+|$)/)![0].length + 1 }, inlineEvent: null, inlineOperation: parsed.operation, mappings: parsed.mappings, for: null, tags: [], location: locationOf(header) };\n }\n const inline = inlineHeader.exec(header.content);\n let parent = header;\n let when: ConditionSyntax | null = null;\n let name: string;\n let targetColumn: number;\n if (inline !== null) {\n if (!inCommand) {\n context.error(DiagnosticCodes.InlineEventOutsideCommand, 'Inline events can only be declared inside commands', locationOf(header));\n context.skipOpaqueBlock(header.indent);\n return undefined;\n }\n if (inline[2] !== undefined) {\n context.error(DiagnosticCodes.InlineEventGeneration, 'Inline events are generation 1 - extract the event before declaring generations', locationOf(header));\n }\n name = inline[1];\n targetColumn = header.indent + header.content.match(/^produces\\s+event\\s+/)![0].length + 1;\n } else if (conditional.test(header.content)) {\n when = parseCondition(context, conditional.exec(header.content)![1], locationOf(header));\n const child = context.peekChild(header.indent);\n if (child === undefined || !eventName.test(child.content)) {\n context.error(DiagnosticCodes.ProducesWhenWithoutEvent, \"Expected an event name on the line after 'produces when'\", locationOf(header));\n context.skipOpaqueBlock(header.indent);\n return undefined;\n }\n context.reader.takeSignificant();\n parent = child;\n name = child.content;\n targetColumn = child.indent + 1;\n } else {\n const plain = plainHeader.exec(header.content);\n if (plain === null) {\n context.error(DiagnosticCodes.InvalidProducesDeclaration, `Invalid produces declaration '${header.content}' - expected 'produces <EventType>' or 'produces when <condition>'`, locationOf(header));\n context.skipOpaqueBlock(header.indent);\n return undefined;\n }\n name = plain[1];\n targetColumn = header.indent + header.content.match(/^produces\\s+/)![0].length + 1;\n }\n const properties: PropertySyntax[] = [];\n const propertyNames = new Set<string>();\n const mappings: PropertyMappingSyntax[] = [];\n const tags: TagSyntax[] = [];\n const metadata = new EventMetadataParser(name);\n let target: ExpressionSyntax | null = null;\n let stream: CommandStreamSyntax | null = null;\n for (let line = context.peekChild(parent.indent); line !== undefined; line = context.peekChild(parent.indent)) {\n context.reader.takeSignificant();\n const keyword = firstWord(line.content);\n const location = locationOf(line);\n if (reserved.has(keyword)) {\n context.error(DiagnosticCodes.ReservedProductionMetadata, `'${keyword}' is system-assigned production metadata and cannot be supplied here`, location);\n context.skipOpaqueBlock(line.indent);\n continue;\n }\n if (inline !== null && (keyword === 'generation' || keyword === 'origin')) {\n context.error(keyword === 'generation' ? DiagnosticCodes.InlineEventGeneration : DiagnosticCodes.ReservedProductionMetadata,\n keyword === 'generation' ? 'Inline events are generation 1 - extract the event before declaring generations' : 'An inline event is local to its command and cannot declare origin', location);\n context.skipOpaqueBlock(line.indent);\n continue;\n }\n if (keyword === 'stream' && !line.content.includes('=')) {\n const route = sourceStreamPattern('^stream\\\\s+([A-Za-z_]\\\\w*\\\\.[A-Za-z_]\\\\w*)$').exec(line.content);\n if (!inCommand) {\n context.error(DiagnosticCodes.ProductionRouteOutsideCommand, 'Only command event productions can declare a stream route.', location);\n context.skipBlock(line.indent);\n } else if (stream !== null) {\n context.error(DiagnosticCodes.InvalidCommandStream, 'A production can declare at most one stream route.', location);\n context.skipBlock(line.indent);\n } else if (route === null) {\n context.error(DiagnosticCodes.InvalidCommandStream, \"Expected 'stream <Source>.<Stream>'.\", location);\n context.skipBlock(line.indent);\n } else {\n const typeLocation = { ...location, column: line.indent + line.content.indexOf(route[1]) + 1 };\n const candidate: PropertySyntax = { kind: 'PropertySyntax', name: 'stream', type: { kind: 'TypeRefSyntax', name: route[1], isCollection: false, isOptional: false, location: typeLocation }, isIdentifier: false, location };\n stream = parseCommandStream(context, line, candidate, false);\n }\n continue;\n }\n if (keyword === 'tag') {\n const tag = parseTag(context, line, false);\n if (tag !== undefined) tags.push(tag);\n continue;\n }\n const forMatch = targetPattern.exec(line.content);\n if (forMatch !== null) {\n if (target !== null) {\n context.error(DiagnosticCodes.DuplicateProducesTarget, `'${parent.content}' already declares where it lands - an event is appended to one event source`, location);\n } else {\n target = parseMappingSource(forMatch[1], location, context);\n }\n continue;\n }\n const match = (inline === null ? mappingPattern : typedMappingPattern).exec(line.content);\n let property = match === null || inline === null ? undefined : parseProperty(context, { ...line, content: match[1].trimEnd() });\n if (match !== null && (inline === null || property !== undefined)) {\n if (property !== undefined) {\n if (property.isIdentifier) {\n context.error(DiagnosticCodes.IdentifierOnEventProperty, `Property '${property.name}' of event '${name}' cannot be marked identifier - an event never carries its event source id`, location);\n property = { ...property, isIdentifier: false };\n }\n const propertyName = property.name;\n if (propertyNames.has(propertyName)) {\n context.error(DiagnosticCodes.DuplicateDeclaration, `Event '${name}' already declares property '${property.name}'`, location);\n }\n propertyNames.add(propertyName);\n properties.push(property);\n }\n mappings.push({ kind: 'PropertyMappingSyntax', property: property?.name ?? unescapeIdentifier(match[1]), source: parseMappingSource(match[2], { ...location, column: line.indent + line.content.length - match[2].length + 1 }, context), location });\n } else if (inline === null || !metadata.tryParse(context, line)) {\n context.error(DiagnosticCodes.InvalidPropertyMapping, `Invalid ${inline === null ? '' : 'inline '}property mapping '${line.content}' - expected '<property>${inline === null ? '' : ' <Type>'} = <source>'`, location);\n }\n }\n if (parent !== header) context.skipBlock(header.indent);\n return {\n kind: 'ProducesSyntax', when, event: name, stream, targetLocation: { ...locationOf(parent), column: targetColumn }, inlineOperation: null, mappings, for: target, tags: inline === null ? tags : [], location: locationOf(header),\n inlineEvent: inline === null ? null : { kind: 'EventSyntax', name, properties, tags, generation: 1, hasGenerationMarker: false, ...metadata.value, location: locationOf(header) },\n };\n}\n"],"mappings":"suBAsBA,MAAMA,EAAwBC,EAAQ,iCAAiC,EACjEC,EAAeD,EAAQ,wEAAwE,EAC/FE,EAAcF,EAAQ,gDAAgD,EACtEG,EAAcH,EAAQ,4BAA4B,EAClDI,EAAYJ,EAAQ,kCAAkC,EACtDK,EAAgBL,EAAQ,kBAAkB,EAC1CM,EAAiBN,EAAQ,mCAAmC,EAC5DO,EAAsBP,EAAQ,6BAA6B,EAC3DQ,kBAAW,IAAI,IAAI,CAAC,YAAa,WAAY,cAAe,YAAa,WAAY,UAAU,CAAC,EAEtG,SAAgB,cAAc,EAAwB,EAAoB,EAAY,GAAmC,CACrH,GAAIT,EAAsB,KAAKU,EAAO,OAAO,EAAG,CAC5C,GAAI,CAACC,EAAW,CACZC,EAAQ,MAAMC,EAAgB,wBAAyB,+CAAgDC,EAAWJ,CAAM,CAAC,EACzHE,EAAQ,gBAAgBF,EAAO,MAAM,EACrC,MACJ,CACA,IAAMK,EAASC,EAAeJ,EAASF,EAAQ,EAAI,EACnD,MAAO,CAAE,KAAM,iBAAkB,KAAM,KAAM,MAAOK,EAAO,UAAU,KAAM,eAAgB,CAAE,GAAG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Prefix","pattern","inlineHeader","plainHeader","conditional","eventName","targetPattern","mappingPattern","typedMappingPattern","reserved","header","inCommand","context","DiagnosticCodes","locationOf","parsed","parseOperation","inline","parent","when","name","targetColumn","parseCondition","child","plain","properties","propertyNames","mappings","tags","metadata","EventMetadataParser","target","stream","line","keyword","firstWord","location","route","sourceStreamPattern","typeLocation","candidate","parseCommandStream","tag","parseTag","forMatch","parseMappingSource","match","property","parseProperty","propertyName","unescapeIdentifier","diagnosticText"],"sources":["../../../../../../Compiler/Parsing/ProducesParser.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { diagnosticText } from '../Diagnostics/DiagnosticArgument';\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { CommandStreamSyntax } from '../Syntax/CommandStreamSyntax';\nimport { sourceStreamPattern } from '../Text/SourceStreamNames';\nimport { parseCommandStream } from './EventSourceParser';\nimport { ConditionSyntax } from '../Syntax/Conditions';\nimport { parseCondition } from './ConditionParser';\nimport { PropertySyntax, TagSyntax } from '../Syntax/Declarations';\nimport { ExpressionSyntax, PropertyMappingSyntax } from '../Syntax/Expressions';\nimport { ProducesSyntax } from '../Syntax/Reactions';\nimport { pattern } from '../Text/patterns';\nimport { parseTag } from './DeclarationParsers';\nimport { EventMetadataParser } from './EventMetadataParser';\nimport { parseMappingSource } from './ExpressionParser';\nimport { firstWord, unescapeIdentifier } from './LineText';\nimport { ParserContext } from './ParserContext';\nimport { parseOperation } from './OperationParser';\nimport { parseProperty } from './PropertyLineParser';\nimport { locationOf, SourceLine } from './SourceLine';\n\nconst inlineOperationPrefix = pattern('^produces\\\\s+operation(?:\\\\s|$)');\nconst inlineHeader = pattern('^produces\\\\s+event\\\\s+([A-Za-z_]\\\\w*)(?:\\\\s+(generation)(?:\\\\s+.*)?)?$');\nconst plainHeader = pattern('^produces\\\\s+([A-Z]\\\\w*(?:\\\\.[A-Za-z_]\\\\w*)*)$');\nconst conditional = pattern('^produces\\\\s+when\\\\s+(.+)$');\nconst eventName = pattern('^[A-Z]\\\\w*(?:\\\\.[A-Za-z_]\\\\w*)*$');\nconst targetPattern = pattern('^for\\\\s+(\\\\S.*)$');\nconst mappingPattern = pattern('^(@?[\\\\w.]+)\\\\s*=(?!=|>)\\\\s*(.+)$');\nconst typedMappingPattern = pattern('^(.+?)\\\\s*=(?!=|>)\\\\s*(.+)$');\nconst reserved = new Set(['namespace', 'sequence', 'correlation', 'causation', 'causedBy', 'occurred']);\n\nexport function parseProduces(context: ParserContext, header: SourceLine, inCommand = false): ProducesSyntax | undefined {\n if (inlineOperationPrefix.test(header.content)) {\n if (!inCommand) {\n context.error(DiagnosticCodes.OperationOutsideCommand, 'Operations can only be produced by commands.', locationOf(header));\n context.skipOpaqueBlock(header.indent);\n return undefined;\n }\n const parsed = parseOperation(context, header, true);\n return { kind: 'ProducesSyntax', when: null, event: parsed.operation.name, targetLocation: { ...locationOf(header), column: header.indent + header.content.match(/^produces\\s+operation(?:\\s+|$)/)![0].length + 1 }, inlineEvent: null, inlineOperation: parsed.operation, mappings: parsed.mappings, for: null, tags: [], location: locationOf(header) };\n }\n const inline = inlineHeader.exec(header.content);\n let parent = header;\n let when: ConditionSyntax | null = null;\n let name: string;\n let targetColumn: number;\n if (inline !== null) {\n if (!inCommand) {\n context.error(DiagnosticCodes.InlineEventOutsideCommand, 'Inline events can only be declared inside commands', locationOf(header));\n context.skipOpaqueBlock(header.indent);\n return undefined;\n }\n if (inline[2] !== undefined) {\n context.error(DiagnosticCodes.InlineEventGeneration, 'Inline events are generation 1 - extract the event before declaring generations', locationOf(header));\n }\n name = inline[1];\n targetColumn = header.indent + header.content.match(/^produces\\s+event\\s+/)![0].length + 1;\n } else if (conditional.test(header.content)) {\n when = parseCondition(context, conditional.exec(header.content)![1], locationOf(header));\n const child = context.peekChild(header.indent);\n if (child === undefined || !eventName.test(child.content)) {\n context.error(DiagnosticCodes.ProducesWhenWithoutEvent, \"Expected an event name on the line after 'produces when'\", locationOf(header));\n context.skipOpaqueBlock(header.indent);\n return undefined;\n }\n context.reader.takeSignificant();\n parent = child;\n name = child.content;\n targetColumn = child.indent + 1;\n } else {\n const plain = plainHeader.exec(header.content);\n if (plain === null) {\n context.error(DiagnosticCodes.InvalidProducesDeclaration, `Invalid produces declaration '${header.content}' - expected 'produces <EventType>' or 'produces when <condition>'`, locationOf(header));\n context.skipOpaqueBlock(header.indent);\n return undefined;\n }\n name = plain[1];\n targetColumn = header.indent + header.content.match(/^produces\\s+/)![0].length + 1;\n }\n const properties: PropertySyntax[] = [];\n const propertyNames = new Set<string>();\n const mappings: PropertyMappingSyntax[] = [];\n const tags: TagSyntax[] = [];\n const metadata = new EventMetadataParser(name);\n let target: ExpressionSyntax | null = null;\n let stream: CommandStreamSyntax | null = null;\n for (let line = context.peekChild(parent.indent); line !== undefined; line = context.peekChild(parent.indent)) {\n context.reader.takeSignificant();\n const keyword = firstWord(line.content);\n const location = locationOf(line);\n if (reserved.has(keyword)) {\n context.error(DiagnosticCodes.ReservedProductionMetadata, `'${keyword}' is system-assigned production metadata and cannot be supplied here`, location);\n context.skipOpaqueBlock(line.indent);\n continue;\n }\n if (inline !== null && (keyword === 'generation' || keyword === 'origin')) {\n context.error(keyword === 'generation' ? DiagnosticCodes.InlineEventGeneration : DiagnosticCodes.ReservedProductionMetadata,\n keyword === 'generation' ? 'Inline events are generation 1 - extract the event before declaring generations' : 'An inline event is local to its command and cannot declare origin', location);\n context.skipOpaqueBlock(line.indent);\n continue;\n }\n if (keyword === 'stream' && !line.content.includes('=')) {\n const route = sourceStreamPattern('^stream\\\\s+([A-Za-z_]\\\\w*\\\\.[A-Za-z_]\\\\w*)$').exec(line.content);\n if (!inCommand) {\n context.error(DiagnosticCodes.ProductionRouteOutsideCommand, 'Only command event productions can declare a stream route.', location);\n context.skipBlock(line.indent);\n } else if (stream !== null) {\n context.error(DiagnosticCodes.InvalidCommandStream, 'A production can declare at most one stream route.', location);\n context.skipBlock(line.indent);\n } else if (route === null) {\n context.error(DiagnosticCodes.InvalidCommandStream, \"Expected 'stream <Source>.<Stream>'.\", location);\n context.skipBlock(line.indent);\n } else {\n const typeLocation = { ...location, column: line.indent + line.content.indexOf(route[1]) + 1 };\n const candidate: PropertySyntax = { kind: 'PropertySyntax', name: 'stream', type: { kind: 'TypeRefSyntax', name: route[1], isCollection: false, isOptional: false, location: typeLocation }, isIdentifier: false, location };\n stream = parseCommandStream(context, line, candidate, false);\n }\n continue;\n }\n if (keyword === 'tag') {\n const tag = parseTag(context, line, false);\n if (tag !== undefined) tags.push(tag);\n continue;\n }\n const forMatch = targetPattern.exec(line.content);\n if (forMatch !== null) {\n if (target !== null) {\n context.error(DiagnosticCodes.DuplicateProducesTarget, `'${parent.content}' already declares where it lands - an event is appended to one event source`, location);\n } else {\n target = parseMappingSource(forMatch[1], location, context);\n }\n continue;\n }\n const match = (inline === null ? mappingPattern : typedMappingPattern).exec(line.content);\n let property = match === null || inline === null ? undefined : parseProperty(context, { ...line, content: match[1].trimEnd() });\n if (match !== null && (inline === null || property !== undefined)) {\n if (property !== undefined) {\n if (property.isIdentifier) {\n context.error(DiagnosticCodes.IdentifierOnEventProperty, `Property '${property.name}' of event '${name}' cannot be marked identifier - an event never carries its event source id`, location);\n property = { ...property, isIdentifier: false };\n }\n const propertyName = property.name;\n if (propertyNames.has(propertyName)) {\n context.error(DiagnosticCodes.DuplicateDeclaration, `Event '${name}' already declares property '${property.name}'`, location);\n }\n propertyNames.add(propertyName);\n properties.push(property);\n }\n mappings.push({ kind: 'PropertyMappingSyntax', property: property?.name ?? unescapeIdentifier(match[1]), source: parseMappingSource(match[2], { ...location, column: line.indent + line.content.length - match[2].length + 1 }, context), location });\n } else if (inline === null || !metadata.tryParse(context, line)) {\n context.error(DiagnosticCodes.InvalidPropertyMapping, `Invalid ${inline === null ? '' : 'inline '}property mapping '${line.content}' - expected '<property>${inline === null ? '' : ' <Type>'} = <source>'`, location, diagnosticText('text', line.content));\n }\n }\n if (parent !== header) context.skipBlock(header.indent);\n return {\n kind: 'ProducesSyntax', when, event: name, stream, targetLocation: { ...locationOf(parent), column: targetColumn }, inlineOperation: null, mappings, for: target, tags: inline === null ? tags : [], location: locationOf(header),\n inlineEvent: inline === null ? null : { kind: 'EventSyntax', name, properties, tags, generation: 1, hasGenerationMarker: false, ...metadata.value, location: locationOf(header) },\n };\n}\n"],"mappings":"4yBAuBA,MAAMA,EAAwBC,EAAQ,iCAAiC,EACjEC,EAAeD,EAAQ,wEAAwE,EAC/FE,EAAcF,EAAQ,gDAAgD,EACtEG,EAAcH,EAAQ,4BAA4B,EAClDI,EAAYJ,EAAQ,kCAAkC,EACtDK,EAAgBL,EAAQ,kBAAkB,EAC1CM,EAAiBN,EAAQ,mCAAmC,EAC5DO,EAAsBP,EAAQ,6BAA6B,EAC3DQ,kBAAW,IAAI,IAAI,CAAC,YAAa,WAAY,cAAe,YAAa,WAAY,UAAU,CAAC,EAEtG,SAAgB,cAAc,EAAwB,EAAoB,EAAY,GAAmC,CACrH,GAAIT,EAAsB,KAAKU,EAAO,OAAO,EAAG,CAC5C,GAAI,CAACC,EAAW,CACZC,EAAQ,MAAMC,EAAgB,wBAAyB,+CAAgDC,EAAWJ,CAAM,CAAC,EACzHE,EAAQ,gBAAgBF,EAAO,MAAM,EACrC,MACJ,CACA,IAAMK,EAASC,EAAeJ,EAASF,EAAQ,EAAI,EACnD,MAAO,CAAE,KAAM,iBAAkB,KAAM,KAAM,MAAOK,EAAO,UAAU,KAAM,eAAgB,CAAE,GAAGD,EAAWJ,CAAM,EAAG,OAAQA,EAAO,OAASA,EAAO,QAAQ,MAAM,gCAAgC,CAAC,CAAE,EAAE,CAAC,OAAS,CAAE,EAAG,YAAa,KAAM,gBAAiBK,EAAO,UAAW,SAAUA,EAAO,SAAU,IAAK,KAAM,KAAM,CAAC,EAAG,SAAUD,EAAWJ,CAAM,CAAE,CAC5V,CACA,IAAMO,EAASf,EAAa,KAAKQ,EAAO,OAA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AAIuB,CAAY,EAC9BxB,EAAW,KAAKsB,CAAQ,CAC5B,CACApB,EAAS,KAAK,CAAE,KAAM,wBAAyB,SAAUoB,GAAU,MAAQG,EAAmBJ,EAAM,EAAE,EAAG,OAAQD,EAAmBC,EAAM,GAAI,CAAE,GAAGV,EAAU,OAAQH,EAAK,OAASA,EAAK,QAAQ,OAASa,EAAM,EAAE,CAAC,OAAS,CAAE,EAAGlC,CAAO,EAAG,UAAS,CAAC,CACxP,MAAWK,IAAW,MAAQ,CAACY,EAAS,SAASjB,EAASqB,CAAI,IAC1DrB,EAAQ,MAAMC,EAAgB,uBAAwB,WAAWI,IAAW,KAAO,GAAK,UAAU,oBAAoBgB,EAAK,QAAQ,0BAA0BhB,IAAW,KAAO,GAAK,UAAU,cAAemB,EAAUe,EAAe,OAAQlB,EAAK,OAAO,CAAC,CAEnQ,CAEA,OADIf,IAAWR,GAAQE,EAAQ,UAAUF,EAAO,MAAM,EAC/C,CACH,KAAM,iBAAkB,OAAM,MAAOU,EAAM,SAAQ,eAAgB,CAAE,GAAGN,EAAWI,CAAM,EAAG,OAAQG,CAAa,EAAG,gBAAiB,KAAM,WAAU,IAAKU,EAAQ,KAAMd,IAAW,KAAOW,EAAO,CAAC,EAAG,SAAUd,EAAWJ,CAAM,EAChO,YAAaO,IAAW,KAAO,KAAO,CAAE,KAAM,cAAe,OAAM,aAAY,OAAM,WAAY,EAAG,oBAAqB,GAAO,GAAGY,EAAS,MAAO,SAAUf,EAAWJ,CAAM,CAAE,CACpL,CACJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{pattern as t}from"../Text/patterns.js";import{locationOf as n}from"./SourceLine.js";import{firstWord as r,splitTopLevel as i,unescapeIdentifier as a}from"./LineText.js";import{parseDescription as o}from"./DescriptionParser.js";import{isFileDirective as s}from"./FileReferences.js";import{parseProjectionExpression as c}from"./ProjectionExpressionParser.js";const l=t(`^projection\\s+(@?[\\w.]+)\\s*(?:=>\\s*([\\w.]+))?$`),u=t(`^(@?[\\w.]+)(?:\\s+key\\s+(.+))?$`),d=t(`^join\\s+(@?[\\w.]+)\\s+on\\s+(@?[\\w.]+)$`),f=t(`^with\\s+(@?[\\w.]+)$`),p=t(`^children\\s+(@?[\\w.]+)\\s+identified\\s+by\\s+(.+)$`),m=t(`^nested\\s+(@?[\\w.]+)$`),h=t(`^remove\\s+with\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$`),g=t(`^remove\\s+via\\s+join\\s+on\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$`),_=t(`^clear\\s+with\\s+(@?[\\w.]+)$`),v=t(`^variant\\s+(@?[\\w.]+)\\s*$`),y=t(`^enters\\s+on\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$`),b=t(`^(increment|decrement|count|clear)\\s+(@?[$\\w.]+)$`),x=t(`^(add|subtract)\\s+(@?[$\\w.]+)\\s+by\\s+(.+)$`),S=t(`^set\\s+(@?[$\\w.]+)\\s+(?:=|to)\\s+(.+)$`),C=t(`^(@?[$\\w.@]+)\\s*=(?!=|>)\\s*(.+)$`),w={increment:`IncrementMappingSyntax`,decrement:`DecrementMappingSyntax`,clear:`ClearMappingSyntax`,count:`CountMappingSyntax`};function parseProjection(t,i){let a=l.exec(i.content);if(a===null)return t.error(e.InvalidProjectionDeclaration,`Invalid projection declaration '${i.content}' - expected 'projection <Name> [=> <ReadModel>]'`,n(i)),t.skipBlock(i.indent),{kind:`ProjectionSyntax`,sourceOptions:t.sourceOptions,name:r(i.content),readModel:null,sequence:null,autoMap:`Inherit`,blocks:[],location:n(i)};let c=a[1],u=null,d=null,f=`Inherit`,p=null,m=[];for(let e=t.peekChild(i.indent);e!==void 0;e=t.peekChild(i.indent)){if(t.reader.takeSignificant(),s(e))continue;let n=r(e.content);if(n===`description`)d=o(t,e,d,`Projection '${c}'`);else if(n===`sequence`)u=e.content.substring(8).trim();else if(n===`automap`)f=`Enabled`;else if(e.content===`no automap`)f=`Disabled`;else if(n===`key`)p=parseKey(t,e);else if(n===`variant`)m.push(parseVariant(t,e));else{let n=parseBlock(t,e,!1);n!==void 0&&m.push(n)}}return reportVariantConflicts(t,m,c),m.length===0&&t.error(e.EmptyProjection,`Projection '${c}' must contain at least one directive`,n(i)),{kind:`ProjectionSyntax`,sourceOptions:t.sourceOptions,name:c,readModel:a[2]??null,sequence:u,autoMap:f,key:p,blocks:m,description:d,location:n(i)}}function reportVariantConflicts(t,n,r){let i=n.filter(e=>e.kind===`ProjectionVariantSyntax`),a=/* @__PURE__ */ new Map;i.forEach(e=>a.set(e.name,[...a.get(e.name)??[],e]));for(let n of[...a.values()].flatMap(e=>e.slice(1)))t.error(e.DuplicateProjectionVariant,`Duplicate variant '${n.name}' - a variant name is declared once`,n.location);let o=/* @__PURE__ */ new Set;for(let i of n.flatMap(e=>e.kind===`ProjectionVariantSyntax`?e.entersOn:[]))i.event.length>0&&o.has(i.event)&&t.error(e.DuplicateVariantEnteringEvent,`Entering event '${i.event}' is claimed more than once in projection '${r}'`,i.location),o.add(i.event)}function parseBlock(t,i,a){let o=n(i);switch(r(i.content)){case`from`:return parseFrom(t,i);case`every`:{let e=!0,{autoMap:n,mappings:r}=parseMappingBlock(t,i,t=>t.content===`exclude children`&&(e=!1,!0));return{kind:`EverySyntax`,includeChildren:e,autoMap:n,mappings:r,location:o}}case`all`:{let{autoMap:e,mappings:n}=parseMappingBlock(t,i);return{kind:`AllSyntax`,autoMap:e,mappings:n,location:o}}case`join`:return parseJoin(t,i);case`children`:return parseChildren(t,i);case`nested`:return parseNested(t,i);case`remove`:return parseRemove(t,i);case`clear`:return a||t.error(e.ClearWithOutsideNestedBlock,`'clear with' is only valid inside a nested block`,o),parseClearWith(t,i);default:t.error(e.UnknownProjectionDirective,`Unexpected '${r(i.content)}' in projection body`,o),t.skipBlock(i.indent);return}}function parseFrom(t,o){let s=[];for(let r of i(o.content.substring(4),`,`)){let i=r.trim();if(i.length===0){t.error(e.FromWithoutEvent,`Expected an event type after 'from'`,n(o));continue}let l=u.exec(i);l===null?t.error(e.InvalidEventReference,`Invalid event reference '${i}'`,n(o)):s.push({kind:`EventSpecSyntax`,event:a(l[1]),key:l[2]===void 0?null:c(l[2],n(o),t),location:n(o)})}let l=[],d=null,f=null;for(let e=t.peekChild(o.indent);e!==void 0;e=t.peekChild(o.indent)){t.reader.takeSignificant();let i=r(e.content);i===`key`?d=parseKey(t,e):i===`parent`?f=c(e.content.substring(6),n(e),t):pushMapping(t,e,l)}return{kind:`FromSyntax`,events:s,key:d,parentKey:f,mappings:l,location:n(o)}}function parseJoin(t,r){let i=d.exec(r.content);if(i===null)return t.error(e.InvalidJoinDeclaration,`Invalid join declaration '${r.content}' - expected 'join <property> on <key>'`,n(r)),t.skipBlock(r.indent),{kind:`JoinSyntax`,property:``,on:``,events:[],location:n(r)};let o=[];for(let i=t.peekChild(r.indent);i!==void 0;i=t.peekChild(r.indent)){t.reader.takeSignificant();let r=f.exec(i.content);if(r===null){t.error(e.JoinWithoutEvent,`Expected 'with <EventType>' in join block, got '${i.content}'`,n(i)),t.skipBlock(i.indent);continue}let{autoMap:s,mappings:c}=parseMappingBlock(t,i);o.push({kind:`JoinEventSyntax`,event:a(r[1]),autoMap:s,mappings:c,location:n(i)})}return{kind:`JoinSyntax`,property:a(i[1]),on:a(i[2]),events:o,location:n(r)}}function parseChildren(t,r){let i=p.exec(r.content);if(i===null)return t.error(e.InvalidChildrenDeclaration,`Invalid children declaration '${r.content}' - expected 'children <collection> identified by <key>'`,n(r)),t.skipBlock(r.indent),{kind:`ChildrenSyntax`,property:``,autoMap:`Inherit`,blocks:[],location:n(r)};let{autoMap:o,blocks:s}=parseChildBlocks(t,r);return{kind:`ChildrenSyntax`,property:a(i[1]),identifiedBy:c(i[2],n(r),t),autoMap:o,blocks:s,location:n(r)}}function parseNested(t,r){let i=m.exec(r.content);if(i===null)return t.error(e.InvalidNestedDeclaration,`Invalid nested declaration '${r.content}' - expected 'nested <property>'`,n(r)),t.skipBlock(r.indent),{kind:`NestedSyntax`,property:``,autoMap:`Inherit`,blocks:[],location:n(r)};let o=a(i[1]),{autoMap:s,blocks:c}=parseChildBlocks(t,r);return c.some(e=>e.kind===`FromSyntax`)||t.error(e.NestedBlockWithoutFrom,`Nested block '${o}' must contain at least one 'from' directive`,n(r)),{kind:`NestedSyntax`,property:o,autoMap:s,blocks:c,location:n(r)}}function parseChildBlocks(e,t){let n=[],r=`Inherit`;for(let i=e.peekChild(t.indent);i!==void 0;i=e.peekChild(t.indent)){if(e.reader.takeSignificant(),i.content===`automap`){r=`Enabled`;continue}if(i.content===`no automap`){r=`Disabled`;continue}let t=parseBlock(e,i,!0);t!==void 0&&n.push(t)}return{autoMap:r,blocks:n}}function parseRemove(t,i){let o=g.exec(i.content);if(o!==null)return{kind:`RemoveViaJoinSyntax`,event:a(o[1]),key:o[2]===void 0?null:c(o[2],n(i),t),location:n(i)};let s=h.exec(i.content);if(s===null){t.error(e.InvalidRemoveDeclaration,`Invalid remove declaration '${i.content}' - expected 'remove with <EventType>' or 'remove via join on <EventType>'`,n(i)),t.skipBlock(i.indent);return}let l=null;for(let a=t.peekChild(i.indent);a!==void 0;a=t.peekChild(i.indent))t.reader.takeSignificant(),r(a.content)===`parent`?l=c(a.content.substring(6),n(a),t):t.error(e.UnknownRemoveDirective,`Unexpected '${a.content}' in remove block - only 'parent' is allowed`,n(a));return{kind:`RemoveWithSyntax`,event:a(s[1]),key:s[2]===void 0?null:c(s[2],n(i),t),parentKey:l,location:n(i)}}function parseClearWith(t,r){let i=_.exec(r.content);return i===null?(t.error(e.InvalidClearDeclaration,`Invalid clear declaration '${r.content}' - expected 'clear with <EventType>'`,n(r)),{kind:`ClearWithSyntax`,event:``,location:n(r)}):{kind:`ClearWithSyntax`,event:a(i[1]),location:n(r)}}function parseVariant(t,i){let o=v.exec(i.content);if(o===null)return t.error(e.InvalidProjectionVariantDeclaration,`Invalid variant declaration '${i.content}' - expected 'variant <Name>'`,n(i)),t.skipBlock(i.indent),{kind:`ProjectionVariantSyntax`,name:r(i.content),entersOn:[],blocks:[],location:n(i)};let s=a(o[1]),c=[],l=[];for(let a=t.peekChild(i.indent);a!==void 0;a=t.peekChild(i.indent)){t.reader.takeSignificant();let i=r(a.content);if(i===`enters`)c.push(parseEntersOn(t,a));else if(i===`variant`)t.error(e.NestedProjectionVariantNotAllowed,`A variant cannot be declared inside another variant`,n(a)),t.skipBlock(a.indent);else{let e=parseBlock(t,a,!1);e!==void 0&&l.push(e)}}return c.length===0&&t.error(e.VariantRequiresEnteringEvent,`Variant '${s}' must declare at least one 'enters on' event`,n(i)),{kind:`ProjectionVariantSyntax`,name:s,entersOn:c,blocks:l,location:n(i)}}function parseEntersOn(t,r){let i=y.exec(r.content);return i===null?(t.error(e.InvalidEntersOnDeclaration,`Invalid 'enters on' declaration '${r.content}' - expected 'enters on <EventType> [key <expression>]'`,n(r)),t.skipBlock(r.indent),{kind:`ProjectionEntersOnSyntax`,event:``,key:null,location:n(r)}):{kind:`ProjectionEntersOnSyntax`,event:a(i[1]),key:i[2]===void 0?null:c(i[2],n(r),t),location:n(r)}}function parseKey(t,r){let i=r.content.substring(3).trim();if(t.peekChild(r.indent)===void 0)return{kind:`ExpressionKeySyntax`,expression:c(i,n(r),t),location:n(r)};let o=[];for(let i=t.peekChild(r.indent);i!==void 0;i=t.peekChild(r.indent)){if(t.reader.takeSignificant(),i.content===`}`)continue;let r=C.exec(i.content);if(r===null){t.sourceOptions.numericMode===`exact`&&t.error(e.InvalidCompositeKeyPart,`Invalid composite key part '${i.content}' - expected '<property> = <expression>'`,n(i));continue}let s=c(r[2],n(i),t);t.sourceOptions.numericMode===`exact`&&s.kind===`TemplateExpressionSyntax`&&t.error(e.TemplateInCompositeKey,`Template expressions are not allowed in composite keys`,n(i)),o.push({kind:`KeyPartSyntax`,property:a(r[1]),expression:s,location:n(i)})}let s=t.reader.peekSignificant();return s!==void 0&&s.indent===r.indent&&s.content===`}`&&t.reader.takeSignificant(),t.sourceOptions.numericMode===`exact`&&o.length===0&&t.error(e.EmptyCompositeKey,`Composite keys must contain at least one part`,n(r)),{kind:`CompositeKeySyntax`,type:i.replace(/\{$/,``).trim(),parts:o,location:n(r)}}function parseMappingBlock(e,t,n=()=>!1){let r=`Inherit`,i=[];for(let a=e.peekChild(t.indent);a!==void 0;a=e.peekChild(t.indent))e.reader.takeSignificant(),a.content===`automap`?r=`Enabled`:a.content===`no automap`?r=`Disabled`:n(a)||pushMapping(e,a,i);return{autoMap:r,mappings:i}}function pushMapping(t,r,i){let o=n(r),s=b.exec(r.content);if(s!==null){s[1]!==`clear`||s[2]!==`with`?i.push({kind:w[s[1]],property:a(s[2]),location:o}):t.sourceOptions.numericMode===`exact`&&t.error(e.InvalidProjectionMapping,`Invalid mapping '${r.content}' - 'clear with' is a block directive and needs an event type; to clear a property named 'with', write 'clear @with'`,o);return}let l=x.exec(r.content);if(l!==null){i.push({kind:l[1]===`add`?`AddMappingSyntax`:`SubtractMappingSyntax`,property:a(l[2]),value:c(l[3],o,t),location:o});return}let u=S.exec(r.content)??C.exec(r.content);u===null?t.sourceOptions.numericMode===`exact`&&t.error(e.InvalidProjectionMapping,`Invalid mapping '${r.content}'`,o):i.push({kind:`SetMappingSyntax`,property:a(u[1]),source:c(u[2],o,t),location:o})}export{parseProjection};
|
|
1
|
+
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{pattern as t}from"../Text/patterns.js";import{locationOf as n}from"./SourceLine.js";import{diagnosticText as r}from"../Diagnostics/DiagnosticArgument.js";import{firstWord as i,splitTopLevel as a,unescapeIdentifier as o}from"./LineText.js";import{parseDescription as s}from"./DescriptionParser.js";import{isFileDirective as c}from"./FileReferences.js";import{parseProjectionExpression as l}from"./ProjectionExpressionParser.js";const u=t(`^projection\\s+(@?[\\w.]+)\\s*(?:=>\\s*([\\w.]+))?$`),d=t(`^(@?[\\w.]+)(?:\\s+key\\s+(.+))?$`),f=t(`^join\\s+(@?[\\w.]+)\\s+on\\s+(@?[\\w.]+)$`),p=t(`^with\\s+(@?[\\w.]+)$`),m=t(`^children\\s+(@?[\\w.]+)\\s+identified\\s+by\\s+(.+)$`),h=t(`^nested\\s+(@?[\\w.]+)$`),g=t(`^remove\\s+with\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$`),_=t(`^remove\\s+via\\s+join\\s+on\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$`),v=t(`^clear\\s+with\\s+(@?[\\w.]+)$`),y=t(`^variant\\s+(@?[\\w.]+)\\s*$`),b=t(`^enters\\s+on\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$`),x=t(`^(increment|decrement|count|clear)\\s+(@?[$\\w.]+)$`),S=t(`^(add|subtract)\\s+(@?[$\\w.]+)\\s+by\\s+(.+)$`),C=t(`^set\\s+(@?[$\\w.]+)\\s+(?:=|to)\\s+(.+)$`),w=t(`^(@?[$\\w.@]+)\\s*=(?!=|>)\\s*(.+)$`),T={increment:`IncrementMappingSyntax`,decrement:`DecrementMappingSyntax`,clear:`ClearMappingSyntax`,count:`CountMappingSyntax`};function parseProjection(t,r){let a=u.exec(r.content);if(a===null)return t.error(e.InvalidProjectionDeclaration,`Invalid projection declaration '${r.content}' - expected 'projection <Name> [=> <ReadModel>]'`,n(r)),t.skipBlock(r.indent),{kind:`ProjectionSyntax`,sourceOptions:t.sourceOptions,name:i(r.content),readModel:null,sequence:null,autoMap:`Inherit`,blocks:[],location:n(r)};let o=a[1],l=null,d=null,f=`Inherit`,p=null,m=[];for(let e=t.peekChild(r.indent);e!==void 0;e=t.peekChild(r.indent)){if(t.reader.takeSignificant(),c(e))continue;let n=i(e.content);if(n===`description`)d=s(t,e,d,`Projection '${o}'`);else if(n===`sequence`)l=e.content.substring(8).trim();else if(n===`automap`)f=`Enabled`;else if(e.content===`no automap`)f=`Disabled`;else if(n===`key`)p=parseKey(t,e);else if(n===`variant`)m.push(parseVariant(t,e));else{let n=parseBlock(t,e,!1);n!==void 0&&m.push(n)}}return reportVariantConflicts(t,m,o),m.length===0&&t.error(e.EmptyProjection,`Projection '${o}' must contain at least one directive`,n(r)),{kind:`ProjectionSyntax`,sourceOptions:t.sourceOptions,name:o,readModel:a[2]??null,sequence:l,autoMap:f,key:p,blocks:m,description:d,location:n(r)}}function reportVariantConflicts(t,n,r){let i=n.filter(e=>e.kind===`ProjectionVariantSyntax`),a=/* @__PURE__ */ new Map;i.forEach(e=>a.set(e.name,[...a.get(e.name)??[],e]));for(let n of[...a.values()].flatMap(e=>e.slice(1)))t.error(e.DuplicateProjectionVariant,`Duplicate variant '${n.name}' - a variant name is declared once`,n.location);let o=/* @__PURE__ */ new Set;for(let i of n.flatMap(e=>e.kind===`ProjectionVariantSyntax`?e.entersOn:[]))i.event.length>0&&o.has(i.event)&&t.error(e.DuplicateVariantEnteringEvent,`Entering event '${i.event}' is claimed more than once in projection '${r}'`,i.location),o.add(i.event)}function parseBlock(t,r,a){let o=n(r);switch(i(r.content)){case`from`:return parseFrom(t,r);case`every`:{let e=!0,{autoMap:n,mappings:i}=parseMappingBlock(t,r,t=>t.content===`exclude children`&&(e=!1,!0));return{kind:`EverySyntax`,includeChildren:e,autoMap:n,mappings:i,location:o}}case`all`:{let{autoMap:e,mappings:n}=parseMappingBlock(t,r);return{kind:`AllSyntax`,autoMap:e,mappings:n,location:o}}case`join`:return parseJoin(t,r);case`children`:return parseChildren(t,r);case`nested`:return parseNested(t,r);case`remove`:return parseRemove(t,r);case`clear`:return a||t.error(e.ClearWithOutsideNestedBlock,`'clear with' is only valid inside a nested block`,o),parseClearWith(t,r);default:t.error(e.UnknownProjectionDirective,`Unexpected '${i(r.content)}' in projection body`,o),t.skipBlock(r.indent);return}}function parseFrom(t,r){let s=[];for(let i of a(r.content.substring(4),`,`)){let a=i.trim();if(a.length===0){t.error(e.FromWithoutEvent,`Expected an event type after 'from'`,n(r));continue}let c=d.exec(a);c===null?t.error(e.InvalidEventReference,`Invalid event reference '${a}'`,n(r)):s.push({kind:`EventSpecSyntax`,event:o(c[1]),key:c[2]===void 0?null:l(c[2],n(r),t),location:n(r)})}let c=[],u=null,f=null;for(let e=t.peekChild(r.indent);e!==void 0;e=t.peekChild(r.indent)){t.reader.takeSignificant();let r=i(e.content);r===`key`?u=parseKey(t,e):r===`parent`?f=l(e.content.substring(6),n(e),t):pushMapping(t,e,c)}return{kind:`FromSyntax`,events:s,key:u,parentKey:f,mappings:c,location:n(r)}}function parseJoin(t,r){let i=f.exec(r.content);if(i===null)return t.error(e.InvalidJoinDeclaration,`Invalid join declaration '${r.content}' - expected 'join <property> on <key>'`,n(r)),t.skipBlock(r.indent),{kind:`JoinSyntax`,property:``,on:``,events:[],location:n(r)};let a=[];for(let i=t.peekChild(r.indent);i!==void 0;i=t.peekChild(r.indent)){t.reader.takeSignificant();let r=p.exec(i.content);if(r===null){t.error(e.JoinWithoutEvent,`Expected 'with <EventType>' in join block, got '${i.content}'`,n(i)),t.skipBlock(i.indent);continue}let{autoMap:s,mappings:c}=parseMappingBlock(t,i);a.push({kind:`JoinEventSyntax`,event:o(r[1]),autoMap:s,mappings:c,location:n(i)})}return{kind:`JoinSyntax`,property:o(i[1]),on:o(i[2]),events:a,location:n(r)}}function parseChildren(t,r){let i=m.exec(r.content);if(i===null)return t.error(e.InvalidChildrenDeclaration,`Invalid children declaration '${r.content}' - expected 'children <collection> identified by <key>'`,n(r)),t.skipBlock(r.indent),{kind:`ChildrenSyntax`,property:``,autoMap:`Inherit`,blocks:[],location:n(r)};let{autoMap:a,blocks:s}=parseChildBlocks(t,r);return{kind:`ChildrenSyntax`,property:o(i[1]),identifiedBy:l(i[2],n(r),t),autoMap:a,blocks:s,location:n(r)}}function parseNested(t,r){let i=h.exec(r.content);if(i===null)return t.error(e.InvalidNestedDeclaration,`Invalid nested declaration '${r.content}' - expected 'nested <property>'`,n(r)),t.skipBlock(r.indent),{kind:`NestedSyntax`,property:``,autoMap:`Inherit`,blocks:[],location:n(r)};let a=o(i[1]),{autoMap:s,blocks:c}=parseChildBlocks(t,r);return c.some(e=>e.kind===`FromSyntax`)||t.error(e.NestedBlockWithoutFrom,`Nested block '${a}' must contain at least one 'from' directive`,n(r)),{kind:`NestedSyntax`,property:a,autoMap:s,blocks:c,location:n(r)}}function parseChildBlocks(e,t){let n=[],r=`Inherit`;for(let i=e.peekChild(t.indent);i!==void 0;i=e.peekChild(t.indent)){if(e.reader.takeSignificant(),i.content===`automap`){r=`Enabled`;continue}if(i.content===`no automap`){r=`Disabled`;continue}let t=parseBlock(e,i,!0);t!==void 0&&n.push(t)}return{autoMap:r,blocks:n}}function parseRemove(t,r){let a=_.exec(r.content);if(a!==null)return{kind:`RemoveViaJoinSyntax`,event:o(a[1]),key:a[2]===void 0?null:l(a[2],n(r),t),location:n(r)};let s=g.exec(r.content);if(s===null){t.error(e.InvalidRemoveDeclaration,`Invalid remove declaration '${r.content}' - expected 'remove with <EventType>' or 'remove via join on <EventType>'`,n(r)),t.skipBlock(r.indent);return}let c=null;for(let a=t.peekChild(r.indent);a!==void 0;a=t.peekChild(r.indent))t.reader.takeSignificant(),i(a.content)===`parent`?c=l(a.content.substring(6),n(a),t):t.error(e.UnknownRemoveDirective,`Unexpected '${a.content}' in remove block - only 'parent' is allowed`,n(a));return{kind:`RemoveWithSyntax`,event:o(s[1]),key:s[2]===void 0?null:l(s[2],n(r),t),parentKey:c,location:n(r)}}function parseClearWith(t,r){let i=v.exec(r.content);return i===null?(t.error(e.InvalidClearDeclaration,`Invalid clear declaration '${r.content}' - expected 'clear with <EventType>'`,n(r)),{kind:`ClearWithSyntax`,event:``,location:n(r)}):{kind:`ClearWithSyntax`,event:o(i[1]),location:n(r)}}function parseVariant(t,r){let a=y.exec(r.content);if(a===null)return t.error(e.InvalidProjectionVariantDeclaration,`Invalid variant declaration '${r.content}' - expected 'variant <Name>'`,n(r)),t.skipBlock(r.indent),{kind:`ProjectionVariantSyntax`,name:i(r.content),entersOn:[],blocks:[],location:n(r)};let s=o(a[1]),c=[],l=[];for(let a=t.peekChild(r.indent);a!==void 0;a=t.peekChild(r.indent)){t.reader.takeSignificant();let r=i(a.content);if(r===`enters`)c.push(parseEntersOn(t,a));else if(r===`variant`)t.error(e.NestedProjectionVariantNotAllowed,`A variant cannot be declared inside another variant`,n(a)),t.skipBlock(a.indent);else{let e=parseBlock(t,a,!1);e!==void 0&&l.push(e)}}return c.length===0&&t.error(e.VariantRequiresEnteringEvent,`Variant '${s}' must declare at least one 'enters on' event`,n(r)),{kind:`ProjectionVariantSyntax`,name:s,entersOn:c,blocks:l,location:n(r)}}function parseEntersOn(t,r){let i=b.exec(r.content);return i===null?(t.error(e.InvalidEntersOnDeclaration,`Invalid 'enters on' declaration '${r.content}' - expected 'enters on <EventType> [key <expression>]'`,n(r)),t.skipBlock(r.indent),{kind:`ProjectionEntersOnSyntax`,event:``,key:null,location:n(r)}):{kind:`ProjectionEntersOnSyntax`,event:o(i[1]),key:i[2]===void 0?null:l(i[2],n(r),t),location:n(r)}}function parseKey(t,r){let i=r.content.substring(3).trim();if(t.peekChild(r.indent)===void 0)return{kind:`ExpressionKeySyntax`,expression:l(i,n(r),t),location:n(r)};let a=[];for(let i=t.peekChild(r.indent);i!==void 0;i=t.peekChild(r.indent)){if(t.reader.takeSignificant(),i.content===`}`)continue;let r=w.exec(i.content);if(r===null){t.sourceOptions.numericMode===`exact`&&t.error(e.InvalidCompositeKeyPart,`Invalid composite key part '${i.content}' - expected '<property> = <expression>'`,n(i));continue}let s=l(r[2],n(i),t);t.sourceOptions.numericMode===`exact`&&s.kind===`TemplateExpressionSyntax`&&t.error(e.TemplateInCompositeKey,`Template expressions are not allowed in composite keys`,n(i)),a.push({kind:`KeyPartSyntax`,property:o(r[1]),expression:s,location:n(i)})}let s=t.reader.peekSignificant();return s!==void 0&&s.indent===r.indent&&s.content===`}`&&t.reader.takeSignificant(),t.sourceOptions.numericMode===`exact`&&a.length===0&&t.error(e.EmptyCompositeKey,`Composite keys must contain at least one part`,n(r)),{kind:`CompositeKeySyntax`,type:i.replace(/\{$/,``).trim(),parts:a,location:n(r)}}function parseMappingBlock(e,t,n=()=>!1){let r=`Inherit`,i=[];for(let a=e.peekChild(t.indent);a!==void 0;a=e.peekChild(t.indent))e.reader.takeSignificant(),a.content===`automap`?r=`Enabled`:a.content===`no automap`?r=`Disabled`:n(a)||pushMapping(e,a,i);return{autoMap:r,mappings:i}}function pushMapping(t,i,a){let s=n(i),c=x.exec(i.content);if(c!==null){c[1]!==`clear`||c[2]!==`with`?a.push({kind:T[c[1]],property:o(c[2]),location:s}):t.sourceOptions.numericMode===`exact`&&t.error(e.InvalidProjectionMapping,`Invalid mapping '${i.content}' - 'clear with' is a block directive and needs an event type; to clear a property named 'with', write 'clear @with'`,s,r(`text`,i.content));return}let u=S.exec(i.content);if(u!==null){a.push({kind:u[1]===`add`?`AddMappingSyntax`:`SubtractMappingSyntax`,property:o(u[2]),value:l(u[3],s,t),location:s});return}let d=C.exec(i.content)??w.exec(i.content);d===null?t.sourceOptions.numericMode===`exact`&&t.error(e.InvalidProjectionMapping,`Invalid mapping '${i.content}'`,s,r(`text`,i.content)):a.push({kind:`SetMappingSyntax`,property:o(d[1]),source:l(d[2],s,t),location:s})}export{parseProjection};
|
|
2
2
|
//# sourceMappingURL=ProjectionParser.js.map
|