MCPcopy Create free account
hub / github.com/FSoft-AI4Code/CodeText-parser / match_from_spans

Function match_from_spans

src/codetext/parser/language_parser.py:172–204  ·  view source on GitHub ↗

Get text from multiple note Args: nodes (List): List of `tree_sitter.Node` blob (str): Full source Return: str: combined text of list node

(nodes, blob: str)

Source from the content-addressed store, hash-verified

170
171
172def match_from_spans(nodes, blob: str) -> str:
173 """
174 Get text from multiple note
175
176 Args:
177 nodes (List): List of `tree_sitter.Node`
178 blob (str): Full source
179
180 Return:
181 str: combined text of list node
182 """
183 assert len(nodes) != 0, "Empty node list"
184 start_point = nodes[0]
185 end_point = nodes[0]
186
187 for node in nodes:
188 if node.start_point[0] < start_point.start_point[0]:
189 start_point = node
190 elif node.end_point[0] > end_point.end_point[0]:
191 end_point = node
192
193 line_start = start_point.start_point[0]
194 char_start = start_point.start_point[1]
195 line_end = end_point.end_point[0]
196 char_end = end_point.end_point[1]
197
198 lines = blob.split('\n')
199 if line_start != line_end:
200 string = '\n'.join([lines[line_start][char_start:]] + lines[line_start+1:line_end] + [lines[line_end][:char_end]])
201 else:
202 string = lines[line_start][char_start:char_end]
203
204 return string, start_point, end_point
205
206
207class LanguageParser(ABC):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected