diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2021-01-11 13:04:59 +0330 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-15 19:13:03 +0100 |
commit | 239472ba699c1e29f8dcb3380529637afeb95f21 (patch) | |
tree | 0c4c87c9063d160e130a53707299b14241a0781b /Userland/Shell/Parser.h | |
parent | 15fde85b214910e76677f86efaed22a4133ed1f6 (diff) | |
download | serenity-239472ba699c1e29f8dcb3380529637afeb95f21.zip |
Shell: Add (basic) support for history event designators
Closes #4888
Diffstat (limited to 'Userland/Shell/Parser.h')
-rw-r--r-- | Userland/Shell/Parser.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Userland/Shell/Parser.h b/Userland/Shell/Parser.h index c0d92e3a55..aa2a3b9e53 100644 --- a/Userland/Shell/Parser.h +++ b/Userland/Shell/Parser.h @@ -43,6 +43,10 @@ public: } RefPtr<AST::Node> parse(); + /// Parse the given string *as* an expression + /// that is to forefully enclose it in double-quotes. + RefPtr<AST::Node> parse_as_single_expression(); + NonnullRefPtrVector<AST::Node> parse_as_multiple_expressions(); struct SavedOffset { size_t offset; @@ -77,6 +81,7 @@ private: RefPtr<AST::Node> parse_doublequoted_string_inner(); RefPtr<AST::Node> parse_variable(); RefPtr<AST::Node> parse_evaluate(); + RefPtr<AST::Node> parse_history_designator(); RefPtr<AST::Node> parse_comment(); RefPtr<AST::Node> parse_bareword(); RefPtr<AST::Node> parse_glob(); @@ -140,6 +145,7 @@ private: Vector<size_t> m_rule_start_offsets; Vector<AST::Position::Line> m_rule_start_lines; + Vector<char> m_extra_chars_not_allowed_in_barewords; bool m_is_in_brace_expansion_spec { false }; bool m_continuation_controls_allowed { false }; }; @@ -215,6 +221,7 @@ list_expression :: ' '* expression (' '+ list_expression)? expression :: evaluate expression? | string_composite expression? | comment expression? + | history_designator expression? | '(' list_expression ')' expression? evaluate :: '$' '(' pipe_sequence ')' @@ -244,6 +251,18 @@ variable :: '$' identifier comment :: '#' [^\n]* +history_designator :: '!' event_selector (':' word_selector_composite)? + +event_selector :: '!' {== '-0'} + | '?' bareword '?' + | bareword {number: index, otherwise: lookup} + +word_selector_composite :: word_selector ('-' word_selector)? + +word_selector :: number + | '^' {== 0} + | '$' {== end} + bareword :: [^"'*$&#|()[\]{} ?;<>] bareword? | '\' [^"'*$&#|()[\]{} ?;<>] bareword? |