aboutsummaryrefslogtreecommitdiff
path: root/src/lexer
diff options
context:
space:
mode:
Diffstat (limited to 'src/lexer')
-rw-r--r--src/lexer/parseline.cc80
-rw-r--r--src/lexer/token.cc2
2 files changed, 81 insertions, 1 deletions
diff --git a/src/lexer/parseline.cc b/src/lexer/parseline.cc
new file mode 100644
index 0000000..064f876
--- /dev/null
+++ b/src/lexer/parseline.cc
@@ -0,0 +1,80 @@
+#include "lexer/parseline.h"
+
+#include <vector>
+
+#include "lexer/enum_type.h"
+#include "util/string.h"
+
+using namespace std;
+
+namespace ov4
+{
+
+char **parseline(const std::string &s)
+{
+ guard_type guard = GUARD_OFF;
+ vector<string> v;
+ size_t len = s.size();
+ string prev_str = "";
+ char c;
+
+ for (size_t i = 0; i < len; i++)
+ {
+
+ c = s[i];
+ if (c == ' ' && guard == GUARD_OFF) continue;
+
+ if (c == '\'' || c == '\"')
+ {
+
+ // turn on GUARD
+ if (guard == GUARD_OFF)
+ {
+ guard = (c == '\'') ? GUARD_STRONG : GUARD_WEAK;
+ if (i+1 == len)
+ {
+ v.push_back(prev_str);
+ prev_str = "";
+ }
+ continue;
+ }
+ // turn off
+ else if (guard == GUARD_STRONG && c == '\'')
+ {
+ guard = GUARD_OFF;
+ if (i+1 == len)
+ {
+ v.push_back(prev_str);
+ prev_str = "";
+ }
+ continue;
+ }
+ // turn off
+ else if (guard == GUARD_WEAK && c == '\"')
+ {
+ guard = GUARD_OFF;
+ if (i+1 == len)
+ {
+ v.push_back(prev_str);
+ prev_str = "";
+ }
+ continue;
+ }
+ // if this (single/double) quotation mark is guarded
+ // it should be saved
+ }
+
+ prev_str += c;
+
+ if ((i+1 >= len) || (s[i+1] == ' ' && guard == GUARD_OFF))
+ {
+ v.push_back(prev_str);
+ prev_str = "";
+ continue;
+ }
+ }
+
+ return string2argv_alloc(v);
+}
+
+}
diff --git a/src/lexer/token.cc b/src/lexer/token.cc
index b9b8242..ec69090 100644
--- a/src/lexer/token.cc
+++ b/src/lexer/token.cc
@@ -12,7 +12,7 @@
using namespace std; // remove this
-constexpr bool TOKEN_DEBUG = true;
+constexpr bool TOKEN_DEBUG = false;
namespace ov4
{