Skip to content

Commit 0960480

Browse files
authored
Merge pull request #338 from julia-vscode/sp/fix-grab-bag
A bunch of fixes
2 parents 426cc2c + fc282a4 commit 0960480

File tree

14 files changed

+552
-168
lines changed

14 files changed

+552
-168
lines changed

src/components/internals.jl

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ end
109109
Parses a function call. Expects to start before the opening parentheses and is passed the expression declaring the function name, `ret`.
110110
"""
111111
function parse_call(ps::ParseState, ret::EXPR, ismacro=false)
112-
if is_minus(ret) || is_not(ret)
112+
if is_minus(ret) || is_not(ret) || is_approx(ret)
113113
arg = @closer ps :unary @closer ps :inwhere @precedence ps PowerOp parse_expression(ps)
114114
if istuple(arg)
115115
pushfirst!(arg.args, ret)
@@ -355,6 +355,17 @@ function get_appropriate_child_to_expand(x)
355355
end
356356
end
357357

358+
is_nonstd_identifier(ps) = VERSION > v"1.3.0-" && isidentifier(ps.nt) && isemptyws(ps.nws) && (kindof(ps.nnt) === Tokens.STRING || kindof(ps.nnt) === Tokens.TRIPLE_STRING)
359+
360+
function parse_nonstd_identifier(ps)
361+
id = INSTANCE(next(ps))
362+
if valof(id) == "var"
363+
EXPR(:NONSTDIDENTIFIER, EXPR[id, INSTANCE(next(ps))])
364+
else
365+
mErrorToken(ps, EXPR(:NONSTDIDENTIFIER, EXPR[id, INSTANCE(next(ps))]), UnexpectedToken)
366+
end
367+
end
368+
358369
function parse_importexport_item(ps, is_colon = false)
359370
if kindof(ps.nt) === Tokens.AT_SIGN
360371
parse_macroname(next(ps))
@@ -368,21 +379,16 @@ function parse_importexport_item(ps, is_colon = false)
368379
elseif !is_colon && isoperator(ps.nt)
369380
next(ps)
370381
EXPR(:OPERATOR, ps.nt.startbyte - ps.t.startbyte, 1 + ps.t.endbyte - ps.t.startbyte, val(ps.t, ps))
371-
elseif VERSION > v"1.3.0-" && isidentifier(ps.nt) && isemptyws(ps.nws) && (kindof(ps.nnt) === Tokens.STRING || kindof(ps.nnt) === Tokens.TRIPLE_STRING)
372-
id = INSTANCE(next(ps))
373-
if valof(id) == "var"
374-
EXPR(:NONSTDIDENTIFIER, EXPR[id, INSTANCE(next(ps))])
375-
else
376-
mErrorToken(ps, EXPR(:NONSTDIDENTIFIER, EXPR[id, INSTANCE(next(ps))]), UnexpectedToken)
377-
end
382+
elseif is_nonstd_identifier(ps)
383+
parse_nonstd_identifier(ps)
378384
else
379385
INSTANCE(next(ps))
380386
end
381387
end
382388
"""
383389
Helper function for parsing import/using statements.
384390
"""
385-
function parse_dot_mod(ps::ParseState, is_colon = false, allow_as = false)
391+
function parse_dot_mod(ps::ParseState, is_colon=false, allow_as=false)
386392
ret = EXPR(EXPR(:OPERATOR, 0, 0, "."), EXPR[], EXPR[])
387393

388394
prevpos = position(ps)
@@ -408,6 +414,11 @@ function parse_dot_mod(ps::ParseState, is_colon = false, allow_as = false)
408414

409415
if kindof(ps.nt) === Tokens.DOT
410416
pushtotrivia!(ret, EXPR(next(ps)))
417+
if kindof(ps.nt) === Tokens.COLON
418+
u = parse_unary_colon(ps, EXPR(:IDENTIFIER, next(ps)))
419+
push!(ret, u)
420+
return ret
421+
end
411422
elseif isoperator(ps.nt) && (ps.nt.dotop || kindof(ps.nt) === Tokens.DOT)
412423
pushtotrivia!(ret, EXPR(:DOT, 1, 1))
413424
ps.nt = RawToken(kindof(ps.nt), ps.nt.startpos, ps.nt.endpos, ps.nt.startbyte + 1, ps.nt.endbyte, ps.nt.token_error, false, ps.nt.suffix)

src/components/keywords.jl

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function parse_kw(ps::ParseState; allow_const_field = false)
7575
elseif k === Tokens.TYPE
7676
return EXPR(:IDENTIFIER, ps)
7777
elseif k === Tokens.STRUCT
78-
return @default ps @closer ps :block parse_blockexpr(ps, :struct)
78+
return @default ps @closer ps :block parse_blockexpr(ps, :struct, allow_const_field = true)
7979
elseif k === Tokens.MUTABLE
8080
return @default ps @closer ps :block parse_mutable(ps)
8181
elseif k === Tokens.OUTER
@@ -246,7 +246,7 @@ function parse_blockexpr_sig(ps::ParseState, head)
246246
if isendoflinews(ps.ws)
247247
return EXPR(:block, EXPR[], nothing)
248248
else
249-
arg = @closer ps :comma @closer ps :ws parse_expression(ps)
249+
arg = @closer ps :comma @closer ps :ws parse_expression(ps)
250250
if iscomma(ps.nt) || !(is_wrapped_assignment(arg) || isidentifier(arg))
251251
arg = EXPR(:block, EXPR[arg])
252252
prevpos = position(ps)
@@ -273,15 +273,23 @@ function parse_blockexpr_sig(ps::ParseState, head)
273273
end
274274
return EXPR(:tuple, args, trivia)
275275
elseif head === :module || head === :baremodule
276-
return isidentifier(ps.nt) ? EXPR(:IDENTIFIER, next(ps)) :
276+
return if isidentifier(ps.nt)
277+
if is_nonstd_identifier(ps)
278+
parse_nonstd_identifier(ps)
279+
else
280+
EXPR(:IDENTIFIER, next(ps))
281+
end
282+
else
277283
@precedence ps 15 @closer ps :ws parse_expression(ps)
284+
end
278285
end
279286
return nothing
280287
end
281288

282289
function parse_do(ps::ParseState, pre::EXPR)
283290
args, trivia = EXPR[pre], EXPR[EXPR(next(ps))]
284291
args1, trivia1 = EXPR[], EXPR[]
292+
285293
@closer ps :comma @closer ps :block while !closer(ps)
286294
push!(args1, @closer ps :ws a = parse_expression(ps))
287295
if kindof(ps.nt) === Tokens.COMMA
@@ -370,7 +378,7 @@ function parse_try(ps::ParseState)
370378
kw = EXPR(ps)
371379
args = EXPR[]
372380
trivia = EXPR[kw]
373-
tryblockargs = parse_block(ps, EXPR[], (Tokens.END, Tokens.CATCH, Tokens.FINALLY))
381+
tryblockargs = parse_block(ps, EXPR[], (Tokens.END, Tokens.CATCH, Tokens.ELSE, Tokens.FINALLY))
374382
push!(args, EXPR(:block, tryblockargs, nothing))
375383

376384
# catch block
@@ -387,7 +395,7 @@ function parse_try(ps::ParseState)
387395
caught = @closer ps :ws parse_expression(ps)
388396
end
389397

390-
catchblockargs = parse_block(ps, EXPR[], (Tokens.END, Tokens.FINALLY))
398+
catchblockargs = parse_block(ps, EXPR[], (Tokens.END, Tokens.FINALLY, Tokens.ELSE))
391399
if !(is_either_id_op_interp(caught) || headof(caught) === :FALSE)
392400
pushfirst!(catchblockargs, caught)
393401
caught = EXPR(:FALSE, 0, 0, "")
@@ -402,14 +410,33 @@ function parse_try(ps::ParseState)
402410
push!(args, caught)
403411
push!(args, catchblock)
404412

405-
# finally block
406-
if kindof(ps.nt) === Tokens.FINALLY
413+
else_trivia = else_arg = nothing
414+
# else block
415+
if kindof(ps.nt) === Tokens.ELSE
407416
if isempty(catchblock.args)
417+
args[3] = EXPR(:block, 0, 0, "")
418+
end
419+
else_trivia = EXPR(next(ps))
420+
else_arg = EXPR(:block, parse_block(ps, EXPR[], (Tokens.FINALLY,Tokens.END)))
421+
end
422+
423+
has_finally = false
424+
if kindof(ps.nt) === Tokens.FINALLY
425+
has_finally = true
426+
if isempty(catchblock.args) && else_trivia === nothing
408427
args[3] = EXPR(:FALSE, 0, 0, "")
409428
end
410429
push!(trivia, EXPR(next(ps)))
411-
finallyblockargs = parse_block(ps)
412-
push!(args, EXPR(:block, finallyblockargs))
430+
push!(args, EXPR(:block, parse_block(ps)))
431+
end
432+
433+
if else_trivia !== nothing
434+
if !has_finally
435+
push!(trivia, EXPR(:FALSE, 0, 0, ""))
436+
push!(args, EXPR(:FALSE, 0, 0, ""))
437+
end
438+
push!(trivia, else_trivia)
439+
push!(args, else_arg)
413440
end
414441

415442
push!(trivia, accept_end(ps))

0 commit comments

Comments
 (0)