Skip to content

Commit 65d6523

Browse files
authored
Merge pull request #18 from c42f/caf/juliasyntax-dev-fixes
Remove use of JuliaSyntax `DOTOP_FLAG` and `is_dotted`
2 parents f4b6df3 + 3514388 commit 65d6523

File tree

6 files changed

+26
-31
lines changed

6 files changed

+26
-31
lines changed

.github/workflows/CI.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ jobs:
1919
fail-fast: false
2020
matrix:
2121
version:
22-
- '1.0'
23-
- '1.11'
2422
- 'nightly'
2523
os:
2624
- ubuntu-latest

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ This work is intended to
2929
Note this is a work in progress; many types of syntax are not yet handled.
3030

3131
1. You need a 1.13.0-DEV build of Julia: At least 1.13.0-DEV.880. Commit `5ebc5b463ea` is currently known to work. Note that JuliaLowering relies on Julia internals and may be broken on the latest Julia dev version from time to time.
32-
2. Use commit `46723f0` of [JuliaSyntax](https://github.com/JuliaLang/JuliaSyntax.jl)
32+
2. Use commit `e02f29f` of [JuliaSyntax](https://github.com/JuliaLang/JuliaSyntax.jl)
3333
3. Get the latest version of [JuliaSyntaxFormatter](https://github.com/c42f/JuliaSyntaxFormatter.jl)
3434
4. Run the demo `include("test/demo.jl")`
3535

src/JuliaLowering.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ using JuliaSyntax: highlight, Kind, @KSet_str
1313
using JuliaSyntax: is_leaf, children, numchildren, head, kind, flags, has_flags, numeric_flags
1414
using JuliaSyntax: filename, first_byte, last_byte, byte_range, sourcefile, source_location, span, sourcetext
1515

16-
using JuliaSyntax: is_literal, is_number, is_operator, is_prec_assignment, is_prefix_call, is_infix_op_call, is_postfix_op_call, is_error, is_dotted
16+
using JuliaSyntax: is_literal, is_number, is_operator, is_prec_assignment, is_prefix_call, is_infix_op_call, is_postfix_op_call, is_error
1717

1818
_include("kinds.jl")
1919
_register_kinds()

src/desugaring.jl

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -690,10 +690,10 @@ function expand_dotcall(ctx, ex)
690690
]
691691
elseif k == K"comparison"
692692
expand_dotcall(ctx, expand_compare_chain(ctx, ex))
693-
elseif (k == K"&&" || k == K"||") && is_dotted(ex)
693+
elseif k == K".&&" || k == K".||"
694694
@ast ctx ex [K"call"
695695
"broadcasted"::K"top"
696-
(k == K"&&" ? "andand" : "oror")::K"top"
696+
(k == K".&&" ? "andand" : "oror")::K"top"
697697
(expand_dotcall(ctx, arg) for arg in children(ex))...
698698
]
699699
else
@@ -702,8 +702,7 @@ function expand_dotcall(ctx, ex)
702702
end
703703

704704
function expand_fuse_broadcast(ctx, ex)
705-
if kind(ex) == K"="
706-
@assert is_dotted(ex)
705+
if kind(ex) == K".=" || kind(ex) == K".op="
707706
@chk numchildren(ex) == 2
708707
lhs = ex[1]
709708
kl = kind(lhs)
@@ -1314,7 +1313,7 @@ end
13141313

13151314
function expand_update_operator(ctx, ex)
13161315
k = kind(ex)
1317-
dotted = is_dotted(ex)
1316+
dotted = k == K".op="
13181317

13191318
@chk numchildren(ex) == 3
13201319
lhs = ex[1]
@@ -1356,7 +1355,7 @@ function expand_update_operator(ctx, ex)
13561355

13571356
@ast ctx ex [K"block"
13581357
stmts...
1359-
[K"="(syntax_flags=(dotted ? JuliaSyntax.DOTOP_FLAG : nothing))
1358+
[(dotted ? K".=" : K"=")
13601359
lhs
13611360
[(dotted ? K"dotcall" : K"call")
13621361
op
@@ -4247,7 +4246,7 @@ function expand_forms_2(ctx::DesugaringContext, ex::SyntaxTree, docs=nothing)
42474246
throw(LoweringError(ex, "unimplemented or unsupported atomic declaration"))
42484247
elseif k == K"call"
42494248
expand_call(ctx, ex)
4250-
elseif k == K"dotcall" || ((k == K"&&" || k == K"||") && is_dotted(ex))
4249+
elseif k == K"dotcall" || k == K".&&" || k == K".||" || k == K".="
42514250
expand_forms_2(ctx, expand_fuse_broadcast(ctx, ex))
42524251
elseif k == K"."
42534252
expand_forms_2(ctx, expand_dot(ctx, ex))
@@ -4283,14 +4282,10 @@ function expand_forms_2(ctx::DesugaringContext, ex::SyntaxTree, docs=nothing)
42834282
adopt_scope(string(k)::K"Identifier", ex)
42844283
children(ex)...
42854284
])
4286-
elseif k == K"op="
4285+
elseif k == K"op=" || k == K".op="
42874286
expand_forms_2(ctx, expand_update_operator(ctx, ex))
42884287
elseif k == K"="
4289-
if is_dotted(ex)
4290-
expand_forms_2(ctx, expand_fuse_broadcast(ctx, ex))
4291-
else
4292-
expand_assignment(ctx, ex)
4293-
end
4288+
expand_assignment(ctx, ex)
42944289
elseif k == K"break"
42954290
numchildren(ex) > 0 ? ex :
42964291
@ast ctx ex [K"break" "loop_exit"::K"symbolic_label"]

src/syntax_graph.jl

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,20 @@ function Base.getproperty(graph::SyntaxGraph, name::Symbol)
137137
end
138138

139139
function sethead!(graph, id::NodeId, h::JuliaSyntax.SyntaxHead)
140-
graph.kind[id] = kind(h)
141-
f = flags(h)
142-
if f != 0
143-
graph.syntax_flags[id] = f
144-
end
140+
sethead!(graph, id, kind(h))
141+
setflags!(graph, id, flags(h))
145142
end
146143

147144
function sethead!(graph, id::NodeId, k::Kind)
148145
graph.kind[id] = k
149146
end
150147

148+
function setflags!(graph, id::NodeId, f::UInt16)
149+
if f != 0
150+
graph.syntax_flags[id] = f
151+
end
152+
end
153+
151154
function _convert_nodes(graph::SyntaxGraph, node::SyntaxNode)
152155
id = newnode!(graph)
153156
sethead!(graph, id, head(node))
@@ -307,6 +310,7 @@ JuliaSyntax.source_line(src::LineNumberNode) = src.line
307310
# The follow somewhat strange cases are for where LineNumberNode is standing in
308311
# for SourceFile because we've only got Expr-based provenance info
309312
JuliaSyntax.sourcefile(src::LineNumberNode) = src
313+
JuliaSyntax.sourcetext(src::LineNumberNode) = SubString("")
310314
JuliaSyntax.source_location(src::LineNumberNode, byte_index::Integer) = (src.line, 0)
311315
JuliaSyntax.source_location(::Type{LineNumberNode}, src::LineNumberNode, byte_index::Integer) = src
312316
JuliaSyntax.filename(src::LineNumberNode) = string(src.file)
@@ -537,13 +541,11 @@ end
537541
JuliaSyntax.sourcefile(ex::SyntaxTree) = sourcefile(sourceref(ex))
538542
JuliaSyntax.byte_range(ex::SyntaxTree) = byte_range(sourceref(ex))
539543

540-
function JuliaSyntax._expr_leaf_val(ex::SyntaxTree)
544+
function JuliaSyntax._expr_leaf_val(ex::SyntaxTree, _...)
541545
name = get(ex, :name_val, nothing)
542-
if !isnothing(name)
543-
Symbol(name)
544-
else
545-
ex.value
546-
end
546+
!isnothing(name) && return Symbol(name)
547+
name = get(ex, :value, nothing)
548+
return name
547549
end
548550

549551
Base.Expr(ex::SyntaxTree) = JuliaSyntax.to_expr(ex)
@@ -604,7 +606,7 @@ macro SyntaxTree(ex_old)
604606
throw(ArgumentError("@SyntaxTree expects a `quote` block or `:`-quoted expression"))
605607
end
606608
# 2. Re-parse the current source file as SyntaxTree instead
607-
fname = String(__source__.file)
609+
fname = isnothing(__source__.file) ? error("No current file") : String(__source__.file)
608610
if occursin(r"REPL\[\d+\]", fname)
609611
# Assume we should look at last history entry in REPL
610612
try

0 commit comments

Comments
 (0)