Skip to content

Commit

Permalink
fix(vasm): Vasm error parsing fix
Browse files Browse the repository at this point in the history
  • Loading branch information
prb28 committed Nov 13, 2018
1 parent 92e9760 commit 2099689
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 15 deletions.
21 changes: 21 additions & 0 deletions src/test/vasm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,5 +254,26 @@ describe("VASM Tests", function () {
expect(error.line).to.be.equal(2);
expect(error.file).to.be.equal("myfile");
});
it("Should parse a multiline error", async function () {
let errStr = "error 9 in line 1 of \"STAT_SVZC\": instruction not supported on selected architecture\n" +
"called from line 798 of \"/myfolder/src/mysource.s\"\n" +
"> move.w ccr,StatusSZ [06]\n" +
"\n" +
"error 2 in line 646 of \"/myfolder/src/mysource.s\": unknown mnemonic <CALLEXEC>\n" +
"> CALLEXEC AllocSignal ;Get signal for Stop/Resume control.";
let errors = parser.parse(errStr);
expect(errors.length).to.be.equal(2);
let i = 0;
let error = errors[i++];
expect(error.msg).to.be.equal("error 9 in line 1 of \"STAT_SVZC\": instruction not supported on selected architecture");
expect(error.severity).to.be.equal("error");
expect(error.file).to.be.equal("/myfolder/src/mysource.s");
expect(error.line).to.be.equal(798);
error = errors[i++];
expect(error.msg).to.be.equal("error 2: unknown mnemonic <CALLEXEC>");
expect(error.severity).to.be.equal("error");
expect(error.file).to.be.equal("/myfolder/src/mysource.s");
expect(error.line).to.be.equal(646);
});
});
});
52 changes: 37 additions & 15 deletions src/vasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,28 +349,50 @@ export class VASMParser implements ExecutorParser {
parse(text: string): ICheckResult[] {
let errors: ICheckResult[] = [];
let lines = text.split(/\r\n|\r|\n/g);
let error: ICheckResult | undefined = undefined;
let lastHeaderLine = "";
for (let lineIndex = 0; lineIndex < lines.length; lineIndex += 1) {
let line = lines[lineIndex];
if ((line.length > 1) && !line.startsWith('>')) {
let match = /(error|warning|message)\s([\d]+)\sin\sline\s([\d]+)\sof\s[\"](.+)[\"]:\s*(.*)/.exec(line);
if (match) {
let error: ICheckResult = new ICheckResult();
error.file = match[4];
error.line = parseInt(match[3]);
error.msg = match[1] + " " + match[2] + ": " + match[5];
error.severity = match[1];
errors.push(error);
} else {
match = /.*error\s([\d]+)\s*:\s*(.*)/.exec(line);
if (line.length > 1) {
if (!line.startsWith('>')) {
let match = /(error|warning|message)\s([\d]+)\sin\sline\s([\d]+)\sof\s[\"](.+)[\"]:\s*(.*)/.exec(line);
if (match) {
let error: ICheckResult = new ICheckResult();
error.severity = 'error';
error.msg = line;
errors.push(error);
if (error !== undefined) {
errors.push(error);
}
error = new ICheckResult();
lastHeaderLine = line;
error.file = match[4];
error.line = parseInt(match[3]);
error.msg = match[1] + " " + match[2] + ": " + match[5];
error.severity = match[1];
} else {
match = /.*error\s([\d]+)\s*:\s*(.*)/.exec(line);
if (match) {
if (error !== undefined) {
errors.push(error);
}
error = new ICheckResult();
lastHeaderLine = line;
error.severity = 'error';
error.msg = line;
} else if (error !== undefined) {
// Errors details parse
let match = /\s*called from line\s([\d]+)\sof\s[\"](.+)[\"]/.exec(line);
if (match) {
error.file = match[2];
error.line = parseInt(match[1]);
error.msg = lastHeaderLine;
}
}
}
}
}
}
// Pushes the last error
if (error !== undefined) {
errors.push(error);
}
return errors;
}
}

0 comments on commit 2099689

Please sign in to comment.