Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ jobs:
fail-fast: false
matrix:
version:
- '1.0'
- '1.11'
- 'nightly'
os:
- ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ This work is intended to
Note this is a work in progress; many types of syntax are not yet handled.

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.
2. Use commit `46723f0` of [JuliaSyntax](https://github.com/JuliaLang/JuliaSyntax.jl)
2. Use commit `e02f29f` of [JuliaSyntax](https://github.com/JuliaLang/JuliaSyntax.jl)
3. Get the latest version of [JuliaSyntaxFormatter](https://github.com/c42f/JuliaSyntaxFormatter.jl)
4. Run the demo `include("test/demo.jl")`

Expand Down
2 changes: 1 addition & 1 deletion src/JuliaLowering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using JuliaSyntax: highlight, Kind, @KSet_str
using JuliaSyntax: is_leaf, children, numchildren, head, kind, flags, has_flags, numeric_flags
using JuliaSyntax: filename, first_byte, last_byte, byte_range, sourcefile, source_location, span, sourcetext

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
using JuliaSyntax: is_literal, is_number, is_operator, is_prec_assignment, is_prefix_call, is_infix_op_call, is_postfix_op_call, is_error

_include("kinds.jl")
_register_kinds()
Expand Down
21 changes: 8 additions & 13 deletions src/desugaring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -690,10 +690,10 @@ function expand_dotcall(ctx, ex)
]
elseif k == K"comparison"
expand_dotcall(ctx, expand_compare_chain(ctx, ex))
elseif (k == K"&&" || k == K"||") && is_dotted(ex)
elseif k == K".&&" || k == K".||"
@ast ctx ex [K"call"
"broadcasted"::K"top"
(k == K"&&" ? "andand" : "oror")::K"top"
(k == K".&&" ? "andand" : "oror")::K"top"
(expand_dotcall(ctx, arg) for arg in children(ex))...
]
else
Expand All @@ -702,8 +702,7 @@ function expand_dotcall(ctx, ex)
end

function expand_fuse_broadcast(ctx, ex)
if kind(ex) == K"="
@assert is_dotted(ex)
if kind(ex) == K".=" || kind(ex) == K".op="
@chk numchildren(ex) == 2
lhs = ex[1]
kl = kind(lhs)
Expand Down Expand Up @@ -1314,7 +1313,7 @@ end

function expand_update_operator(ctx, ex)
k = kind(ex)
dotted = is_dotted(ex)
dotted = k == K".op="

@chk numchildren(ex) == 3
lhs = ex[1]
Expand Down Expand Up @@ -1356,7 +1355,7 @@ function expand_update_operator(ctx, ex)

@ast ctx ex [K"block"
stmts...
[K"="(syntax_flags=(dotted ? JuliaSyntax.DOTOP_FLAG : nothing))
[(dotted ? K".=" : K"=")
lhs
[(dotted ? K"dotcall" : K"call")
op
Expand Down Expand Up @@ -4247,7 +4246,7 @@ function expand_forms_2(ctx::DesugaringContext, ex::SyntaxTree, docs=nothing)
throw(LoweringError(ex, "unimplemented or unsupported atomic declaration"))
elseif k == K"call"
expand_call(ctx, ex)
elseif k == K"dotcall" || ((k == K"&&" || k == K"||") && is_dotted(ex))
elseif k == K"dotcall" || k == K".&&" || k == K".||" || k == K".="
expand_forms_2(ctx, expand_fuse_broadcast(ctx, ex))
elseif k == K"."
expand_forms_2(ctx, expand_dot(ctx, ex))
Expand Down Expand Up @@ -4283,14 +4282,10 @@ function expand_forms_2(ctx::DesugaringContext, ex::SyntaxTree, docs=nothing)
adopt_scope(string(k)::K"Identifier", ex)
children(ex)...
])
elseif k == K"op="
elseif k == K"op=" || k == K".op="
expand_forms_2(ctx, expand_update_operator(ctx, ex))
elseif k == K"="
if is_dotted(ex)
expand_forms_2(ctx, expand_fuse_broadcast(ctx, ex))
else
expand_assignment(ctx, ex)
end
expand_assignment(ctx, ex)
elseif k == K"break"
numchildren(ex) > 0 ? ex :
@ast ctx ex [K"break" "loop_exit"::K"symbolic_label"]
Expand Down
26 changes: 14 additions & 12 deletions src/syntax_graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,20 @@ function Base.getproperty(graph::SyntaxGraph, name::Symbol)
end

function sethead!(graph, id::NodeId, h::JuliaSyntax.SyntaxHead)
graph.kind[id] = kind(h)
f = flags(h)
if f != 0
graph.syntax_flags[id] = f
end
sethead!(graph, id, kind(h))
setflags!(graph, id, flags(h))
end

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

function setflags!(graph, id::NodeId, f::UInt16)
if f != 0
graph.syntax_flags[id] = f
end
end

function _convert_nodes(graph::SyntaxGraph, node::SyntaxNode)
id = newnode!(graph)
sethead!(graph, id, head(node))
Expand Down Expand Up @@ -307,6 +310,7 @@ JuliaSyntax.source_line(src::LineNumberNode) = src.line
# The follow somewhat strange cases are for where LineNumberNode is standing in
# for SourceFile because we've only got Expr-based provenance info
JuliaSyntax.sourcefile(src::LineNumberNode) = src
JuliaSyntax.sourcetext(src::LineNumberNode) = SubString("")
JuliaSyntax.source_location(src::LineNumberNode, byte_index::Integer) = (src.line, 0)
JuliaSyntax.source_location(::Type{LineNumberNode}, src::LineNumberNode, byte_index::Integer) = src
JuliaSyntax.filename(src::LineNumberNode) = string(src.file)
Expand Down Expand Up @@ -537,13 +541,11 @@ end
JuliaSyntax.sourcefile(ex::SyntaxTree) = sourcefile(sourceref(ex))
JuliaSyntax.byte_range(ex::SyntaxTree) = byte_range(sourceref(ex))

function JuliaSyntax._expr_leaf_val(ex::SyntaxTree)
function JuliaSyntax._expr_leaf_val(ex::SyntaxTree, _...)
name = get(ex, :name_val, nothing)
if !isnothing(name)
Symbol(name)
else
ex.value
end
!isnothing(name) && return Symbol(name)
name = get(ex, :value, nothing)
return name
end

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