237237function _fl_parse_hook (code, filename, lineno, offset, options)
238238 @static if VERSION >= v " 1.8.0-DEV.1370" # https://github.com/JuliaLang/julia/pull/43876
239239 return Core. Compiler. fl_parse (code, filename, lineno, offset, options)
240- else
240+ elseif VERSION >= v " 1.6 "
241241 return Core. Compiler. fl_parse (code, filename, offset, options)
242+ else
243+ if options === :all
244+ ex = Base. parse_input_line (String (code), filename= filename, depwarn= false )
245+ if ! Meta. isexpr (ex, :toplevel )
246+ ex = Expr (:toplevel , ex)
247+ end
248+ return ex, sizeof (code)
249+ elseif options === :statement || options == :atom
250+ ex, pos = Meta. parse (code, offset+ 1 , greedy= options== :statement , raise= false )
251+ return ex, pos- 1
252+ else
253+ error (" Unknown parse options $options " )
254+ end
242255 end
243256end
244257
248261# FIXME : Improve this in Base somehow?
249262Base. Meta. ParseError (e:: JuliaSyntax.ParseError ) = e
250263
251- const _default_parser = Core. _parse
264+ const _default_parser = VERSION < v " 1.6 " ? nothing : Core. _parse
252265
253266"""
254267 enable_in_core!([enable=true; freeze_world_age, debug_filename])
@@ -266,6 +279,9 @@ Keyword arguments:
266279"""
267280function enable_in_core! (enable= true ; freeze_world_age = true ,
268281 debug_filename = get (ENV , " JULIA_SYNTAX_DEBUG_FILE" , nothing ))
282+ if VERSION < v " 1.6"
283+ error (" Cannot use JuliaSyntax as the main Julia parser in Julia version $VERSION < 1.6" )
284+ end
269285 _parser_world_age[] = freeze_world_age ? Base. get_world_counter () : _latest_world
270286 if enable && ! isnothing (debug_filename)
271287 _debug_log[] = open (debug_filename, " w" )
0 commit comments