v1.4.4
This commit is contained in:
commit
9c94d113d3
10260 changed files with 1237388 additions and 0 deletions
66
source/core/StarShellParser.hpp
Normal file
66
source/core/StarShellParser.hpp
Normal file
|
@ -0,0 +1,66 @@
|
|||
#ifndef STAR_SHELL_PARSER_HPP
|
||||
#define STAR_SHELL_PARSER_HPP
|
||||
|
||||
#include "StarString.hpp"
|
||||
#include "StarEncode.hpp"
|
||||
#include "StarBytes.hpp"
|
||||
#include "StarFormat.hpp"
|
||||
|
||||
namespace Star {
|
||||
|
||||
// Currently the specification of the "language" is incredibly simple The only
|
||||
// thing we process are quoted strings and backslashes Backslashes function as
|
||||
// a useful subset of C++ This means: Newline: \n Tab: \t Backslash: \\ Single
|
||||
// Quote: \' Double Quote: \" Null: \0 Space: "\ " (without quotes ofc, not
|
||||
// actually C++) Also \v \b \a \f \r Plus Unicode \uxxxx Not implemented octal
|
||||
// and hexadecimal, because it's possible to construct invalid unicode code
|
||||
// points using them
|
||||
|
||||
STAR_EXCEPTION(ShellParsingException, StarException);
|
||||
|
||||
class ShellParser {
|
||||
public:
|
||||
ShellParser();
|
||||
typedef String::Char Char;
|
||||
|
||||
enum class TokenType {
|
||||
Word,
|
||||
// TODO: braces, brackets, actual shell stuff
|
||||
|
||||
};
|
||||
|
||||
struct Token {
|
||||
TokenType type;
|
||||
String token;
|
||||
};
|
||||
|
||||
List<Token> tokenize(String const& command);
|
||||
StringList tokenizeToStringList(String const& command);
|
||||
|
||||
private:
|
||||
void init(String const& command);
|
||||
|
||||
String word();
|
||||
Char parseBackslash();
|
||||
Char parseUnicodeEscapeSequence(Maybe<Char> previousCodepoint = {});
|
||||
|
||||
bool isSpace(Char letter) const;
|
||||
bool isQuote(Char letter) const;
|
||||
|
||||
bool inQuotedString() const;
|
||||
bool notDone() const;
|
||||
|
||||
Maybe<Char> current() const;
|
||||
Maybe<Char> next();
|
||||
Maybe<Char> previous();
|
||||
|
||||
String::const_iterator m_begin;
|
||||
String::const_iterator m_current;
|
||||
String::const_iterator m_end;
|
||||
|
||||
Char m_quotedType;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue