From 35d9fc10e7d73f4c0d12d4ae7be2c86bdbdda29e Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Sat, 9 Apr 2022 11:36:19 -0400 Subject: [PATCH] implement SQL function calls, unquote --- sqlog/compiler.fnl | 1 + sqlog/macros.fnl | 1 + 2 files changed, 2 insertions(+) diff --git a/sqlog/compiler.fnl b/sqlog/compiler.fnl index e2ec9e2..c116c64 100644 --- a/sqlog/compiler.fnl +++ b/sqlog/compiler.fnl @@ -175,6 +175,7 @@ [:set column subexpr] (.. column " = " (self:gen-expr analysis subexpr)) (where [:var name] (. analysis.variable-mapping name)) (self:gen-expr analysis (. analysis.variable-mapping name)) (where [op lhs rhs] (. infix-ops op)) (.. "(" (self:gen-expr analysis lhs) " " op " " (self:gen-expr analysis rhs) ")") + [funcname & args] (.. funcname "(" (cat args ", " #(self:gen-expr analysis $1)) ")") _ (error (.. "Unrecognized expression " (fv expr))))) (fn Compiler.gen-rule-clause [self analysis-parent [head & literals]] diff --git a/sqlog/macros.fnl b/sqlog/macros.fnl index 419f902..992b57d 100644 --- a/sqlog/macros.fnl +++ b/sqlog/macros.fnl @@ -4,6 +4,7 @@ (fn clause [c] (match c + (where [escape expr] (list? c) (= (tostring escape) :unquote)) expr (where [escape expr] (list? c) (= (tostring escape) :hashfn)) `[:const ,expr] (where [name & params] (sequence? c)) `[:literal ,(tostring name) ,(icollect [_ param (ipairs params)] (clause param))] (where [head & args] (list? c) (sym? head)) (icollect [_ expr (ipairs args) :into [(tostring head)]] (clause expr))