Tweak impossible pattern error messages

This commit is contained in:
Max Brunsfeld 2020-08-20 13:24:42 -07:00
parent 4301110c12
commit 9daec9cb22
10 changed files with 19 additions and 17 deletions

View file

@ -667,8 +667,8 @@ class Language {
const errorId = getValue(TRANSFER_BUFFER + SIZE_OF_INT, 'i32');
const errorByte = getValue(TRANSFER_BUFFER, 'i32');
const errorIndex = UTF8ToString(sourceAddress, errorByte).length;
const suffix = source.substr(errorIndex, 100);
const word = suffix.match(QUERY_WORD_REGEX)[0];
const suffix = source.substr(errorIndex, 100).split('\n')[0];
let word = suffix.match(QUERY_WORD_REGEX)[0];
let error;
switch (errorId) {
case 2:
@ -681,10 +681,12 @@ class Language {
error = new RangeError(`Bad capture name @${word}`);
break;
case 5:
error = new SyntaxError(`Impossible pattern at offset ${errorIndex}: '${suffix}'...`);
error = new TypeError(`Bad pattern structure at offset ${errorIndex}: '${suffix}'...`);
word = "";
break;
default:
error = new SyntaxError(`Bad syntax at offset ${errorIndex}: '${suffix}'...`);
word = "";
break;
}
error.index = errorIndex;