blob: 052d5a980a356e4cb274e7604e5f98512f5d4c22 [file] [log] [blame]
Václav Kubernát624a8872018-03-02 17:28:47 +01001/*
2 * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
Václav Kubernátd6662962018-03-22 17:41:33 +01003 * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
Václav Kubernát624a8872018-03-02 17:28:47 +01004 *
5 * Written by Václav Kubernát <kubervac@fit.cvut.cz>
6 *
Václav Kubernátd6662962018-03-22 17:41:33 +01007*/
Václav Kubernát624a8872018-03-02 17:28:47 +01008
9#pragma once
Václav Kubernát509ce652019-05-29 19:46:44 +020010#include "ast_commands.hpp"
11#include "ast_path.hpp"
Václav Kubernát43908fb2020-01-02 19:05:51 +010012#include "data_query.hpp"
Václav Kubernát509ce652019-05-29 19:46:44 +020013#include "schema.hpp"
Václav Kubernátb61336d2018-05-28 17:35:03 +020014
Václav Kubernát624a8872018-03-02 17:28:47 +010015
Václav Kubernátb96eef72018-05-04 19:10:22 +020016class InvalidCommandException : public std::invalid_argument {
17public:
18 using std::invalid_argument::invalid_argument;
19 ~InvalidCommandException() override;
20};
21
Václav Kubernát624a8872018-03-02 17:28:47 +010022class TooManyArgumentsException : public std::invalid_argument {
23public:
24 using std::invalid_argument::invalid_argument;
25 ~TooManyArgumentsException() override;
26};
27
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010028struct Completions {
29 bool operator==(const Completions& b) const;
30 std::set<std::string> m_completions;
31 int m_contextLength;
32};
33
Václav Kubernát48fc3832018-05-28 14:21:22 +020034class Parser {
Václav Kubernát624a8872018-03-02 17:28:47 +010035public:
Václav Kubernát28cf3362020-06-29 17:52:51 +020036 Parser(const std::shared_ptr<const Schema> schema, WritableOps writableOps = WritableOps::No, const std::shared_ptr<const DataQuery> dataQuery = nullptr);
Václav Kubernátb61336d2018-05-28 17:35:03 +020037 command_ parseCommand(const std::string& line, std::ostream& errorStream);
Václav Kubernát2eaceb82018-10-08 19:56:30 +020038 void changeNode(const dataPath_& name);
Václav Kubernát59e4ee42020-07-08 17:32:45 +020039 [[nodiscard]] std::string currentNode() const;
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010040 Completions completeCommand(const std::string& line, std::ostream& errorStream) const;
Václav Kubernát82086872020-04-29 01:09:50 +020041 dataPath_ currentPath();
Václav Kubernát624a8872018-03-02 17:28:47 +010042
43private:
Václav Kubernáta10d8b62018-06-13 17:42:46 +020044 const std::shared_ptr<const Schema> m_schema;
Václav Kubernát43908fb2020-01-02 19:05:51 +010045 const std::shared_ptr<const DataQuery> m_dataquery;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020046 dataPath_ m_curDir;
Václav Kubernát28cf3362020-06-29 17:52:51 +020047 const WritableOps m_writableOps;
Václav Kubernát624a8872018-03-02 17:28:47 +010048};