2929# next if the incomplete stream was to continue. (Though this is just rough. In
3030# practice several categories are combined for the purposes of the REPL -
3131# perhaps we can/should do something more precise in the future.)
32- function _incomplete_tag (n:: SyntaxNode )
32+ function _incomplete_tag (n:: SyntaxNode , codelen )
3333 i,c = _first_error (n)
34- if isnothing (c)
34+ if isnothing (c) || last_byte (c) < codelen || codelen == 0
3535 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
3644 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
4146 cs = children (c)
4247 length (cs) > 0
4348 end
@@ -71,10 +76,8 @@ function _incomplete_tag(n::SyntaxNode)
7176end
7277
7378# -------------------------------------------------------------------------------
74- @static if isdefined (Core, :_setparser! )
79+ if isdefined (Core, :_setparser! )
7580 const _set_core_parse_hook = Core. _setparser!
76- elseif isdefined (Core, :set_parser )
77- const _set_core_parse_hook = Core. set_parser
7881else
7982 function _set_core_parse_hook (parser)
8083 # 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
164167 if any_error (stream)
165168 tree = build_tree (SyntaxNode, stream,
166169 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
173172 # Here we replicate the particular messages
174173 msg =
175174 tag === :string ? " incomplete: invalid string syntax" :
@@ -180,6 +179,9 @@ function _core_parser_hook(code, filename::String, lineno::Int, offset::Int, opt
180179 " incomplete: premature end of input"
181180 error_ex = Expr (:incomplete , msg)
182181 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.
183185 error_ex = Expr (:error , ParseError (stream, filename= filename, first_line= lineno))
184186 end
185187 ex = options === :all ? Expr (:toplevel , error_ex) : error_ex
0 commit comments