Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add some support for public keyword #886

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions src/fst.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
Const,
Import,
Export,
Public,
Using,
File,
Quotenode,
Expand Down Expand Up @@ -425,7 +426,7 @@ is_opener(t::JuliaSyntax.GreenNode) = kind(t) in KSet"{ ( ["
function is_iterable(t::JuliaSyntax.GreenNode)
if !(
kind(t) in
KSet"parens tuple vect vcat braces curly comprehension typed_comprehension macrocall ref typed_vcat import using export"
KSet"parens tuple vect vcat braces curly comprehension typed_comprehension macrocall ref typed_vcat import using export public"
)
is_func_call(t)
else
Expand All @@ -447,7 +448,7 @@ function is_named_iterable(x::FST)
end

function is_import_expr(x::FST)
return x.typ in (Import, Using, Export)
return x.typ in (Import, Using, Export, Public)
end

"""
Expand Down
13 changes: 12 additions & 1 deletion src/styles/default/nest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ function nest!(
n_import!(style, fst, s, lineage)
elseif fst.typ === Export
n_export!(style, fst, s, lineage)
elseif fst.typ === Public
n_public!(style, fst, s, lineage)
elseif fst.typ === Using
n_using!(style, fst, s, lineage)
elseif fst.typ === Where
Expand Down Expand Up @@ -242,7 +244,7 @@ function n_do!(
return nested
end

# Import,Using,Export
# Import,Using,Export,Public
function n_using!(
ds::AbstractStyle,
fst::FST,
Expand Down Expand Up @@ -303,6 +305,15 @@ function n_export!(
n_using!(ds, fst, s, lineage)
end

function n_public!(
ds::AbstractStyle,
fst::FST,
s::State,
lineage::Vector{Tuple{FNode,Union{Nothing,Metadata}}},
)
n_using!(ds, fst, s, lineage)
end

function n_import!(
ds::AbstractStyle,
fst::FST,
Expand Down
18 changes: 16 additions & 2 deletions src/styles/default/pretty.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ function pretty(
p_import(style, node, s, ctx, lineage)
elseif k === K"export"
p_export(style, node, s, ctx, lineage)
elseif k === K"public"
p_public(style, node, s, ctx, lineage)
elseif k === K"using"
p_using(style, node, s, ctx, lineage)
elseif k === K"importpath"
Expand Down Expand Up @@ -2598,14 +2600,14 @@ function p_import(
end

for a in children(cst)
if kind(a) in KSet"import export using"
if kind(a) in KSet"import export public using"
add_node!(t, pretty(style, a, s, ctx, lineage), s; join_lines = true)
add_node!(t, Whitespace(1), s)
elseif kind(a) === K":" && haschildren(a)
nodes = children(a)
for n in nodes
add_node!(t, pretty(style, n, s, ctx, lineage), s; join_lines = true)
if kind(n) in KSet"import export using"
if kind(n) in KSet"import export public using"
add_node!(t, Whitespace(1), s)
elseif kind(n) in KSet", :"
add_node!(t, Placeholder(1), s)
Expand Down Expand Up @@ -2633,6 +2635,18 @@ function p_export(
t
end

function p_public(
ds::AbstractStyle,
cst::JuliaSyntax.GreenNode,
s::State,
ctx::PrettyContext,
lineage::Vector{Tuple{JuliaSyntax.Kind,Bool,Bool}},
)
t = p_import(ds, cst, s, ctx, lineage)
t.typ = Public
t
end

function p_using(
ds::AbstractStyle,
cst::JuliaSyntax.GreenNode,
Expand Down
1 change: 1 addition & 0 deletions src/styles/sciml/nest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ for f in [
:n_import!,
:n_using!,
:n_export!,
:n_public!,
:n_vcat!,
:n_ncat!,
:n_typedvcat!,
Expand Down
1 change: 1 addition & 0 deletions src/styles/sciml/pretty.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ for f in [
:p_import,
:p_using,
:p_export,
:p_public,
:p_vcat,
:p_ncat,
:p_typedvcat,
Expand Down
8 changes: 8 additions & 0 deletions src/styles/yas/nest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,14 @@ function n_export!(
)
n_using!(ys, fst, s, lineage)
end
function n_public!(
ys::YASStyle,
fst::FST,
s::State,
lineage::Vector{Tuple{FNode,Union{Nothing,Metadata}}},
)
n_using!(ys, fst, s, lineage)
end
function n_import!(
ys::YASStyle,
fst::FST,
Expand Down
16 changes: 14 additions & 2 deletions src/styles/yas/pretty.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ function p_import(
end

for a in children(cst)
if kind(a) in KSet"import export using"
if kind(a) in KSet"import export using public"
add_node!(t, pretty(style, a, s, ctx, lineage), s; join_lines = true)
add_node!(t, Whitespace(1), s)
elseif kind(a) === K":" && haschildren(a)
nodes = children(a)
for n in nodes
add_node!(t, pretty(style, n, s, ctx, lineage), s; join_lines = true)
if kind(n) in KSet"import export using :"
if kind(n) in KSet"import export using public :"
add_node!(t, Whitespace(1), s)
elseif kind(n) in KSet","
add_node!(t, Placeholder(1), s)
Expand Down Expand Up @@ -116,6 +116,18 @@ function p_export(
t
end

function p_public(
ys::YASStyle,
cst::JuliaSyntax.GreenNode,
s::State,
ctx::PrettyContext,
lineage::Vector{Tuple{JuliaSyntax.Kind,Bool,Bool}},
)
t = p_import(ys, cst, s, ctx, lineage)
t.typ = Public
t
end

function p_curly(
ys::YASStyle,
cst::JuliaSyntax.GreenNode,
Expand Down