mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:47:44 +00:00
Shell: Add support for brace expansions
This adds support for (basic) brace expansions with the following syntaxes: - `{expr?,expr?,expr?,...}` which is directly equivalent to `(expr expr expr ...)`, with the missing expressions replaced with an empty string literal. - `{expr..expr}` which is a new range expansion, with two modes: - if both expressions are one unicode code point long, the range is equivalent to the two code points and all code points between the two (numerically). - if both expressions are numeric, the range is equivalent to both numbers, and all numbers between the two. - otherwise, it is equivalent to `(expr expr)`. Closes #3832.
This commit is contained in:
parent
567f2f3548
commit
5640e1bc3a
9 changed files with 374 additions and 3 deletions
|
@ -77,6 +77,8 @@ private:
|
|||
RefPtr<AST::Node> parse_comment();
|
||||
RefPtr<AST::Node> parse_bareword();
|
||||
RefPtr<AST::Node> parse_glob();
|
||||
RefPtr<AST::Node> parse_brace_expansion();
|
||||
RefPtr<AST::Node> parse_brace_expansion_spec();
|
||||
|
||||
template<typename A, typename... Args>
|
||||
NonnullRefPtr<A> create(Args... args);
|
||||
|
@ -86,6 +88,7 @@ private:
|
|||
char consume();
|
||||
bool expect(char);
|
||||
bool expect(const StringView&);
|
||||
bool next_is(const StringView&);
|
||||
|
||||
void restore_to(size_t offset, AST::Position::Line line)
|
||||
{
|
||||
|
@ -133,6 +136,8 @@ private:
|
|||
|
||||
Vector<size_t> m_rule_start_offsets;
|
||||
Vector<AST::Position::Line> m_rule_start_lines;
|
||||
|
||||
bool m_is_in_brace_expansion_spec { false };
|
||||
};
|
||||
|
||||
#if 0
|
||||
|
@ -206,6 +211,7 @@ string_composite :: string string_composite?
|
|||
| variable string_composite?
|
||||
| bareword string_composite?
|
||||
| glob string_composite?
|
||||
| brace_expansion string_composite?
|
||||
|
||||
string :: '"' dquoted_string_inner '"'
|
||||
| "'" [^']* "'"
|
||||
|
@ -232,6 +238,11 @@ bareword_with_tilde_expansion :: '~' bareword?
|
|||
|
||||
glob :: [*?] bareword?
|
||||
| bareword [*?]
|
||||
|
||||
brace_expansion :: '{' brace_expansion_spec '}'
|
||||
|
||||
brace_expansion_spec :: expression? (',' expression?)*
|
||||
| expression '..' expression
|
||||
)";
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue