Skip to content

Commit

Permalink
Removed support for const/local/global syntax from @funsql notation
Browse files Browse the repository at this point in the history
  • Loading branch information
xitology committed Jun 14, 2024
1 parent a4d373a commit 4bd4ce2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
18 changes: 2 additions & 16 deletions docs/src/test/nodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,29 +242,15 @@ A parameter of a query function accepts a type declaration.
end
=#

The `@funsql` macro applied to a constant definition transliterates the value.

@funsql const ip_or_er_visit_q = concept_by_code("Visit", "IP", "ER")

display(ip_or_er_visit_q)
#=>
let q1 = From(:concept),
q2 = q1 |>
Where(Fun.and(Fun."="(Get.vocabulary_id, "Visit"),
Fun.in(Get.concept_code, "IP", "ER")))
q2
end
=#

A single `@funsql` macro can wrap multiple definitions.

@funsql begin
SNOMED(codes...) = concept_by_code("SNOMED", $(codes...))

const myocardial_infarction_q = SNOMED("22298006")
MYOCARDIAL_INFARCTION() = SNOMED("22298006")
end

display(myocardial_infarction_q)
display(@funsql MYOCARDIAL_INFARCTION())
#=>
let q1 = From(:concept),
q2 = q1 |>
Expand Down
2 changes: 2 additions & 0 deletions src/dissect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ function dissect(scr::Symbol, @nospecialize(pat))
ex1 = dissect(scr, pat.args[1])
ex2 = dissect(scr, pat.args[2])
:($ex2 && $ex1)
elseif pat.head === :(::) && nargs == 1
:($scr isa $(pat.args[1]))
elseif pat.head === :(::) && nargs == 2
ex1 = dissect(scr, pat.args[1])
ex2 = :($scr isa $(pat.args[2]))
Expand Down
9 changes: 3 additions & 6 deletions src/nodes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,7 @@ function transliterate(@nospecialize(ex), ctx::TransliterateContext)
elseif @dissect(ex, Expr(:parameters, args...))
# ; args...
return Expr(:parameters, Any[transliterate(arg, ctx) for arg in args]...)
elseif @dissect(ex, Expr(op := :const || :global || :local, arg))
return Expr(op, transliterate(arg, ctx))
elseif @dissect(ex, Expr(:macrocall, GlobalRef(Core, Symbol("@cmd")), _..., name::String))
elseif @dissect(ex, Expr(:macrocall, GlobalRef(Core, Symbol("@cmd")), ::LineNumberNode, name::String))
# `name`
return QuoteNode(Symbol(name))
elseif @dissect(ex, Expr(:call, Expr(:., over, QuoteNode(name)), args...))
Expand Down Expand Up @@ -619,14 +617,13 @@ function transliterate(@nospecialize(ex), ctx::TransliterateContext)
# name(args...)
trs = Any[transliterate(arg, ctx) for arg in args]
return :($(esc(Symbol("funsql_$name")))($(trs...)))
elseif @dissect(ex, Expr(:call, Expr(:macrocall, GlobalRef(Core, Symbol("@cmd")), _..., name::String), args...))
elseif @dissect(ex, Expr(:call, Expr(:macrocall, GlobalRef(Core, Symbol("@cmd")), ::LineNumberNode, name::String), args...))
# `name`(args...)
trs = Any[transliterate(arg, ctx) for arg in args]
return :($(esc(Symbol("funsql_$name")))($(trs...)))
elseif @dissect(ex, Expr(:block, args...))
# begin; args...; end
if all(arg isa LineNumberNode ||
@dissect(arg, Expr(:(=) || :const || :global || :local, _...))
if all(@dissect(arg, ::LineNumberNode || Expr(:(=), _...))
for arg in args)
trs = Any[]
for arg in args
Expand Down

0 comments on commit 4bd4ce2

Please sign in to comment.