diff --git a/src/musredit_qt5/mupp/PmuppScript.cpp b/src/musredit_qt5/mupp/PmuppScript.cpp index ea5c1a5e..829637c8 100644 --- a/src/musredit_qt5/mupp/PmuppScript.cpp +++ b/src/musredit_qt5/mupp/PmuppScript.cpp @@ -36,6 +36,8 @@ #include #include +#include // Q_ASSERT + #include "PmuppScript.h" //-------------------------------------------------------------------------- @@ -85,7 +87,7 @@ int PmuppScript::executeScript() } QString cmd; - int status=0; + int status; for (int i=0; i will eventually handle variable definition here ..." << std::endl; + status = var_cmd(cmd); } else if (cmd.startsWith("col")) { std::cout << "debug> will eventually handle linking of a variable to a collection ..." << std::endl; } else { @@ -663,6 +665,47 @@ int PmuppScript::macro(const QString str, const QString plotFln) return 0; } +//-------------------------------------------------------------------------- +/** + * @brief PmuppScript::var_cmd + * @param str + * @return + */ +int PmuppScript::var_cmd(const QString str) +{ + QStringList tok; + int idx=0; + + // get linked collection index for further use + tok = str.split(' ', QString::SkipEmptyParts); + if (tok[1].endsWith("Err")) // error variable no need to do something + return 0; + idx = getCollectionIndex(tok[1]); + if (idx == -1) // var not linked to collection, ignore it + return 0; + + // check for the related error variable if present + QString varErr = QString("%1%2").arg(tok[1]).arg("Err"); + QString varErrCmd(""); + for (int i=0; iGetCollection(idx), parse_str); + fVarHandler.push_back(varHandler); + + return 0; +} + //-------------------------------------------------------------------------- /** * @brief PmuppScript::foundLabel @@ -749,3 +792,34 @@ QString PmuppScript::getNicerLabel(const QString label) return nice; } + +//-------------------------------------------------------------------------- +/** + * @brief PmuppScript::getCollectionIndex + * @param var_name + * @return + */ +int PmuppScript::getCollectionIndex(const QString var_name) +{ + int idx = -1; + QString cmd; + QStringList tok; + bool ok; + + for (int i=0; i dvec, double &min, double &max); QString getNicerLabel(const QString label); + + int getCollectionIndex(const QString var_name); }; #endif // _PMUPPSCRIPT_H_ diff --git a/src/musredit_qt5/mupp/var/include/PVarHandler.h b/src/musredit_qt5/mupp/var/include/PVarHandler.h index 98f607fd..02277ec4 100644 --- a/src/musredit_qt5/mupp/var/include/PVarHandler.h +++ b/src/musredit_qt5/mupp/var/include/PVarHandler.h @@ -35,21 +35,25 @@ #include +#include "Pmupp.h" #include class PVarHandler { public: - PVarHandler(); + PVarHandler(PmuppCollection *coll, std::string parse_str); - void setInput(QString &str) { fInput = str.toLatin1().data(); } - bool parse(); - bool semcheck(); + bool isValid() { return fIsValid; } std::vector getValues(); std::vector getErrors(); private: - std::string fInput; ///< the variable input to be parsed + PmuppCollection *fColl; ///< collection need for parsing and evaluation + std::string fParseStr; ///< the variable input to be parsed + + bool fIsValid; mupp::ast::statement_list fAst; ///< the AST + + void injectPredefVariables(); }; #endif //_PVARHANDLER_H_ diff --git a/src/musredit_qt5/mupp/var/src/PVarHandler.cpp b/src/musredit_qt5/mupp/var/src/PVarHandler.cpp index b04b7569..62e134df 100644 --- a/src/musredit_qt5/mupp/var/src/PVarHandler.cpp +++ b/src/musredit_qt5/mupp/var/src/PVarHandler.cpp @@ -1,83 +1,98 @@ -/*************************************************************************** - - PVarHandler.cpp - - Author: Andreas Suter - e-mail: andreas.suter@psi.ch - -***************************************************************************/ - -/*************************************************************************** - * Copyright (C) 2007-2020 by Andreas Suter * - * andreas.suter@psi.ch * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "PVarHandler.h" - -//-------------------------------------------------------------------------- -/** - * @brief PVarHandler::PVarHandler - */ -PVarHandler::PVarHandler() -{ - fInput = ""; -} - -//-------------------------------------------------------------------------- -/** - * @brief PVarHandler::parse - * @return - */ -bool PVarHandler::parse() -{ - return true; -} - -//-------------------------------------------------------------------------- -/** - * @brief PVarHandler::semcheck - * @return - */ -bool PVarHandler::semcheck() -{ - return true; -} - -//-------------------------------------------------------------------------- -/** - * @brief PVarHandler::getValues - * @return - */ -std::vector PVarHandler::getValues() -{ - std::vector result; - - return result; -} - -//-------------------------------------------------------------------------- -/** - * @brief PVarHandler::getErrors - * @return - */ -std::vector PVarHandler::getErrors() -{ - std::vector result; - - return result; -} +/*************************************************************************** + + PVarHandler.cpp + + Author: Andreas Suter + e-mail: andreas.suter@psi.ch + +***************************************************************************/ + +/*************************************************************************** + * Copyright (C) 2007-2020 by Andreas Suter * + * andreas.suter@psi.ch * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include + +#include "PVarHandler.h" + +/* +#include "PSkipper.hpp" +#include "PErrorHandler.hpp" +#include "PStatement.hpp" +#include "PAstDump.hpp" +#include "PProgram.hpp" +*/ + +//-------------------------------------------------------------------------- +/** + * @brief PVarHandler::PVarHandler + */ +PVarHandler::PVarHandler(PmuppCollection *coll, std::string parse_str) : + fColl(coll), fParseStr(parse_str), fIsValid(false) +{ + injectPredefVariables(); +} + +//-------------------------------------------------------------------------- +/** + * @brief PVarHandler::getValues + * @return + */ +std::vector PVarHandler::getValues() +{ + std::vector result; + + return result; +} + +//-------------------------------------------------------------------------- +/** + * @brief PVarHandler::getErrors + * @return + */ +std::vector PVarHandler::getErrors() +{ + std::vector result; + + return result; +} + +//-------------------------------------------------------------------------- +/** + * @brief PVarHandler::injectPredefVariables + */ +void PVarHandler::injectPredefVariables() +{ + mupp::ast::statement var_stat; + mupp::ast::variable_declaration var; + + std::string varName, errVarName; + for (int i=0; iGetNoOfRuns(); i++) { + varName = fColl->GetRun(i).GetName().toLatin1().data(); + errVarName = varName + "Err"; + // inject err_name + var.lhs.name = errVarName; + var_stat = var; + fAst.push_front(var_stat); + // inject var_name + var.lhs.name = varName; + var_stat = var; + fAst.push_front(var_stat); + } +}