Skip to content

Commit

Permalink
Blocks can be used as datafilter function parameters
Browse files Browse the repository at this point in the history
.. mostly to make using the activities() function a lot
   simpler. A parameter can include a block of code that
   should be evaluated as a parameter.

   e.g:

   activities("isRun", { xx <- metrics(date);
                         yy <- metrics(Pace); } );

   this avoids having to declare a function and call it
   just so we can pass as a function parameter.
  • Loading branch information
liversedge committed Sep 4, 2021
1 parent 578a7fb commit e3e826a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/Core/DataFilter.cpp
Expand Up @@ -1651,6 +1651,9 @@ void Leaf::validateFilter(Context *context, DataFilterRuntime *df, Leaf *leaf)
DataFiltererrors << tr("activities(\"fexpr\", expr) - where fexpr is a filter expression");
}

// validate the expression
if (leaf->fparms.count() == 2) validateFilter(context,df,leaf->fparms[1]);

} else if (leaf->function == "daterange") {

if (leaf->fparms.count()==1) {
Expand Down
12 changes: 9 additions & 3 deletions src/Core/DataFilter.y
Expand Up @@ -72,7 +72,7 @@ extern Leaf *DataFilterroot; // root node for parsed statement

%locations

%type <leaf> symbol array select literal lexpr cexpr expr parms block statement expression;
%type <leaf> symbol array select literal lexpr cexpr expr parms block statement expression parameter;
%type <leaf> simple_statement if_clause while_clause function_def;
%type <leaf> python_script;
%type <comp> statements
Expand Down Expand Up @@ -233,17 +233,23 @@ function_def:
}
;

parameter:

lexpr { $$ = $1; }
| block { $$ = $1; }
;

/*
* A parameter list, as passed to a function
*/
parms:

lexpr { $$ = new Leaf(@1.first_column, @1.last_column);
parameter { $$ = new Leaf(@1.first_column, @1.last_column);
$$->type = Leaf::Function;
$$->series = NULL; // not tiz/best
$$->fparms << $1;
}
| parms ',' lexpr { $1->fparms << $3;
| parms ',' parameter { $1->fparms << $3;
$1->leng = @3.last_column; }
;

Expand Down

0 comments on commit e3e826a

Please sign in to comment.