Improved error handling for most calculations
This commit is contained in:
@@ -28,10 +28,21 @@ export function parse(string){
|
||||
if (results.length === 1){
|
||||
return results[0];
|
||||
} else if (results.length === 0){
|
||||
// Valid parsing up until now, but need more. Unexpected end of input.
|
||||
return null;
|
||||
// Valid parsing up until now, but need more
|
||||
throw new EndOfInputError('Unexpected end of input');
|
||||
} else {
|
||||
console.warn('Grammar is ambiguous!', {string, results});
|
||||
return results[0];
|
||||
}
|
||||
}
|
||||
|
||||
export function prettifyParseError(e){
|
||||
if (e.message) e = e.message
|
||||
return e.toString().split('.')[0];
|
||||
}
|
||||
|
||||
class EndOfInputError extends Error {
|
||||
constructor(message = '', ...args) {
|
||||
super(message, ...args);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user