1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:38:11 +00:00

Shell: Add 'if' expressions

```sh
if foo bar baz {
    quux
} else if foobar || whatever {
    echo I ran out of example words
} else {
    exit 2
}
```
This commit is contained in:
AnotherTest 2020-08-11 12:05:46 +04:30 committed by Andreas Kling
parent c2be38e50f
commit b90eb5c9ba
4 changed files with 210 additions and 2 deletions

View file

@ -52,6 +52,7 @@ private:
RefPtr<AST::Node> parse_command();
RefPtr<AST::Node> parse_control_structure();
RefPtr<AST::Node> parse_for_loop();
RefPtr<AST::Node> parse_if_expr();
RefPtr<AST::Node> parse_redirection();
RefPtr<AST::Node> parse_list_expression();
RefPtr<AST::Node> parse_expression();
@ -125,9 +126,14 @@ variable_decls :: identifier '=' expression (' '+ variable_decls)? ' '*
pipe_sequence :: command '|' pipe_sequence
| command
control_structure :: for_loop
control_structure :: for_expr
| if_expr
for_expr :: 'for' ws+ (identifier ' '+ 'in' ws*)? expression ws+ '{' toplevel '}'
for_loop :: 'for' ws+ (identifier ' '+ 'in' ws*)? expression ws+ '{' toplevel '}'
if_expr :: 'if' ws+ or_logical_sequence ws+ '{' toplevel '}' else_clause?
else_clause :: else '{' toplevel '}'
| else if_expr
command :: redirection command
| list_expression command?