aboutsummaryrefslogtreecommitdiff
path: root/src/lexer/ast.cc
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-09-15 13:48:09 +0000
committer_ov4 <ov4@ov4.org>2026-09-15 13:48:09 +0000
commit165ead4adbf8494db82f7be35c6f8d52ac47ebef (patch)
tree1f5176e3ab097f376c38de2ba2cee7bc1c0d4c6a /src/lexer/ast.cc
parenta6b19b1f4ce89c7daa94f47d7927a0954c0c019e (diff)
add subshell ast
prepare for real subshell and expansion
Diffstat (limited to 'src/lexer/ast.cc')
-rw-r--r--src/lexer/ast.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/lexer/ast.cc b/src/lexer/ast.cc
index 55b4c42..292728b 100644
--- a/src/lexer/ast.cc
+++ b/src/lexer/ast.cc
@@ -10,6 +10,7 @@
#include "lexer/symbol_property.h"
#include "util/io.h"
#include "error.h"
+#include "magic_enum/magic_enum.hpp"
using namespace std;
@@ -62,6 +63,25 @@ void T_lexer::parse(size_t cmd_begin, size_t cmd_end, size_t ast_vec)
int max_depth = -1;
size_t found_pos = string::npos;
+ // if it's fully inside bracket
+ // then it's subshell
+ loggerln("parse: left token type: {}, right: {}",
+ magic_enum::enum_name(token[cmd_begin].token_type),
+ magic_enum::enum_name(token[cmd_end-1].token_type));
+ if (token[cmd_begin].token_type == LEFT_BRACKET && token[cmd_end-1].token_type == RIGHT_BRACKET)
+ {
+ ast[ast_vec].subshell = true;
+ loggerln("parse: detect subshell {}", ast_vec);
+
+ // eat () subshell token
+ cmd_begin++;
+ cmd_end--;
+ }
+ else
+ {
+ ast[ast_vec].subshell = false;
+ }
+
for (size_t i = cmd_begin; i < cmd_end; i++)
{
if (token[i].bracket_depth > max_depth)