diff --git a/src/defs_regex.ts b/src/defs_regex.ts index 496facf..e08e33f 100644 --- a/src/defs_regex.ts +++ b/src/defs_regex.ts @@ -33,7 +33,7 @@ export default { registers: /\b(?:[abcdefhlir]|ix|iy|af'?|bc|de|hl|pc|sp|ix[hlu]|iy[hlu]|[lh]x|x[lh]|[lh]y|y[lh])\b/i, condFlags: /\b(j[pr]|call|ret)(?:\s+([cmpz]|n[cz]|p[eo]))$/i, regsOrConds: /^([abcdefhlimprz]|ix|iy|af'?|bc|de|hl|pc|sp|ix[hlu]|iy[hlu]|[lh]x|x[lh]|[lh]y|y[lh]|n[cz]|p[eo])\b/i, - operators: /(?<=["'\w)])\s*([+\-\/%\^#]|[><=~&!\^\|\*]{1,2}|>>>|>=|<=|=>|<>|!=|mod|shl|shr|and|or|xor)\s*(?=[\w\$#%\.('"])/gi, + operators: /(?<=["'\w\)】])((?:\s*(?:[+\-\/%\^#]|[><=~&!\^\|\*]{1,2}|>>>|>=|<=|=>|<>|!=)\s*)|(?:\s+(?:mod|shl|shr|and|or|xor)\s+))(?=[\w\$#%\.\(【'"])/gi, labelDefinition: /^\@?((\$\$(?!\.))?[\w\.]+)(:|\s|$)/, parentLabel: /^(((\@|\$\$)(?!\.))?\w[\w\.]*)(?::|\s|$)/, evalExpression: /^\@?([\w\.]+)((?:\:?\s*)=\s*|(?:\:\s*|\s+)(?:(?:equ|eval)\s+))(.+)(;.*)?$/i, diff --git a/src/formatProcessor.ts b/src/formatProcessor.ts index be48203..b6482eb 100644 --- a/src/formatProcessor.ts +++ b/src/formatProcessor.ts @@ -338,18 +338,29 @@ export class FormatProcessor extends ConfigPropsProvider { let wasOperator = false; args.flatMap(arg => { - const matches = arg.matchAll(regex.operators); - const results = []; + const stringsMatches: string[] = []; + const safeArg = arg.replaceAll(regex.stringBounds, (match) => { + const i = stringsMatches.push(match); + return `【${i.toString().padStart(3, '0')}】`; + }); + + const results: string[] = []; + const matches = safeArg.matchAll(regex.operators); let beginIndex = 0; for (const match of matches) { const { [1]: operator, input, index } = match; - if (input && index !== undefined) { + if (input && index) { results.push(input.slice(beginIndex, index), `⨂${operator.trim()}`); beginIndex = index + operator.length; } } - results.push(arg.slice(beginIndex)); - return results; + results.push(safeArg.slice(beginIndex)); + + return results.map((fragment) => + fragment.replaceAll(/【(\d+)】/g, (_, counter) => { + return stringsMatches[parseInt(counter) - 1]; + }) + ); }).forEach((value, idx) => { if (value[0] === '⨂') { @@ -411,6 +422,8 @@ export class FormatProcessor extends ConfigPropsProvider { checkRegsOrConds: true })) ); + + wasOperator = false; }); } );