diff --git a/src/parse_tree.cpp b/src/parse_tree.cpp index f07102d87..a98971602 100644 --- a/src/parse_tree.cpp +++ b/src/parse_tree.cpp @@ -1073,26 +1073,6 @@ static inline bool is_help_argument(const wcstring &txt) { return txt == L"-h" || txt == L"--help"; } -// Return the location of the equals sign, or npos if the string does -// not look like a variable assignment like FOO=bar. The detection -// works similar as in some POSIX shells: only letters and numbers qre -// allowed on the left hand side, no quotes or escaping. -maybe_t variable_assignment_equals_pos(const wcstring &txt) { - enum { init, has_some_variable_identifier } state = init; - // TODO bracket indexing - for (size_t i = 0; i < txt.size(); i++) { - wchar_t c = txt[i]; - if (state == init) { - if (!valid_var_name_char(c)) return {}; - state = has_some_variable_identifier; - } else { - if (c == '=') return {i}; - if (!valid_var_name_char(c)) return {}; - } - } - return {}; -} - /// Return a new parse token, advancing the tokenizer. static inline parse_token_t next_parse_token(tokenizer_t *tok, maybe_t *out_token, wcstring *storage) { diff --git a/src/parse_tree.h b/src/parse_tree.h index d1f60834d..bd228590c 100644 --- a/src/parse_tree.h +++ b/src/parse_tree.h @@ -235,9 +235,6 @@ using parsed_source_ref_t = std::shared_ptr; parsed_source_ref_t parse_source(wcstring src, parse_tree_flags_t flags, parse_error_list_t *errors, parse_token_type_t goal = symbol_job_list); -/// The position of the equal sign in a variable assignment like foo=bar. -maybe_t variable_assignment_equals_pos(const wcstring &txt); - /// Error message for improper use of the exec builtin. #define EXEC_ERR_MSG _(L"The '%ls' command can not be used in a pipeline") diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index 51d48a105..d2f3d7760 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -851,3 +851,23 @@ move_word_state_machine_t::move_word_state_machine_t(move_word_style_t syl) : state(0), style(syl) {} void move_word_state_machine_t::reset() { state = 0; } + +// Return the location of the equals sign, or npos if the string does +// not look like a variable assignment like FOO=bar. The detection +// works similar as in some POSIX shells: only letters and numbers qre +// allowed on the left hand side, no quotes or escaping. +maybe_t variable_assignment_equals_pos(const wcstring &txt) { + enum { init, has_some_variable_identifier } state = init; + // TODO bracket indexing + for (size_t i = 0; i < txt.size(); i++) { + wchar_t c = txt[i]; + if (state == init) { + if (!valid_var_name_char(c)) return {}; + state = has_some_variable_identifier; + } else { + if (c == '=') return {i}; + if (!valid_var_name_char(c)) return {}; + } + } + return {}; +} diff --git a/src/tokenizer.h b/src/tokenizer.h index 90563b701..a588c2ca6 100644 --- a/src/tokenizer.h +++ b/src/tokenizer.h @@ -210,4 +210,7 @@ class move_word_state_machine_t { void reset(); }; +/// The position of the equal sign in a variable assignment like foo=bar. +maybe_t variable_assignment_equals_pos(const wcstring &txt); + #endif