-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommandPreprocessor.h
88 lines (78 loc) · 2.28 KB
/
CommandPreprocessor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* CommandPreprocessor.h
*
* Created on: Nov 21, 2016
* Author: paul
*/
#ifndef SRC_COMMANDPREPROCESSOR_H_
#define SRC_COMMANDPREPROCESSOR_H_
#include <string>
#include <iostream>
#include <vector>
#include <stdexcept>
#include <exception>
class iash;
class UserCommand;
/**
* Processes raw input for iash and converts the input into UserCommands that
* can then be run by the CommandDispatcher. There is no need to instantiate
* this manually, it is used internally by iash.
*
* @since 0.5
*/
class CommandPreprocessor {
public:
/**
* Creates a CommandPreprocessor for the given shell.
*
* @param parent the shell that this CommandPreprocessor is attached to
*/
CommandPreprocessor(iash *parent);
virtual ~CommandPreprocessor();
/**
* Takes the raw input string and converts it into a vector of UserCommands
* that can be passed to the CommandDispatcher. Note that this will
* automatically call cleanup().
*
* @param raw the raw command string
* @return a reference to a vector of the UserCommands contained in
* the raw command string.
*/
const std::vector<UserCommand>& process (const std::string& raw);
/**
* Gets the UserCommands that were parsed from the last call to process.
*
* @return a reference to a vector of the UserCommands contained in the
* raw command string.
*/
const std::vector<UserCommand>& getCommands () const;
/**
* Cleans up stream objects that were opened on the last call to process.
* <p>
* In order to implement I/O redirection, CommandPreprocessor dynamically
* opens I/O streams when the user wants them redirected from/to file or
* another command. As such, it is necessary to clean up the streams after
* the commands have finished.
* <p>
* This is called automatically by process().
*/
void cleanup ();
private:
iash *m_parent;
std::vector<std::ios*> m_dynamicStreams;
std::vector<UserCommand> m_allCommands;
};
/**
* Thrown when the CommandPreprocessor encounters an iash syntax error. This is
* automatically caught by the iash shell.
*/
class SyntaxException : public std::runtime_error {
public:
/**
* Constructs a SyntaxException with the given reason.
*
* @param reason the syntax error
*/
SyntaxException(const std::string &reason);
};
#endif /* SRC_COMMANDPREPROCESSOR_H_ */