Skip to content

Commit 45e5013

Browse files
authored
Merge pull request #91 from TidierOrg/bugfix-package-function-escaping
Bug fix to allow `PackageName.function()` within macros to be used without escaping
2 parents 98e9b09 + c09ee82 commit 45e5013

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# TidierData.jl updates
22

3+
## v0.14.7 - 2024-02-16
4+
- Bug fix to allow `PackageName.function()` within macros to be used without escaping
5+
36
## v0.14.6 - 2024-02-03
47
- Bug fix to ensure that data type constructors are not escaped
58

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "TidierData"
22
uuid = "fe2206b3-d496-4ee9-a338-6a095c4ece80"
33
authors = ["Karandeep Singh"]
4-
version = "0.14.6"
4+
version = "0.14.7"
55

66
[deps]
77
Chain = "8be319e6-bccf-4806-a6f7-6fae938471bc"

src/parsing.jl

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,12 @@ function parse_escape_function(rhs_expr::Union{Expr,Symbol})
353353
if hasproperty(Base, variable) && !(typeof(getproperty(Base, variable)) <: Function)
354354
# Remove the escaping if referring to a constant value like Base.pi and Base.Int64
355355
return variable
356-
elseif @capture(x, variable_Symbol) && hasproperty(Core, variable) && !(typeof(getproperty(Core, variable)) <: Function)
356+
elseif hasproperty(Core, variable) && !(typeof(getproperty(Core, variable)) <: Function)
357357
# Remove the escaping if referring to a data type like Core.Int64
358358
return variable
359+
elseif hasproperty(Statistics, variable) && !(typeof(getproperty(Statistics, variable)) <: Function)
360+
# Because Statistics is re-exported
361+
return variable
359362
elseif variable in not_escaped[]
360363
return variable
361364
elseif contains(string(variable), r"[^\W0-9]\w*$") # valid variable name
@@ -366,17 +369,17 @@ function parse_escape_function(rhs_expr::Union{Expr,Symbol})
366369
elseif @capture(x, fn_(args__))
367370
if fn in not_escaped[]
368371
return x
369-
elseif hasproperty(Base, fn) && typeof(getproperty(Base, fn)) <: Function
372+
elseif fn isa Symbol && hasproperty(Base, fn) && typeof(getproperty(Base, fn)) <: Function
370373
return x
371-
elseif hasproperty(Core, fn) && typeof(getproperty(Core, fn)) <: Function
374+
elseif fn isa Symbol && hasproperty(Core, fn) && typeof(getproperty(Core, fn)) <: Function
372375
return x
373-
elseif hasproperty(Statistics, fn) && typeof(getproperty(Statistics, fn)) <: Function
376+
elseif fn isa Symbol && hasproperty(Statistics, fn) && typeof(getproperty(Statistics, fn)) <: Function
374377
return x
375-
elseif hasproperty(Base, fn) && typeof(getproperty(Base, fn)) <: Type
378+
elseif fn isa Symbol && hasproperty(Base, fn) && typeof(getproperty(Base, fn)) <: Type
376379
return x
377-
elseif hasproperty(Core, fn) && typeof(getproperty(Core, fn)) <: Type
380+
elseif fn isa Symbol && hasproperty(Core, fn) && typeof(getproperty(Core, fn)) <: Type
378381
return x
379-
elseif hasproperty(Statistics, fn) && typeof(getproperty(Statistics, fn)) <: Type
382+
elseif fn isa Symbol && hasproperty(Statistics, fn) && typeof(getproperty(Statistics, fn)) <: Type
380383
return x
381384
elseif contains(string(fn), r"[^\W0-9]\w*$") # valid variable name
382385
return :($(esc(fn))($(args...)))
@@ -388,17 +391,17 @@ function parse_escape_function(rhs_expr::Union{Expr,Symbol})
388391
# return x
389392
if fn in not_escaped[]
390393
return x
391-
elseif hasproperty(Base, fn) && typeof(getproperty(Base, fn)) <: Function
394+
elseif fn isa Symbol && hasproperty(Base, fn) && typeof(getproperty(Base, fn)) <: Function
392395
return x
393-
elseif hasproperty(Core, fn) && typeof(getproperty(Core, fn)) <: Function
396+
elseif fn isa Symbol && hasproperty(Core, fn) && typeof(getproperty(Core, fn)) <: Function
394397
return x
395-
elseif hasproperty(Statistics, fn) && typeof(getproperty(Statistics, fn)) <: Function
398+
elseif fn isa Symbol && hasproperty(Statistics, fn) && typeof(getproperty(Statistics, fn)) <: Function
396399
return x
397-
elseif hasproperty(Base, fn) && typeof(getproperty(Base, fn)) <: Type
400+
elseif fn isa Symbol && hasproperty(Base, fn) && typeof(getproperty(Base, fn)) <: Type
398401
return x
399-
elseif hasproperty(Core, fn) && typeof(getproperty(Core, fn)) <: Type
402+
elseif fn isa Symbol && hasproperty(Core, fn) && typeof(getproperty(Core, fn)) <: Type
400403
return x
401-
elseif hasproperty(Statistics, fn) && typeof(getproperty(Statistics, fn)) <: Type
404+
elseif fn isa Symbol && hasproperty(Statistics, fn) && typeof(getproperty(Statistics, fn)) <: Type
402405
return x
403406
elseif contains(string(fn), r"[^\W0-9]\w*$") # valid variable name
404407
return :($(esc(fn)).($(args...)))

0 commit comments

Comments
 (0)