Skip to content

Commit

Permalink
Merge pull request #85 from TidierOrg/no-escape-types
Browse files Browse the repository at this point in the history
  • Loading branch information
kdpsingh authored Feb 4, 2024
2 parents f4569d4 + 4d8ae87 commit 98e9b09
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# TidierData.jl updates

## v0.14.6 - 2024-02-03
- Bug fix to ensure that data type constructors are not escaped

## v0.14.5 - 2024-01-23
- Adds `@relocate()`

Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TidierData"
uuid = "fe2206b3-d496-4ee9-a338-6a095c4ece80"
authors = ["Karandeep Singh"]
version = "0.14.5"
version = "0.14.6"

[deps]
Chain = "8be319e6-bccf-4806-a6f7-6fae938471bc"
Expand Down
34 changes: 28 additions & 6 deletions src/parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ function parse_escape_function(rhs_expr::Union{Expr,Symbol})
# If it's already escaped, make sure it needs to remain escaped
if @capture(x, esc(variable_Symbol))
if hasproperty(Base, variable) && !(typeof(getproperty(Base, variable)) <: Function)
# Remove the escaping if referring to a constant value like Base.pi
# Remove the escaping if referring to a constant value like Base.pi and Base.Int64
return variable
elseif @capture(x, variable_Symbol) && hasproperty(Core, variable) && !(typeof(getproperty(Core, variable)) <: Function)
# Remove the escaping if referring to a data type like Core.Int64
Expand All @@ -364,21 +364,41 @@ function parse_escape_function(rhs_expr::Union{Expr,Symbol})
return variable
end
elseif @capture(x, fn_(args__))
if hasproperty(Base, fn) && typeof(getproperty(Base, fn)) <: Function
if fn in not_escaped[]
return x
elseif hasproperty(Base, fn) && typeof(getproperty(Base, fn)) <: Function
return x
elseif hasproperty(Core, fn) && typeof(getproperty(Core, fn)) <: Function
return x
elseif hasproperty(Statistics, fn) && typeof(getproperty(Statistics, fn)) <: Function
return x
elseif fn in not_escaped[]
elseif hasproperty(Base, fn) && typeof(getproperty(Base, fn)) <: Type
return x
elseif hasproperty(Core, fn) && typeof(getproperty(Core, fn)) <: Type
return x
elseif hasproperty(Statistics, fn) && typeof(getproperty(Statistics, fn)) <: Type
return x
elseif contains(string(fn), r"[^\W0-9]\w*$") # valid variable name
return :($(esc(fn))($(args...)))
else
return x
end
elseif @capture(x, fn_.(args__))
if fn in [:esc :in : : :Ref :Set :Cols :(:) : :across :desc :mean :std :var :median :first :last :minimum :maximum :sum :length :skipmissing :quantile :passmissing :startswith :contains :endswith]
# if fn in [:esc :in :∈ :∉ :Ref :Set :Cols :(:) :∘ :across :desc :mean :std :var :median :first :last :minimum :maximum :sum :length :skipmissing :quantile :passmissing :startswith :contains :endswith]
# return x
if fn in not_escaped[]
return x
elseif hasproperty(Base, fn) && typeof(getproperty(Base, fn)) <: Function
return x
elseif hasproperty(Core, fn) && typeof(getproperty(Core, fn)) <: Function
return x
elseif hasproperty(Statistics, fn) && typeof(getproperty(Statistics, fn)) <: Function
return x
elseif hasproperty(Base, fn) && typeof(getproperty(Base, fn)) <: Type
return x
elseif hasproperty(Core, fn) && typeof(getproperty(Core, fn)) <: Type
return x
elseif hasproperty(Statistics, fn) && typeof(getproperty(Statistics, fn)) <: Type
return x
elseif contains(string(fn), r"[^\W0-9]\w*$") # valid variable name
return :($(esc(fn)).($(args...)))
Expand Down Expand Up @@ -439,9 +459,11 @@ function parse_interpolation(var_expr::Union{Expr,Symbol,Number,String};
elseif @capture(x, variable_Symbol)
if variable in not_escaped[]
return variable
elseif hasproperty(Base, variable) && !(typeof(getproperty(Base, variable)) <: Function)
elseif hasproperty(Base, variable) && !(typeof(getproperty(Base, variable)) <: Function) && !(typeof(getproperty(Base, variable)) <: Type)
return esc(variable)
elseif @capture(x, variable_Symbol) && hasproperty(Core, variable) && !(typeof(getproperty(Core, variable)) <: Function)
elseif hasproperty(Core, variable) && !(typeof(getproperty(Core, variable)) <: Function) && !(typeof(getproperty(Core, variable)) <: Type)
return esc(variable)
elseif hasproperty(Statistics, variable) && !(typeof(getproperty(Statistics, variable)) <: Function) && !(typeof(getproperty(Statistics, variable)) <: Type)
return esc(variable)
else
return variable
Expand Down

2 comments on commit 98e9b09

@kdpsingh
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
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/100217

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 v0.14.6 -m "<description of version>" 98e9b093588b018ef38bc6d7be248a413cb8accd
git push origin v0.14.6

Please sign in to comment.