Skip to content

Commit

Permalink
change implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
pdeffebach committed Dec 21, 2023
1 parent e396f01 commit 2eff53f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
32 changes: 11 additions & 21 deletions src/parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ a `QuoteNode` or an expression beginning with
If input is not a valid column identifier,
returns `nothing`.
"""
get_column_expr(x) = nothing
function get_column_expr(e::Expr)
get_column_expr(x; allow_multicol::Bool = false) = nothing
function get_column_expr(e::Expr; allow_multicol::Bool = false)
e.head == :$ && return e.args[1]
onearg(e, :AsTable) && return :($AsTable($(e.args[2])))
if onearg(e, :cols)
Expand All @@ -29,14 +29,18 @@ function get_column_expr(e::Expr)
if e.head === :call
e1 = e.args[1]
if e1 === :All || e1 === :Not || e1 === :Between || e1 == :Cols
s = "Multi-column references outside of @select, @rselect, @select!" *
" and @rselect! must be wrapped in AsTable"
throw(ArgumentError(s))
if allow_multicol
return e
else
s = "Multi-column references outside of @select, @rselect, @select!" *
" and @rselect! must be wrapped in AsTable"
throw(ArgumentError(s))
end
end
end
return nothing
end
get_column_expr(x::QuoteNode) = x
get_column_expr(x::QuoteNode; allow_multicol::Bool = false) = x

get_column_expr_rename(x) = nothing
function get_column_expr_rename(e::Expr)
Expand Down Expand Up @@ -352,21 +356,7 @@ function fun_to_vec(ex::Expr;
# :x
# handled below via dispatch on ::QuoteNode

# Do we give special treatment to All() etc?
# Only applies when allow_multicol is
# set to true.
# Otherwise, these are treated as
# normal functions
if allow_multicol
exhead = ex.head
if ex.head === :call
if exhead === :All || exhead === :Not || exhead === :Cols || exhead === :Between
return ex
end
end
end

ex_col = get_column_expr(ex)
ex_col = get_column_expr(ex; allow_multicol = allow_multicol)
if ex_col !== nothing
return ex_col
end
Expand Down
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ my_tests = ["dataframes.jl",
"byrow.jl",
"astable.jl",
"astable_flag.jl",
"passmissing.jl"]
"passmissing.jl",
"multicol.jl"]

println("Running tests:")

Expand Down

0 comments on commit 2eff53f

Please sign in to comment.