import { Scope } from "../../../types/Scope"; import { Token, TokenGroup } from "../../../types/Token"; import { ScriptAlertDescriptor } from "../../../types/script/ScriptAlertDescriptor"; import { ScriptDescriptorType } from "../../../types/script/ScriptDescriptorType"; export function parseAlert( tokens: Token[] ): ScriptAlertDescriptor | null { const stringPositions = tokens .map( ( x, idx ) => ( { index: idx, symbol: x } ) ) .filter( ( { symbol } ) => symbol.group === TokenGroup.Custom && symbol.section === 'string' ) .map( x => x.index ); let fullText = ''; for( let i=stringPositions[0]; i < tokens.length; i++ ) { const start = i === stringPositions[0]; const symbol = tokens[i]; if( symbol.group === TokenGroup.Custom && symbol.section === 'string' ) { fullText += `${start ? '' : ' + '}"${symbol.key}"`; } else if( symbol.group === TokenGroup.Custom ) { fullText += `${start ? '' : ' + '}{{variable:${symbol.key}}}`; } else { break; } } return { type: ScriptDescriptorType.Alert, isAsync: false, variables: [], text: fullText }; }