From 89a7ca120c140b8196495fdca2bfa27d99ab186b Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+ttytm@users.noreply.github.com> Date: Mon, 18 Mar 2024 18:39:51 +0100 Subject: [PATCH] update --- .gitmodules | 4 +-- analyzer/parser/parser.v | 10 +++---- analyzer/psi/AstNode.v | 4 +-- analyzer/psi/PsiElement.v | 28 +++++++++---------- analyzer/psi/PsiElementImpl.v | 28 +++++++++---------- analyzer/psi/PsiFile.v | 6 ++-- analyzer/psi/PsiNamedElement.v | 4 +-- analyzer/psi/StubBase.v | 4 +-- analyzer/psi/StubbedElementTypeImpl.v | 4 +-- analyzer/psi/TreeWalker.v | 4 +-- tree_sitter/core | 1 - {tree_sitter => tree_sitter_v_api}/bindings.h | 0 {tree_sitter => tree_sitter_v_api}/bindings.v | 4 +-- tree_sitter_v_api/core | 1 + .../examples/cursor.v | 6 ++-- .../examples/simple.v | 6 ++-- .../examples/with_old_tree.v | 6 ++-- .../generate_types.vsh | 4 +-- .../node_types.v | 16 +++++------ .../simple_test.v | 6 ++-- .../tools/project-checker.v | 4 +-- .../tree_sitter.c.v | 13 ++++----- .../tree_sitter.v | 2 +- 23 files changed, 82 insertions(+), 83 deletions(-) delete mode 160000 tree_sitter/core rename {tree_sitter => tree_sitter_v_api}/bindings.h (100%) rename {tree_sitter => tree_sitter_v_api}/bindings.v (88%) create mode 160000 tree_sitter_v_api/core rename {tree_sitter => tree_sitter_v_api}/examples/cursor.v (80%) rename {tree_sitter => tree_sitter_v_api}/examples/simple.v (77%) rename {tree_sitter => tree_sitter_v_api}/examples/with_old_tree.v (80%) rename {tree_sitter => tree_sitter_v_api}/generate_types.vsh (97%) rename {tree_sitter => tree_sitter_v_api}/node_types.v (97%) rename {tree_sitter => tree_sitter_v_api}/simple_test.v (83%) rename {tree_sitter => tree_sitter_v_api}/tools/project-checker.v (97%) rename {tree_sitter => tree_sitter_v_api}/tree_sitter.c.v (97%) rename {tree_sitter => tree_sitter_v_api}/tree_sitter.v (99%) diff --git a/.gitmodules b/.gitmodules index 147f841c..272349e6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ -[submodule "v_tree_sitter/core"] - path = tree_sitter/core +[submodule "tree_sitter_v_api/core"] + path = tree_sitter_v_api/core url = https://github.com/tree-sitter/tree-sitter.git branch = master diff --git a/analyzer/parser/parser.v b/analyzer/parser/parser.v index a6c6d1c9..4d9fbef3 100644 --- a/analyzer/parser/parser.v +++ b/analyzer/parser/parser.v @@ -1,12 +1,12 @@ module parser -import tree_sitter as ts +import tree_sitter_v_api as api import os // ParseResult represents the result of a parsing operation. pub struct ParseResult { pub: - tree &ts.Tree[ts.NodeType] = unsafe { nil } // Resulting tree or nil if the source could not be parsed. + tree &api.Tree[api.NodeType] = unsafe { nil } // Resulting tree or nil if the source could not be parsed. source_text string // Source code. pub mut: path string // Path of the file that was parsed. @@ -94,9 +94,9 @@ pub fn parse_code(code string) ParseResult { // res2 = parser.parse_code_with_tree(code2, res.tree) // println(res2.tree // } -pub fn parse_code_with_tree(code string, old_tree &ts.Tree[ts.NodeType]) ParseResult { - mut parser := ts.new_parser[ts.NodeType](ts.type_factory) - parser.set_language(ts.language) +pub fn parse_code_with_tree(code string, old_tree &api.Tree[api.NodeType]) ParseResult { + mut parser := api.new_parser[api.NodeType](api.type_factory) + parser.set_language(api.language) raw_tree := if isnil(old_tree) { unsafe { nil } } else { old_tree.raw_tree } tree := parser.parse_string(source: code, tree: raw_tree) return ParseResult{ diff --git a/analyzer/psi/AstNode.v b/analyzer/psi/AstNode.v index 95b66e34..c207ba22 100644 --- a/analyzer/psi/AstNode.v +++ b/analyzer/psi/AstNode.v @@ -1,8 +1,8 @@ module psi -import tree_sitter as ts +import tree_sitter_v_api as api -pub fn (node AstNode) parent_of_type(typ ts.NodeType) ?AstNode { +pub fn (node AstNode) parent_of_type(typ api.NodeType) ?AstNode { mut res := node for { res = res.parent()? diff --git a/analyzer/psi/PsiElement.v b/analyzer/psi/PsiElement.v index d35ff664..5e8ac991 100644 --- a/analyzer/psi/PsiElement.v +++ b/analyzer/psi/PsiElement.v @@ -1,10 +1,10 @@ module psi -import tree_sitter as ts +import tree_sitter_v_api as api pub type ID = int -pub type AstNode = ts.Node[ts.NodeType] +pub type AstNode = api.Node[api.NodeType] pub interface PsiElement { node AstNode // base node from Tree Sitter @@ -12,7 +12,7 @@ pub interface PsiElement { stub_id StubId get_stub() ?&StubBase stub_list() &StubList - element_type() ts.NodeType + element_type() api.NodeType node() AstNode // return base node from Tree Sitter containing_file() &PsiFile // return file where the element is located is_equal(other PsiElement) bool // return true if the element is equal to the other element @@ -31,21 +31,21 @@ pub interface PsiElement { parent_nth(depth int) ?PsiElement // parent_of_type returns the parent node with the specified type. // If no such node exists, none is returned. - parent_of_type(typ ts.NodeType) ?PsiElement + parent_of_type(typ api.NodeType) ?PsiElement // parent_of_any_type returns the parent node with one of the specified types. // If no such node exists, none is returned. - parent_of_any_type(types ...ts.NodeType) ?PsiElement + parent_of_any_type(types ...api.NodeType) ?PsiElement // inside returns true if the node is inside a node with the specified type. - inside(typ ts.NodeType) bool + inside(typ api.NodeType) bool // is_parent_of returns true if the passed node is a child of the given node. is_parent_of(element PsiElement) bool // sibling_of_type_backward returns the previous node at the same nesting level with the specified type. // If no such node exists, none is returned. - sibling_of_type_backward(typ ts.NodeType) ?PsiElement + sibling_of_type_backward(typ api.NodeType) ?PsiElement // parent_of_type_or_self returns the parent node with the specified type, or the // node itself if its type matches the specified one. // If no such node exists, none is returned. - parent_of_type_or_self(typ ts.NodeType) ?PsiElement + parent_of_type_or_self(typ api.NodeType) ?PsiElement // children returns all child nodes. children() []PsiElement // named_children returns child nodes except unknown nodes. @@ -73,27 +73,27 @@ pub interface PsiElement { prev_sibling() ?PsiElement // prev_sibling_of_type returns the previous node at the same nesting level with the specified type. // If no such node exists, none is returned. - prev_sibling_of_type(typ ts.NodeType) ?PsiElement + prev_sibling_of_type(typ api.NodeType) ?PsiElement // prev_sibling_or_stub returns the previous node at the same nesting level or stub. // If the node is the first child node or stub, none is returned. prev_sibling_or_stub() ?PsiElement // find_child_by_type returns the first child node with the specified type. // If no such node is found, none is returned. - find_child_by_type(typ ts.NodeType) ?PsiElement + find_child_by_type(typ api.NodeType) ?PsiElement // has_child_of_type returns true if the node has a child with the specified type. - has_child_of_type(typ ts.NodeType) bool + has_child_of_type(typ api.NodeType) bool // find_child_by_type_or_stub returns the first child node with the specified type or stub. // If no such node is found, none is returned. - find_child_by_type_or_stub(typ ts.NodeType) ?PsiElement + find_child_by_type_or_stub(typ api.NodeType) ?PsiElement // find_child_by_name returns the first child node with the specified name. // If no such node is found, none is returned. find_child_by_name(name string) ?PsiElement // find_children_by_type returns all child nodes with the specified type. // If no such nodes are found, an empty array is returned. - find_children_by_type(typ ts.NodeType) []PsiElement + find_children_by_type(typ api.NodeType) []PsiElement // find_children_by_type_or_stub returns all child nodes with the specified type or stub. // If no such nodes are found, an empty array is returned. - find_children_by_type_or_stub(typ ts.NodeType) []PsiElement + find_children_by_type_or_stub(typ api.NodeType) []PsiElement // get_text returns the text of the node. get_text() string // text_matches returns true if the text of the node matches the specified value. diff --git a/analyzer/psi/PsiElementImpl.v b/analyzer/psi/PsiElementImpl.v index 6ecfc76f..6a9de403 100644 --- a/analyzer/psi/PsiElementImpl.v +++ b/analyzer/psi/PsiElementImpl.v @@ -1,6 +1,6 @@ module psi -import tree_sitter as ts +import tree_sitter_v_api as api pub struct PsiElementImpl { pub: @@ -48,7 +48,7 @@ pub fn (n &PsiElementImpl) stub_list() &StubList { return n.stubs_list } -pub fn (n &PsiElementImpl) element_type() ts.NodeType { +pub fn (n &PsiElementImpl) element_type() api.NodeType { if stub := n.get_stub() { return stub.element_type() } @@ -138,7 +138,7 @@ pub fn (n &PsiElementImpl) parent_nth(depth int) ?PsiElement { return create_element(parent, n.containing_file) } -pub fn (n &PsiElementImpl) parent_of_type(typ ts.NodeType) ?PsiElement { +pub fn (n &PsiElementImpl) parent_of_type(typ api.NodeType) ?PsiElement { mut res := PsiElement(n) for { res = res.parent()? @@ -150,7 +150,7 @@ pub fn (n &PsiElementImpl) parent_of_type(typ ts.NodeType) ?PsiElement { return none } -pub fn (n &PsiElementImpl) parent_of_any_type(types ...ts.NodeType) ?PsiElement { +pub fn (n &PsiElementImpl) parent_of_any_type(types ...api.NodeType) ?PsiElement { mut res := PsiElement(n) for { res = res.parent()? @@ -163,7 +163,7 @@ pub fn (n &PsiElementImpl) parent_of_any_type(types ...ts.NodeType) ?PsiElement return none } -pub fn (n &PsiElementImpl) inside(typ ts.NodeType) bool { +pub fn (n &PsiElementImpl) inside(typ api.NodeType) bool { mut res := PsiElement(n) for { res = res.parent() or { return false } @@ -196,7 +196,7 @@ pub fn (n &PsiElementImpl) is_parent_of(element PsiElement) bool { return false } -pub fn (n &PsiElementImpl) sibling_of_type_backward(typ ts.NodeType) ?PsiElement { +pub fn (n &PsiElementImpl) sibling_of_type_backward(typ api.NodeType) ?PsiElement { mut res := PsiElement(n) for { res = res.prev_sibling_or_stub()? @@ -208,7 +208,7 @@ pub fn (n &PsiElementImpl) sibling_of_type_backward(typ ts.NodeType) ?PsiElement return none } -pub fn (n &PsiElementImpl) parent_of_type_or_self(typ ts.NodeType) ?PsiElement { +pub fn (n &PsiElementImpl) parent_of_type_or_self(typ api.NodeType) ?PsiElement { if n.node.type_name == typ { return create_element(n.node, n.containing_file) } @@ -311,7 +311,7 @@ pub fn (n &PsiElementImpl) prev_sibling() ?PsiElement { return create_element(sibling, n.containing_file) } -pub fn (n &PsiElementImpl) prev_sibling_of_type(typ ts.NodeType) ?PsiElement { +pub fn (n &PsiElementImpl) prev_sibling_of_type(typ api.NodeType) ?PsiElement { mut res := PsiElement(n) for { res = res.prev_sibling_or_stub()? @@ -335,12 +335,12 @@ pub fn (n &PsiElementImpl) prev_sibling_or_stub() ?PsiElement { return n.prev_sibling() } -pub fn (n &PsiElementImpl) find_child_by_type(typ ts.NodeType) ?PsiElement { +pub fn (n &PsiElementImpl) find_child_by_type(typ api.NodeType) ?PsiElement { ast_node := n.node.first_node_by_type(typ)? return create_element(ast_node, n.containing_file) } -pub fn (n &PsiElementImpl) has_child_of_type(typ ts.NodeType) bool { +pub fn (n &PsiElementImpl) has_child_of_type(typ api.NodeType) bool { if stub := n.get_stub() { return stub.has_child_of_type(node_type_to_stub_type(typ)) } @@ -352,7 +352,7 @@ pub fn (n &PsiElementImpl) has_child_of_type(typ ts.NodeType) bool { return false } -pub fn (n &PsiElementImpl) find_child_by_type_or_stub(typ ts.NodeType) ?PsiElement { +pub fn (n &PsiElementImpl) find_child_by_type_or_stub(typ api.NodeType) ?PsiElement { if stub := n.get_stub() { child := stub.get_child_by_type(node_type_to_stub_type(typ))? return child.get_psi() @@ -367,7 +367,7 @@ pub fn (n &PsiElementImpl) find_child_by_name(name string) ?PsiElement { return create_element(ast_node, n.containing_file) } -pub fn (n &PsiElementImpl) find_children_by_type(typ ts.NodeType) []PsiElement { +pub fn (n &PsiElementImpl) find_children_by_type(typ api.NodeType) []PsiElement { mut result := []PsiElement{} mut child := n.node.first_child() or { return [] } for { @@ -379,7 +379,7 @@ pub fn (n &PsiElementImpl) find_children_by_type(typ ts.NodeType) []PsiElement { return result } -pub fn (n &PsiElementImpl) find_children_by_type_or_stub(typ ts.NodeType) []PsiElement { +pub fn (n &PsiElementImpl) find_children_by_type_or_stub(typ api.NodeType) []PsiElement { if stub := n.get_stub() { return stub.get_children_by_type(node_type_to_stub_type(typ)).get_psi() } @@ -395,7 +395,7 @@ pub fn (n &PsiElementImpl) find_children_by_type_or_stub(typ ts.NodeType) []PsiE return result } -pub fn (n &PsiElementImpl) find_last_child_by_type(typ ts.NodeType) ?PsiElement { +pub fn (n &PsiElementImpl) find_last_child_by_type(typ api.NodeType) ?PsiElement { ast_node := n.node.last_node_by_type(typ)? return create_element(ast_node, n.containing_file) } diff --git a/analyzer/psi/PsiFile.v b/analyzer/psi/PsiFile.v index aa734fa6..6e16680a 100644 --- a/analyzer/psi/PsiFile.v +++ b/analyzer/psi/PsiFile.v @@ -4,8 +4,8 @@ import lsp import time import utils import loglib -import tree_sitter as ts import analyzer.parser +import tree_sitter_v_api as api @[heap] pub struct PsiFile { @@ -13,12 +13,12 @@ pub: path string stub_list &StubList = unsafe { nil } pub mut: - tree &ts.Tree[ts.NodeType] = unsafe { nil } + tree &api.Tree[api.NodeType] = unsafe { nil } source_text string root PsiElement } -pub fn new_psi_file(path string, tree &ts.Tree[ts.NodeType], source_text string) &PsiFile { +pub fn new_psi_file(path string, tree &api.Tree[api.NodeType], source_text string) &PsiFile { mut file := &PsiFile{ path: path tree: unsafe { tree } diff --git a/analyzer/psi/PsiNamedElement.v b/analyzer/psi/PsiNamedElement.v index 9f902cea..43bab031 100644 --- a/analyzer/psi/PsiNamedElement.v +++ b/analyzer/psi/PsiNamedElement.v @@ -1,9 +1,9 @@ module psi -import tree_sitter as ts +import tree_sitter_v_api as api pub interface PsiNamedElement { - parent_of_type(typ ts.NodeType) ?PsiElement + parent_of_type(typ api.NodeType) ?PsiElement identifier_text_range() TextRange identifier() ?PsiElement name() string diff --git a/analyzer/psi/StubBase.v b/analyzer/psi/StubBase.v index defa9864..95e2dd2e 100644 --- a/analyzer/psi/StubBase.v +++ b/analyzer/psi/StubBase.v @@ -1,6 +1,6 @@ module psi -import tree_sitter as ts +import tree_sitter_v_api as api pub type StubId = int @@ -74,7 +74,7 @@ pub fn (s &StubBase) stub_type() StubType { return s.stub_type } -pub fn (s &StubBase) element_type() ts.NodeType { +pub fn (s &StubBase) element_type() api.NodeType { return match s.stub_type { .root { .unknown } .function_declaration { .function_declaration } diff --git a/analyzer/psi/StubbedElementTypeImpl.v b/analyzer/psi/StubbedElementTypeImpl.v index bb13e5f5..2888a386 100644 --- a/analyzer/psi/StubbedElementTypeImpl.v +++ b/analyzer/psi/StubbedElementTypeImpl.v @@ -1,7 +1,7 @@ module psi import utils -import tree_sitter as ts +import tree_sitter_v_api as api pub enum StubType as u8 { root @@ -60,7 +60,7 @@ pub enum StubType as u8 { embedded_definition } -pub fn node_type_to_stub_type(typ ts.NodeType) StubType { +pub fn node_type_to_stub_type(typ api.NodeType) StubType { return match typ { .function_declaration { .function_declaration } .receiver { .receiver } diff --git a/analyzer/psi/TreeWalker.v b/analyzer/psi/TreeWalker.v index ecc63cd7..8ce3b85a 100644 --- a/analyzer/psi/TreeWalker.v +++ b/analyzer/psi/TreeWalker.v @@ -1,11 +1,11 @@ module psi -import tree_sitter as ts +import tree_sitter_v_api as api struct TreeWalker { mut: already_visited_children bool - cursor ts.TreeCursor[ts.NodeType] @[required] + cursor api.TreeCursor[api.NodeType] @[required] } pub fn (mut tw TreeWalker) next() ?AstNode { diff --git a/tree_sitter/core b/tree_sitter/core deleted file mode 160000 index 30fd71f5..00000000 --- a/tree_sitter/core +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 30fd71f5acbb8979b980e8df15cabd2ba5b70cca diff --git a/tree_sitter/bindings.h b/tree_sitter_v_api/bindings.h similarity index 100% rename from tree_sitter/bindings.h rename to tree_sitter_v_api/bindings.h diff --git a/tree_sitter/bindings.v b/tree_sitter_v_api/bindings.v similarity index 88% rename from tree_sitter/bindings.v rename to tree_sitter_v_api/bindings.v index a015f036..13e88ecf 100644 --- a/tree_sitter/bindings.v +++ b/tree_sitter_v_api/bindings.v @@ -1,9 +1,9 @@ -module tree_sitter +module tree_sitter_v_api import x.json2 import os -#flag -I @VMODROOT/tree_sitter +#flag -I @VMODROOT/tree_sitter_v_api #flag -I @VMODROOT/tree_sitter_v/src #flag @VMODROOT/tree_sitter_v/src/parser.c diff --git a/tree_sitter_v_api/core b/tree_sitter_v_api/core new file mode 160000 index 00000000..d569d0ea --- /dev/null +++ b/tree_sitter_v_api/core @@ -0,0 +1 @@ +Subproject commit d569d0ea6af7c937ee19b2ab1f0fb89bd0e79419 diff --git a/tree_sitter/examples/cursor.v b/tree_sitter_v_api/examples/cursor.v similarity index 80% rename from tree_sitter/examples/cursor.v rename to tree_sitter_v_api/examples/cursor.v index 8b1607c5..b21f1db9 100644 --- a/tree_sitter/examples/cursor.v +++ b/tree_sitter_v_api/examples/cursor.v @@ -1,10 +1,10 @@ module main -import tree_sitter as ts +import tree_sitter_v_api as api fn main() { - mut p := ts.new_parser[ts.NodeType](ts.type_factory) - p.set_language(ts.language) + mut p := api.new_parser[api.NodeType](api.type_factory) + p.set_language(api.language) code := ' fn foo() int { diff --git a/tree_sitter/examples/simple.v b/tree_sitter_v_api/examples/simple.v similarity index 77% rename from tree_sitter/examples/simple.v rename to tree_sitter_v_api/examples/simple.v index fa6401a5..233a4520 100644 --- a/tree_sitter/examples/simple.v +++ b/tree_sitter_v_api/examples/simple.v @@ -1,10 +1,10 @@ module main -import tree_sitter as ts +import tree_sitter_v_api as api fn main() { - mut p := ts.new_parser[ts.NodeType](ts.type_factory) - p.set_language(ts.language) + mut p := api.new_parser[api.NodeType](api.type_factory) + p.set_language(api.language) code := 'fn main() {}' tree := p.parse_string(source: code) diff --git a/tree_sitter/examples/with_old_tree.v b/tree_sitter_v_api/examples/with_old_tree.v similarity index 80% rename from tree_sitter/examples/with_old_tree.v rename to tree_sitter_v_api/examples/with_old_tree.v index ecf70adf..dffd4dd8 100644 --- a/tree_sitter/examples/with_old_tree.v +++ b/tree_sitter_v_api/examples/with_old_tree.v @@ -1,11 +1,11 @@ module main import time -import tree_sitter as ts +import tree_sitter_v_api as api fn main() { - mut p := ts.new_parser[ts.NodeType](ts.type_factory) - p.set_language(ts.language) + mut p := api.new_parser[api.NodeType](api.type_factory) + p.set_language(api.language) code := ' fn foo() int { diff --git a/tree_sitter/generate_types.vsh b/tree_sitter_v_api/generate_types.vsh similarity index 97% rename from tree_sitter/generate_types.vsh rename to tree_sitter_v_api/generate_types.vsh index 6a3ac345..926d7a0a 100644 --- a/tree_sitter/generate_types.vsh +++ b/tree_sitter_v_api/generate_types.vsh @@ -70,7 +70,7 @@ mut supertype_node_groups := map[string][]string{} sb.writeln('// This is an AUTO-GENERATED file. DO NOT EDIT this file directly! See `generate_types.vsh`') -sb.writeln('module tree_sitter') +sb.writeln('module tree_sitter_v_api') sb.writeln('\n') sb.writeln('import arrays { merge }') @@ -170,7 +170,7 @@ sb.writeln('\n') sb.writeln('pub struct ${node_type_factory_sym_name} {}') sb.writeln('\n') sb.writeln('pub fn (nf ${node_type_factory_sym_name}) get_type(type_name string) ${node_type_enum_name} {') -sb.writeln(' return tree_sitter.node_type_name_to_enum[type_name] or { NodeType.unknown }') +sb.writeln(' return tree_sitter_v_api.node_type_name_to_enum[type_name] or { NodeType.unknown }') sb.writeln('}') sb.writeln('\n') sb.writeln('const node_type_name_to_enum = {') diff --git a/tree_sitter/node_types.v b/tree_sitter_v_api/node_types.v similarity index 97% rename from tree_sitter/node_types.v rename to tree_sitter_v_api/node_types.v index 8732ec5a..9546a0c0 100644 --- a/tree_sitter/node_types.v +++ b/tree_sitter_v_api/node_types.v @@ -1,5 +1,5 @@ // This is an AUTO-GENERATED file. DO NOT EDIT this file directly! See `generate_types.vsh` -module tree_sitter +module tree_sitter_v_api import arrays { merge } @@ -259,11 +259,11 @@ const supertype__top_level_declaration_nodes = [ ] pub fn (typ NodeType) group() SuperType { - return if typ in tree_sitter.supertype__top_level_declaration_nodes { + return if typ in tree_sitter_v_api.supertype__top_level_declaration_nodes { SuperType.top_level_declaration - } else if typ in tree_sitter.supertype__expression_nodes { + } else if typ in tree_sitter_v_api.supertype__expression_nodes { SuperType.expression - } else if typ in tree_sitter.supertype__statement_nodes { + } else if typ in tree_sitter_v_api.supertype__statement_nodes { SuperType.statement } else { SuperType.unknown @@ -303,15 +303,15 @@ const literal_node_types = [ ] pub fn (typ NodeType) is_declaration() bool { - return typ in tree_sitter.declaration_node_types + return typ in tree_sitter_v_api.declaration_node_types } pub fn (typ NodeType) is_identifier() bool { - return typ in tree_sitter.identifier_node_types + return typ in tree_sitter_v_api.identifier_node_types } pub fn (typ NodeType) is_literal() bool { - return typ in tree_sitter.literal_node_types + return typ in tree_sitter_v_api.literal_node_types } pub const type_factory = &VNodeTypeFactory{} @@ -319,7 +319,7 @@ pub const type_factory = &VNodeTypeFactory{} pub struct VNodeTypeFactory {} pub fn (nf VNodeTypeFactory) get_type(type_name string) NodeType { - return tree_sitter.node_type_name_to_enum[type_name] or { NodeType.unknown } + return tree_sitter_v_api.node_type_name_to_enum[type_name] or { NodeType.unknown } } const node_type_name_to_enum = { diff --git a/tree_sitter/simple_test.v b/tree_sitter_v_api/simple_test.v similarity index 83% rename from tree_sitter/simple_test.v rename to tree_sitter_v_api/simple_test.v index b2981080..274db695 100644 --- a/tree_sitter/simple_test.v +++ b/tree_sitter_v_api/simple_test.v @@ -1,8 +1,8 @@ -import tree_sitter as ts +import tree_sitter_v_api as api fn test_simple() { - mut p := ts.new_parser[ts.NodeType](ts.type_factory) - p.set_language(ts.language) + mut p := api.new_parser[api.NodeType](api.type_factory) + p.set_language(api.language) code := 'fn main() {}' tree := p.parse_string(source: code) diff --git a/tree_sitter/tools/project-checker.v b/tree_sitter_v_api/tools/project-checker.v similarity index 97% rename from tree_sitter/tools/project-checker.v rename to tree_sitter_v_api/tools/project-checker.v index 669f4c45..a2396a11 100644 --- a/tree_sitter/tools/project-checker.v +++ b/tree_sitter_v_api/tools/project-checker.v @@ -6,7 +6,7 @@ import sync import os import time import analyzer.parser -import tree_sitter as ts +import tree_sitter_v_api as api fn main() { mut checker := Checker{ @@ -15,7 +15,7 @@ fn main() { checker.check() } -pub type AstNode = ts.Node[ts.NodeType] +pub type AstNode = api.Node[api.NodeType] struct ErrorInfo { path string diff --git a/tree_sitter/tree_sitter.c.v b/tree_sitter_v_api/tree_sitter.c.v similarity index 97% rename from tree_sitter/tree_sitter.c.v rename to tree_sitter_v_api/tree_sitter.c.v index d691144f..abc65d8b 100644 --- a/tree_sitter/tree_sitter.c.v +++ b/tree_sitter_v_api/tree_sitter.c.v @@ -1,15 +1,14 @@ -module tree_sitter +module tree_sitter_v_api // This file contains the bindings for C API of tree-sitter. -// They are not indented to be used directly, but rather to be used by the -// wrapper from "tree_sitter.v". +// They are indented to be used by wrapper functions in "tree_sitter.v". // -// See the header file "./lib/api.h" for comments for functions and structures. +// See "core/lib/include/tree_sitter/api.h" for function references. // We directly build "lib.c" rather using the static library. -#flag -I @VMODROOT/tree_sitter/core/lib/include -#flag -I @VMODROOT/tree_sitter/core/lib/src -#flag @VMODROOT/tree_sitter/core/lib/src/lib.c +#flag -I @VMODROOT/tree_sitter_v_api/core/lib/include +#flag -I @VMODROOT/tree_sitter_v_api/core/lib/src +#flag @VMODROOT/tree_sitter_v_api/core/lib/src/lib.c #include "tree_sitter/api.h" pub enum TSVInputEncoding { diff --git a/tree_sitter/tree_sitter.v b/tree_sitter_v_api/tree_sitter.v similarity index 99% rename from tree_sitter/tree_sitter.v rename to tree_sitter_v_api/tree_sitter.v index 26691de9..b5afba02 100644 --- a/tree_sitter/tree_sitter.v +++ b/tree_sitter_v_api/tree_sitter.v @@ -1,4 +1,4 @@ -module tree_sitter +module tree_sitter_v_api pub type TSParser = C.TSParser pub type TSLanguage = C.TSLanguage