From 1c630655b2beb0f4b84fb7e1bc034ba62520be37 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Mon, 21 Sep 2026 04:50:06 +0000 Subject: fix name typo, and remove outdated parse --- include/all.h | 1 - include/eval.h | 2 +- include/lang_analysis/ast.h | 30 +++++++++++++++++++++ include/lang_analysis/enum_type.h | 35 ++++++++++++++++++++++++ include/lang_analysis/lexer_class.h | 42 +++++++++++++++++++++++++++++ include/lang_analysis/parseline.h | 10 +++++++ include/lang_analysis/symbol_property.h | 48 +++++++++++++++++++++++++++++++++ include/lang_analysis/token.h | 25 +++++++++++++++++ include/lexer/ast.h | 30 --------------------- include/lexer/enum_type.h | 35 ------------------------ include/lexer/lexer_class.h | 42 ----------------------------- include/lexer/parseline.h | 10 ------- include/lexer/symbol_property.h | 48 --------------------------------- include/lexer/token.h | 25 ----------------- include/parse.h | 13 --------- 15 files changed, 191 insertions(+), 205 deletions(-) create mode 100644 include/lang_analysis/ast.h create mode 100644 include/lang_analysis/enum_type.h create mode 100644 include/lang_analysis/lexer_class.h create mode 100644 include/lang_analysis/parseline.h create mode 100644 include/lang_analysis/symbol_property.h create mode 100644 include/lang_analysis/token.h delete mode 100644 include/lexer/ast.h delete mode 100644 include/lexer/enum_type.h delete mode 100644 include/lexer/lexer_class.h delete mode 100644 include/lexer/parseline.h delete mode 100644 include/lexer/symbol_property.h delete mode 100644 include/lexer/token.h delete mode 100644 include/parse.h (limited to 'include') diff --git a/include/all.h b/include/all.h index 8c0d6f9..742eb00 100644 --- a/include/all.h +++ b/include/all.h @@ -12,6 +12,5 @@ #include "handler.h" #include "init.h" #include "job.h" -#include "parse.h" #include "path.h" #include "option.h" diff --git a/include/eval.h b/include/eval.h index 0466cb4..360de66 100644 --- a/include/eval.h +++ b/include/eval.h @@ -1,7 +1,7 @@ #pragma once #include "all.h" -#include "lexer/lexer_class.h" +#include "lang_analysis/lexer_class.h" namespace ov4 { diff --git a/include/lang_analysis/ast.h b/include/lang_analysis/ast.h new file mode 100644 index 0000000..9e5a717 --- /dev/null +++ b/include/lang_analysis/ast.h @@ -0,0 +1,30 @@ +#pragma once + +#include + +#include "lang_analysis/lexer_class.h" +#include "lang_analysis/enum_type.h" +#include "lang_analysis/token.h" + +using namespace std; // remove this + +namespace ov4 +{ + +class T_lexer::T_ast +{ +public: + T_ast() = default; + + enum_token_type token_type; + string command_text; + size_t left = string::npos; + size_t right = string::npos; + + // if this is marked as `subshell` + // it will fork a subshell + // then the subshell will handler the rest + bool subshell; +}; + +} diff --git a/include/lang_analysis/enum_type.h b/include/lang_analysis/enum_type.h new file mode 100644 index 0000000..bfc7cdc --- /dev/null +++ b/include/lang_analysis/enum_type.h @@ -0,0 +1,35 @@ +#pragma once + +namespace ov4 +{ + +enum enum_token_type +{ + TEXT, // foo + SINGLE_QUOTATION, // ' + DOUBLE_QUOTATION, // " + LOGIC_AND, // && + LOGIC_OR, // || + ASYNC, // & + PIPE, // | + SEMICOLON, // ; + EXPAND, // $ + LEFT_BRACKET, // ( + RIGHT_BRACKET, // ) +}; + +enum guard_type +{ + GUARD_OFF, + GUARD_WEAK, + GUARD_STRONG, +}; + +enum class child_existence_type +{ + NOT_EXIST, + OPTIONAL, + EXIST, +}; + +} diff --git a/include/lang_analysis/lexer_class.h b/include/lang_analysis/lexer_class.h new file mode 100644 index 0000000..4100b97 --- /dev/null +++ b/include/lang_analysis/lexer_class.h @@ -0,0 +1,42 @@ +#pragma once + +#include +#include +#include + +#include "lang_analysis/enum_type.h" + +using namespace std; + +namespace ov4 +{ + +class T_lexer +{ +public: + + // token.h + class T_token; + string trim(const string &s, const string &trim_target = " \t"); + bool is_single_symbol(char c); + void bracket_depth_changer(char c, int &bracket_depth); + bool token_continue(const string &s, char next); + void token_push(const string &push_s, int bracket_depth, bool force_text = false); + int tokenizer(const string &s); + + // ast.h + class T_ast; + string final_trim(size_t _begin, size_t _end); + size_t alloc_ast(); + int get_pivot_order(enum_token_type x); + bool is_operator(enum_token_type x); + void parse(size_t cmd_begin, size_t cmd_end, size_t ast_vec); + + // shared + std::vector ast; + std::vector token; + size_t ast_index = 0; + +}; + +} diff --git a/include/lang_analysis/parseline.h b/include/lang_analysis/parseline.h new file mode 100644 index 0000000..e52b50e --- /dev/null +++ b/include/lang_analysis/parseline.h @@ -0,0 +1,10 @@ +#pragma once + +#include + +namespace ov4 +{ + +char **parseline(const std::string &s); + +} diff --git a/include/lang_analysis/symbol_property.h b/include/lang_analysis/symbol_property.h new file mode 100644 index 0000000..f21b145 --- /dev/null +++ b/include/lang_analysis/symbol_property.h @@ -0,0 +1,48 @@ +#pragma once + +#include +#include + +#include "lang_analysis/enum_type.h" + +using namespace std; + +namespace ov4 +{ + +class T_property +{ +public: + bool continuable = true; + + // -1 means it's NOT operator + // any positive values mean it's operator + int pivot_priority = -1; + + // require: MUST + // accept: optional, but if it doesn't accept, but there is indeed a child, then error + child_existence_type left; + child_existence_type right; + + enum_token_type enum_type = TEXT; +}; + +inline const unordered_map symbol_property = { + + // bracket + {"(", {.continuable = false, .enum_type = LEFT_BRACKET}}, + {")", {.continuable = false, .enum_type = RIGHT_BRACKET}}, + + // operator + {"&", {.continuable = true, .pivot_priority = 2000, .left = child_existence_type::EXIST, .right = child_existence_type::NOT_EXIST, .enum_type = ASYNC}}, + {"|", {.continuable = true, .pivot_priority = 100, .left = child_existence_type::EXIST, .right = child_existence_type::EXIST, .enum_type = PIPE}}, + {"&&", {.continuable = true, .pivot_priority = 1000, .left = child_existence_type::EXIST, .right = child_existence_type::EXIST, .enum_type = LOGIC_AND}}, + {"||", {.continuable = true, .pivot_priority = 1000, .left = child_existence_type::EXIST, .right = child_existence_type::EXIST, .enum_type = LOGIC_OR}}, + +}; + +string symbol_enum2string(enum_token_type e); + +bool symbol_contains_enum_type(enum_token_type e); + +} diff --git a/include/lang_analysis/token.h b/include/lang_analysis/token.h new file mode 100644 index 0000000..508d142 --- /dev/null +++ b/include/lang_analysis/token.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +#include "lang_analysis/lexer_class.h" +#include "lang_analysis/enum_type.h" +#include "lang_analysis/symbol_property.h" + +using namespace std; // remove this + +namespace ov4 +{ + +class T_lexer::T_token +{ +public: + T_token() = default; + + enum_token_type token_type; + string text; + guard_type guard = GUARD_OFF; + int bracket_depth = 0; +}; + +} diff --git a/include/lexer/ast.h b/include/lexer/ast.h deleted file mode 100644 index 871afaf..0000000 --- a/include/lexer/ast.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include - -#include "lexer/lexer_class.h" -#include "lexer/enum_type.h" -#include "lexer/token.h" - -using namespace std; // remove this - -namespace ov4 -{ - -class T_lexer::T_ast -{ -public: - T_ast() = default; - - enum_token_type token_type; - string command_text; - size_t left = string::npos; - size_t right = string::npos; - - // if this is marked as `subshell` - // it will fork a subshell - // then the subshell will handler the rest - bool subshell; -}; - -} diff --git a/include/lexer/enum_type.h b/include/lexer/enum_type.h deleted file mode 100644 index bfc7cdc..0000000 --- a/include/lexer/enum_type.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -namespace ov4 -{ - -enum enum_token_type -{ - TEXT, // foo - SINGLE_QUOTATION, // ' - DOUBLE_QUOTATION, // " - LOGIC_AND, // && - LOGIC_OR, // || - ASYNC, // & - PIPE, // | - SEMICOLON, // ; - EXPAND, // $ - LEFT_BRACKET, // ( - RIGHT_BRACKET, // ) -}; - -enum guard_type -{ - GUARD_OFF, - GUARD_WEAK, - GUARD_STRONG, -}; - -enum class child_existence_type -{ - NOT_EXIST, - OPTIONAL, - EXIST, -}; - -} diff --git a/include/lexer/lexer_class.h b/include/lexer/lexer_class.h deleted file mode 100644 index 04b2e1c..0000000 --- a/include/lexer/lexer_class.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "lexer/enum_type.h" - -using namespace std; - -namespace ov4 -{ - -class T_lexer -{ -public: - - // token.h - class T_token; - string trim(const string &s, const string &trim_target = " \t"); - bool is_single_symbol(char c); - void bracket_depth_changer(char c, int &bracket_depth); - bool token_continue(const string &s, char next); - void token_push(const string &push_s, int bracket_depth, bool force_text = false); - int tokenizer(const string &s); - - // ast.h - class T_ast; - string final_trim(size_t _begin, size_t _end); - size_t alloc_ast(); - int get_pivot_order(enum_token_type x); - bool is_operator(enum_token_type x); - void parse(size_t cmd_begin, size_t cmd_end, size_t ast_vec); - - // shared - std::vector ast; - std::vector token; - size_t ast_index = 0; - -}; - -} diff --git a/include/lexer/parseline.h b/include/lexer/parseline.h deleted file mode 100644 index e52b50e..0000000 --- a/include/lexer/parseline.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include - -namespace ov4 -{ - -char **parseline(const std::string &s); - -} diff --git a/include/lexer/symbol_property.h b/include/lexer/symbol_property.h deleted file mode 100644 index c933605..0000000 --- a/include/lexer/symbol_property.h +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once - -#include -#include - -#include "lexer/enum_type.h" - -using namespace std; - -namespace ov4 -{ - -class T_property -{ -public: - bool continuable = true; - - // -1 means it's NOT operator - // any positive values mean it's operator - int pivot_priority = -1; - - // require: MUST - // accept: optional, but if it doesn't accept, but there is indeed a child, then error - child_existence_type left; - child_existence_type right; - - enum_token_type enum_type = TEXT; -}; - -inline const unordered_map symbol_property = { - - // bracket - {"(", {.continuable = false, .enum_type = LEFT_BRACKET}}, - {")", {.continuable = false, .enum_type = RIGHT_BRACKET}}, - - // operator - {"&", {.continuable = true, .pivot_priority = 2000, .left = child_existence_type::EXIST, .right = child_existence_type::NOT_EXIST, .enum_type = ASYNC}}, - {"|", {.continuable = true, .pivot_priority = 100, .left = child_existence_type::EXIST, .right = child_existence_type::EXIST, .enum_type = PIPE}}, - {"&&", {.continuable = true, .pivot_priority = 1000, .left = child_existence_type::EXIST, .right = child_existence_type::EXIST, .enum_type = LOGIC_AND}}, - {"||", {.continuable = true, .pivot_priority = 1000, .left = child_existence_type::EXIST, .right = child_existence_type::EXIST, .enum_type = LOGIC_OR}}, - -}; - -string symbol_enum2string(enum_token_type e); - -bool symbol_contains_enum_type(enum_token_type e); - -} diff --git a/include/lexer/token.h b/include/lexer/token.h deleted file mode 100644 index 93bdc22..0000000 --- a/include/lexer/token.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include - -#include "lexer/lexer_class.h" -#include "lexer/enum_type.h" -#include "lexer/symbol_property.h" - -using namespace std; // remove this - -namespace ov4 -{ - -class T_lexer::T_token -{ -public: - T_token() = default; - - enum_token_type token_type; - string text; - guard_type guard = GUARD_OFF; - int bracket_depth = 0; -}; - -} diff --git a/include/parse.h b/include/parse.h deleted file mode 100644 index 8fdbe12..0000000 --- a/include/parse.h +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include -#include - -#include "global.h" - -namespace ov4 -{ - -int parseline(const char *cmdline, char **argv); - -} -- cgit v1.3.1-4-g156e