mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-22 19:18:31 +00:00
show line where mini notation parse errors happen
This commit is contained in:
parent
5a76bc93b8
commit
ecf837636b
@ -160,11 +160,19 @@ export const getLeafLocation = (code, leaf, globalOffset = 0) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// takes quoted mini string, returns ast
|
// takes quoted mini string, returns ast
|
||||||
export const mini2ast = (code) => krill.parse(code);
|
export const mini2ast = (code, start, userCode) => {
|
||||||
|
try {
|
||||||
|
return krill.parse(code);
|
||||||
|
} catch (error) {
|
||||||
|
const region = [error.location.start.offset + start, error.location.end.offset + start];
|
||||||
|
const line = userCode.slice(0, region[0]).split('\n').length;
|
||||||
|
throw new Error(`[mini] parse error at line ${line}: ${error.message}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// takes quoted mini string, returns all nodes that are leaves
|
// takes quoted mini string, returns all nodes that are leaves
|
||||||
export const getLeaves = (code) => {
|
export const getLeaves = (code, start, userCode) => {
|
||||||
const ast = mini2ast(code);
|
const ast = mini2ast(code, start, userCode);
|
||||||
let leaves = [];
|
let leaves = [];
|
||||||
patternifyAST(
|
patternifyAST(
|
||||||
ast,
|
ast,
|
||||||
@ -180,8 +188,8 @@ export const getLeaves = (code) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// takes quoted mini string, returns locations [fromCol,toCol] of all leaf nodes
|
// takes quoted mini string, returns locations [fromCol,toCol] of all leaf nodes
|
||||||
export const getLeafLocations = (code, offset = 0) => {
|
export const getLeafLocations = (code, start = 0, userCode) => {
|
||||||
return getLeaves(code).map((l) => getLeafLocation(code, l, offset));
|
return getLeaves(code, start, userCode).map((l) => getLeafLocation(code, l, start));
|
||||||
};
|
};
|
||||||
|
|
||||||
// mini notation only (wraps in "")
|
// mini notation only (wraps in "")
|
||||||
|
|||||||
@ -15,7 +15,7 @@ export function transpiler(input, options = {}) {
|
|||||||
|
|
||||||
let miniLocations = [];
|
let miniLocations = [];
|
||||||
const collectMiniLocations = (value, node) => {
|
const collectMiniLocations = (value, node) => {
|
||||||
const leafLocs = getLeafLocations(`"${value}"`, node.start); // stimmt!
|
const leafLocs = getLeafLocations(`"${value}"`, node.start, input);
|
||||||
miniLocations = miniLocations.concat(leafLocs);
|
miniLocations = miniLocations.concat(leafLocs);
|
||||||
};
|
};
|
||||||
let widgets = [];
|
let widgets = [];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user