Skip to content

Commit fbd9337

Browse files
committed
make minimal_reparse more robust
when the new CST contains errors
1 parent 1d76214 commit fbd9337

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/utils.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,16 @@ end
314314

315315
function minimal_reparse(s0, s1, x0 = CSTParser.parse(s0, true), x1 = CSTParser.parse(s1, true); inds = false)
316316
if sizeof(s0) !== x0.fullspan
317-
error("minimal reparse - input text length doesn't match the full span of the provided CST.")
317+
error("minimal reparse - original input text length doesn't match the full span of the provided CST.")
318318
# return inds ? (1:0, 1:length(x1.args), 1:0) : x1
319319
end
320+
321+
if has_error(x1)
322+
return inds ? (1:0, 1:length(x1.args), 1:0) : x1 # Error while re-parsing, so lets return the whole expression instead of patching
323+
end
324+
320325
if sizeof(s1) !== x1.fullspan
321-
error("minimal reparse - input text length doesn't match the full span of the provided CST.")
326+
error("minimal reparse - new input text length doesn't match the full span of the provided CST.")
322327
# return inds ? (1:0, 1:length(x1.args), 1:0) : x1
323328
end
324329
isempty(x0.args) && return inds ? (1:0, 1:length(x1.args), 1:0) : x1 # Original CST was empty

0 commit comments

Comments
 (0)