Skip to content

Commit

Permalink
Merge pull request #22 from JuliaPluto/primitive
Browse files Browse the repository at this point in the history
support `primitive type` expr
  • Loading branch information
Pangoraw authored Aug 20, 2024
2 parents 264aa19 + 31dcae4 commit 8a83345
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "ExpressionExplorer"
uuid = "21656369-7473-754a-2065-74616d696c43"
license = "MIT"
authors = ["Paul Berg <[email protected]>", "Fons van der Plas <[email protected]>"]
version = "1.0.2"
version = "1.0.3"

[compat]
julia = "1.6"
Expand Down
10 changes: 9 additions & 1 deletion src/explore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,12 @@ function explore_abstract!(ex::Expr, scopestate::ScopeState)
explore_struct!(Expr(:struct, false, ex.args[1], Expr(:block, nothing)), scopestate)
end

function explore_primitive!(ex::Expr, scopestate::ScopeState)
type_name, type_body = ex.args
symstate = explore_struct!(Expr(:struct, false, type_name, Expr(:block)), scopestate)
union!(symstate, explore!(type_body, scopestate))
end

function explore_function_macro!(ex::Expr, scopestate::ScopeState)
symstate = SymbolsState()
# Creates local scope
Expand Down Expand Up @@ -784,6 +790,8 @@ function explore!(ex::Expr, scopestate::ScopeState)::SymbolsState
return explore!(ex.args[2], scopestate)
elseif ex.head === :struct
return explore_struct!(ex, scopestate)
elseif ex.head === :primitive
return explore_primitive!(ex, scopestate)
elseif ex.head === :abstract
return explore_abstract!(ex, scopestate)
elseif ex.head === :function || ex.head === :macro
Expand Down Expand Up @@ -966,7 +974,7 @@ function explore_funcdef!(ex::Expr, scopestate::ScopeState)::Tuple{FunctionName,
return name, symstate

elseif ex.head === :(<:)
# for use in `struct` and `abstract`
# for use in `struct`, `abstract` and `primitive`
name, symstate = uncurly!(ex.args[1], scopestate)
if length(ex.args) != 1
union!(symstate, explore!(ex.args[2], scopestate))
Expand Down
9 changes: 9 additions & 0 deletions test/ExpressionExplorer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ end
@test testee(:(let abstract type a end end), [], [:a], [], [
:a => ([], [], [], [])
])
@test testee(:(primitive type Int24 24 end), [], [:Int24], [], [
:Int24 => ([], [], [], [])
])
@test testee(:(primitive type Int24 <: Integer 24 end), [], [:Int24], [], [
:Int24 => ([:Integer], [], [], [])
])
@test testee(:(primitive type Int24 <: Integer size end), [:size], [:Int24], [], [
:Int24 => ([:Integer], [], [], [])
])

@test testee(:(module a; f(x) = x; z = r end), [], [:a], [], [])
end
Expand Down

2 comments on commit 8a83345

@Pangoraw
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/113487

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.3 -m "<description of version>" 8a83345856911ebd89ce6376b0ec372d051a5cd7
git push origin v1.0.3

Please sign in to comment.