Commit 193ba609 authored by Ole Voldsæter's avatar Ole Voldsæter

fixed "rowtotal", "tag", "concat" and "cut" + fixed a bug that prevented more...

fixed "rowtotal", "tag", "concat" and "cut" + fixed a bug that prevented more than one option parameter
parent 40f16418
......@@ -137,7 +137,7 @@ format_vars
;
<display_format>
: #"\%[^\s]+"
: #"\%[^\s,)]+"
;
drop_cases
......@@ -320,6 +320,7 @@ option_param
: varlist
| numlist
| string
| display_format
;
local
......
......@@ -30,8 +30,8 @@
;; mapping of grammar production names to transformation functions
(def transformations
{
:options (fn [& args] (reduce #(assoc %1 (keyword (first %2)) (second %2)) {} args))
:option (fn [& args] args)
:options (fn [& args] (reduce #(assoc %1 (keyword (first %2)) (apply concat (second %2))) {} args))
:option (fn [name & args] [name args])
:option_param (fn [& args] args)
:analysis (fn [& args] {:command "analysis"
:message (str "Ignoring \"" (-> args first trim) "\"")})
......
......@@ -14,7 +14,7 @@
; ends
; group
(defonce compute-funcs {
(def compute-funcs {
:diff "diff"
:rowfirst "rowfirst"
:rowlast "rowlast"
......@@ -29,9 +29,13 @@
:rowtotal "rowtotal"
:std "std_val"
:tag "tag"
:concat "concat"
:cut "cut"
:group "group"
:ends "ends"
})
(defonce aggregate-funcs {
(def aggregate-funcs {
:count "agg_count"
:iqr "agg_iqr"
:kurt "agg_kurt"
......@@ -93,12 +97,30 @@
:rowtotal (make-compute
varname
"rowtotal"
[(make-varlist-expression varlist)]
[(make-varlist-expression varlist) (-> (get-var-length-option :missing 1 options) nil? not)]
filter)
:tag (make-compute
varname
"tag"
[(make-varlist-expression varlist)]
[(make-varlist-expression varlist) (-> (get-var-length-option :missing 1 options) nil? not)]
filter)
:concat (make-compute
varname
"concat"
[(make-varlist-expression varlist)
(->> (get-var-length-option :format 1 options) (get options) first)
(->> (get-var-length-option :decode 1 options) nil? not)
(->> (get-var-length-option :maxlength 4 options) (get options) first :values first)
(->> (get-var-length-option :punct 1 options) (get options) first)]
filter)
:cut (make-compute
varname
"cut"
[(first varlist)
(->> options :at (transduce (map #(:values %)) concat) (assoc {"$type" "NumberListExpression"} :values))
(->> (get-var-length-option :group 1 options) (get options) first :values first)
(->> (get-var-length-option :icodes 2 options) nil? not)
(->> (get-var-length-option :label 3 options) nil? not)]
filter)
; default
(make-compute
......
......@@ -236,7 +236,7 @@
)
(is
(=
(parse-and-transform "append using a, test_option(1 2/4 5 (2) 9 10 13 : 19) ")
(parse-and-transform "append using a, test_option(1 2/4 5 (2) 9 10 13 : 19, %1.2)")
'{:command "append"
:files ("a")
:mod-varlist ()
......@@ -253,7 +253,8 @@
{"$type" "NumberRangeExpression"
:from 10
:step 3
:to 19})})}}
:to 19})}
"%1.2")}}
)
)
)
......
......@@ -86,7 +86,9 @@
:variables ({"$type" "VariableSymbolExpression"
:variableName "a"}
{"$type" "VariableSymbolExpression"
:variableName "b"})}})
:variableName "b"})}}
{:argumentName "EXP2"
:argumentValue false})
:function "rowtotal"
:isSdtlName true}
:mod-varlist ["some-var"]
......@@ -102,7 +104,9 @@
:variables ({"$type" "VariableSymbolExpression"
:variableName "a"}
{"$type" "VariableSymbolExpression"
:variableName "b"})}})
:variableName "b"})}}
{:argumentName "EXP2"
:argumentValue true})
:function "rowtotal"
:isSdtlName true}
:mod-varlist ["some-var"]
......@@ -118,7 +122,9 @@
:variables ({"$type" "VariableSymbolExpression"
:variableName "a"}
{"$type" "VariableSymbolExpression"
:variableName "b"})}})
:variableName "b"})}}
{:argumentName "EXP2"
:argumentValue false})
:function "tag"
:isSdtlName true}
:mod-varlist ["some-var"]
......@@ -134,7 +140,9 @@
:variables ({"$type" "VariableSymbolExpression"
:variableName "a"}
{"$type" "VariableSymbolExpression"
:variableName "b"})}})
:variableName "b"})}}
{:argumentName "EXP2"
:argumentValue true})
:function "tag"
:isSdtlName true}
:mod-varlist ["some-var"]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment