Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JASP configuration file feature + remote option #5062

Draft
wants to merge 38 commits into
base: stable
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
6c46eaf
Implements a data mode
JorisGoosen May 21, 2021
003123c
SKF JASP postmerge and fix
JorisGoosen Sep 21, 2021
aa63d26
latest version of jaspProcessControl and other submodules
JorisGoosen Dec 1, 2021
82f7f86
post qt6 merge fixes
JorisGoosen Mar 10, 2022
825d474
post rebase fixes 10-11-22
JorisGoosen Nov 10, 2022
8a49630
post rebase fix 7-12-22
JorisGoosen Dec 7, 2022
3d71dac
(event)=>{}
JorisGoosen Dec 7, 2022
7edb7cd
Rebasing mistake
boutinb Jan 27, 2023
6349af9
Make sure editing is quick and analyses are hidden in dataMode (#5040)
JorisGoosen Mar 1, 2023
191709f
dirty fix for the resize dialog (#5042)
RensDofferhoff Mar 1, 2023
55fea62
odule shenanigans
JorisGoosen Mar 16, 2023
aba724b
start
RensDofferhoff Apr 3, 2023
5f2fb73
progress
RensDofferhoff Apr 4, 2023
bef03ee
progress
RensDofferhoff Apr 5, 2023
a6a1bf2
progress
RensDofferhoff Apr 5, 2023
a44a893
progress
RensDofferhoff Apr 6, 2023
84807bc
progress
RensDofferhoff Apr 7, 2023
f286ea0
before overhaul
RensDofferhoff Apr 10, 2023
b0c3a38
functional
RensDofferhoff Apr 12, 2023
72b965f
giant oops
RensDofferhoff Apr 12, 2023
6945cab
v1
RensDofferhoff Apr 12, 2023
c94ee85
enabled sounds better
RensDofferhoff Apr 13, 2023
53c39e4
oops
RensDofferhoff Apr 15, 2023
b20d6ae
oops
RensDofferhoff Apr 15, 2023
d71aaa2
oops
RensDofferhoff Apr 16, 2023
c826d3d
constant access improvements
RensDofferhoff Apr 18, 2023
2d54356
add option locking
RensDofferhoff Apr 18, 2023
d56c6d3
oops
RensDofferhoff May 11, 2023
0dd5bbf
progress
RensDofferhoff May 12, 2023
3ed5704
factory
RensDofferhoff May 12, 2023
bb506d6
more extendable this way
RensDofferhoff May 15, 2023
8d58dd8
a small comment never hurts
RensDofferhoff May 15, 2023
f431a57
add toml
RensDofferhoff May 16, 2023
8a8df43
forgot the parser lib
RensDofferhoff May 16, 2023
a58c026
Documentation for analysis writers
RensDofferhoff May 17, 2023
8a232b9
Update jasp-qml-guide.md
RensDofferhoff May 22, 2023
c976461
dont change the submodule commits
RensDofferhoff May 22, 2023
311866d
added local conf browser
RensDofferhoff May 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more extendable this way
  • Loading branch information
RensDofferhoff committed May 22, 2023
commit bb506d67411f1d296941e7803c81a8f370b2a5e1
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
#include "jaspConfParser.h"
#include "jaspConfFormatParser.h"
#include "log.h"

#include<iostream>

JASPConfigurationParser* JASPConfParser::_instance = nullptr;

JASPConfigurationParser* JASPConfParser::getInstance()
{
if(!_instance)
_instance = new JASPConfParser();
return _instance;
}

JASPConfParser::JASPConfParser()
JASPConfFormatParser::JASPConfFormatParser()
{
_parser.set_logger([](size_t line, size_t col, const std::string& msg, const std::string &rule) {
Log::log() << "JASPConfiguration parse error: line" << line << " column:" << col << ": " << msg << "\n";
Expand All @@ -25,6 +16,7 @@ JASPConfParser::JASPConfParser()
_parser["JASPConf"] = parseJASPConf;
_parser["ModuleStmt"] = parseModuleStmt;
_parser["AnalysisStmt"] = parseAnalysisStmt;
_parser["CommandStmt"] = parseCommandStmt;
_parser["OptionStmt"] = parseOptionStmt;
_parser["OptionDef"] = parseOptionDef;
_parser["LoadModuleList"] = parseLoadModuleList;
Expand All @@ -38,7 +30,7 @@ JASPConfParser::JASPConfParser()
_parser["Bool"] = parseBool;
}

std::any JASPConfParser::parseBool(const peg::SemanticValues &vs, std::any &dt)
std::any JASPConfFormatParser::parseBool(const peg::SemanticValues &vs, std::any &dt)
{
switch (vs.choice()) {
case 0: //true
Expand All @@ -48,7 +40,7 @@ std::any JASPConfParser::parseBool(const peg::SemanticValues &vs, std::any &dt)
}
}

bool JASPConfParser::parse(JASPConfiguration* target, const QString &input)
bool JASPConfFormatParser::parse(JASPConfiguration* target, const QString &input)
{
try {
std::any dt = target;
Expand All @@ -60,27 +52,27 @@ bool JASPConfParser::parse(JASPConfiguration* target, const QString &input)
return false;
}

std::any JASPConfParser::parseInt(const peg::SemanticValues &vs, std::any &dt)
std::any JASPConfFormatParser::parseInt(const peg::SemanticValues &vs, std::any &dt)
{
return vs.token_to_number<long long>();
}

std::any JASPConfParser::parseFloat(const peg::SemanticValues &vs, std::any &dt)
std::any JASPConfFormatParser::parseFloat(const peg::SemanticValues &vs, std::any &dt)
{
return vs.token_to_number<double>();
}

std::any JASPConfParser::parseString(const peg::SemanticValues &vs, std::any &dt)
std::any JASPConfFormatParser::parseString(const peg::SemanticValues &vs, std::any &dt)
{
return QString(vs.token_to_string().c_str());
}

std::any JASPConfParser::parseName(const peg::SemanticValues &vs, std::any &dt)
std::any JASPConfFormatParser::parseName(const peg::SemanticValues &vs, std::any &dt)
{
return QString(vs.token_to_string().c_str());
}

std::any JASPConfParser::parseValue(const peg::SemanticValues &vs, std::any &dt)
std::any JASPConfFormatParser::parseValue(const peg::SemanticValues &vs, std::any &dt)
{
switch (vs.choice()) {
case 0: //Bool
Expand All @@ -98,12 +90,12 @@ std::any JASPConfParser::parseValue(const peg::SemanticValues &vs, std::any &dt)
}
}

std::any JASPConfParser::parseKeyValuePair(const peg::SemanticValues &vs, std::any& dt)
std::any JASPConfFormatParser::parseKeyValuePair(const peg::SemanticValues &vs, std::any& dt)
{
return KeyValue{any_cast<QString>(vs[0]), any_cast<QVariant>(vs[1])};
}

std::any JASPConfParser::parseVersion(const peg::SemanticValues &vs, std::any &dt)
std::any JASPConfFormatParser::parseVersion(const peg::SemanticValues &vs, std::any &dt)
{
try
{
Expand All @@ -116,15 +108,15 @@ std::any JASPConfParser::parseVersion(const peg::SemanticValues &vs, std::any &d
}
}

std::any JASPConfParser::parseLoadModuleList(const peg::SemanticValues &vs, std::any &dt)
std::any JASPConfFormatParser::parseLoadModuleList(const peg::SemanticValues &vs, std::any &dt)
{
QStringList list;
for(int i = 0; i < vs.size(); i++)
list.push_back(any_cast<QString>(vs[i]));
return list;
}

std::any JASPConfParser::parseOptionDef(const peg::SemanticValues &vs, std::any &dt)
std::any JASPConfFormatParser::parseOptionDef(const peg::SemanticValues &vs, std::any &dt)
{
switch (vs.choice()) {
case 0: //lock
Expand All @@ -134,15 +126,21 @@ std::any JASPConfParser::parseOptionDef(const peg::SemanticValues &vs, std::any
}
}

std::any JASPConfParser::parseOptionStmt(const peg::SemanticValues &vs, std::any &dt)
std::any JASPConfFormatParser::parseOptionStmt(const peg::SemanticValues &vs, std::any &dt)
{
std::vector<Option> options;
for(auto& option : vs)
options.push_back(any_cast<Option>(option));
return options;
}

std::any JASPConfParser::parseAnalysisStmt(const peg::SemanticValues &vs, std::any &dt)

std::any JASPConfFormatParser::parseCommandStmt(const peg::SemanticValues &vs, std::any &dt)
{
return Commands{vs.token_to_string().c_str()};
}

std::any JASPConfFormatParser::parseAnalysisStmt(const peg::SemanticValues &vs, std::any &dt)
{
Analysis res;
res.name = any_cast<QString>(vs[0]);
Expand All @@ -159,7 +157,7 @@ std::any JASPConfParser::parseAnalysisStmt(const peg::SemanticValues &vs, std::a
return res;
}

std::any JASPConfParser::parseModuleStmt(const peg::SemanticValues &vs, std::any &dt)
std::any JASPConfFormatParser::parseModuleStmt(const peg::SemanticValues &vs, std::any &dt)
{
Module res;
res.name = any_cast<QString>(vs[0]);
Expand All @@ -173,7 +171,7 @@ std::any JASPConfParser::parseModuleStmt(const peg::SemanticValues &vs, std::any
return res;
}

std::any JASPConfParser::parseJASPConf(const peg::SemanticValues &vs, std::any &dt)
std::any JASPConfFormatParser::parseJASPConf(const peg::SemanticValues &vs, std::any &dt)
{
JASPConfiguration* conf = any_cast<JASPConfiguration*>(dt);
for(int i = 0; i < vs.size(); i++)
Expand All @@ -200,11 +198,15 @@ std::any JASPConfParser::parseJASPConf(const peg::SemanticValues &vs, std::any &
}
else if(vs[i].type() == typeid(LoadModulesList)) //LoadModulesList
{
conf->_modulesToLoad += any_cast<LoadModulesList>(vs[i]);
conf->setAdditionalModules(any_cast<LoadModulesList>(vs[i]));
}
else if(vs[i].type() == typeid(Version)) //Version
{
conf->_jaspVersion = any_cast<Version>(vs[i]);
conf->setJASPVersion(any_cast<Version>(vs[i]));
}
else if(vs[i].type() == typeid(Commands)) //Commands
{
conf->setStartupCommands(any_cast<Commands>(vs[i]).commands);
}
}
return conf;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
#ifndef JASPCONF_PARSER_H
#define JASPCONF_PARSER_H
#ifndef JASPCONF_FORMAT_PARSER_H
#define JASPCONF_FORMAT_PARSER_H

#include "jaspConfigurationParser.h"
#include "peglib/peglib.h"


class JASPConfParser : public JASPConfigurationParser
class JASPConfFormatParser : public JASPConfigurationParser
{

public:
JASPConfFormatParser();
bool parse(JASPConfiguration* target, const QString& input) override;


protected:
// singleton stuff
JASPConfigurationParser* getInstance() override;
JASPConfParser(JASPConfigurationParser& other) = delete;
void operator=(const JASPConfigurationParser&) = delete;

private:
JASPConfParser();

static JASPConfigurationParser* _instance;

struct KeyValue { QString key; QVariant value; };
struct Option { KeyValue keyValue; bool locked; };
struct Analysis { QString name; std::vector<Option> options; std::vector<KeyValue> constants; };
struct Module { QString name; std::vector<Analysis> analyses; std::vector<KeyValue> constants; };
struct Commands { QString commands; };
using LoadModulesList = QStringList;

static std::any parseBool(const peg::SemanticValues &vs, std::any& dt);
Expand All @@ -40,6 +33,7 @@ class JASPConfParser : public JASPConfigurationParser
static std::any parseLoadModuleList(const peg::SemanticValues &vs, std::any& dt);
static std::any parseOptionDef(const peg::SemanticValues &vs, std::any& dt);
static std::any parseOptionStmt(const peg::SemanticValues &vs, std::any& dt);
static std::any parseCommandStmt(const peg::SemanticValues &vs, std::any& dt);
static std::any parseAnalysisStmt(const peg::SemanticValues &vs, std::any& dt);
static std::any parseModuleStmt(const peg::SemanticValues &vs, std::any& dt);
static std::any parseJASPConf(const peg::SemanticValues &vs, std::any& dt);
Expand All @@ -53,11 +47,12 @@ class JASPConfParser : public JASPConfigurationParser
const char* _jaspConfigGrammar = R"(
JASPConf <- Format? Statement* Version Statement*

Statement <- ModuleStmt / LoadModuleList / KeyValuePair / Comment
Statement <- ModuleStmt / LoadModuleList / KeyValuePair / CommandStmt / Comment
ModuleStmt <- 'Module' Name Comment? ( AnalysisStmt / KeyValuePair / Comment )* 'End Module' Comment?
AnalysisStmt <- 'Analysis' Name Comment? ( OptionStmt / KeyValuePair / Comment )* 'End Analysis' Comment?
OptionStmt <- 'Options' Comment? OptionDef* 'End Options' Comment?
OptionStmt <- 'Options' Comment? (OptionDef / Comment)* 'End Options' Comment?
OptionDef <- (KeyValuePair 'lock' Comment?) / (KeyValuePair Comment?)
CommandStmt <- 'CMD' Comment? < (!'END CMD' .)* > 'END CMD' Comment?

LoadModuleList <- 'Enable Modules' ':' List(Name, ',') Comment?
Format <- 'Format' ':' < [0-9.]* > Comment?
Expand All @@ -74,7 +69,7 @@ class JASPConfParser : public JASPConfigurationParser

~Comment <- '#' (!EndOfLine .)* EndOfLine
EndOfLine <- '\r\n' / '\n' / '\r'
%whitespace <- [ \t\n]*
%whitespace <- [ \t\r\n]*

# Macros
List(I, D) ← I (D I)*
Expand Down
13 changes: 13 additions & 0 deletions Desktop/gui/jaspConfiguration/jaspConfigurationParser.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
#include "jaspConfigurationParser.h"
#include "jaspConfFormatParser.h"
#include "log.h"


JASPConfigurationParser *JASPConfigurationParser::getParser(const Format format)
{
//add cases here as more formats/parsers are added
return new JASPConfFormatParser();

}

JASPConfigurationParser::JASPConfigurationParser()
{

}
21 changes: 8 additions & 13 deletions Desktop/gui/jaspConfiguration/jaspConfigurationParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,17 @@ class JASPConfigurationParser
{

public:
virtual bool parse(JASPConfiguration* target, const QString& input);
enum class Format {
JASP
};

//factory function
static JASPConfigurationParser* getParser(const QString& inputPath = "", const QString& input = "");

protected:
// singleton stuff
virtual JASPConfigurationParser* getInstance();
JASPConfigurationParser(JASPConfigurationParser& other) = delete;
void operator=(const JASPConfigurationParser&) = delete;
JASPConfigurationParser();

private:
JASPConfigurationParser* _instance = nullptr;
//factory function
static JASPConfigurationParser* getParser(const Format format);

virtual bool parse(JASPConfiguration* target, const QString& input) = 0;

protected:
JASPConfigurationParser();
};

#endif // JASPCONFIGURATION_PARSER_H
4 changes: 2 additions & 2 deletions Desktop/gui/jaspConfiguration/jaspconfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void JASPConfiguration::processConfiguration()
throw std::runtime_error("Error fetching remote configuration file " + reply->request().url().toString().toStdString() + " : " + reply->errorString().toStdString());
QByteArray payload = reply->readAll();
clear();
if(!JASPConfigurationParser::getInstance()->parse(this, payload))
if(!JASPConfigurationParser::getParser(JASPConfigurationParser::Format::JASP)->parse(this, payload))
throw std::runtime_error("Parsing failed");

auto localConfFile = getLocalConfFile(true);
Expand Down Expand Up @@ -119,7 +119,7 @@ bool JASPConfiguration::processLocal()
{
auto localConfFile = getLocalConfFile();
QTextStream in(localConfFile.get());
if(!JASPConfigurationParser::getInstance()->parse(this, in.readAll()))
if(!JASPConfigurationParser::getParser(JASPConfigurationParser::Format::JASP)->parse(this, in.readAll()))
throw std::runtime_error("Parsing failed");
}
catch(std::runtime_error& e)
Expand Down
22 changes: 13 additions & 9 deletions Desktop/gui/jaspConfiguration/jaspconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,35 @@
#include <QObject>
#include <QVariant>
#include <QFile>
#include <QRegularExpression>
#include "version.h"
#include "json/json.h"

class JASPConfiguration : public QObject
{
Q_OBJECT
public:
//read and parse local and remote configuration
void processConfiguration();

//QML programming constants interface
Q_INVOKABLE bool constantExists(const QString& constant, const QString& module = "", const QString& analysis = "");
Q_INVOKABLE QVariant getConstant(const QString& constant, const QVariant& defaultValue = QVariant(), const QString& module = "", const QString& analysis = "");

//Predefined analysis options interface
//C++ configuration access functions
bool optionSet(const QString& module, const QString& analysis, const QString& optionName);
bool optionsSet(const QString& module, const QString& analysis);
bool optionLocked(const QString& module, const QString& analysis, const QString& optionName);
Json::Value getAnalysisOptionValues(const QString& module, const QString& analysis);

const QStringList* getAdditionalModules() { return &_modulesToLoad; }

//read and parse local and remote configuration
void processConfiguration();

//let the parser fill in the data
friend class JASPConfigurationParser;
//Parser set functions
bool addConstant(QString key, QVariant value, QString moduleName = "", QString analysisName = "");
bool addOption(QString key, QVariant value, bool locked, QString moduleName = "", QString analysisName = "");
void setAdditionalModule(const QString& module) { _modulesToLoad.push_back(module); };
void setAdditionalModules(const QStringList& modules) { _modulesToLoad += modules; };
void setStartupCommands(const QString& commands) { _startupCommands += commands; };
void setJASPVersion(const Version& v) { _jaspVersion = v; };


//singleton stuff
Expand All @@ -50,8 +54,7 @@ private slots:
private:
bool processLocal();
void clear();
bool addConstant(QString key, QVariant value, QString moduleName = "", QString analysisName = "");
bool addOption(QString key, QVariant value, bool locked, QString moduleName = "", QString analysisName = "");


std::shared_ptr<QFile> getLocalConfFile(bool truncate = false);

Expand All @@ -61,6 +64,7 @@ private slots:
QMap<QString, QMap<QString, QMap<QString, QVariant>>> _definedConstants;
QMap<QString, QMap<QString, Json::Value>> _analysisOptions;
QMap<QString, QMap<QString, QMap<QString, bool>>> _analysisOptionsLocked;
QString _startupCommands;
QStringList _modulesToLoad;

const QString configurationFilename = "userConfiguration.conf";
Expand Down
4 changes: 2 additions & 2 deletions Desktop/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ MainWindow::MainWindow(QApplication * application) : QObject(application), _appl

makeConnections();

_jaspConfiguration->processConfiguration();

qmlRegisterUncreatableType<JASPControl> ("JASP", 1, 0 ,"JASP", "Impossible to create JASP Object" ); //This is here to keep JASP.enum short I guess?
qmlRegisterUncreatableType<MessageForwarder> ("JASP", 1, 0, "MessageForwarder", "You can't touch this" );

Expand Down Expand Up @@ -211,6 +209,8 @@ MainWindow::MainWindow(QApplication * application) : QObject(application), _appl
JASPVersionChecker * jaspVersionChecker = new JASPVersionChecker(this);
connect(jaspVersionChecker, &JASPVersionChecker::showDownloadButton, this, &MainWindow::setDownloadNewJASPUrl);

QTimer::singleShot(0, this, [&]() { _jaspConfiguration->processConfiguration(); });

JASPTIMER_FINISH(MainWindowConstructor);
}

Expand Down