29
29
# next if the incomplete stream was to continue. (Though this is just rough. In
30
30
# practice several categories are combined for the purposes of the REPL -
31
31
# perhaps we can/should do something more precise in the future.)
32
- function _incomplete_tag (n:: SyntaxNode )
32
+ function _incomplete_tag (n:: SyntaxNode , codelen )
33
33
i,c = _first_error (n)
34
- if isnothing (c)
34
+ if isnothing (c) || last_byte (c) < codelen || codelen == 0
35
35
return :none
36
+ elseif first_byte (c) < codelen
37
+ if kind (c) == K " ErrorEofMultiComment" && last_byte (c) == codelen
38
+ # This is the one weird case where the token itself is an
39
+ # incomplete error
40
+ return :comment
41
+ else
42
+ return :none
43
+ end
36
44
end
37
- # TODO : Check error hits last character
38
- if kind (c) == K " ErrorEofMultiComment"
39
- return :comment
40
- elseif kind (c) == K " error" && begin
45
+ if kind (c) == K " error" && begin
41
46
cs = children (c)
42
47
length (cs) > 0
43
48
end
@@ -71,10 +76,8 @@ function _incomplete_tag(n::SyntaxNode)
71
76
end
72
77
73
78
# -------------------------------------------------------------------------------
74
- @static if isdefined (Core, :_setparser! )
79
+ if isdefined (Core, :_setparser! )
75
80
const _set_core_parse_hook = Core. _setparser!
76
- elseif isdefined (Core, :set_parser )
77
- const _set_core_parse_hook = Core. set_parser
78
81
else
79
82
function _set_core_parse_hook (parser)
80
83
# HACK! Fool the runtime into allowing us to set Core._parse, even during
@@ -164,12 +167,8 @@ function _core_parser_hook(code, filename::String, lineno::Int, offset::Int, opt
164
167
if any_error (stream)
165
168
tree = build_tree (SyntaxNode, stream,
166
169
wrap_toplevel_as_kind= K " None" , first_line= lineno)
167
- _,err = _first_error (tree)
168
- # In the flisp parser errors are normally `Expr(:error, msg)` where
169
- # `msg` is a String. By using a ParseError for msg we can do fancy
170
- # error reporting instead.
171
- if last_byte (err) == lastindex (code)
172
- tag = _incomplete_tag (tree)
170
+ tag = _incomplete_tag (tree, lastindex (code))
171
+ if tag != = :none
173
172
# Here we replicate the particular messages
174
173
msg =
175
174
tag === :string ? " incomplete: invalid string syntax" :
@@ -180,6 +179,9 @@ function _core_parser_hook(code, filename::String, lineno::Int, offset::Int, opt
180
179
" incomplete: premature end of input"
181
180
error_ex = Expr (:incomplete , msg)
182
181
else
182
+ # In the flisp parser errors are normally `Expr(:error, msg)` where
183
+ # `msg` is a String. By using a JuliaSyntax.ParseError for msg
184
+ # we can do fancy error reporting instead.
183
185
error_ex = Expr (:error , ParseError (stream, filename= filename, first_line= lineno))
184
186
end
185
187
ex = options === :all ? Expr (:toplevel , error_ex) : error_ex
0 commit comments