Tweak impossible pattern error messages
This commit is contained in:
parent
4301110c12
commit
9daec9cb22
10 changed files with 19 additions and 17 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@
|
|||
"__ZNSt3__212basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEED2Ev",
|
||||
"__ZdlPv",
|
||||
"__Znwm",
|
||||
"___assert_fail",
|
||||
"_abort",
|
||||
"_iswalnum",
|
||||
"_iswalpha",
|
||||
|
|
@ -73,8 +72,6 @@
|
|||
"_ts_query_capture_count",
|
||||
"_ts_query_capture_name_for_id",
|
||||
"_ts_query_captures_wasm",
|
||||
"_ts_query_context_delete",
|
||||
"_ts_query_context_new",
|
||||
"_ts_query_delete",
|
||||
"_ts_query_matches_wasm",
|
||||
"_ts_query_new",
|
||||
|
|
|
|||
|
|
@ -30,6 +30,9 @@ describe("Query", () => {
|
|||
assert.throws(() => {
|
||||
JavaScript.query("(function_declaration non_existent:(identifier))");
|
||||
}, "Bad field name 'non_existent'");
|
||||
assert.throws(() => {
|
||||
JavaScript.query("(function_declaration name:(statement_block))");
|
||||
}, "Bad pattern structure at offset 22: 'name:(statement_block))'");
|
||||
});
|
||||
|
||||
it("throws an error on invalid predicates", () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue