Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/core/StarShellParser.hpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-20 14:33:09 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-20 14:33:09 +1000
commit6352e8e3196f78388b6c771073f9e03eaa612673 (patch)
treee23772f79a7fbc41bc9108951e9e136857484bf4 /source/core/StarShellParser.hpp
parent6741a057e5639280d85d0f88ba26f000baa58f61 (diff)
everything everywhere
all at once
Diffstat (limited to 'source/core/StarShellParser.hpp')
-rw-r--r--source/core/StarShellParser.hpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/source/core/StarShellParser.hpp b/source/core/StarShellParser.hpp
new file mode 100644
index 0000000..8e89273
--- /dev/null
+++ b/source/core/StarShellParser.hpp
@@ -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