From 997357d5b1ba4196e4025f4793d27331c0dce0de Mon Sep 17 00:00:00 2001 From: Ned Palacios Date: Sun, 10 Sep 2023 15:56:00 +0800 Subject: [PATCH] todo 2. --- context.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/context.go b/context.go index 99f46ce..9bb674c 100644 --- a/context.go +++ b/context.go @@ -1,5 +1,7 @@ package errgoengine +import sitter "github.com/smacker/go-tree-sitter" + type MainError struct { ErrorNode *StackTraceEntry Document *Document @@ -48,3 +50,34 @@ func (data *ContextData) AddVariable(name string, value string) { data.Variables[name] = value } + +func getNearestNodeWithSymbol(data *ContextData, rootNode SyntaxNode, sym Symbol) SyntaxNode { + cursor := sitter.NewTreeCursor(rootNode.Node) + cursor.GoToFirstChild() + + defer cursor.Close() + + for { + if n := cursor.CurrentNode(); n.IsNamed() { + wrappedNode := WrapNode(rootNode.Doc, n) + gotSym := data.Analyzer.AnalyzeNode(wrappedNode) + if gotSym == sym { + return wrappedNode + } else if n.NamedChildCount() != 0 { + gotNode := getNearestNodeWithSymbol(data, wrappedNode, sym) + if gotNode == nil { + // TODO: + } + } + } + + if !cursor.GoToNextSibling() { + break + } + } +} + +func NearestNodeWithSymbol(data *ContextData, rootNode SyntaxNode, sym Symbol, callback func(*sitter.QueryMatch, *sitter.Query) bool) { + + queryStr := "" +}