aboutsummaryrefslogtreecommitdiff
path: root/module-test/lexer_test.cc
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-09-08 12:31:17 +0000
committer_ov4 <ov4@ov4.org>2026-09-08 12:31:17 +0000
commit02e7e15bdc8f36f08e90f69096a4cb93006885e8 (patch)
treedcc8211fe64c7c530208ceade2220fa77d439193 /module-test/lexer_test.cc
parentbb39c49a0dbfd0ee05ec5ac3bba96916b175fa92 (diff)
add argument helper
Diffstat (limited to 'module-test/lexer_test.cc')
-rw-r--r--module-test/lexer_test.cc119
1 files changed, 119 insertions, 0 deletions
diff --git a/module-test/lexer_test.cc b/module-test/lexer_test.cc
new file mode 100644
index 0000000..036386e
--- /dev/null
+++ b/module-test/lexer_test.cc
@@ -0,0 +1,119 @@
+// test lexer
+// $ g++ module-test/ast.cc -std=c++23 -Iinclude -Ithird_party/magic_enum/include
+
+#include <iostream>
+#include <string>
+#include <type_traits>
+#include <unistd.h>
+#include <cstring>
+#include <vector>
+#include <print>
+
+#include "magic_enum/magic_enum.hpp"
+
+#include "lexer/shared.h"
+#include "lexer/ast.h"
+#include "lexer/enum_type.h"
+#include "lexer/token.h"
+
+using namespace std;
+using namespace ov4;
+
+constexpr int MAXLINE = 1024;
+
+
+
+
+int main()
+{
+ int test_case = 10;
+ string s;
+
+ switch (test_case)
+ {
+ case 0:
+ s = "hello | hi || foo && bar || baz &";
+ break;
+ case 1:
+ s = "hi";
+ break;
+ case 2:
+ s = "&&";
+ break;
+ case 3:
+ s = "hi (hello || foo)";
+ break;
+ case 4:
+ s = "alpha || beta (gamma argument && (delta || epsilon second_argument & ) )";
+ break;
+ case 5:
+ s = "alpha || beta && (gamma || epsilon)";
+ break;
+
+ // bracket matching test
+ case 6:
+ s = ")alpha && beta(";
+ break;
+
+ // basic scriptio continua
+ // syntax is wrong but just to test tokenizer
+ case 7:
+ s = "((alpha&|&&beta)||gamma&&&delta)";
+ break;
+
+ // simple guard test
+ case 8:
+ s = "\'text\' &&";
+ break;
+
+ // guard test
+ case 9:
+ s = "\'realOperator\' && \"fake&&\" real ||";
+ break;
+
+ // guard test
+ // with space
+ case 10:
+ s = "\'This should be 1 token\' symbol && text \'&&\'";
+ break;
+
+ default:
+ return 0;
+ }
+
+
+
+ tokenizer(s);
+ cout << "---------- tokenizer ----------" << endl;
+ for (auto c : token)
+ {
+ if (c.token_type == LOGIC_AND)
+ println("{} LOGIC_AND", c.bracket_depth);
+ else if (c.token_type == LOGIC_OR)
+ println("{} LOGIC_OR", c.bracket_depth);
+ else if (c.token_type == ASYNC)
+ println("{} ASYNC", c.bracket_depth);
+ else if (c.token_type == PIPE)
+ println("{} PIPE", c.bracket_depth);
+ else if (c.token_type == LEFT_BRACKET)
+ println("{} LEFT_BRACKET", c.bracket_depth);
+ else if (c.token_type == RIGHT_BRACKET)
+ println("{} RIGHT_BRACKET", c.bracket_depth);
+ else if (c.token_type == TEXT)
+ println("{} TEXT .{}.", c.bracket_depth, c.text);
+ }
+
+ cout << "---------- parse ----------" << endl;
+
+ parse(0, token.size(), alloc_ast());
+
+ cout << "---------- AST ----------" << endl;
+ for (size_t i = 0; i < ast.size(); i++)
+ {
+ print("{}: type: {} left: {} right: {}", i, magic_enum::enum_name(ast[i].token_type), ast[i].left, ast[i].right);
+ if (ast[i].token_type == TEXT)
+ print(" command: {}", ast[i].command_text);
+ println();
+ }
+ return 0;
+}