mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-19 13:01:32 +01:00
Half a boost::spirit parser for RQL.
This commit is contained in:
parent
184cf0c0d8
commit
588dbb6b0b
@ -17,6 +17,64 @@
|
|||||||
#include "lastfmstationdialog.h"
|
#include "lastfmstationdialog.h"
|
||||||
#include "ui_lastfmstationdialog.h"
|
#include "ui_lastfmstationdialog.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <boost/spirit/include/qi.hpp>
|
||||||
|
#include <boost/fusion/include/std_pair.hpp>
|
||||||
|
|
||||||
|
#include <QtDebug>
|
||||||
|
#include <QValidator>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
namespace qi = boost::spirit::qi;
|
||||||
|
using boost::spirit::lit;
|
||||||
|
|
||||||
|
template <typename Iterator>
|
||||||
|
struct rql : qi::grammar<Iterator, std::vector<std::pair<std::string, std::string> >()> {
|
||||||
|
rql() : rql::base_type(query) {
|
||||||
|
query = pair % lit(' ') >> qi::eoi;
|
||||||
|
pair = key >> lit(':') >> value;
|
||||||
|
key = qi::string("simart") |
|
||||||
|
qi::string("tag") |
|
||||||
|
qi::string("user") |
|
||||||
|
qi::string("library") |
|
||||||
|
qi::string("loved");
|
||||||
|
value = (unquoted | quoted);
|
||||||
|
unquoted = +(qi::char_ - lit(' ') - lit('"'));
|
||||||
|
quoted = '"' >> +(qi::char_ - '"') >> '"';
|
||||||
|
}
|
||||||
|
|
||||||
|
qi::rule<Iterator, std::vector<std::pair<std::string, std::string> >()> query;
|
||||||
|
qi::rule<Iterator, std::pair<std::string, std::string>()> pair;
|
||||||
|
qi::rule<Iterator, std::string()> key;
|
||||||
|
qi::rule<Iterator, std::string()> value, unquoted, quoted;
|
||||||
|
};
|
||||||
|
|
||||||
|
class RQLValidator : public QValidator {
|
||||||
|
public:
|
||||||
|
QValidator::State validate(QString& str, int& pos) const {
|
||||||
|
std::string input = str.toStdString();
|
||||||
|
rql<std::string::iterator> parser;
|
||||||
|
std::vector<std::pair<std::string, std::string> > results;
|
||||||
|
bool ret = qi::parse(input.begin(), input.end(), parser, results);
|
||||||
|
|
||||||
|
qDebug() << "Success:" << ret;
|
||||||
|
|
||||||
|
for (std::vector<std::pair<std::string, std::string> >::const_iterator it = results.begin();
|
||||||
|
it != results.end(); ++it) {
|
||||||
|
qDebug("key:%s value:%s", it->first.c_str(), it->second.c_str());
|
||||||
|
}
|
||||||
|
qDebug() << "---";
|
||||||
|
|
||||||
|
return ret ? Acceptable : Intermediate;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
LastFMStationDialog::LastFMStationDialog(QWidget* parent)
|
LastFMStationDialog::LastFMStationDialog(QWidget* parent)
|
||||||
: QDialog(parent),
|
: QDialog(parent),
|
||||||
ui_(new Ui_LastFMStationDialog)
|
ui_(new Ui_LastFMStationDialog)
|
||||||
@ -24,6 +82,8 @@ LastFMStationDialog::LastFMStationDialog(QWidget* parent)
|
|||||||
ui_->setupUi(this);
|
ui_->setupUi(this);
|
||||||
|
|
||||||
resize(sizeHint());
|
resize(sizeHint());
|
||||||
|
|
||||||
|
ui_->content->setValidator(new RQLValidator());
|
||||||
}
|
}
|
||||||
|
|
||||||
LastFMStationDialog::~LastFMStationDialog() {
|
LastFMStationDialog::~LastFMStationDialog() {
|
||||||
@ -39,3 +99,6 @@ void LastFMStationDialog::SetType(Type type) {
|
|||||||
QString LastFMStationDialog::content() const {
|
QString LastFMStationDialog::content() const {
|
||||||
return ui_->content->text();
|
return ui_->content->text();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LastFMStationDialog::accept() {
|
||||||
|
}
|
||||||
|
@ -37,6 +37,9 @@ class LastFMStationDialog : public QDialog {
|
|||||||
void SetType(Type type);
|
void SetType(Type type);
|
||||||
QString content() const;
|
QString content() const;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
virtual void accept();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui_LastFMStationDialog* ui_;
|
Ui_LastFMStationDialog* ui_;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user