Refactor so engines use 0-based document ranges
This commit is contained in:
@ -85,7 +85,7 @@ export default class BrainfuckLanguageEngine implements LanguageEngine<BFRS> {
|
||||
// Add instruction to AST
|
||||
ast.push({
|
||||
instr: { type: char as BF_OP, param: jumpTarget },
|
||||
location: { line: lIdx + 1, char: cIdx + 1 },
|
||||
location: { line: lIdx, char: cIdx },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -98,7 +98,7 @@ export default class ChefLanguageEngine implements LanguageEngine<T.ChefRS> {
|
||||
} else {
|
||||
// Next step is a regular method instruction
|
||||
const nextOp = currFrame.recipe.method[currFrame.pc];
|
||||
nextStepLocation = this.convertTo1Index(nextOp.location);
|
||||
nextStepLocation = nextOp.location;
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,19 +191,6 @@ export default class ChefLanguageEngine implements LanguageEngine<T.ChefRS> {
|
||||
if (opOutput) return opOutput;
|
||||
}
|
||||
|
||||
private convertTo1Index(location: DocumentRange): DocumentRange {
|
||||
const lineNum = location.line + 1;
|
||||
const charRange = location.charRange
|
||||
? {
|
||||
start: location.charRange.start
|
||||
? location.charRange.start + 1
|
||||
: undefined,
|
||||
end: location.charRange.end ? location.charRange.end + 1 : undefined,
|
||||
}
|
||||
: undefined;
|
||||
return { line: lineNum, charRange };
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty the first N dishes of given kitchen into text output.
|
||||
* @param numDishes Number of dishes to empty as output
|
||||
|
@ -57,7 +57,7 @@ export default class DeadfishLanguageEngine implements LanguageEngine<DFRS> {
|
||||
if (OP_CHARS.includes(char as DF_OP)) {
|
||||
ast.push({
|
||||
instr: char as DF_OP,
|
||||
location: { line: lIdx + 1, char: cIdx + 1 },
|
||||
location: { line: lIdx, char: cIdx },
|
||||
});
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user