diff --git a/src/DataFilter.cpp b/src/DataFilter.cpp index 433394983..5ba563344 100644 --- a/src/DataFilter.cpp +++ b/src/DataFilter.cpp @@ -537,17 +537,20 @@ void Leaf::validateFilter(DataFilter *df, Leaf *leaf) leaf->inerror = true; } - if (leaf->function == "daterange" && !dateRangeValidSymbols.exactMatch(symbol)) { - DataFiltererrors << QString(QObject::tr("invalid literal for daterange(): %1")).arg(symbol); - leaf->inerror = true; + if (leaf->function == "daterange") { - } else { - // convert to int days since using current date range config - // should be able to get from parent somehow - leaf->type = Leaf::Integer; - if (symbol == "start") leaf->lvalue.i = QDate(1900,01,01).daysTo(df->context->currentDateRange().from); - else if (symbol == "stop") leaf->lvalue.i = QDate(1900,01,01).daysTo(df->context->currentDateRange().to); - else leaf->lvalue.i = 0; + if (!dateRangeValidSymbols.exactMatch(symbol)) { + DataFiltererrors << QString(QObject::tr("invalid literal for daterange(): %1")).arg(symbol); + leaf->inerror = true; + + } else { + // convert to int days since using current date range config + // should be able to get from parent somehow + leaf->type = Leaf::Integer; + if (symbol == "start") leaf->lvalue.i = QDate(1900,01,01).daysTo(df->context->currentDateRange().from); + else if (symbol == "stop") leaf->lvalue.i = QDate(1900,01,01).daysTo(df->context->currentDateRange().to); + else leaf->lvalue.i = 0; + } } if (leaf->function == "config" && !configValidSymbols.exactMatch(symbol)) { diff --git a/src/DataFilter.y b/src/DataFilter.y index 0d55d79e3..ad6f0bc39 100644 --- a/src/DataFilter.y +++ b/src/DataFilter.y @@ -70,7 +70,7 @@ extern Leaf *root; // root node for parsed statement %locations -%type symbol value lexpr expr parms; +%type symbol literal lexpr expr parms; %right '?' ':' %left ADD SUBTRACT @@ -168,64 +168,6 @@ expr : expr SUBTRACT expr { $$ = new Leaf(@1.first_column, @3.last_ } - | value { $$ = $1; } - - /* functions all have zero or more parameters */ - - | symbol '(' parms ')' { /* need to convert symbol to a function */ - $1->type = Leaf::Function; - $1->series = NULL; // not tiz/best - $1->function = *($1->lvalue.n); - $1->fparms = $3->fparms; - } - - | symbol '(' ')' { - /* need to convert symbol to function */ - $1->type = Leaf::Function; - $1->series = NULL; // not tiz/best - $1->function = *($1->lvalue.n); - $1->fparms.clear(); // no parameters! - } - - | '(' expr ')' { $$ = new Leaf(@2.first_column, @2.last_column); - $$->type = Leaf::Logical; - $$->lvalue.l = $2; - $$->op = 0; } - - - ; - -cop : EQ - | NEQ - | LT - | LTE - | GT - | GTE - | MATCHES - | ENDSWITH - | BEGINSWITH - | CONTAINS - ; - -symbol : SYMBOL { $$ = new Leaf(@1.first_column, @1.last_column); - $$->type = Leaf::Symbol; - if (QString(DataFiltertext) == "BikeScore") - $$->lvalue.n = new QString("BikeScore™"); - else - $$->lvalue.n = new QString(DataFiltertext); - } - ; - -value : symbol { $$ = $1; } - - | DF_STRING { $$ = new Leaf(@1.first_column, @1.last_column); $$->type = Leaf::String; - QString s2(DataFiltertext); - $$->lvalue.s = new QString(s2.mid(1,s2.length()-2)); } - | DF_FLOAT { $$ = new Leaf(@1.first_column, @1.last_column); $$->type = Leaf::Float; - $$->lvalue.f = QString(DataFiltertext).toFloat(); } - | DF_INTEGER { $$ = new Leaf(@1.first_column, @1.last_column); $$->type = Leaf::Integer; - $$->lvalue.i = QString(DataFiltertext).toInt(); } - | BEST '(' symbol ',' lexpr ')' { $$ = new Leaf(@1.first_column, @6.last_column); $$->type = Leaf::Function; $$->function = QString($1); $$->series = $3; @@ -274,6 +216,64 @@ value : symbol { $$ = $1; } $$->series = $3; $$->lvalue.l = NULL; } + + /* functions all have zero or more parameters */ + + | symbol '(' parms ')' { /* need to convert symbol to a function */ + $1->type = Leaf::Function; + $1->series = NULL; // not tiz/best + $1->function = *($1->lvalue.n); + $1->fparms = $3->fparms; + } + + | symbol '(' ')' { + /* need to convert symbol to function */ + $1->type = Leaf::Function; + $1->series = NULL; // not tiz/best + $1->function = *($1->lvalue.n); + $1->fparms.clear(); // no parameters! + } + + | '(' expr ')' { $$ = new Leaf(@2.first_column, @2.last_column); + $$->type = Leaf::Logical; + $$->lvalue.l = $2; + $$->op = 0; } + + | symbol { $$ = $1; } + + | literal { $$ = $1; } + + ; + +cop : EQ + | NEQ + | LT + | LTE + | GT + | GTE + | MATCHES + | ENDSWITH + | BEGINSWITH + | CONTAINS + ; + +symbol : SYMBOL { $$ = new Leaf(@1.first_column, @1.last_column); + $$->type = Leaf::Symbol; + if (QString(DataFiltertext) == "BikeScore") + $$->lvalue.n = new QString("BikeScore™"); + else + $$->lvalue.n = new QString(DataFiltertext); + } + ; + +literal : DF_STRING { $$ = new Leaf(@1.first_column, @1.last_column); $$->type = Leaf::String; + QString s2(DataFiltertext); + $$->lvalue.s = new QString(s2.mid(1,s2.length()-2)); } + | DF_FLOAT { $$ = new Leaf(@1.first_column, @1.last_column); $$->type = Leaf::Float; + $$->lvalue.f = QString(DataFiltertext).toFloat(); } + | DF_INTEGER { $$ = new Leaf(@1.first_column, @1.last_column); $$->type = Leaf::Integer; + $$->lvalue.i = QString(DataFiltertext).toInt(); } + ; %%