Symbols without aliases should be used for lookahead

This commit is contained in:
Daumantas Kavolis 2023-06-15 15:55:32 +03:00
parent 7267384970
commit 1f52f2f1dc
9 changed files with 115 additions and 7 deletions

View file

@ -361,6 +361,11 @@ uint16_t ts_node_symbol_wasm(const TSTree *tree) {
return ts_node_symbol(node);
}
uint16_t ts_node_grammar_symbol_wasm(const TSTree *tree) {
TSNode node = unmarshal_node(tree);
return ts_node_grammar_symbol(node);
}
uint32_t ts_node_child_count_wasm(const TSTree *tree) {
TSNode node = unmarshal_node(tree);
return ts_node_child_count(node);
@ -621,6 +626,11 @@ uint16_t ts_node_parse_state_wasm(const TSTree *tree) {
return ts_node_parse_state(node);
}
uint16_t ts_node_next_parse_state_wasm(const TSTree *tree) {
TSNode node = unmarshal_node(tree);
return ts_node_next_parse_state(node);
}
/******************/
/* Section - Query */
/******************/

View file

@ -209,10 +209,19 @@ class Node {
return C._ts_node_symbol_wasm(this.tree[0]);
}
get grammarId() {
marshalNode(this);
return C._ts_node_grammar_symbol_wasm(this.tree[0]);
}
get type() {
return this.tree.language.types[this.typeId] || 'ERROR';
}
get grammarType() {
return this.tree.language.types[this.grammarId] || 'ERROR';
}
get endPosition() {
marshalNode(this);
C._ts_node_end_point_wasm(this.tree[0]);
@ -233,6 +242,11 @@ class Node {
return C._ts_node_parse_state_wasm(this.tree[0]);
}
get nextParseState() {
marshalNode(this);
return C._ts_node_next_parse_state_wasm(this.tree[0]);
}
isNamed() {
marshalNode(this);
return C._ts_node_is_named_wasm(this.tree[0]) === 1;

View file

@ -59,6 +59,7 @@
"_ts_node_is_missing_wasm",
"_ts_node_is_named_wasm",
"_ts_node_parse_state_wasm",
"_ts_node_next_parse_state_wasm",
"_ts_node_named_child_count_wasm",
"_ts_node_named_child_wasm",
"_ts_node_named_children_wasm",
@ -72,6 +73,7 @@
"_ts_node_start_index_wasm",
"_ts_node_start_point_wasm",
"_ts_node_symbol_wasm",
"_ts_node_grammar_symbol_wasm",
"_ts_node_to_string_wasm",
"_ts_parser_delete",
"_ts_parser_enable_logger_wasm",

View file

@ -327,7 +327,7 @@ describe("Node", () => {
});
describe(".parseState", () => {
const text = "10 * 5";
const text = "10 / 5";
it(`returns node parse state ids`, async () => {
tree = await parser.parse(text)
@ -335,9 +335,13 @@ describe("Node", () => {
const [numerator, slash, denominator] = quotientNode.children;
assert.equal(tree.rootNode.parseState, 0);
assert.equal(numerator.parseState, 1);
assert.equal(slash.parseState, 553);
assert.equal(denominator.parseState, 185);
// parse states will change on any change to the grammar so test that it
// returns something instead
assert.isAbove(numerator.parseState, 0);
assert.isAbove(numerator.nextParseState, 0);
assert.isAbove(slash.parseState, 0);
assert.isAbove(denominator.parseState, 0);
assert.isAbove(denominator.nextParseState, 0);
})
});

View file

@ -55,11 +55,14 @@ declare module 'web-tree-sitter' {
) => string | null;
export interface SyntaxNode {
id: number;
typeId: number;
grammarId: number;
tree: Tree;
type: string;
grammarType: string;
text: string;
parseState: number;
nextParseState: number;
startPosition: Point;
endPosition: Point;
startIndex: number;