@@ -150,19 +150,24 @@ struct ParseError <: Exception
150150end
151151
152152function _jl_parse (text:: AbstractString , filename:: AbstractString ,
153- pos:: Integer , rule :: Integer )
153+ pos:: Integer ; options ... )
154154 if pos < 1 || pos > ncodeunits (text) + 1
155155 throw (BoundsError (text, pos))
156156 end
157- # Technically only need pointers to UTF-8 buffers here. For now converting
158- # to a plain String is the easy way to ensure that.
157+ # Technically only need pointers to UTF-8 buffers here. Converting to a
158+ # plain String is the easy way to ensure that.
159159 filename = String (filename)
160160 text = String (text)
161+ options = values (options)
162+ if length (options) == 1 && haskey (options, :rule )
163+ # Hack: Pass rule as a symbol for benefit of jl_fl_parse
164+ options = options. rule
165+ end
161166 # Call into the parser which can be replaced globally during bootstrap with
162167 # jl_set_parser
163168 ex,pos = ccall (:jl_parse , Any,
164- (Ptr{UInt8}, Csize_t, Ptr{UInt8}, Csize_t, Csize_t, Cint ),
165- text, sizeof (text), filename, sizeof (filename), pos- 1 , rule )
169+ (Ptr{UInt8}, Csize_t, Ptr{UInt8}, Csize_t, Csize_t, Any ),
170+ text, sizeof (text), filename, sizeof (filename), pos- 1 , options )
166171 # internally, pos is a zero-based byte offset - convert back.
167172 ex, pos+ 1
168173end
@@ -190,12 +195,7 @@ julia> Meta.parse("x = 3, y = 5", 5)
190195function parse (str:: AbstractString , pos:: Integer ; greedy:: Bool = true , raise:: Bool = true ,
191196 depwarn:: Bool = true )
192197 filename = " none"
193- JL_PARSE_ATOM = 1
194- JL_PARSE_STATEMENT = 2
195- rule = greedy ? JL_PARSE_STATEMENT : JL_PARSE_ATOM
196- # For now, assume all parser warnings are depwarns
197- # TODO : remove parser-depwarn; parser no longer emits warnings.
198- ex, pos = _jl_parse (str, " none" , pos, rule)
198+ ex, pos = _jl_parse (str, " none" , pos; rule= greedy ? :statement : :atom )
199199 if raise && isa (ex,Expr) && ex. head === :error
200200 throw (ParseError (ex. args[1 ]))
201201 end
@@ -240,13 +240,11 @@ function parse(str::AbstractString; raise::Bool=true, depwarn::Bool=true)
240240end
241241
242242function parseatom (text:: AbstractString , pos:: Integer ; filename= " none" )
243- JL_PARSE_ATOM = 1
244- return _jl_parse (text, filename, pos, JL_PARSE_ATOM)
243+ return _jl_parse (text, filename, pos; rule= :atom )
245244end
246245
247246function parseall (text:: AbstractString ; filename= " none" )
248- JL_PARSE_ALL = 3
249- ex,_ = _jl_parse (text, filename, 1 , JL_PARSE_ALL)
247+ ex,_ = _jl_parse (text, filename, 1 ; rule= :all )
250248 return ex
251249end
252250
0 commit comments