From f87a823b07be07aa96bd89c44fbdfd638bf30dc7 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Tue, 23 Feb 2016 08:21:58 -0500 Subject: [PATCH] parameterized-emit iterate: first light --- c/mapping/mlr_dsl_cst.c | 3 +- c/reg_test/expected/out | 61 +++++++++++++++++++++++++++++++++++++++++ c/reg_test/run | 11 ++++++++ c/todo.txt | 14 +++++++++- 4 files changed, 86 insertions(+), 3 deletions(-) diff --git a/c/mapping/mlr_dsl_cst.c b/c/mapping/mlr_dsl_cst.c index 7934ae8ee..266d2675d 100644 --- a/c/mapping/mlr_dsl_cst.c +++ b/c/mapping/mlr_dsl_cst.c @@ -617,7 +617,6 @@ static void mlr_dsl_cst_node_evaluate_emit2temp( // xxx temp #define TEMP_FLATTEN_SEP ":" -// xxx handle too-short, too-long, just-right cases static void mlr_dsl_cst_node_evaluate_emit2temp_aux( mlhmmv_level_t* plevel, char* oosvar_name, @@ -636,7 +635,7 @@ static void mlr_dsl_cst_node_evaluate_emit2temp_aux( if (plevel_value->is_terminal) { lrec_put(pnextrec, oosvar_name, mv_alloc_format_val(&plevel_value->u.mlrval), FREE_ENTRY_VALUE); - sllv_append(poutrecs, pnextrec); // xxx temp + sllv_append(poutrecs, pnextrec); } else { mlr_dsl_cst_node_evaluate_emit2temp_aux(pe->level_value.u.pnext_level, oosvar_name, diff --git a/c/reg_test/expected/out b/c/reg_test/expected/out index aa9e5df7d..6dae1fcc4 100644 --- a/c/reg_test/expected/out +++ b/c/reg_test/expected/out @@ -12762,6 +12762,67 @@ AST END STATEMENTS (1): 9 (strnum_literal). +================================================================ +PARAMETERIZED EMIT + +mlr put @sum[$a] = $x; filter false; end{ emit(@sum); } ./reg_test/input/abixy +sum:pan=0.502626 +sum:eks=0.611784 +sum:wye=0.573289 +sum:zee=0.598554 +sum:hat=0.031442 + +mlr put @sum[$a] = $x; filter false; end{ emit(@sum,"a"); } ./reg_test/input/abixy +a=pan,sum=0.502626 +a=eks,sum=0.611784 +a=wye,sum=0.573289 +a=zee,sum=0.598554 +a=hat,sum=0.031442 + +mlr put @sum[$a] = $x; filter false; end{ emit(@sum,"a","b"); } ./reg_test/input/abixy +a=pan,sum=0.502626 +a=eks,sum=0.611784 +a=wye,sum=0.573289 +a=zee,sum=0.598554 +a=hat,sum=0.031442 + +mlr put @sum[$a][$b] = $x; filter false; end{ emit(@sum); } ./reg_test/input/abixy +sum:pan:pan=0.346790 +sum:pan:wye=0.502626 +sum:eks:pan=0.758680 +sum:eks:wye=0.381399 +sum:eks:zee=0.611784 +sum:wye:wye=0.204603 +sum:wye:pan=0.573289 +sum:zee:pan=0.527126 +sum:zee:wye=0.598554 +sum:hat:wye=0.031442 + +mlr put @sum[$a][$b] = $x; filter false; end{ emit(@sum,"a"); } ./reg_test/input/abixy +a=pan,sum:pan=0.346790 +a=pan,sum:wye=0.502626 +a=eks,sum:pan=0.758680 +a=eks,sum:wye=0.381399 +a=eks,sum:zee=0.611784 +a=wye,sum:wye=0.204603 +a=wye,sum:pan=0.573289 +a=zee,sum:pan=0.527126 +a=zee,sum:wye=0.598554 +a=hat,sum:wye=0.031442 + +mlr put @sum[$a][$b] = $x; filter false; end{ emit(@sum,"a","b"); } ./reg_test/input/abixy +a=pan,b=pan,sum=0.346790 +a=pan,b=wye,sum=0.502626 +a=eks,b=pan,sum=0.758680 +a=eks,b=wye,sum=0.381399 +a=eks,b=zee,sum=0.611784 +a=wye,b=wye,sum=0.204603 +a=wye,b=pan,sum=0.573289 +a=zee,b=pan,sum=0.527126 +a=zee,b=wye,sum=0.598554 +a=hat,b=wye,sum=0.031442 + + ================================================================ CHAINING diff --git a/c/reg_test/run b/c/reg_test/run index 94a6b2811..3538a950b 100755 --- a/c/reg_test/run +++ b/c/reg_test/run @@ -1227,6 +1227,17 @@ run_mlr put -v 'begin{@a=1}; $e=2; $f==$g||$h==$i {$s=1;$t=2}; $x=6; end{@z run_mlr put -v 'begin{@a=1}; $e=2; $f==$g||$h==$i {$s=1;$t=2;$u=3}; $x=6; end{@z=9}' /dev/null run_mlr put -v 'begin{@a=1}; $e=2; $f==$g||$h==$i {$s=1;@t["u".$5]=2;emit @v,@w;dump}; $x=6; end{@z=9}' /dev/null +# ---------------------------------------------------------------- +announce PARAMETERIZED EMIT + +run_mlr put '@sum[$a] = $x; filter false; end{ emit(@sum); }' $indir/abixy +run_mlr put '@sum[$a] = $x; filter false; end{ emit(@sum,"a"); }' $indir/abixy +run_mlr put '@sum[$a] = $x; filter false; end{ emit(@sum,"a","b"); }' $indir/abixy + +run_mlr put '@sum[$a][$b] = $x; filter false; end{ emit(@sum); }' $indir/abixy +run_mlr put '@sum[$a][$b] = $x; filter false; end{ emit(@sum,"a"); }' $indir/abixy +run_mlr put '@sum[$a][$b] = $x; filter false; end{ emit(@sum,"a","b"); }' $indir/abixy + # ---------------------------------------------------------------- announce CHAINING diff --git a/c/todo.txt b/c/todo.txt index 4b3483404..f035c485c 100644 --- a/c/todo.txt +++ b/c/todo.txt @@ -11,8 +11,9 @@ TOP-OF-LIST SUMMARY * allow begin/end srec assignments in the grammar, to allow better error messages than 'syntax error' in the caller ? rethink filter ... ? +* parameterized emit neatens * tri-split null. then RT @sum[$group] = @sum[$group] + $value etc. be sure $nosuch sums to MT_ABSENT. -w then parameterized emit (spec & impl) +* += et al.: do node-copy & expand right in the parser. * 64-bit lengths for containers. test with 5-billion-integer-seq data. @@ -36,6 +37,17 @@ w then parameterized emit (spec & impl) - nest - shuffle +================================================================ +PARAMETERIZED EMIT + +* evolve & extend the UTs +* handle too-short, too-long, just-right cases +* rename functions +* rename variables as needed for clarity +* needs significant comment-by-example +* emit w/ and w/o parentheses in the grammar -- try to get just one +* mld section, w/ olh brief example & xref to it. + ================================================================ PATTERN-ACTION AST