WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 2ec05d5

Browse files
authored
Allow K"error" when parsing to SyntaxTree (JuliaLang#60327)
I had assumed a valid parse since parse errors would detonate in lowering anyway, but that was wrong: JETLS uses `ignore_errors=true` in parsing to SyntaxTree. I plan to make some larger changes where I'll make sure `RawGreenNode->SyntaxTree` is more thoroughly tested, but this is a quick fix to get JETLS working.
1 parent 3a274d5 commit 2ec05d5

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

JuliaLowering/src/syntax_graph.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -877,12 +877,10 @@ function _green_to_ast(parent::Kind, ex::SyntaxTree; eq_to_kw=false)
877877
makenode(graph, ex, ex, _map_green_to_ast(k, children(ex); eq_to_kw))
878878
elseif k === K"parens"
879879
cs = _map_green_to_ast(parent, children(ex); eq_to_kw)
880-
@assert length(cs) === 1
881-
cs[1]
880+
length(cs) === 1 ? cs[1] : makenode(graph, ex, ex, cs)
882881
elseif k in KSet"var char"
883882
cs = _map_green_to_ast(parent, children(ex))
884-
@assert length(cs) === 1
885-
cs[1]
883+
length(cs) === 1 ? cs[1] : makenode(graph, ex, ex, cs)
886884
elseif k === K"=" && eq_to_kw
887885
setattr!(makenode(graph, ex, ex, _map_green_to_ast(k, children(ex))),
888886
:kind, K"kw")
@@ -894,8 +892,11 @@ function _green_to_ast(parent::Kind, ex::SyntaxTree; eq_to_kw=false)
894892
# M.@x parses to (. M (macro_name x))
895893
# @M.x parses to (macro_name (. M x))
896894
# We want (. M @x) (both identifiers) in either case
897-
@assert numchildren(ex) === 2 && kind(ex[1]) === K"@"
898-
id = ex[2]
895+
cs = _map_green_to_ast(k, children(ex))
896+
if length(cs) !== 1 || !(kind(cs[1]) in KSet". Identifier")
897+
return makenode(graph, ex, ex, cs)
898+
end
899+
id = cs[1]
899900
mname_raw = (kind(id) === K"." ? id[2] : id).name_val
900901
mac_id = setattr!(makeleaf(graph, ex, K"Identifier"), :name_val,
901902
lower_identifier_name(mname_raw, K"macro_name"))

JuliaLowering/test/syntax_graph.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ end
4545
@test Expr(parsestmt(SyntaxTree, "begin a + b ; c end", filename="none")) ==
4646
Meta.parse("begin a + b ; c end")
4747

48+
# Parsing to SyntaxTree: errors should fall through
49+
@test parsestmt(SyntaxTree, "@"; ignore_errors=true) isa SyntaxTree
50+
@test parsestmt(SyntaxTree, "@@@"; ignore_errors=true) isa SyntaxTree
51+
@test parsestmt(SyntaxTree, "(a b c)"; ignore_errors=true) isa SyntaxTree
52+
@test parsestmt(SyntaxTree, "'a b c'"; ignore_errors=true) isa SyntaxTree
53+
54+
# @SyntaxTree
4855
tree1 = JuliaLowering.@SyntaxTree :(some_unique_identifier)
4956
@test tree1 isa SyntaxTree
5057
@test kind(tree1) == K"Identifier"

0 commit comments

Comments
 (0)