diff options
| -rw-r--r-- | include/lexer/symbol_property.h | 3 | ||||
| -rw-r--r-- | include/util/string.h | 1 | ||||
| -rw-r--r-- | module-test/argument_printer.cc | 2 | ||||
| -rw-r--r-- | module-test/lexer_test.cc | 14 | ||||
| -rw-r--r-- | src/lexer/token.cc | 9 | ||||
| -rw-r--r-- | src/util/string.cc | 10 |
6 files changed, 30 insertions, 9 deletions
diff --git a/include/lexer/symbol_property.h b/include/lexer/symbol_property.h index 8b05c14..c933605 100644 --- a/include/lexer/symbol_property.h +++ b/include/lexer/symbol_property.h @@ -28,9 +28,6 @@ public: }; inline const unordered_map<string, T_property> symbol_property = { - // non-operator - {"\'", {.enum_type = SINGLE_QUOTATION}}, - {"\"", {.enum_type = SINGLE_QUOTATION}}, // bracket {"(", {.continuable = false, .enum_type = LEFT_BRACKET}}, diff --git a/include/util/string.h b/include/util/string.h index 1c7f812..3f1cb0c 100644 --- a/include/util/string.h +++ b/include/util/string.h @@ -13,5 +13,6 @@ namespace ov4 void string2argv(const std::vector<std::string> &s, char **argv); void argv2string(std::vector<std::string> &s, const char * const * argv); std::string safe_str(const char *s, const char *fallback = ""); +void print_str_hex(const std::string &s); } diff --git a/module-test/argument_printer.cc b/module-test/argument_printer.cc index 8b8c6c3..4c23ff2 100644 --- a/module-test/argument_printer.cc +++ b/module-test/argument_printer.cc @@ -1,5 +1,5 @@ // print all arguments -// $ g++ module-test/argument_printer.cc -std=c++23 +// $ g++ module-test/argument_printer.cc -std=c++23 -o module-test/argument_printer.out #include <iostream> diff --git a/module-test/lexer_test.cc b/module-test/lexer_test.cc index 20e9556..cbc55d7 100644 --- a/module-test/lexer_test.cc +++ b/module-test/lexer_test.cc @@ -6,6 +6,7 @@ g++ \ src/lexer/token.cc \ src/lexer/ast.cc \ src/lexer/symbol_property.cc \ + src/util/string.cc \ -std=c++23 -Iinclude -Ithird_party/magic_enum/include \ -O0 -ggdb3 -fno-omit-frame-pointer -fno-inline -D_GLIBCXX_ASSERTIONS \ -o module-test/lexer_test.out @@ -27,6 +28,7 @@ g++ \ #include "lexer/token.h" #include "global.h" #include "error.h" +#include "util/string.h" using namespace std; using namespace ov4; @@ -37,7 +39,7 @@ constexpr int MAXLINE = 1024; int main() { verbose = true; - int test_case = 17; + int test_case = 19; string s; switch (test_case) @@ -126,6 +128,16 @@ int main() s = "((alpha)"; break; + // quotation mark in command + case 18: + s = "argument_printer.out \"hello hi\" second third &"; + break; + + // harder quotation mark test + case 19: + s = "alpha \"arg1 arg2 \'arg3 arg4\' arg5\" && beta &"; + break; + default: return 0; } diff --git a/src/lexer/token.cc b/src/lexer/token.cc index 26ad1f2..b9b8242 100644 --- a/src/lexer/token.cc +++ b/src/lexer/token.cc @@ -12,7 +12,7 @@ using namespace std; // remove this -constexpr bool TOKEN_DEBUG = false; +constexpr bool TOKEN_DEBUG = true; namespace ov4 { @@ -35,7 +35,8 @@ bool T_lexer::is_single_symbol(char c) { string s = " "; s[0] = c; - if (symbol_property.contains(s)) + // quotation marks are treated as text + if (symbol_property.contains(s) && c != '\'' && c != '\"') return true; return false; } @@ -119,8 +120,8 @@ void T_lexer::token_push(const string &push_s, int bracket_depth, bool force_tex else { if constexpr (TOKEN_DEBUG) loggerln("token_push: adding text"); - if (force_text) - trimmed = trim(trimmed, "\'\""); + // if (force_text) + // trimmed = trim(trimmed, "\'\""); tmp.token_type = TEXT; tmp.text = trimmed; } diff --git a/src/util/string.cc b/src/util/string.cc index c486a4f..9fad804 100644 --- a/src/util/string.cc +++ b/src/util/string.cc @@ -1,5 +1,7 @@ #include "util/string.h" +#include <print> + using namespace std; namespace ov4 @@ -40,4 +42,12 @@ std::string safe_str(const char *s, const char *fallback) return (s != nullptr) ? s : fallback; } +void print_str_hex(const std::string &s) +{ + for (unsigned char c : s) + { + print("{:02X} ", c); + } +} + } |
