@cratis/screenplay-language 4.259.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundles/compiler/Authoring/QuickFixes.js +6 -2
- package/dist/bundles/compiler/Authoring/QuickFixes.js.map +1 -1
- package/dist/bundles/compiler/Authoring/StructuredValueQuickFix.js +3 -0
- package/dist/bundles/compiler/Authoring/StructuredValueQuickFix.js.map +1 -0
- package/dist/bundles/compiler/Diagnostics/DiagnosticCodes.js +1 -1
- package/dist/bundles/compiler/Diagnostics/DiagnosticCodes.js.map +1 -1
- package/dist/bundles/compiler/Parsing/CaptureParser.js +1 -1
- package/dist/bundles/compiler/Parsing/CaptureParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/CompositionParser.js +1 -1
- package/dist/bundles/compiler/Parsing/CompositionParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/ExpressionParser.js +1 -1
- package/dist/bundles/compiler/Parsing/ExpressionParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/OperationParser.js +1 -1
- package/dist/bundles/compiler/Parsing/OperationParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/ProducesParser.js +1 -1
- package/dist/bundles/compiler/Parsing/ProducesParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/ProjectionParser.js +1 -1
- package/dist/bundles/compiler/Parsing/ProjectionParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/ReactionParser.js +1 -1
- package/dist/bundles/compiler/Parsing/ReactionParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/ScreenParser.js +1 -1
- package/dist/bundles/compiler/Parsing/ScreenParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/SeedParser.js +1 -1
- package/dist/bundles/compiler/Parsing/SeedParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationCaseParser.js +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationCaseParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationExampleParser.js +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationExampleParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationParser.js +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationResponseParser.js +1 -1
- package/dist/bundles/compiler/Parsing/SpecificationResponseParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/StructuredBlockParser.js +2 -0
- package/dist/bundles/compiler/Parsing/StructuredBlockParser.js.map +1 -0
- package/dist/bundles/compiler/Parsing/UiBindingParser.js +1 -1
- package/dist/bundles/compiler/Parsing/UiBindingParser.js.map +1 -1
- package/dist/bundles/example-analysis.js +1 -1
- package/dist/bundles/example-analysis.js.map +1 -1
- package/dist/bundles/keyword-docs.js +1 -1
- package/dist/bundles/keyword-docs.js.map +1 -1
- package/dist/keyword-docs.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -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{diagnosticText as s}from"../Diagnostics/DiagnosticArgument.js";import{firstWord as c,unescapeIdentifier as l}from"./LineText.js";import{
|
|
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{tryParseStructuredMapping as u}from"./StructuredBlockParser.js";import{parseTag as d}from"./DeclarationParsers.js";import"../Syntax/CaptureEventsSource.js";import{parseProjectionExpression as f}from"./ProjectionExpressionParser.js";const grammar=e=>({legacy:i(e),native:r(e)}),p=grammar(`^capture\\s+([A-Za-z_]\\w*)$`),m=/^[A-Za-z_][\w.]*$/,h=/\s+is\s+event\s+source$/,g=grammar(`^append\\s+([A-Z]\\w*)$`),_=grammar(`^children\\s+([a-z_]\\w*)\\s+identified\\s+by\\s+([\\w.]+)$`),v=grammar(`^nested\\s+([\\w.]+)$`),select=(e,t)=>e.sourceOptions.numericMode===`exact`?t.native:t.legacy,y=r(`^(@?[\\w.]+)\\s*=(?!=|>)\\s*(.+)$`),b=r(`^([a-z_]\\w*)\\s*=\\s*(.+)$`),x=r(`^"(${t})"\\s*=>\\s*(\\w+)$`),S=r(`^split\\s+(\\S+)\\s+by\\s+"(${t})"$`),C=new RegExp(r(`"${t}"|[\\w.]+`).source,`gu`),w=r(`^[\\w.]+$`);function parseCapture(t,n){let r=t;t=t.valueContext;let i=select(t,p).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=!1,u=[],d=[],f=[],m=[];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,l]=parseKey(i.content.substring(3).trim(),l);break;case`map`:u.push(...parseMap(t,i));break;case`append`:pushAppend(t,i,d);break;case`children`:{let n=select(t,_).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&&f.push({kind:`CaptureChildrenSyntax`,property:n[1],identifiedBy:n[2],...r,location:a(i)});break}case`nested`:{let n=select(t,v).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&&m.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,...eventSourceKeyMarker(l),map:u,appends:d,children:f,nested:m,location:a(n)}}function parseKey(e,t){let n=h.exec(e);return n===null?[e,t]:[e.substring(0,n.index),!0]}function eventSourceKeyMarker(e){return e?{keyIsEventSource:e}:{}}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`?m.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=S.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(),w.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:f(s[1],r,t),separator:n(s[2]),targets:c,location:r});continue}let s=b.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,d=l.startsWith("`")?u>=0&&l.substring(u+1).trim()===`translate`:l.endsWith(` translate`),p=l.startsWith("`")&&u>=0&&(t.sourceOptions.numericMode!==`exact`||d||l.substring(u+1).trim()===``)?l.substring(0,u+1):d?l.substring(0,l.length-10).trimEnd():l,m=[];if(d)for(let r=t.peekChild(o.indent);r!==void 0;r=t.peekChild(o.indent)){t.reader.takeSignificant();let i=x.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:f(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,g).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 f=[],p=[],m=null,mapping=(n,r=!1)=>{let i=a(n);if(c(n.content)===`tag`){let e=d(t.valueContext,n,!1);e!==void 0&&p.push(e);return}let m=y.exec(n.content),h=m===null?u(t.valueContext,n):void 0;m===null?h===void 0?t.error(r?e.InvalidPropertyMapping:e.UnknownAppendDirective,`Unexpected '${n.content}' in append body`,i,r?s(`text`,n.content):{}):f.push(h):f.push({kind:`PropertyMappingSyntax`,property:l(m[1]),source:o(m[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`){m=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:m,mappings:f,tags:p,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`):C)??[]],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","eventSourceKeyRules","appendRules","childrenRules","nestedRules","context","rules","mappingPattern","mapEntryPattern","translationPattern","stringBodyPattern","splitPattern","whenTokens","splitTarget","owner","name","line","DiagnosticCodes","locationOf","key","keyIsEventSource","map","appends","children","nested","child","firstWord","match","body","marker","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 eventSourceKeyRules = /\\s+is\\s+event\\s+source$/;\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 let keyIsEventSource = false;\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, keyIsEventSource] = parseKey(child.content.substring('key'.length).trim(), keyIsEventSource); 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, ...eventSourceKeyMarker(keyIsEventSource), map, appends, children, nested, location: locationOf(line) };\n}\n\nfunction parseKey(key: string, keyIsEventSource: boolean): [string, boolean] {\n const marker = eventSourceKeyRules.exec(key);\n return marker !== null ? [key.substring(0, marker.index), true] : [key, keyIsEventSource];\n}\n\nfunction eventSourceKeyMarker(keyIsEventSource: boolean): { keyIsEventSource?: boolean } {\n return keyIsEventSource ? { keyIsEventSource } : {};\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,EAAsB,0BACtBC,EAAc,QAAQ,yBAAyB,EAC/CC,EAAgB,QAAQ,6DAA6D,EACrFC,EAAc,QAAQ,uBAAuB,EAC7C,QAAU,EAAwB,IAAsDC,EAAQ,cAAc,cAAgB,QAAUC,EAAM,OAASA,EAAM,OAC7JC,EAAiBb,EAAQ,mCAAmC,EAC5Dc,EAAkBd,EAAQ,6BAA6B,EACvDe,EAAqBf,EAAQ,MAAMgB,EAAkB,oBAAoB,EACzEC,EAAejB,EAAQ,+BAA+BgB,EAAkB,IAAI,EAC5EE,EAAa,IAAI,OAAOlB,EAAQ,IAAIgB,EAAkB,UAAU,CAAC,CAAC,OAAQ,IAAI,EAC9EG,EAAcnB,EAAQ,WAAW,EAIvC,SAAgB,aAAa,EAAwB,EAAiC,CAElF,IAAMoB,EAAQT,EACd,EAAUA,EAAQ,aAClB,IAAMU,EAAO,OAAOV,EAASN,CAAW,CAAC,CA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names":["legacyPattern","pattern","parseMappingSource","pattern","source","nativePattern","headerRules","eventNameRules","eventSourceKeyRules","appendRules","childrenRules","nestedRules","context","rules","mappingPattern","mapEntryPattern","translationPattern","stringBodyPattern","splitPattern","whenTokens","splitTarget","owner","name","line","DiagnosticCodes","locationOf","key","keyIsEventSource","map","appends","children","nested","child","firstWord","match","body","marker","settings","settingName","syntaxKind","seen","setting","location","targets","target","parseProjectionExpression","unescapeString","raw","closing","translate","text","translations","entry","translated","mappings","tags","when","tag","parseTag","mapped","structured","tryParseStructuredMapping","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';\nimport { tryParseStructuredMapping } from './StructuredBlockParser';\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 eventSourceKeyRules = /\\s+is\\s+event\\s+source$/;\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 let keyIsEventSource = false;\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, keyIsEventSource] = parseKey(child.content.substring('key'.length).trim(), keyIsEventSource); 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, ...eventSourceKeyMarker(keyIsEventSource), map, appends, children, nested, location: locationOf(line) };\n}\n\nfunction parseKey(key: string, keyIsEventSource: boolean): [string, boolean] {\n const marker = eventSourceKeyRules.exec(key);\n return marker !== null ? [key.substring(0, marker.index), true] : [key, keyIsEventSource];\n}\n\nfunction eventSourceKeyMarker(keyIsEventSource: boolean): { keyIsEventSource?: boolean } {\n return keyIsEventSource ? { keyIsEventSource } : {};\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 const structured = mapped === null ? tryParseStructuredMapping(context.valueContext, child) : undefined;\n if (mapped !== null) mappings.push({ kind: 'PropertyMappingSyntax', property: unescapeIdentifier(mapped[1]), source: parseMappingSource(mapped[2], location, context.valueContext), location });\n else if (structured !== undefined) mappings.push(structured);\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":"ivBAoBA,MAAM,QAAW,IAAwD,CAAE,OAAQA,EAAcI,CAAM,EAAG,OAAQH,EAAQG,CAAM,CAAE,GAC5HE,EAAc,QAAQ,8BAA8B,EACpDC,EAAiB,oBACjBC,EAAsB,0BACtBC,EAAc,QAAQ,yBAAyB,EAC/CC,EAAgB,QAAQ,6DAA6D,EACrFC,EAAc,QAAQ,uBAAuB,EAC7C,QAAU,EAAwB,IAAsDC,EAAQ,cAAc,cAAgB,QAAUC,EAAM,OAASA,EAAM,OAC7JC,EAAiBb,EAAQ,mCAAmC,EAC5Dc,EAAkBd,EAAQ,6BAA6B,EACvDe,EAAqBf,EAAQ,MAAMgB,EAAkB,oBAAoB,EACzEC,EAAejB,EAAQ,+BAA+BgB,EAAkB,IAAI,EAC5EE,EAAa,IAAI,OAAOlB,EAAQ,IAAIgB,EAAkB,UAAU,CAAC,CAAC,OAAQ,IAAI,EAC9EG,EAAcnB,EAAQ,WAAW,EAIvC,SAAgB,aAAa,EAAwB,EAAiC,CAElF,IAAMoB,EAAQT,EACd,EAAUA,EAAQ,aAClB,IAAMU,EAAO,OAAOV,EAASN,CAAW,CAAC,CAAC,KAAKiB,EAAK,OAAO,CAAC,GAAG,IAAM,GACjED,IAAS,IAAMV,EAAQ,cAAc,cAAgB,SAASA,EAAQ,MAAMY,EAAgB,0BAA2B,gCAAgCD,EAAK,QAAQ,+BAAgCE,EAAWF,CAAI,CAAC,EACxN,IAAInB,EAAqC,KACrCsB,EAAqB,KACrBC,EAAmB,GACjBC,EAAmC,CAAC,EACpCC,EAAiC,CAAC,EAClCC,EAAoC,CAAC,EACrCC,EAAgC,CAAC,EACvC,IAAK,IAAIC,EAAQpB,EAAQ,UAAUW,EAAK,M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,EAAG,OAAO,MAAM,kBAAmB,CAAC,QAAQA,EAAO,EAAE,CAAC,CAAC,EAC7E,GAAIA,EAAO,KAAO,OAEuH,OADjIA,EAAO,SAAW,GAAKA,EAAO,KAAO,KAAa,MAAM,kBAAmB,CAAC,QAAQA,EAAO,EAAE,CAAC,EAAG,QAAQA,EAAO,EAAE,EAAG,QAAQA,EAAO,EAAE,CAAC,GAC3IzD,EAAQ,MAAMY,EAAgB,4BAA6B,8CAA8CD,EAAK,QAAQ,GAAImB,CAAQ,EAAU,MAEhJ,GAAI2B,EAAO,KAAO,MAAQA,EAAO,KAAO,MAAgH,OAAvGzD,EAAQ,MAAMY,EAAgB,kBAAmB,0BAA0BD,EAAK,QAAQ,GAAImB,CAAQ,EAAU,KAC/J,GAAI2B,EAAO,OAAS,GAAM,EAAyH,OAApHzD,EAAQ,MAAMY,EAAgB,8BAA+B,8BAA8B6C,EAAO,GAAG,GAAI3B,CAAQ,EAAU,KAC1J,IAAM4B,EAAa,CAAC,QAAQD,EAAO,EAAE,CAAC,EACtC,IAAK,IAAIE,EAAQ,EAAGA,EAAQF,EAAO,OAAS,EAAG,GAAS,EAAG,CACvD,GAAIA,EAAOE,KAAWF,EAAO,GAA8I,OAAxIzD,EAAQ,MAAMY,EAAgB,qBAAsB,wDAAwDD,EAAK,QAAQ,GAAImB,CAAQ,EAAU,KAClL4B,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{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{stringBodyPattern as t,unescapeString as n}from"../Text/StringLiteral.js";import{pattern as r}from"../Text/patterns.js";import{locationOf as i}from"./SourceLine.js";import{parseMappingSource as a}from"./ExpressionParser.js";const
|
|
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{pattern as r}from"../Text/patterns.js";import{locationOf as i}from"./SourceLine.js";import{parseMappingSource as a}from"./ExpressionParser.js";import{parseStructuredValue as o,tryParseStructuredMapping as s}from"./StructuredBlockParser.js";const c=`(?:([A-Za-z_]\\w*)|"(${t})")\\.(\\w+(?:\\.\\w+)*)`,l=r(`^exposure\\s+for\\s+([A-Za-z_]\\w*)$`),u=r(`^instance\\s+([A-Za-z_]\\w*)$`),d=r(`^property\\s+${c}(?:\\s+label\\s+"(${t})")?(?:\\s+operations\\s+([\\w-]+(?:\\s*,\\s*[\\w-]+)*))?(?:\\s+fields\\s+(\\w+(?:\\s*,\\s*\\w+)*))?(?:\\s+reexposes\\s+([A-Za-z_]\\w*))?$`),f=r(`^set\\s+${c}\\s*=\\s*(.+)$`),p=r(`^set\\s+${c}(?:\\s+(none|empty))?$`),m=r(`^items\\s+${c}$`),h=r(`^item\\s+(?:([A-Za-z_][\\w-]*)|"(${t})")$`),g=r(`^([A-Za-z_]\\w*)\\s*=\\s*(.+)$`),_=[`add`,`remove`,`reorder`,`edit-fields`],reference=(e,t)=>e[t]??n(e[t+1]),list=e=>e.trim()===`none`?[]:e.split(`,`).map(e=>e.trim()).filter(e=>e.length>0);function parseExposure(t,n){let r=l.exec(n.content);r===null&&t.error(e.InvalidExposureDeclaration,`Invalid exposure declaration '${n.content}' - expected 'exposure for <Owner>'`,i(n));let a=[];for(let e=t.peekChild(n.indent);e!==void 0;e=t.peekChild(n.indent)){t.reader.takeSignificant();let n=parseExposedProperty(t,e);n!==void 0&&a.push(n)}return{kind:`ExposureSyntax`,owner:r?.[1]??n.content,properties:a,location:i(n)}}function parseInstance(t,n){let r=u.exec(n.content);r===null&&t.error(e.InvalidInstanceContribution,`Invalid instance declaration '${n.content}' - expected 'instance <Screen or Template>'`,i(n));let a=[];for(let e=t.peekChild(n.indent);e!==void 0;e=t.peekChild(n.indent)){t.reader.takeSignificant();let n=parseContribution(t,e);n!==void 0&&a.push(n)}return{kind:`InstanceContributionsSyntax`,instance:r?.[1]??n.content,contributions:a,location:i(n)}}function parseExposedProperty(t,r){let a=d.exec(r.content);if(a===null){t.error(e.InvalidExposureDeclaration,`Invalid exposed property '${r.content}' - expected 'property <component>.<path> [label "<text>"] [operations <add|remove|reorder|edit-fields>, ...] [fields <field>, ...] [reexposes <Owner>]'`,i(r));return}let o=a[5]===void 0?[]:list(a[5]),s=o.find(e=>!_.includes(e));if(s!==void 0)t.error(e.InvalidExposureDeclaration,`Unknown collection operation '${s}' - expected add, remove, reorder, edit-fields or none`,i(r));else return{kind:`ExposedPropertySyntax`,component:reference(a,1),path:a[3],label:a[4]===void 0?null:n(a[4]),isCollection:a[5]!==void 0,operations:o,restrictsFields:a[6]!==void 0,editableFields:a[6]===void 0?[]:list(a[6]),reExposes:a[7]??null,location:i(r)}}function parseContribution(t,n){let r=f.exec(n.content);if(r!==null)return t.skipBlock(n.indent),{kind:`InstanceContributionSyntax`,component:reference(r,1),path:r[3],value:a(r[4],i(n),t),items:[],location:i(n)};let s=p.exec(n.content);if(s!==null)return{kind:`InstanceContributionSyntax`,component:reference(s,1),path:s[3],value:o(t,n,s[4]?.trim()),items:[],location:i(n)};let c=m.exec(n.content);if(c!==null){let e=[];for(let r=t.peekChild(n.indent);r!==void 0;r=t.peekChild(n.indent)){t.reader.takeSignificant();let n=parseItem(t,r);n!==void 0&&e.push(n)}return{kind:`InstanceContributionSyntax`,component:reference(c,1),path:c[3],value:null,items:e,location:i(n)}}t.error(e.InvalidInstanceContribution,`Invalid instance contribution '${n.content}' - expected 'set <component>.<path> = <value>' or 'items <component>.<path>'`,i(n)),t.skipBlock(n.indent)}function parseItem(t,n){let r=h.exec(n.content);if(r===null){t.error(e.InvalidInstanceContribution,`Invalid contributed item '${n.content}' - expected 'item <id>'`,i(n)),t.skipBlock(n.indent);return}let o=[];for(let r=t.peekChild(n.indent);r!==void 0;r=t.peekChild(n.indent)){t.reader.takeSignificant();let n=g.exec(r.content),c=n===null?s(t,r):void 0;c===void 0?n===null?(t.error(e.InvalidInstanceContribution,`Invalid item value '${r.content}' - expected '<field> = <value>'`,i(r)),t.skipBlock(r.indent)):o.push({kind:`ContributedItemValueSyntax`,field:n[1],value:a(n[2],i(r),t),location:i(r)}):o.push({kind:`ContributedItemValueSyntax`,field:c.property,value:c.source,location:i(r)})}return{kind:`ContributedItemSyntax`,id:reference(r,1),values:o,location:i(n)}}export{parseExposure,parseInstance};
|
|
2
2
|
//# sourceMappingURL=CompositionParser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CompositionParser.js","names":["component","stringBodyPattern","exposureHeader","pattern","instanceHeader","exposedProperty","setPattern","itemsPattern","itemPattern","itemValuePattern","operations","match","group","unescapeString","text","entry","header","context","DiagnosticCodes","locationOf","properties","line","property","contributions","contribution","granted","unknown","operation","set","parseMappingSource","items","parsed","child","item","values","value"],"sources":["../../../../../../Compiler/Parsing/CompositionParser.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { ContributedItemSyntax, ContributedItemValueSyntax, ExposedPropertySyntax, ExposureSyntax, InstanceContributionSyntax, InstanceContributionsSyntax } from '../Syntax/CompositionSyntax';\nimport { stringBodyPattern, unescapeString } from '../Text/StringLiteral';\nimport { pattern } from '../Text/patterns';\nimport { parseMappingSource } from './ExpressionParser';\nimport { ParserContext } from './ParserContext';\nimport { locationOf, SourceLine } from './SourceLine';\n\nconst component = `(?:([A-Za-z_]\\\\w*)|\"(${stringBodyPattern})\")\\\\.(\\\\w+(?:\\\\.\\\\w+)*)`;\nconst exposureHeader = pattern('^exposure\\\\s+for\\\\s+([A-Za-z_]\\\\w*)$');\nconst instanceHeader = pattern('^instance\\\\s+([A-Za-z_]\\\\w*)$');\nconst exposedProperty = pattern(`^property\\\\s+${component}(?:\\\\s+label\\\\s+\"(${stringBodyPattern})\")?(?:\\\\s+operations\\\\s+([\\\\w-]+(?:\\\\s*,\\\\s*[\\\\w-]+)*))?(?:\\\\s+fields\\\\s+(\\\\w+(?:\\\\s*,\\\\s*\\\\w+)*))?(?:\\\\s+reexposes\\\\s+([A-Za-z_]\\\\w*))?$`);\nconst setPattern = pattern(`^set\\\\s+${component}\\\\s*=\\\\s*(.+)$`);\nconst itemsPattern = pattern(`^items\\\\s+${component}$`);\nconst itemPattern = pattern(`^item\\\\s+(?:([A-Za-z_][\\\\w-]*)|\"(${stringBodyPattern})\")$`);\nconst itemValuePattern = pattern('^([A-Za-z_]\\\\w*)\\\\s*=\\\\s*(.+)$');\nconst operations = ['add', 'remove', 'reorder', 'edit-fields'];\nconst exposedPropertyShape = '\\'property <component>.<path> [label \"<text>\"] [operations <add|remove|reorder|edit-fields>, ...] [fields <field>, ...] [reexposes <Owner>]\\'';\n\nconst reference = (match: RegExpExecArray, group: number): string => match[group] ?? unescapeString(match[group + 1]);\nconst list = (text: string): string[] => text.trim() === 'none' ? [] : text.split(',').map(entry => entry.trim()).filter(entry => entry.length > 0);\n\n// 'exposure for <Owner>' - the port of the C# CompositionParser.ParseExposure.\nexport function parseExposure(context: ParserContext, header: SourceLine): ExposureSyntax {\n const match = exposureHeader.exec(header.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidExposureDeclaration, `Invalid exposure declaration '${header.content}' - expected 'exposure for <Owner>'`, locationOf(header));\n }\n const properties: ExposedPropertySyntax[] = [];\n for (let line = context.peekChild(header.indent); line !== undefined; line = context.peekChild(header.indent)) {\n context.reader.takeSignificant();\n const property = parseExposedProperty(context, line);\n if (property !== undefined) properties.push(property);\n }\n return { kind: 'ExposureSyntax', owner: match?.[1] ?? header.content, properties, location: locationOf(header) };\n}\n\n// 'instance <Instance>' - the port of the C# CompositionParser.ParseInstance.\nexport function parseInstance(context: ParserContext, header: SourceLine): InstanceContributionsSyntax {\n const match = instanceHeader.exec(header.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidInstanceContribution, `Invalid instance declaration '${header.content}' - expected 'instance <Screen or Template>'`, locationOf(header));\n }\n const contributions: InstanceContributionSyntax[] = [];\n for (let line = context.peekChild(header.indent); line !== undefined; line = context.peekChild(header.indent)) {\n context.reader.takeSignificant();\n const contribution = parseContribution(context, line);\n if (contribution !== undefined) contributions.push(contribution);\n }\n return { kind: 'InstanceContributionsSyntax', instance: match?.[1] ?? header.content, contributions, location: locationOf(header) };\n}\n\nfunction parseExposedProperty(context: ParserContext, line: SourceLine): ExposedPropertySyntax | undefined {\n const match = exposedProperty.exec(line.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidExposureDeclaration, `Invalid exposed property '${line.content}' - expected ${exposedPropertyShape}`, locationOf(line));\n return undefined;\n }\n const granted = match[5] === undefined ? [] : list(match[5]);\n const unknown = granted.find(operation => !operations.includes(operation));\n if (unknown !== undefined) {\n context.error(DiagnosticCodes.InvalidExposureDeclaration, `Unknown collection operation '${unknown}' - expected add, remove, reorder, edit-fields or none`, locationOf(line));\n return undefined;\n }\n return {\n kind: 'ExposedPropertySyntax',\n component: reference(match, 1),\n path: match[3],\n label: match[4] === undefined ? null : unescapeString(match[4]),\n isCollection: match[5] !== undefined,\n operations: granted,\n restrictsFields: match[6] !== undefined,\n editableFields: match[6] === undefined ? [] : list(match[6]),\n reExposes: match[7] ?? null,\n location: locationOf(line)\n };\n}\n\nfunction parseContribution(context: ParserContext, line: SourceLine): InstanceContributionSyntax | undefined {\n const set = setPattern.exec(line.content);\n if (set !== null) {\n context.skipBlock(line.indent);\n return { kind: 'InstanceContributionSyntax', component: reference(set, 1), path: set[3], value: parseMappingSource(set[4], locationOf(line), context), items: [], location: locationOf(line) };\n }\n const items = itemsPattern.exec(line.content);\n if (items !== null) {\n const parsed: ContributedItemSyntax[] = [];\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n const item = parseItem(context, child);\n if (item !== undefined) parsed.push(item);\n }\n return { kind: 'InstanceContributionSyntax', component: reference(items, 1), path: items[3], value: null, items: parsed, location: locationOf(line) };\n }\n context.error(DiagnosticCodes.InvalidInstanceContribution, `Invalid instance contribution '${line.content}' - expected 'set <component>.<path> = <value>' or 'items <component>.<path>'`, locationOf(line));\n context.skipBlock(line.indent);\n return undefined;\n}\n\nfunction parseItem(context: ParserContext, line: SourceLine): ContributedItemSyntax | undefined {\n const match = itemPattern.exec(line.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidInstanceContribution, `Invalid contributed item '${line.content}' - expected 'item <id>'`, locationOf(line));\n context.skipBlock(line.indent);\n return undefined;\n }\n const values: ContributedItemValueSyntax[] = [];\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n const value = itemValuePattern.exec(child.content);\n if (value === null) {\n context.error(DiagnosticCodes.InvalidInstanceContribution, `Invalid item value '${child.content}' - expected '<field> = <value>'`, locationOf(child));\n context.skipBlock(child.indent);\n continue;\n }\n values.push({ kind: 'ContributedItemValueSyntax', field: value[1], value: parseMappingSource(value[2], locationOf(child), context), location: locationOf(child) });\n }\n return { kind: 'ContributedItemSyntax', id: reference(match, 1), values, location: locationOf(line) };\n}\n"],"mappings":"gWAWA,MAAMA,EAAY,wBAAwBC,EAAkB,0BACtDC,EAAiBC,EAAQ,sCAAsC,EAC/DC,EAAiBD,EAAQ,+BAA+B,EACxDE,EAAkBF,EAAQ,gBAAgBH,EAAU,oBAAoBC,EAAkB,2IAA2I,EACrOK,EAAaH,EAAQ,WAAWH,EAAU,eAAe,EACzDO,EAAeJ,EAAQ,aAAaH,EAAU,EAAE,EAChDQ,EAAcL,EAAQ,oCAAoCF,EAAkB,KAAK,EACjFQ,EAAmBN,EAAQ,gCAAgC,EAC3DO,EAAa,CAAC,MAAO,SAAU,UAAW,aAAa,EAGvD,WAAa,EAAw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AAM,MAAM,GAGlCE,EAAO,KAAK,CAAE,KAAM,6BAA8B,MAAOC,EAAM,GAAI,MAAON,EAAmBM,EAAM,GAAIhB,EAAWa,CAAK,EAAGf,CAAO,EAAG,SAAUE,EAAWa,CAAK,CAAE,CAAC,CACrK,CACA,MAAO,CAAE,KAAM,wBAAyB,GAAI,UAAUrB,EAAO,CAAC,EAAG,SAAQ,SAAUQ,EAAWE,CAAI,CAAE,CACxG"}
|
|
1
|
+
{"version":3,"file":"CompositionParser.js","names":["component","stringBodyPattern","exposureHeader","pattern","instanceHeader","exposedProperty","setPattern","setBlockPattern","itemsPattern","itemPattern","itemValuePattern","operations","match","group","unescapeString","text","entry","header","context","DiagnosticCodes","locationOf","properties","line","property","contributions","contribution","granted","unknown","operation","set","parseMappingSource","setBlock","parseStructuredValue","items","parsed","child","item","values","value","structured","tryParseStructuredMapping"],"sources":["../../../../../../Compiler/Parsing/CompositionParser.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { ContributedItemSyntax, ContributedItemValueSyntax, ExposedPropertySyntax, ExposureSyntax, InstanceContributionSyntax, InstanceContributionsSyntax } from '../Syntax/CompositionSyntax';\nimport { stringBodyPattern, unescapeString } from '../Text/StringLiteral';\nimport { pattern } from '../Text/patterns';\nimport { parseMappingSource } from './ExpressionParser';\nimport { ParserContext } from './ParserContext';\nimport { locationOf, SourceLine } from './SourceLine';\nimport { parseStructuredValue, StructuredMarker, tryParseStructuredMapping } from './StructuredBlockParser';\n\nconst component = `(?:([A-Za-z_]\\\\w*)|\"(${stringBodyPattern})\")\\\\.(\\\\w+(?:\\\\.\\\\w+)*)`;\nconst exposureHeader = pattern('^exposure\\\\s+for\\\\s+([A-Za-z_]\\\\w*)$');\nconst instanceHeader = pattern('^instance\\\\s+([A-Za-z_]\\\\w*)$');\nconst exposedProperty = pattern(`^property\\\\s+${component}(?:\\\\s+label\\\\s+\"(${stringBodyPattern})\")?(?:\\\\s+operations\\\\s+([\\\\w-]+(?:\\\\s*,\\\\s*[\\\\w-]+)*))?(?:\\\\s+fields\\\\s+(\\\\w+(?:\\\\s*,\\\\s*\\\\w+)*))?(?:\\\\s+reexposes\\\\s+([A-Za-z_]\\\\w*))?$`);\nconst setPattern = pattern(`^set\\\\s+${component}\\\\s*=\\\\s*(.+)$`);\nconst setBlockPattern = pattern(`^set\\\\s+${component}(?:\\\\s+(none|empty))?$`);\nconst itemsPattern = pattern(`^items\\\\s+${component}$`);\nconst itemPattern = pattern(`^item\\\\s+(?:([A-Za-z_][\\\\w-]*)|\"(${stringBodyPattern})\")$`);\nconst itemValuePattern = pattern('^([A-Za-z_]\\\\w*)\\\\s*=\\\\s*(.+)$');\nconst operations = ['add', 'remove', 'reorder', 'edit-fields'];\nconst exposedPropertyShape = '\\'property <component>.<path> [label \"<text>\"] [operations <add|remove|reorder|edit-fields>, ...] [fields <field>, ...] [reexposes <Owner>]\\'';\n\nconst reference = (match: RegExpExecArray, group: number): string => match[group] ?? unescapeString(match[group + 1]);\nconst list = (text: string): string[] => text.trim() === 'none' ? [] : text.split(',').map(entry => entry.trim()).filter(entry => entry.length > 0);\n\n// 'exposure for <Owner>' - the port of the C# CompositionParser.ParseExposure.\nexport function parseExposure(context: ParserContext, header: SourceLine): ExposureSyntax {\n const match = exposureHeader.exec(header.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidExposureDeclaration, `Invalid exposure declaration '${header.content}' - expected 'exposure for <Owner>'`, locationOf(header));\n }\n const properties: ExposedPropertySyntax[] = [];\n for (let line = context.peekChild(header.indent); line !== undefined; line = context.peekChild(header.indent)) {\n context.reader.takeSignificant();\n const property = parseExposedProperty(context, line);\n if (property !== undefined) properties.push(property);\n }\n return { kind: 'ExposureSyntax', owner: match?.[1] ?? header.content, properties, location: locationOf(header) };\n}\n\n// 'instance <Instance>' - the port of the C# CompositionParser.ParseInstance.\nexport function parseInstance(context: ParserContext, header: SourceLine): InstanceContributionsSyntax {\n const match = instanceHeader.exec(header.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidInstanceContribution, `Invalid instance declaration '${header.content}' - expected 'instance <Screen or Template>'`, locationOf(header));\n }\n const contributions: InstanceContributionSyntax[] = [];\n for (let line = context.peekChild(header.indent); line !== undefined; line = context.peekChild(header.indent)) {\n context.reader.takeSignificant();\n const contribution = parseContribution(context, line);\n if (contribution !== undefined) contributions.push(contribution);\n }\n return { kind: 'InstanceContributionsSyntax', instance: match?.[1] ?? header.content, contributions, location: locationOf(header) };\n}\n\nfunction parseExposedProperty(context: ParserContext, line: SourceLine): ExposedPropertySyntax | undefined {\n const match = exposedProperty.exec(line.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidExposureDeclaration, `Invalid exposed property '${line.content}' - expected ${exposedPropertyShape}`, locationOf(line));\n return undefined;\n }\n const granted = match[5] === undefined ? [] : list(match[5]);\n const unknown = granted.find(operation => !operations.includes(operation));\n if (unknown !== undefined) {\n context.error(DiagnosticCodes.InvalidExposureDeclaration, `Unknown collection operation '${unknown}' - expected add, remove, reorder, edit-fields or none`, locationOf(line));\n return undefined;\n }\n return {\n kind: 'ExposedPropertySyntax',\n component: reference(match, 1),\n path: match[3],\n label: match[4] === undefined ? null : unescapeString(match[4]),\n isCollection: match[5] !== undefined,\n operations: granted,\n restrictsFields: match[6] !== undefined,\n editableFields: match[6] === undefined ? [] : list(match[6]),\n reExposes: match[7] ?? null,\n location: locationOf(line)\n };\n}\n\nfunction parseContribution(context: ParserContext, line: SourceLine): InstanceContributionSyntax | undefined {\n const set = setPattern.exec(line.content);\n if (set !== null) {\n context.skipBlock(line.indent);\n return { kind: 'InstanceContributionSyntax', component: reference(set, 1), path: set[3], value: parseMappingSource(set[4], locationOf(line), context), items: [], location: locationOf(line) };\n }\n const setBlock = setBlockPattern.exec(line.content);\n if (setBlock !== null) {\n return { kind: 'InstanceContributionSyntax', component: reference(setBlock, 1), path: setBlock[3], value: parseStructuredValue(context, line, setBlock[4]?.trim() as StructuredMarker), items: [], location: locationOf(line) };\n }\n const items = itemsPattern.exec(line.content);\n if (items !== null) {\n const parsed: ContributedItemSyntax[] = [];\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n const item = parseItem(context, child);\n if (item !== undefined) parsed.push(item);\n }\n return { kind: 'InstanceContributionSyntax', component: reference(items, 1), path: items[3], value: null, items: parsed, location: locationOf(line) };\n }\n context.error(DiagnosticCodes.InvalidInstanceContribution, `Invalid instance contribution '${line.content}' - expected 'set <component>.<path> = <value>' or 'items <component>.<path>'`, locationOf(line));\n context.skipBlock(line.indent);\n return undefined;\n}\n\nfunction parseItem(context: ParserContext, line: SourceLine): ContributedItemSyntax | undefined {\n const match = itemPattern.exec(line.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidInstanceContribution, `Invalid contributed item '${line.content}' - expected 'item <id>'`, locationOf(line));\n context.skipBlock(line.indent);\n return undefined;\n }\n const values: ContributedItemValueSyntax[] = [];\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n const value = itemValuePattern.exec(child.content);\n const structured = value === null ? tryParseStructuredMapping(context, child) : undefined;\n if (structured !== undefined) {\n values.push({ kind: 'ContributedItemValueSyntax', field: structured.property, value: structured.source, location: locationOf(child) });\n continue;\n }\n if (value === null) {\n context.error(DiagnosticCodes.InvalidInstanceContribution, `Invalid item value '${child.content}' - expected '<field> = <value>'`, locationOf(child));\n context.skipBlock(child.indent);\n continue;\n }\n values.push({ kind: 'ContributedItemValueSyntax', field: value[1], value: parseMappingSource(value[2], locationOf(child), context), location: locationOf(child) });\n }\n return { kind: 'ContributedItemSyntax', id: reference(match, 1), values, location: locationOf(line) };\n}\n"],"mappings":"icAYA,MAAMA,EAAY,wBAAwBC,EAAkB,0BACtDC,EAAiBC,EAAQ,sCAAsC,EAC/DC,EAAiBD,EAA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ral.js";import{nativePattern as n,pattern as r}from"../Text/patterns.js";import{isExactNumberToken as i,parseExactNumber as a}from"../Syntax/ExactNumber.js";import{InvalidStructuredValue as o,StructuredValueParser as s}from"./StructuredValueParser.js";const c=r(`^@?[A-Za-z_]\\w*(\\.@?[A-Za-z_$]\\w*)*$`),l=n(`^@?[A-Za-z_]\\w*(\\.@?[A-Za-z_$]\\w*)*$`),u=r(`^-?\\d+(\\.\\d+)?$`),d=[`command`,`arguments`,`tenant`,`causedBy`,`causation`,`occurred`,`identity`],f=[`subject`,`name`,`userName`],p=[`id`,`name`,`userName`,`isAuthenticated`,`roles`,`claims`]
|
|
1
|
+
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{unescapeString as t}from"../Text/StringLiteral.js";import{nativePattern as n,pattern as r}from"../Text/patterns.js";import{isExactNumberToken as i,parseExactNumber as a}from"../Syntax/ExactNumber.js";import{InvalidStructuredValue as o,StructuredValueParser as s}from"./StructuredValueParser.js";const c=r(`^@?[A-Za-z_]\\w*(\\.@?[A-Za-z_$]\\w*)*$`),l=n(`^@?[A-Za-z_]\\w*(\\.@?[A-Za-z_$]\\w*)*$`),u=r(`^-?\\d+(\\.\\d+)?$`),d=[`command`,`arguments`,`tenant`,`causedBy`,`causation`,`occurred`,`identity`],f=[`subject`,`name`,`userName`],p=[`id`,`name`,`userName`,`isAuthenticated`,`roles`,`claims`],m=`Screenplay has no JSON values - write the object or list as an indented block: one 'member = value' line per member, one 'item' line per list element, and '<name> none' for an empty list`;function parseModeledMappingSource(e,t,n){return parseMappingSource(e,t,n,!0)}function parseMappingSource(t,n,r,i=!1){if(t=t.trim(),t===`$refusal`||t.startsWith(`$refusal.`))return{kind:`RefusalExpressionSyntax`,member:t===`$refusal`?``:t.substring(9),location:n};if(t===`$eventSourceId`)return{kind:`EventSourceIdExpressionSyntax`,location:n};if(t===`$eventContext.eventSourceId`)return{kind:`EventContextExpressionSyntax`,path:`eventSourceId`,location:n};if(t===`$identity`||t===`$identity.`)return r?.error(e.InvalidExpression,`Invalid expression '${t}'`,n),{kind:`RawExpressionSyntax`,text:t,location:n};if(t.startsWith(`$identity.`)){let e=t.substring(10);return r?.deferIdentityValidation!==!0&&warnOnUnknownIdentityProperty(e.split(`.`)[0],`$identity`,n,r),{kind:`IdentityExpressionSyntax`,path:e,location:n}}if(t.startsWith(`$context.`)){let e=t.substring(9);return warnOnUnknownContextPath(e,n,r),{kind:`ContextExpressionSyntax`,path:e,location:n}}if(t.startsWith(`$env.`))return{kind:`EnvironmentExpressionSyntax`,name:t.substring(5),location:n};if(t.startsWith(`$strings.`))return{kind:`StringsExpressionSyntax`,key:t.substring(9),location:n};if(t.startsWith(`$.`))return{kind:`SourceItemExpressionSyntax`,path:t.substring(2),location:n};if(t.startsWith(`{`)||t.startsWith(`[`)){r?.error(e.InlineJsonValue,m,n);try{return new s(t,n,r).parse()}catch(i){if(!(i instanceof o))throw i;return r?.error(e.InvalidStructuredValue,`Invalid inline structured value: ${i.message}`,n),{kind:`RawExpressionSyntax`,text:t,location:n}}}let a=r===void 0?parseLiteral(t,n):parseLiteral(t,n,r);return a===void 0?(i||r?.sourceOptions.numericMode===`exact`?l:c).test(t)?{kind:`PathExpressionSyntax`,path:t,location:n}:{kind:`RawExpressionSyntax`,text:t,location:n}:a}function warnOnUnknownContextPath(t,n,r){let[i,a]=t.split(`.`);d.includes(i)?a!==void 0&&i===`causedBy`&&!f.includes(a)?r?.warning(e.UnknownContextCausedByProperty,`Unknown $context.causedBy property '${a}' - expected ${f.join(`, `)}`,n):a!==void 0&&i===`identity`&&warnOnUnknownIdentityProperty(a,`$context.identity`,n,r):r?.warning(e.UnknownContextPath,`Unknown $context path '${t}' - expected one of ${d.join(`, `)}`,n)}function warnOnUnknownIdentityProperty(t,n,r,i){p.includes(t)||i?.warning(e.UnknownContextIdentityProperty,`Unknown ${n} property '${t}' - expected ${p.join(`, `)}`,r)}function parseLiteral(n,r,o){let literal=e=>({kind:`LiteralExpressionSyntax`,value:e,location:r});switch(n){case`true`:return literal(!0);case`false`:return literal(!1);case`null`:return literal(null)}if(n.length>=2&&(n.startsWith(`"`)&&n.endsWith(`"`)||n.startsWith(`'`)&&n.endsWith(`'`)))return literal(t(n.substring(1,n.length-1)));if(o?.sourceOptions.numericMode===`exact`){if(!i(n))return;let t=a(n);return t===void 0?(o.error(e.InexactNumericLiteral,`Numeric literal is not exactly representable in the bounded Decimal domain.`,r),{kind:`RawExpressionSyntax`,text:n,location:r}):literal(t)}if(u.test(n)&&!Number.isNaN(Number(n)))return literal(Number(n))}export{p as identityProperties,m as inlineJsonMessage,parseLiteral,parseMappingSource,parseModeledMappingSource};
|
|
2
2
|
//# sourceMappingURL=ExpressionParser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpressionParser.js","names":["pathPattern","pattern","nativePathPattern","nativePattern","numberPattern","contextRoots","causedByProperties","identityProperties","text","location","context","DiagnosticCodes","path","StructuredValueParser","error","InvalidStructuredValue","literal","nativeIdentifiers","root","member","unescapeString","isExactNumberToken","number","parseExactNumber"],"sources":["../../../../../../Compiler/Parsing/ExpressionParser.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { SourceLocation } from '../Diagnostics/SourceLocation';\nimport { ExpressionSyntax, LiteralExpressionSyntax } from '../Syntax/Expressions';\nimport { ExactNumber, isExactNumberToken, parseExactNumber } from '../Syntax/ExactNumber';\nimport { nativePattern, pattern } from '../Text/patterns';\nimport { unescapeString } from '../Text/StringLiteral';\nimport { ParserContext } from './ParserContext';\nimport { InvalidStructuredValue, StructuredValueParser } from './StructuredValueParser';\n\nconst pathPattern = pattern('^@?[A-Za-z_]\\\\w*(\\\\.@?[A-Za-z_$]\\\\w*)*$');\nconst nativePathPattern = nativePattern('^@?[A-Za-z_]\\\\w*(\\\\.@?[A-Za-z_$]\\\\w*)*$');\nconst numberPattern = pattern('^-?\\\\d+(\\\\.\\\\d+)?$');\nconst contextRoots = ['command', 'arguments', 'tenant', 'causedBy', 'causation', 'occurred', 'identity'];\nconst causedByProperties = ['subject', 'name', 'userName'];\nexport const identityProperties = ['id', 'name', 'userName', 'isAuthenticated', 'roles', 'claims'];\n\n// Reads the right-hand side of a mapping or a rule operand - the port of the C# ExpressionParser's\n// ParseMappingSource. With a context it also reports what the C# compiler reports while reading one: an\n// unknown $context path, and an inline structured value that is not valid JSON.\nexport function parseModeledMappingSource(text: string, location: SourceLocation, context: ParserContext): ExpressionSyntax {\n return parseMappingSource(text, location, context, true);\n}\n\nexport function parseMappingSource(text: string, location: SourceLocation, context?: ParserContext, nativeIdentifiers = false): ExpressionSyntax {\n text = text.trim();\n if (text === '$refusal' || text.startsWith('$refusal.')) {\n return { kind: 'RefusalExpressionSyntax', member: text === '$refusal' ? '' : text.substring('$refusal.'.length), location };\n }\n if (text === '$eventSourceId') {\n return { kind: 'EventSourceIdExpressionSyntax', location };\n }\n if (text === '$eventContext.eventSourceId') {\n return { kind: 'EventContextExpressionSyntax', path: 'eventSourceId', location };\n }\n if (text === '$identity' || text === '$identity.') {\n context?.error(DiagnosticCodes.InvalidExpression, `Invalid expression '${text}'`, location);\n return { kind: 'RawExpressionSyntax', text, location };\n }\n if (text.startsWith('$identity.')) {\n const path = text.substring('$identity.'.length);\n if (context?.deferIdentityValidation !== true) warnOnUnknownIdentityProperty(path.split('.')[0], '$identity', location, context);\n return { kind: 'IdentityExpressionSyntax', path, location };\n }\n if (text.startsWith('$context.')) {\n const path = text.substring('$context.'.length);\n warnOnUnknownContextPath(path, location, context);\n return { kind: 'ContextExpressionSyntax', path, location };\n }\n if (text.startsWith('$env.')) {\n return { kind: 'EnvironmentExpressionSyntax', name: text.substring('$env.'.length), location };\n }\n if (text.startsWith('$strings.')) {\n return { kind: 'StringsExpressionSyntax', key: text.substring('$strings.'.length), location };\n }\n if (text.startsWith('$.')) {\n return { kind: 'SourceItemExpressionSyntax', path: text.substring('$.'.length), location };\n }\n if (text.startsWith('{') || text.startsWith('[')) {\n try {\n return new StructuredValueParser(text, location, context).parse();\n } catch (error) {\n if (!(error instanceof InvalidStructuredValue)) {\n throw error;\n }\n context?.error(DiagnosticCodes.InvalidStructuredValue, `Invalid inline structured value: ${error.message}`, location);\n return { kind: 'RawExpressionSyntax', text, location };\n }\n }\n const literal = context === undefined ? parseLiteral(text, location) : parseLiteral(text, location, context);\n if (literal !== undefined) {\n return literal;\n }\n if ((nativeIdentifiers || context?.sourceOptions.numericMode === 'exact' ? nativePathPattern : pathPattern).test(text)) {\n return { kind: 'PathExpressionSyntax', path: text, location };\n }\n return { kind: 'RawExpressionSyntax', text, location };\n}\n\nfunction warnOnUnknownContextPath(path: string, location: SourceLocation, context: ParserContext | undefined): void {\n const [root, member] = path.split('.');\n if (!contextRoots.includes(root)) {\n context?.warning(DiagnosticCodes.UnknownContextPath, `Unknown $context path '${path}' - expected one of ${contextRoots.join(', ')}`, location);\n } else if (member !== undefined && root === 'causedBy' && !causedByProperties.includes(member)) {\n context?.warning(DiagnosticCodes.UnknownContextCausedByProperty,\n `Unknown $context.causedBy property '${member}' - expected ${causedByProperties.join(', ')}`, location);\n } else if (member !== undefined && root === 'identity') {\n warnOnUnknownIdentityProperty(member, '$context.identity', location, context);\n }\n}\n\nfunction warnOnUnknownIdentityProperty(member: string, root: string, location: SourceLocation, context: ParserContext | undefined): void {\n if (!identityProperties.includes(member)) {\n context?.warning(DiagnosticCodes.UnknownContextIdentityProperty,\n `Unknown ${root} property '${member}' - expected ${identityProperties.join(', ')}`, location);\n }\n}\n\nexport function parseLiteral(text: string, location: SourceLocation): LiteralExpressionSyntax | undefined;\nexport function parseLiteral(text: string, location: SourceLocation, context: ParserContext): ExpressionSyntax | undefined;\nexport function parseLiteral(text: string, location: SourceLocation, context?: ParserContext): ExpressionSyntax | undefined {\n const literal = (value: string | number | boolean | null | ExactNumber): LiteralExpressionSyntax => ({ kind: 'LiteralExpressionSyntax', value, location });\n switch (text) {\n case 'true':\n return literal(true);\n case 'false':\n return literal(false);\n case 'null':\n return literal(null);\n }\n const quoted = text.length >= 2 && ((text.startsWith('\"') && text.endsWith('\"')) || (text.startsWith('\\'') && text.endsWith('\\'')));\n if (quoted) {\n return literal(unescapeString(text.substring(1, text.length - 1)));\n }\n if (context?.sourceOptions.numericMode === 'exact') {\n if (!isExactNumberToken(text)) return undefined;\n const number = parseExactNumber(text);\n if (number !== undefined) return literal(number);\n context.error(DiagnosticCodes.InexactNumericLiteral, 'Numeric literal is not exactly representable in the bounded Decimal domain.', location);\n return { kind: 'RawExpressionSyntax', text, location };\n }\n // .NET also parses digits from other scripts; JavaScript's Number does not, so such a number is left to\n // be read as raw text - a divergence no real document is expected to meet.\n if (numberPattern.test(text) && !Number.isNaN(Number(text))) {\n return literal(Number(text));\n }\n return undefined;\n}\n"],"mappings":"uaAYA,MAAMA,EAAcC,EAAQ,yCAAyC,EAC/DC,EAAoBC,EAAc,yCAAyC,EAC3EC,EAAgBH,EAAQ,oBAAoB,EAC5CI,EAAe,CAAC,UAAW,YAAa,SAAU,WAAY,YAAa,WAAY,UAAU,EACjGC,EAAqB,CAAC,UAAW,OAAQ,UAAU,EAC5CC,EAAqB,CAAC,KAAM,OAAQ,WAAY,kBAAmB,QAAS,QAAQ,EAKjG,SAAgB,0BAA0B,EAAc,EAA0B,EAA0C,CACxH,OAAO,mBAAmBC,EAAMC,EAAUC,EAAS,EAAI,CAC3D,CAEA,SAAgB,mBAAmB,EAAc,EAA0B,EAAyB,EAAoB,GAAyB,CAE7I,GADA,EAAOF,EAAK,KAAK,EACbA,IAAS,YAAcA,EAAK,WAAW,WAAW,EAClD,MAAO,CAAE,KAAM,0BAA2B,OAAQA,IAAS,WAAa,GAAKA,EAAK,UAAU,CAAkB,EAAG,UAAS,EAE9H,GAAIA,IAAS,iBACT,MAAO,CAAE,KAAM,gCAAiC,UAAS,EAE7D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S,GAAG,GAAOA,EAAK,WAAW,GAAI,GAAKA,EAAK,SAAS,GAAI,GAE5H,OAAO,QAAQY,EAAeZ,EAAK,UAAU,EAAGA,EAAK,OAAS,CAAC,CAAC,CAAC,EAErE,GAAIE,GAAS,cAAc,cAAgB,QAAS,CAChD,GAAI,CAACW,EAAmBb,CAAI,EAAG,OAC/B,IAAMc,EAASC,EAAiBf,CAAI,EAGpC,OAFIc,IAAW,IAAA,IACfZ,EAAQ,MAAMC,EAAgB,sBAAuB,8EAA+EF,CAAQ,EACrI,CAAE,KAAM,sBAAuB,OAAM,UAAS,GAFpB,QAAQa,CAAM,CAGnD,CAGA,GAAIlB,EAAc,KAAKI,CAAI,GAAK,CAAC,OAAO,MAAM,OAAOA,CAAI,CAAC,EACtD,OAAO,QAAQ,OAAOA,CAAI,CAAC,CAGnC"}
|
|
1
|
+
{"version":3,"file":"ExpressionParser.js","names":["pathPattern","pattern","nativePathPattern","nativePattern","numberPattern","contextRoots","causedByProperties","identityProperties","inlineJsonMessage","text","location","context","DiagnosticCodes","path","StructuredValueParser","error","InvalidStructuredValue","literal","nativeIdentifiers","root","member","unescapeString","isExactNumberToken","number","parseExactNumber"],"sources":["../../../../../../Compiler/Parsing/ExpressionParser.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { SourceLocation } from '../Diagnostics/SourceLocation';\nimport { ExpressionSyntax, LiteralExpressionSyntax } from '../Syntax/Expressions';\nimport { ExactNumber, isExactNumberToken, parseExactNumber } from '../Syntax/ExactNumber';\nimport { nativePattern, pattern } from '../Text/patterns';\nimport { unescapeString } from '../Text/StringLiteral';\nimport { ParserContext } from './ParserContext';\nimport { InvalidStructuredValue, StructuredValueParser } from './StructuredValueParser';\n\nconst pathPattern = pattern('^@?[A-Za-z_]\\\\w*(\\\\.@?[A-Za-z_$]\\\\w*)*$');\nconst nativePathPattern = nativePattern('^@?[A-Za-z_]\\\\w*(\\\\.@?[A-Za-z_$]\\\\w*)*$');\nconst numberPattern = pattern('^-?\\\\d+(\\\\.\\\\d+)?$');\nconst contextRoots = ['command', 'arguments', 'tenant', 'causedBy', 'causation', 'occurred', 'identity'];\nconst causedByProperties = ['subject', 'name', 'userName'];\nexport const identityProperties = ['id', 'name', 'userName', 'isAuthenticated', 'roles', 'claims'];\n\n// Reads the right-hand side of a mapping or a rule operand - the port of the C# ExpressionParser's\n// ParseMappingSource. With a context it also reports what the C# compiler reports while reading one: an\n// unknown $context path, and an inline structured value that is not valid JSON.\nexport const inlineJsonMessage = \"Screenplay has no JSON values - write the object or list as an indented block: one 'member = value' line per member, one 'item' line per list element, and '<name> none' for an empty list\";\n\nexport function parseModeledMappingSource(text: string, location: SourceLocation, context: ParserContext): ExpressionSyntax {\n return parseMappingSource(text, location, context, true);\n}\n\nexport function parseMappingSource(text: string, location: SourceLocation, context?: ParserContext, nativeIdentifiers = false): ExpressionSyntax {\n text = text.trim();\n if (text === '$refusal' || text.startsWith('$refusal.')) {\n return { kind: 'RefusalExpressionSyntax', member: text === '$refusal' ? '' : text.substring('$refusal.'.length), location };\n }\n if (text === '$eventSourceId') {\n return { kind: 'EventSourceIdExpressionSyntax', location };\n }\n if (text === '$eventContext.eventSourceId') {\n return { kind: 'EventContextExpressionSyntax', path: 'eventSourceId', location };\n }\n if (text === '$identity' || text === '$identity.') {\n context?.error(DiagnosticCodes.InvalidExpression, `Invalid expression '${text}'`, location);\n return { kind: 'RawExpressionSyntax', text, location };\n }\n if (text.startsWith('$identity.')) {\n const path = text.substring('$identity.'.length);\n if (context?.deferIdentityValidation !== true) warnOnUnknownIdentityProperty(path.split('.')[0], '$identity', location, context);\n return { kind: 'IdentityExpressionSyntax', path, location };\n }\n if (text.startsWith('$context.')) {\n const path = text.substring('$context.'.length);\n warnOnUnknownContextPath(path, location, context);\n return { kind: 'ContextExpressionSyntax', path, location };\n }\n if (text.startsWith('$env.')) {\n return { kind: 'EnvironmentExpressionSyntax', name: text.substring('$env.'.length), location };\n }\n if (text.startsWith('$strings.')) {\n return { kind: 'StringsExpressionSyntax', key: text.substring('$strings.'.length), location };\n }\n if (text.startsWith('$.')) {\n return { kind: 'SourceItemExpressionSyntax', path: text.substring('$.'.length), location };\n }\n if (text.startsWith('{') || text.startsWith('[')) {\n // Screenplay has no JSON. The value is still read so the tree stays whole and printing it writes the block form.\n context?.error(DiagnosticCodes.InlineJsonValue, inlineJsonMessage, location);\n try {\n return new StructuredValueParser(text, location, context).parse();\n } catch (error) {\n if (!(error instanceof InvalidStructuredValue)) {\n throw error;\n }\n context?.error(DiagnosticCodes.InvalidStructuredValue, `Invalid inline structured value: ${error.message}`, location);\n return { kind: 'RawExpressionSyntax', text, location };\n }\n }\n const literal = context === undefined ? parseLiteral(text, location) : parseLiteral(text, location, context);\n if (literal !== undefined) {\n return literal;\n }\n if ((nativeIdentifiers || context?.sourceOptions.numericMode === 'exact' ? nativePathPattern : pathPattern).test(text)) {\n return { kind: 'PathExpressionSyntax', path: text, location };\n }\n return { kind: 'RawExpressionSyntax', text, location };\n}\n\nfunction warnOnUnknownContextPath(path: string, location: SourceLocation, context: ParserContext | undefined): void {\n const [root, member] = path.split('.');\n if (!contextRoots.includes(root)) {\n context?.warning(DiagnosticCodes.UnknownContextPath, `Unknown $context path '${path}' - expected one of ${contextRoots.join(', ')}`, location);\n } else if (member !== undefined && root === 'causedBy' && !causedByProperties.includes(member)) {\n context?.warning(DiagnosticCodes.UnknownContextCausedByProperty,\n `Unknown $context.causedBy property '${member}' - expected ${causedByProperties.join(', ')}`, location);\n } else if (member !== undefined && root === 'identity') {\n warnOnUnknownIdentityProperty(member, '$context.identity', location, context);\n }\n}\n\nfunction warnOnUnknownIdentityProperty(member: string, root: string, location: SourceLocation, context: ParserContext | undefined): void {\n if (!identityProperties.includes(member)) {\n context?.warning(DiagnosticCodes.UnknownContextIdentityProperty,\n `Unknown ${root} property '${member}' - expected ${identityProperties.join(', ')}`, location);\n }\n}\n\nexport function parseLiteral(text: string, location: SourceLocation): LiteralExpressionSyntax | undefined;\nexport function parseLiteral(text: string, location: SourceLocation, context: ParserContext): ExpressionSyntax | undefined;\nexport function parseLiteral(text: string, location: SourceLocation, context?: ParserContext): ExpressionSyntax | undefined {\n const literal = (value: string | number | boolean | null | ExactNumber): LiteralExpressionSyntax => ({ kind: 'LiteralExpressionSyntax', value, location });\n switch (text) {\n case 'true':\n return literal(true);\n case 'false':\n return literal(false);\n case 'null':\n return literal(null);\n }\n const quoted = text.length >= 2 && ((text.startsWith('\"') && text.endsWith('\"')) || (text.startsWith('\\'') && text.endsWith('\\'')));\n if (quoted) {\n return literal(unescapeString(text.substring(1, text.length - 1)));\n }\n if (context?.sourceOptions.numericMode === 'exact') {\n if (!isExactNumberToken(text)) return undefined;\n const number = parseExactNumber(text);\n if (number !== undefined) return literal(number);\n context.error(DiagnosticCodes.InexactNumericLiteral, 'Numeric literal is not exactly representable in the bounded Decimal domain.', location);\n return { kind: 'RawExpressionSyntax', text, location };\n }\n // .NET also parses digits from other scripts; JavaScript's Number does not, so such a number is left to\n // be read as raw text - a divergence no real document is expected to meet.\n if (numberPattern.test(text) && !Number.isNaN(Number(text))) {\n return literal(Number(text));\n }\n return undefined;\n}\n"],"mappings":"uaAYA,MAAMA,EAAcC,EAAQ,yCAAyC,EAC/DC,EAAoBC,EAAc,yCAAyC,EAC3EC,EAAgBH,EAAQ,oBAAoB,EAC5CI,EAAe,CAAC,UAAW,YAAa,SAAU,WAAY,YAAa,WAAY,UAAU,EACjGC,EAAqB,CAAC,UAAW,OAAQ,UAAU,EAC5CC,EAAqB,CAAC,KAAM,OAAQ,WAAY,kBAAmB,QAAS,QAAQ,EAKpFC,EAAoB,6LAEjC,SAAgB,0BAA0B,EAAc,EAA0B,EAA0C,CACxH,OAAO,mBAAmBC,EAAMC,EAAUC,EAAS,EAAI,CAC3D,CAEA,SAAgB,mBAAmB,EAAc,EAA0B,EAAyB,E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IA,SAAgB,aAAa,EAAc,EAA0B,EAAuD,CACxH,IAAM,QAAW,IAAoF,CAAE,KAAM,0BAA2B,QAAO,UAAS,GACxJ,OAAQD,EAAR,CACI,IAAK,OACD,OAAO,QAAQ,EAAI,EACvB,IAAK,QACD,OAAO,QAAQ,EAAK,EACxB,IAAK,OACD,OAAO,QAAQ,IAAI,CAC3B,CAEA,GADeA,EAAK,QAAU,IAAOA,EAAK,WAAW,GAAG,GAAKA,EAAK,SAAS,GAAG,GAAOA,EAAK,WAAW,GAAI,GAAKA,EAAK,SAAS,GAAI,GAE5H,OAAO,QAAQY,EAAeZ,EAAK,UAAU,EAAGA,EAAK,OAAS,CAAC,CAAC,CAAC,EAErE,GAAIE,GAAS,cAAc,cAAgB,QAAS,CAChD,GAAI,CAACW,EAAmBb,CAAI,EAAG,OAC/B,IAAMc,EAASC,EAAiBf,CAAI,EAGpC,OAFIc,IAAW,IAAA,IACfZ,EAAQ,MAAMC,EAAgB,sBAAuB,8EAA+EF,CAAQ,EACrI,CAAE,KAAM,sBAAuB,OAAM,UAAS,GAFpB,QAAQa,CAAM,CAGnD,CAGA,GAAInB,EAAc,KAAKK,CAAI,GAAK,CAAC,OAAO,MAAM,OAAOA,CAAI,CAAC,EACtD,OAAO,QAAQ,OAAOA,CAAI,CAAC,CAGnC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{pattern as t}from"../Text/patterns.js";import{locationOf as n}from"./SourceLine.js";import{parseMappingSource as r}from"./ExpressionParser.js";import{firstWord as i}from"./LineText.js";import{parseProperty as a,tryParseProperty as o}from"./PropertyLineParser.js";import{
|
|
1
|
+
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{pattern as t}from"../Text/patterns.js";import{locationOf as n}from"./SourceLine.js";import{parseMappingSource as r}from"./ExpressionParser.js";import{firstWord as i}from"./LineText.js";import{parseProperty as a,tryParseProperty as o}from"./PropertyLineParser.js";import{parseStructuredValue as s,trailingMarker as c}from"./StructuredBlockParser.js";import{parseDescription as l}from"./DescriptionParser.js";import{isFileDirective as u}from"./FileReferences.js";import{parseCode as d,parseFile as f,parseImplementationWrapper as p}from"./ImplementationParser.js";const m=t(`^system\\s+([A-Za-z_]\\w*)$`),h=t(`^operation\\s+([A-Za-z_]\\w*)$`),g=t(`^produces\\s+operation\\s+([A-Za-z_]\\w*)$`),_=t(`^uses\\s+([A-Za-z_]\\w*)$`),v=t(`^(.+?)\\s*=(?!=|>)\\s*(.+)$`),y=/* @__PURE__ */ new Set([`for`,`tag`,`generation`,`origin`,`documentation`,`namespace`,`sequence`,`correlation`,`causation`,`causedBy`,`occurred`]);function rejectOperationChildren(e,t,r,i){let a=e.peekChild(t.indent);a!==void 0&&(e.error(r,i,n(a)),e.skipBlock(t.indent))}function parseSystem(t,r){let a=m.exec(r.content);a===null&&t.error(e.InvalidSystemDeclaration,`Expected 'system <Name>'.`,n(r));let o=null;for(let s=t.peekChild(r.indent);s!==void 0;s=t.peekChild(r.indent))t.reader.takeSignificant(),i(s.content)===`description`?o=l(t,s,o,`System '${a?.[1]??``}'`):(t.error(e.InvalidSystemDeclaration,`A system accepts only a description; abilities are not supported.`,n(s)),t.skipBlock(s.indent));return{kind:`SystemSyntax`,name:a?.[1]??``,description:o,location:n(r)}}function parseOperation(t,u,d=!1){let f=(d?g:h).exec(u.content),p=f?.[1]??``;f===null&&t.error(e.InvalidOperationDeclaration,`Expected an operation declaration with one name.`,n(u));let m=null,b=null,x=n(u),S=null,C=null,w=[],T=[],E=/* @__PURE__ */ new Set;for(let f=t.peekChild(u.indent);f!==void 0;f=t.peekChild(u.indent)){t.reader.takeSignificant();let u=v.exec(f.content),h=d&&u===null?c(f.content):void 0,g=f;d&&u!==null?g={...f,content:u[1].trimEnd()}:h!==void 0&&(g={...f,content:f.content.substring(0,f.content.length-h.length-1)});let D=d&&u===null&&(h!==void 0||t.peekChild(f.indent)!==void 0);if(u===null&&y.has(i(f.content)))t.error(e.InvalidOperationDeclaration,`Operations cannot declare event routing or metadata; escape a keyword-named input with @.`,n(f)),t.skipBlock(f.indent);else if(!_.test(f.content)&&o(g)!==void 0){let i=a(t,g);d&&u===null&&!D&&t.error(e.InvalidOperationMapping,`An inline operation input requires '<property> <Type> = <source>'.`,n(f)),i.isSubject&&t.error(e.InvalidSubjectOwner,`The subject modifier is only valid on event properties, not operation inputs (decision 0008: one data subject per event).`,n(f)),(i.isIdentifier||i.isGenerated)&&t.error(e.InvalidOperationDeclaration,`Operation inputs cannot be identifier or generated properties.`,n(f)),E.has(i.name)&&t.error(e.DuplicateDeclaration,`Operation '${p}' already declares input '${i.name}'.`,n(f)),E.add(i.name),w.push(i),d&&u!==null&&T.push({kind:`PropertyMappingSyntax`,property:i.name,source:r(u[2],{...n(f),column:f.indent+f.content.length-u[2].length+1},t),location:n(f)}),D&&T.push({kind:`PropertyMappingSyntax`,property:i.name,source:s(t,f,h),location:n(f)}),rejectOperationChildren(t,f,e.InvalidOperationDeclaration,`An operation input cannot have children.`)}else if(i(f.content)===`description`)m=l(t,f,m,`Operation '${p}'`);else if(_.test(f.content))b===null?(b=_.exec(f.content)[1],x={...n(f),column:n(f).column+f.content.indexOf(b,4)}):t.error(e.InvalidSystemReference,`An operation declares exactly one 'uses <System>'.`,n(f)),rejectOperationChildren(t,f,e.InvalidSystemReference,`A system reference cannot have children.`);else if(f.content===`execute`||f.content===`compensate`){let r=parseOperationPhase(t,f);f.content===`execute`?S===null?S=r:t.error(e.InvalidOperationDeclaration,`An operation declares execute at most once.`,n(f)):C===null?C=r:t.error(e.InvalidOperationDeclaration,`An operation declares compensate at most once.`,n(f))}else t.error(e.InvalidOperationDeclaration,`Unexpected '${f.content}' in operation - expected uses, an input, description, execute or compensate.`,n(f)),t.skipBlock(f.indent)}return b===null&&t.error(e.InvalidSystemReference,`An operation requires exactly one 'uses <System>'.`,n(u)),{operation:{kind:`OperationSyntax`,name:p,uses:b??``,usesLocation:x,inputs:w,description:m,execute:S,compensate:C,location:n(u)},mappings:T}}function parseOperationPhase(t,r){let a=null,o=null,s=null,c=null,m=!1;for(let h=t.peekChild(r.indent);h!==void 0;h=t.peekChild(r.indent))if(t.reader.takeSignificant(),i(h.content)===`description`)a=l(t,h,a,`Operation phase '${r.content}'`);else if(i(h.content)===`implementation`){m&&t.error(e.ConflictingImplementationSources,`A phase cannot mix wrapped and direct sources or repeat its wrapper.`,n(h));let r=p(t,h);m||(o=r.file,s=r.code,c=r.implementation),m=!0}else if(u(h)||h.content.startsWith("```")){m&&t.error(e.ConflictingImplementationSources,`A phase has at most one file or inline payload.`,n(h));let r=u(h)?f(t,h):null,i=r===null?d(t,h):null;m||(o=r,s=i),m=!0,r!==null&&rejectOperationChildren(t,h,e.InvalidImplementationBlock,`A file directive cannot have children.`)}else t.error(e.InvalidOperationDeclaration,`A phase accepts description, file, a tagged fence or implementation.`,n(h)),t.skipBlock(h.indent);return{kind:`OperationPhaseSyntax`,description:a,file:o,code:s,implementation:c,location:n(r)}}export{parseOperation,parseSystem,rejectOperationChildren};
|
|
2
2
|
//# sourceMappingURL=OperationParser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OperationParser.js","names":["systemHeader","pattern","operationHeader","inlineHeader","usesPattern","typedMapping","eventMetadata","child","context","line","code","message","locationOf","match","header","DiagnosticCodes","description","firstWord","parseDescription","inline","name","uses","usesLocation","execute","compensate","inputs","mappings","names","typed","propertyLine","tryParseProperty","property","parseProperty","parseMappingSource","phase","file","implementation","sourceSelected","source","parseImplementationWrapper","isFileDirective","parsedFile","parseFile","parsedCode","parseCode"],"sources":["../../../../../../Compiler/Parsing/OperationParser.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { PropertySyntax } from '../Syntax/Declarations';\nimport { pattern } from '../Text/patterns';\nimport { PropertyMappingSyntax } from '../Syntax/Expressions';\nimport { OperationPhaseSyntax, OperationSyntax, SystemSyntax } from '../Syntax/Operations';\nimport { parseDescription } from './DescriptionParser';\nimport { parseMappingSource } from './ExpressionParser';\nimport { isFileDirective } from './FileReferences';\nimport { parseCode, parseFile, parseImplementationWrapper } from './ImplementationParser';\nimport { firstWord } from './LineText';\nimport { ParserContext } from './ParserContext';\nimport { parseProperty, tryParseProperty } from './PropertyLineParser';\nimport { locationOf, SourceLine } from './SourceLine';\n\nconst systemHeader = pattern('^system\\\\s+([A-Za-z_]\\\\w*)$');\nconst operationHeader = pattern('^operation\\\\s+([A-Za-z_]\\\\w*)$');\nconst inlineHeader = pattern('^produces\\\\s+operation\\\\s+([A-Za-z_]\\\\w*)$');\nconst usesPattern = pattern('^uses\\\\s+([A-Za-z_]\\\\w*)$');\nconst typedMapping = pattern('^(.+?)\\\\s*=(?!=|>)\\\\s*(.+)$');\nconst eventMetadata = new Set(['for', 'tag', 'generation', 'origin', 'documentation', 'namespace', 'sequence', 'correlation', 'causation', 'causedBy', 'occurred']);\n\nexport function rejectOperationChildren(context: ParserContext, line: SourceLine, code: string, message: string): void {\n const child = context.peekChild(line.indent);\n if (child === undefined) return;\n context.error(code, message, locationOf(child));\n context.skipBlock(line.indent);\n}\n\nexport function parseSystem(context: ParserContext, header: SourceLine): SystemSyntax {\n const match = systemHeader.exec(header.content);\n if (match === null) context.error(DiagnosticCodes.InvalidSystemDeclaration, \"Expected 'system <Name>'.\", locationOf(header));\n let description: string | null = null;\n for (let child = context.peekChild(header.indent); child !== undefined; child = context.peekChild(header.indent)) {\n context.reader.takeSignificant();\n if (firstWord(child.content) === 'description') description = parseDescription(context, child, description, `System '${match?.[1] ?? ''}'`);\n else {\n context.error(DiagnosticCodes.InvalidSystemDeclaration, 'A system accepts only a description; abilities are not supported.', locationOf(child));\n context.skipBlock(child.indent);\n }\n }\n return { kind: 'SystemSyntax', name: match?.[1] ?? '', description, location: locationOf(header) };\n}\n\nexport function parseOperation(context: ParserContext, header: SourceLine, inline = false): { operation: OperationSyntax; mappings: PropertyMappingSyntax[] } {\n const match = (inline ? inlineHeader : operationHeader).exec(header.content);\n const name = match?.[1] ?? '';\n if (match === null) context.error(DiagnosticCodes.InvalidOperationDeclaration, 'Expected an operation declaration with one name.', locationOf(header));\n let description: string | null = null;\n let uses: string | null = null;\n let usesLocation = locationOf(header);\n let execute: OperationPhaseSyntax | null = null;\n let compensate: OperationPhaseSyntax | null = null;\n const inputs: PropertySyntax[] = [];\n const mappings: PropertyMappingSyntax[] = [];\n const names = new Set<string>();\n for (let line = context.peekChild(header.indent); line !== undefined; line = context.peekChild(header.indent)) {\n context.reader.takeSignificant();\n const typed = typedMapping.exec(line.content);\n const propertyLine = inline && typed !== null ? { ...line, content: typed[1].trimEnd() } : line;\n if (typed === null && eventMetadata.has(firstWord(line.content))) {\n context.error(DiagnosticCodes.InvalidOperationDeclaration, 'Operations cannot declare event routing or metadata; escape a keyword-named input with @.', locationOf(line));\n context.skipBlock(line.indent);\n continue;\n }\n if (!usesPattern.test(line.content) && tryParseProperty(propertyLine) !== undefined) {\n const property = parseProperty(context, propertyLine)!;\n if (inline && typed === null) context.error(DiagnosticCodes.InvalidOperationMapping, \"An inline operation input requires '<property> <Type> = <source>'.\", locationOf(line));\n if (property.isSubject) context.error(DiagnosticCodes.InvalidSubjectOwner, 'The subject modifier is only valid on event properties, not operation inputs (decision 0008: one data subject per event).', locationOf(line));\n if (property.isIdentifier || property.isGenerated) context.error(DiagnosticCodes.InvalidOperationDeclaration, 'Operation inputs cannot be identifier or generated properties.', locationOf(line));\n if (names.has(property.name)) context.error(DiagnosticCodes.DuplicateDeclaration, `Operation '${name}' already declares input '${property.name}'.`, locationOf(line));\n names.add(property.name);\n inputs.push(property);\n if (inline && typed !== null) mappings.push({ kind: 'PropertyMappingSyntax', property: property.name, source: parseMappingSource(typed[2], { ...locationOf(line), column: line.indent + line.content.length - typed[2].length + 1 }, context), location: locationOf(line) });\n rejectOperationChildren(context, line, DiagnosticCodes.InvalidOperationDeclaration, 'An operation input cannot have children.');\n } else if (firstWord(line.content) === 'description') description = parseDescription(context, line, description, `Operation '${name}'`);\n else if (usesPattern.test(line.content)) {\n if (uses !== null) context.error(DiagnosticCodes.InvalidSystemReference, \"An operation declares exactly one 'uses <System>'.\", locationOf(line));\n else {\n uses = usesPattern.exec(line.content)![1];\n usesLocation = { ...locationOf(line), column: locationOf(line).column + line.content.indexOf(uses, 4) };\n }\n rejectOperationChildren(context, line, DiagnosticCodes.InvalidSystemReference, 'A system reference cannot have children.');\n } else if (line.content === 'execute' || line.content === 'compensate') {\n const phase = parseOperationPhase(context, line);\n if (line.content === 'execute') {\n if (execute !== null) context.error(DiagnosticCodes.InvalidOperationDeclaration, 'An operation declares execute at most once.', locationOf(line));\n else execute = phase;\n } else {\n if (compensate !== null) context.error(DiagnosticCodes.InvalidOperationDeclaration, 'An operation declares compensate at most once.', locationOf(line));\n else compensate = phase;\n }\n } else {\n context.error(DiagnosticCodes.InvalidOperationDeclaration, `Unexpected '${line.content}' in operation - expected uses, an input, description, execute or compensate.`, locationOf(line));\n context.skipBlock(line.indent);\n }\n }\n if (uses === null) context.error(DiagnosticCodes.InvalidSystemReference, \"An operation requires exactly one 'uses <System>'.\", locationOf(header));\n return { operation: { kind: 'OperationSyntax', name, uses: uses ?? '', usesLocation, inputs, description, execute, compensate, location: locationOf(header) }, mappings };\n}\n\nfunction parseOperationPhase(context: ParserContext, header: SourceLine): OperationPhaseSyntax {\n let description: string | null = null;\n let file: OperationPhaseSyntax['file'] = null;\n let code: OperationPhaseSyntax['code'] = null;\n let implementation: OperationPhaseSyntax['implementation'] = null;\n let sourceSelected = false;\n for (let line = context.peekChild(header.indent); line !== undefined; line = context.peekChild(header.indent)) {\n context.reader.takeSignificant();\n if (firstWord(line.content) === 'description') {\n description = parseDescription(context, line, description, `Operation phase '${header.content}'`);\n continue;\n }\n if (firstWord(line.content) === 'implementation') {\n if (sourceSelected) context.error(DiagnosticCodes.ConflictingImplementationSources, 'A phase cannot mix wrapped and direct sources or repeat its wrapper.', locationOf(line));\n const source = parseImplementationWrapper(context, line);\n if (!sourceSelected) { file = source.file; code = source.code; implementation = source.implementation; }\n sourceSelected = true;\n } else if (isFileDirective(line) || line.content.startsWith('```')) {\n if (sourceSelected) context.error(DiagnosticCodes.ConflictingImplementationSources, 'A phase has at most one file or inline payload.', locationOf(line));\n const parsedFile = isFileDirective(line) ? parseFile(context, line) : null;\n const parsedCode = parsedFile === null ? parseCode(context, line) : null;\n if (!sourceSelected) { file = parsedFile; code = parsedCode; }\n sourceSelected = true;\n if (parsedFile !== null) rejectOperationChildren(context, line, DiagnosticCodes.InvalidImplementationBlock, 'A file directive cannot have children.');\n } else {\n context.error(DiagnosticCodes.InvalidOperationDeclaration, 'A phase accepts description, file, a tagged fence or implementation.', locationOf(line));\n context.skipBlock(line.indent);\n }\n }\n return { kind: 'OperationPhaseSyntax', description, file, code, implementation, location: locationOf(header) };\n}\n"],"mappings":"4lBAiBA,MAAMA,EAAeC,EAAQ,6BAA6B,EACpDC,EAAkBD,EAAQ,gCAAgC,EAC1DE,EAAeF,EAAQ,4CAA4C,EACnEG,EAAcH,EAAQ,2BAA2B,EACjDI,EAAeJ,EAAQ,6BAA6B,EACpDK,kBAAgB,IAAI,IAAI,CAAC,MAAO,MAAO,aAAc,SAAU,gBAAiB,YAAa,WAAY,cAAe,YAAa,WAAY,UAAU,CAAC,EAElK,SAAgB,wBAAwB,EAAwB,EAAkB,EAAc,EAAuB,CACnH,IAAMC,EAAQC,EAAQ,UAAUC,EAAK,MAAM,EACvCF,IAAU,IAAA,KACdC,EAAQ,MAAME,EAAMC,EAASC,EAAWL,CAAK,CAAC,EAC9CC,EAAQ,UAAUC,EAAK,MAAM,EACjC,CAEA,SAAgB,YAAY,EAAwB,EAAkC,CAClF,IAAMI,EAAQb,EAAa,KAAKc,EAAO,OAA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EAAK,OAAO,IAAM,cAC5B,EAAcS,EAAiBV,EAASC,EAAMO,EAAa,oBAAoBF,EAAO,QAAQ,EAAE,OAGpG,GAAIG,EAAUR,EAAK,OAAO,IAAM,iBAAkB,CAC1C4B,GAAgB7B,EAAQ,MAAMO,EAAgB,iCAAkC,uEAAwEH,EAAWH,CAAI,CAAC,EAC5K,IAAM6B,EAASC,EAA2B/B,EAASC,CAAI,EAClD4B,IAAkB,EAAOC,EAAO,KAAM,EAAOA,EAAO,KAAM,EAAiBA,EAAO,gBACvF,EAAiB,EACrB,MAAO,GAAIE,EAAgB/B,CAAI,GAAKA,EAAK,QAAQ,WAAW,KAAK,EAAG,CAC5D4B,GAAgB7B,EAAQ,MAAMO,EAAgB,iCAAkC,kDAAmDH,EAAWH,CAAI,CAAC,EACvJ,IAAMgC,EAAaD,EAAgB/B,CAAI,EAAIiC,EAAUlC,EAASC,CAAI,EAAI,KAChEkC,EAAaF,IAAe,KAAOG,EAAUpC,EAASC,CAAI,EAAI,KAC/D4B,IAAkB,EAAOI,EAAY,EAAOE,GACjD,EAAiB,GACbF,IAAe,MAAM,wBAAwBjC,EAASC,EAAMM,EAAgB,2BAA4B,wCAAwC,CACxJ,MACIP,EAAQ,MAAMO,EAAgB,4BAA6B,uEAAwEH,EAAWH,CAAI,CAAC,EACnJD,EAAQ,UAAUC,EAAK,MAAM,EAGrC,MAAO,CAAE,KAAM,uBAAwB,cAAa,OAAM,OAAM,iBAAgB,SAAUG,EAAWE,CAAM,CAAE,CACjH"}
|
|
1
|
+
{"version":3,"file":"OperationParser.js","names":["systemHeader","pattern","operationHeader","inlineHeader","usesPattern","typedMapping","eventMetadata","child","context","line","code","message","locationOf","match","header","DiagnosticCodes","description","firstWord","parseDescription","inline","name","uses","usesLocation","execute","compensate","inputs","mappings","names","typed","marker","trailingMarker","propertyLine","structured","tryParseProperty","property","parseProperty","parseMappingSource","parseStructuredValue","phase","file","implementation","sourceSelected","source","parseImplementationWrapper","isFileDirective","parsedFile","parseFile","parsedCode","parseCode"],"sources":["../../../../../../Compiler/Parsing/OperationParser.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { PropertySyntax } from '../Syntax/Declarations';\nimport { pattern } from '../Text/patterns';\nimport { PropertyMappingSyntax } from '../Syntax/Expressions';\nimport { OperationPhaseSyntax, OperationSyntax, SystemSyntax } from '../Syntax/Operations';\nimport { parseDescription } from './DescriptionParser';\nimport { parseMappingSource } from './ExpressionParser';\nimport { isFileDirective } from './FileReferences';\nimport { parseCode, parseFile, parseImplementationWrapper } from './ImplementationParser';\nimport { firstWord } from './LineText';\nimport { ParserContext } from './ParserContext';\nimport { parseProperty, tryParseProperty } from './PropertyLineParser';\nimport { locationOf, SourceLine } from './SourceLine';\nimport { parseStructuredValue, trailingMarker } from './StructuredBlockParser';\n\nconst systemHeader = pattern('^system\\\\s+([A-Za-z_]\\\\w*)$');\nconst operationHeader = pattern('^operation\\\\s+([A-Za-z_]\\\\w*)$');\nconst inlineHeader = pattern('^produces\\\\s+operation\\\\s+([A-Za-z_]\\\\w*)$');\nconst usesPattern = pattern('^uses\\\\s+([A-Za-z_]\\\\w*)$');\nconst typedMapping = pattern('^(.+?)\\\\s*=(?!=|>)\\\\s*(.+)$');\nconst eventMetadata = new Set(['for', 'tag', 'generation', 'origin', 'documentation', 'namespace', 'sequence', 'correlation', 'causation', 'causedBy', 'occurred']);\n\nexport function rejectOperationChildren(context: ParserContext, line: SourceLine, code: string, message: string): void {\n const child = context.peekChild(line.indent);\n if (child === undefined) return;\n context.error(code, message, locationOf(child));\n context.skipBlock(line.indent);\n}\n\nexport function parseSystem(context: ParserContext, header: SourceLine): SystemSyntax {\n const match = systemHeader.exec(header.content);\n if (match === null) context.error(DiagnosticCodes.InvalidSystemDeclaration, \"Expected 'system <Name>'.\", locationOf(header));\n let description: string | null = null;\n for (let child = context.peekChild(header.indent); child !== undefined; child = context.peekChild(header.indent)) {\n context.reader.takeSignificant();\n if (firstWord(child.content) === 'description') description = parseDescription(context, child, description, `System '${match?.[1] ?? ''}'`);\n else {\n context.error(DiagnosticCodes.InvalidSystemDeclaration, 'A system accepts only a description; abilities are not supported.', locationOf(child));\n context.skipBlock(child.indent);\n }\n }\n return { kind: 'SystemSyntax', name: match?.[1] ?? '', description, location: locationOf(header) };\n}\n\nexport function parseOperation(context: ParserContext, header: SourceLine, inline = false): { operation: OperationSyntax; mappings: PropertyMappingSyntax[] } {\n const match = (inline ? inlineHeader : operationHeader).exec(header.content);\n const name = match?.[1] ?? '';\n if (match === null) context.error(DiagnosticCodes.InvalidOperationDeclaration, 'Expected an operation declaration with one name.', locationOf(header));\n let description: string | null = null;\n let uses: string | null = null;\n let usesLocation = locationOf(header);\n let execute: OperationPhaseSyntax | null = null;\n let compensate: OperationPhaseSyntax | null = null;\n const inputs: PropertySyntax[] = [];\n const mappings: PropertyMappingSyntax[] = [];\n const names = new Set<string>();\n for (let line = context.peekChild(header.indent); line !== undefined; line = context.peekChild(header.indent)) {\n context.reader.takeSignificant();\n const typed = typedMapping.exec(line.content);\n const marker = inline && typed === null ? trailingMarker(line.content) : undefined;\n let propertyLine = line;\n if (inline && typed !== null) propertyLine = { ...line, content: typed[1].trimEnd() };\n else if (marker !== undefined) propertyLine = { ...line, content: line.content.substring(0, line.content.length - marker.length - 1) };\n const structured = inline && typed === null && (marker !== undefined || context.peekChild(line.indent) !== undefined);\n if (typed === null && eventMetadata.has(firstWord(line.content))) {\n context.error(DiagnosticCodes.InvalidOperationDeclaration, 'Operations cannot declare event routing or metadata; escape a keyword-named input with @.', locationOf(line));\n context.skipBlock(line.indent);\n continue;\n }\n if (!usesPattern.test(line.content) && tryParseProperty(propertyLine) !== undefined) {\n const property = parseProperty(context, propertyLine)!;\n if (inline && typed === null && !structured) context.error(DiagnosticCodes.InvalidOperationMapping, \"An inline operation input requires '<property> <Type> = <source>'.\", locationOf(line));\n if (property.isSubject) context.error(DiagnosticCodes.InvalidSubjectOwner, 'The subject modifier is only valid on event properties, not operation inputs (decision 0008: one data subject per event).', locationOf(line));\n if (property.isIdentifier || property.isGenerated) context.error(DiagnosticCodes.InvalidOperationDeclaration, 'Operation inputs cannot be identifier or generated properties.', locationOf(line));\n if (names.has(property.name)) context.error(DiagnosticCodes.DuplicateDeclaration, `Operation '${name}' already declares input '${property.name}'.`, locationOf(line));\n names.add(property.name);\n inputs.push(property);\n if (inline && typed !== null) mappings.push({ kind: 'PropertyMappingSyntax', property: property.name, source: parseMappingSource(typed[2], { ...locationOf(line), column: line.indent + line.content.length - typed[2].length + 1 }, context), location: locationOf(line) });\n if (structured) mappings.push({ kind: 'PropertyMappingSyntax', property: property.name, source: parseStructuredValue(context, line, marker), location: locationOf(line) });\n rejectOperationChildren(context, line, DiagnosticCodes.InvalidOperationDeclaration, 'An operation input cannot have children.');\n } else if (firstWord(line.content) === 'description') description = parseDescription(context, line, description, `Operation '${name}'`);\n else if (usesPattern.test(line.content)) {\n if (uses !== null) context.error(DiagnosticCodes.InvalidSystemReference, \"An operation declares exactly one 'uses <System>'.\", locationOf(line));\n else {\n uses = usesPattern.exec(line.content)![1];\n usesLocation = { ...locationOf(line), column: locationOf(line).column + line.content.indexOf(uses, 4) };\n }\n rejectOperationChildren(context, line, DiagnosticCodes.InvalidSystemReference, 'A system reference cannot have children.');\n } else if (line.content === 'execute' || line.content === 'compensate') {\n const phase = parseOperationPhase(context, line);\n if (line.content === 'execute') {\n if (execute !== null) context.error(DiagnosticCodes.InvalidOperationDeclaration, 'An operation declares execute at most once.', locationOf(line));\n else execute = phase;\n } else {\n if (compensate !== null) context.error(DiagnosticCodes.InvalidOperationDeclaration, 'An operation declares compensate at most once.', locationOf(line));\n else compensate = phase;\n }\n } else {\n context.error(DiagnosticCodes.InvalidOperationDeclaration, `Unexpected '${line.content}' in operation - expected uses, an input, description, execute or compensate.`, locationOf(line));\n context.skipBlock(line.indent);\n }\n }\n if (uses === null) context.error(DiagnosticCodes.InvalidSystemReference, \"An operation requires exactly one 'uses <System>'.\", locationOf(header));\n return { operation: { kind: 'OperationSyntax', name, uses: uses ?? '', usesLocation, inputs, description, execute, compensate, location: locationOf(header) }, mappings };\n}\n\nfunction parseOperationPhase(context: ParserContext, header: SourceLine): OperationPhaseSyntax {\n let description: string | null = null;\n let file: OperationPhaseSyntax['file'] = null;\n let code: OperationPhaseSyntax['code'] = null;\n let implementation: OperationPhaseSyntax['implementation'] = null;\n let sourceSelected = false;\n for (let line = context.peekChild(header.indent); line !== undefined; line = context.peekChild(header.indent)) {\n context.reader.takeSignificant();\n if (firstWord(line.content) === 'description') {\n description = parseDescription(context, line, description, `Operation phase '${header.content}'`);\n continue;\n }\n if (firstWord(line.content) === 'implementation') {\n if (sourceSelected) context.error(DiagnosticCodes.ConflictingImplementationSources, 'A phase cannot mix wrapped and direct sources or repeat its wrapper.', locationOf(line));\n const source = parseImplementationWrapper(context, line);\n if (!sourceSelected) { file = source.file; code = source.code; implementation = source.implementation; }\n sourceSelected = true;\n } else if (isFileDirective(line) || line.content.startsWith('```')) {\n if (sourceSelected) context.error(DiagnosticCodes.ConflictingImplementationSources, 'A phase has at most one file or inline payload.', locationOf(line));\n const parsedFile = isFileDirective(line) ? parseFile(context, line) : null;\n const parsedCode = parsedFile === null ? parseCode(context, line) : null;\n if (!sourceSelected) { file = parsedFile; code = parsedCode; }\n sourceSelected = true;\n if (parsedFile !== null) rejectOperationChildren(context, line, DiagnosticCodes.InvalidImplementationBlock, 'A file directive cannot have children.');\n } else {\n context.error(DiagnosticCodes.InvalidOperationDeclaration, 'A phase accepts description, file, a tagged fence or implementation.', locationOf(line));\n context.skipBlock(line.indent);\n }\n }\n return { kind: 'OperationPhaseSyntax', description, file, code, implementation, location: locationOf(header) };\n}\n"],"mappings":"krBAkBA,MAAMA,EAAeC,EAAQ,6BAA6B,EACpDC,EAAkBD,EAAQ,gCAAgC,EAC1DE,EAAeF,EAAQ,4CA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EAAiBA,EAAO,gBACvF,EAAiB,EACrB,MAAO,GAAIE,EAAgBnC,CAAI,GAAKA,EAAK,QAAQ,WAAW,KAAK,EAAG,CAC5DgC,GAAgBjC,EAAQ,MAAMO,EAAgB,iCAAkC,kDAAmDH,EAAWH,CAAI,CAAC,EACvJ,IAAMoC,EAAaD,EAAgBnC,CAAI,EAAIqC,EAAUtC,EAASC,CAAI,EAAI,KAChEsC,EAAaF,IAAe,KAAOG,EAAUxC,EAASC,CAAI,EAAI,KAC/DgC,IAAkB,EAAOI,EAAY,EAAOE,GACjD,EAAiB,GACbF,IAAe,MAAM,wBAAwBrC,EAASC,EAAMM,EAAgB,2BAA4B,wCAAwC,CACxJ,MACIP,EAAQ,MAAMO,EAAgB,4BAA6B,uEAAwEH,EAAWH,CAAI,CAAC,EACnJD,EAAQ,UAAUC,EAAK,MAAM,EAGrC,MAAO,CAAE,KAAM,uBAAwB,cAAa,OAAM,OAAM,iBAAgB,SAAUG,EAAWE,CAAM,CAAE,CACjH"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{pattern as t}from"../Text/patterns.js";import{locationOf as n}from"./SourceLine.js";import{parseMappingSource as r}from"./ExpressionParser.js";import{diagnosticText as i}from"../Diagnostics/DiagnosticArgument.js";import{firstWord as a,unescapeIdentifier as o}from"./LineText.js";import{parseProperty as s}from"./PropertyLineParser.js";import{
|
|
1
|
+
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{pattern as t}from"../Text/patterns.js";import{locationOf as n}from"./SourceLine.js";import{parseMappingSource as r}from"./ExpressionParser.js";import{diagnosticText as i}from"../Diagnostics/DiagnosticArgument.js";import{firstWord as a,unescapeIdentifier as o}from"./LineText.js";import{parseProperty as s}from"./PropertyLineParser.js";import{parseStructuredValue as c,trailingMarker as l,tryParseStructuredMapping as u}from"./StructuredBlockParser.js";import{parseCondition as d}from"./ConditionParser.js";import{sourceStreamPattern as f}from"../Text/SourceStreamNames.js";import{parseCommandStream as p}from"./EventSourceParser.js";import{EventMetadataParser as m}from"./EventMetadataParser.js";import{parseTag as h}from"./DeclarationParsers.js";import{parseOperation as g}from"./OperationParser.js";const _=t(`^produces\\s+operation(?:\\s|$)`),v=t(`^produces\\s+event\\s+([A-Za-z_]\\w*)(?:\\s+(generation)(?:\\s+.*)?)?$`),y=t(`^produces\\s+([A-Z]\\w*(?:\\.[A-Za-z_]\\w*)*)$`),b=t(`^produces\\s+when\\s+(.+)$`),x=t(`^[A-Z]\\w*(?:\\.[A-Za-z_]\\w*)*$`),S=t(`^for\\s+(\\S.*)$`),C=t(`^(@?[\\w.]+)\\s*=(?!=|>)\\s*(.+)$`),w=t(`^(.+?)\\s*=(?!=|>)\\s*(.+)$`),T=/* @__PURE__ */ new Set([`namespace`,`sequence`,`correlation`,`causation`,`causedBy`,`occurred`]);function parseProduces(t,E,D=!1){if(_.test(E.content)){if(!D){t.error(e.OperationOutsideCommand,`Operations can only be produced by commands.`,n(E)),t.skipOpaqueBlock(E.indent);return}let r=g(t,E,!0);return{kind:`ProducesSyntax`,when:null,event:r.operation.name,targetLocation:{...n(E),column:E.indent+E.content.match(/^produces\s+operation(?:\s+|$)/)[0].length+1},inlineEvent:null,inlineOperation:r.operation,mappings:r.mappings,for:null,tags:[],location:n(E)}}let O=v.exec(E.content),k=E,A=null,j,M;if(O!==null){if(!D){t.error(e.InlineEventOutsideCommand,`Inline events can only be declared inside commands`,n(E)),t.skipOpaqueBlock(E.indent);return}O[2]!==void 0&&t.error(e.InlineEventGeneration,`Inline events are generation 1 - extract the event before declaring generations`,n(E)),j=O[1],M=E.indent+E.content.match(/^produces\s+event\s+/)[0].length+1}else if(b.test(E.content)){A=d(t,b.exec(E.content)[1],n(E));let r=t.peekChild(E.indent);if(r===void 0||!x.test(r.content)){t.error(e.ProducesWhenWithoutEvent,`Expected an event name on the line after 'produces when'`,n(E)),t.skipOpaqueBlock(E.indent);return}t.reader.takeSignificant(),k=r,j=r.content,M=r.indent+1}else{let r=y.exec(E.content);if(r===null){t.error(e.InvalidProducesDeclaration,`Invalid produces declaration '${E.content}' - expected 'produces <EventType>' or 'produces when <condition>'`,n(E)),t.skipOpaqueBlock(E.indent);return}j=r[1],M=E.indent+E.content.match(/^produces\s+/)[0].length+1}let N=[],P=/* @__PURE__ */ new Set,F=[],I=[],L=new m(j),R=null,z=null;for(let d=t.peekChild(k.indent);d!==void 0;d=t.peekChild(k.indent)){t.reader.takeSignificant();let m=a(d.content),g=n(d);if(T.has(m)){t.error(e.ReservedProductionMetadata,`'${m}' is system-assigned production metadata and cannot be supplied here`,g),t.skipOpaqueBlock(d.indent);continue}if(O!==null&&(m===`generation`||m===`origin`)){t.error(m===`generation`?e.InlineEventGeneration:e.ReservedProductionMetadata,m===`generation`?`Inline events are generation 1 - extract the event before declaring generations`:`An inline event is local to its command and cannot declare origin`,g),t.skipOpaqueBlock(d.indent);continue}if(m===`stream`&&!d.content.includes(`=`)){let n=f(`^stream\\s+([A-Za-z_]\\w*\\.[A-Za-z_]\\w*)$`).exec(d.content);if(!D)t.error(e.ProductionRouteOutsideCommand,`Only command event productions can declare a stream route.`,g),t.skipBlock(d.indent);else if(z!==null)t.error(e.InvalidCommandStream,`A production can declare at most one stream route.`,g),t.skipBlock(d.indent);else if(n===null)t.error(e.InvalidCommandStream,`Expected 'stream <Source>.<Stream>'.`,g),t.skipBlock(d.indent);else{let e={...g,column:d.indent+d.content.indexOf(n[1])+1},r={kind:`PropertySyntax`,name:`stream`,type:{kind:`TypeRefSyntax`,name:n[1],isCollection:!1,isOptional:!1,location:e},isIdentifier:!1,location:g};z=p(t,d,r,!1)}continue}if(m===`tag`){let e=h(t,d,!1);e!==void 0&&I.push(e);continue}let _=S.exec(d.content);if(_!==null){R===null?R=r(_[1],g,t):t.error(e.DuplicateProducesTarget,`'${k.content}' already declares where it lands - an event is appended to one event source`,g);continue}let v=(O===null?C:w).exec(d.content);if(v===null&&O===null){let e=u(t,d);if(e!==void 0){F.push(e);continue}}let y=l(d.content),b=v===null&&O!==null&&!d.content.includes(`=`)&&![`id`,`description`,`documentation`].includes(m)&&d.content.includes(` `)&&(y!==void 0||t.peekChild(d.indent)!==void 0),x=b?y===void 0?d.content:d.content.substring(0,d.content.length-y.length-1):v?.[1].trimEnd(),E=x===void 0||O===null?void 0:s(t,{...d,content:x});if((v!==null||b)&&(O===null||E!==void 0)){if(E!==void 0){E.isIdentifier&&(t.error(e.IdentifierOnEventProperty,`Property '${E.name}' of event '${j}' cannot be marked identifier - an event never carries its event source id`,g),E={...E,isIdentifier:!1});let n=E.name;P.has(n)&&t.error(e.DuplicateDeclaration,`Event '${j}' already declares property '${E.name}'`,g),P.add(n),N.push(E)}F.push(v===null?{kind:`PropertyMappingSyntax`,property:E.name,source:c(t,d,y),location:g}:{kind:`PropertyMappingSyntax`,property:E?.name??o(v[1]),source:r(v[2],{...g,column:d.indent+d.content.length-v[2].length+1},t),location:g})}else(O===null||!L.tryParse(t,d))&&t.error(e.InvalidPropertyMapping,`Invalid ${O===null?``:`inline `}property mapping '${d.content}' - expected '<property>${O===null?``:` <Type>`} = <source>'`,g,i(`text`,d.content))}return k!==E&&t.skipBlock(E.indent),{kind:`ProducesSyntax`,when:A,event:j,stream:z,targetLocation:{...n(k),column:M},inlineOperation:null,mappings:F,for:R,tags:O===null?I:[],location:n(E),inlineEvent:O===null?null:{kind:`EventSyntax`,name:j,properties:N,tags:I,generation:1,hasGenerationMarker:!1,...L.value,location:n(E)}}}export{parseProduces};
|
|
2
2
|
//# sourceMappingURL=ProducesParser.js.map
|