Created
June 2, 2021 16:39
-
-
Save andreypopp/b6622ed7931bfb06d6ddc2536788a595 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct WithLoc{T} | |
expr::CSTParser.EXPR | |
value::T | |
end | |
"""Concept Expression referenced from another location.""" | |
struct ReferencedConceptExpression <: FunOHDSI.ConceptExpression | |
name::Symbol | |
end | |
REPL.derive_tojs(ReferencedConceptExpression) | |
""" Find "interesting" info in code expressions.""" | |
find(expr::CSTParser.EXPR) = | |
find′([], expr) | |
function find′(res, expr::CSTParser.EXPR) | |
found = find′(res, expr, FunOHDSI.ConceptExpression) | |
if found !== nothing | |
push!(res, WithLoc(expr, found)) | |
elseif @isexpr expr Expr(_, args...) | |
# otherwise recurse further into an expresion | |
for arg in args | |
find′(res, arg) | |
end | |
end | |
res | |
end | |
""" Find `ConceptExpression` info in code expressions.""" | |
function find′( | |
res, | |
expr::CSTParser.EXPR, | |
typ::Type{FunOHDSI.ConceptExpression}; | |
assume=false | |
) | |
if @isexpr expr Expr(:call, :(|>), a, b) | |
a = find′(res, a, typ; assume=true) | |
if a === nothing; return end | |
b = find′(res, b, typ; assume=true) | |
if b === nothing; return end | |
b(a) | |
elseif @isexpr expr Expr(:call, :Concept, id::Int) | |
FunOHDSI.Concept(Expr(id)) | |
elseif @isexpr expr Expr(:call, :ConceptParents) | |
FunOHDSI.ConceptParents() | |
elseif @isexpr expr Expr(:call, :ConceptChildren) | |
FunOHDSI.ConceptChildren() | |
elseif @isexpr expr Expr(:call, :ConceptDescendants) | |
FunOHDSI.ConceptDescendants() | |
elseif @isexpr expr Expr(:call, :ConceptAncestors) | |
FunOHDSI.ConceptAncestors() | |
elseif @isexpr expr Expr(:call, :IncludeConcepts, args...) | |
exprs = FunOHDSI.ConceptExpression[] | |
for a in args | |
e = find′(res, a, typ; assume=true) | |
if e === nothing; return end | |
push!(exprs, e) | |
end | |
FunOHDSI.IncludeConcepts(exprs...) | |
elseif @isexpr expr name::Symbol | |
if assume | |
ReferencedConceptExpression(Expr(name)) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment