Skip to content

Commit

Permalink
Follow-up fixes and improvements to #25
Browse files Browse the repository at this point in the history
  • Loading branch information
mborik committed May 3, 2023
1 parent a1ee475 commit 8ab09ae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/defs_regex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 18 additions & 5 deletions src/formatProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] === '⨂') {
Expand Down Expand Up @@ -411,6 +422,8 @@ export class FormatProcessor extends ConfigPropsProvider {
checkRegsOrConds: true
}))
);

wasOperator = false;
});
}
);
Expand Down

0 comments on commit 8ab09ae

Please sign in to comment.