codedthinking / Kezdi.jl

Julia package for data manipulation and analysis
https://codedthinking.github.io/Kezdi.jl/
Other
18 stars 0 forks source link

Rewrite variable references to DataFrame column references #33

Closed korenmiklos closed 1 week ago

korenmiklos commented 2 weeks ago

https://expronicon.rogerluo.dev/api#transform

korenmiklos commented 2 weeks ago
julia> dump(:(x = y + 1))
Expr
  head: Symbol =
  args: Array{Any}((2,))
    1: Symbol x
    2: Expr
      head: Symbol call
      args: Array{Any}((3,))
        1: Symbol +
        2: Symbol y
        3: Int64 1

julia> dump(:(:x = :y + 1))
Expr
  head: Symbol =
  args: Array{Any}((2,))
    1: QuoteNode
      value: Symbol x
    2: Expr
      head: Symbol call
      args: Array{Any}((3,))
        1: Symbol +
        2: QuoteNode
          value: Symbol y
        3: Int64 1

julia> QuoteNode(:x)
:(:x)

julia> expr = :(x = y + 1)
:(x = y + 1)

julia> expr.args[1] = QuoteNode(expr.args[1])
:(:x)

julia> dump(expr)
Expr
  head: Symbol =
  args: Array{Any}((2,))
    1: QuoteNode
      value: Symbol x
    2: Expr
      head: Symbol call
      args: Array{Any}((3,))
        1: Symbol +
        2: Symbol y
        3: Int64 1

julia> expr.args[2].args[2] = QuoteNode(expr.args[2].args[2])
:(:y)

julia> dump(expr)
Expr
  head: Symbol =
  args: Array{Any}((2,))
    1: QuoteNode
      value: Symbol x
    2: Expr
      head: Symbol call
      args: Array{Any}((3,))
        1: Symbol +
        2: QuoteNode
          value: Symbol y
        3: Int64 1

Variable references could be parsed via https://expronicon.rogerluo.dev/

korenmiklos commented 1 week ago

This is pretty functional in the codegen branch. Closing this and we can open more specific issues.