Skip to content

Commit

Permalink
style: Rename "bracket" to "parentheses"
Browse files Browse the repository at this point in the history
- Parentheses: `( )`
- Brackets: `[ ]`
- Braces: `{ }`

All of them mean something different for bash ofc.
In bash's documentation they use the same terminology.

Leaving it as it is with bracket is confusing when going through the code and you start to wonder if we handle `[ ]`, which we don't.

I guess you can name all of them brackets, but since we have support for both parentheses `( )` and braces `{ }`, using the term in a general way is just not very clear.
  • Loading branch information
itislu committed Jul 24, 2024
1 parent c1c3757 commit fe968ca
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 62 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ https://starchart.cc/LeaYeh/minishell
| | | | Support logical `AND` `&&`. ||
| | | | Support logical `OR` `\|\|`. ||
| | | | Support sequential operator `;`. | 🛇 |
| | | | Support left and right brackets `()` for `SUBSHELL`. ||
| | | | Support left and right parentheses `()` for `SUBSHELL`. ||
| | | | Support `WORD` representing basic words. ||
| | | | Recognize `ASSIGNMENT_WORD` `=` for local variable assignments. ||
| Frontend | Parser | Syntax Analysis | Analyze syntax of token list and report syntax errors based on Shift-Reduce algorithm with predefined grammar rules and then output as command table list. ||
Expand Down Expand Up @@ -301,8 +301,8 @@ In addition to the mandatory parts, in this project, we implemented all function
* `APPEND`: This token type represents append redirection, indicating that the output should be appended to a file rather than overwriting it.
* `OR`: This token type represents the logical OR operator, typically used in conditional statements or command chaining.
* `AND`: This token type represents the logical AND operator, also used in conditional statements or command chaining.
* `L_BRACKET`: This token type represents a left bracket, which may be used to denote the start of a group or condition in certain contexts.
* `R_BRACKET`: This token type represents a right bracket, used to denote the end of a group or condition in corresponding contexts.
* `L_PAREN`: This token type represents a left parenthesis, which may be used to denote the start of a group or condition in certain contexts.
* `R_PAREN`: This token type represents a right parenthesis, used to denote the end of a group or condition in corresponding contexts.

### Parser

Expand Down Expand Up @@ -486,7 +486,7 @@ Part of BNF grammar:
```bnf
pipe_sequence : command | pipe_sequence PIPE command;
command : simple_command | subshell | subshell redirect_list;
subshell : L_BRACKET and_or R_BRACKET;
subshell : L_PAREN and_or R_PAREN;
simple_command : cmd_prefix cmd_word cmd_suffix | cmd_prefix cmd_word | cmd_prefix | cmd_name cmd_suffix | cmd_name;
```

Expand Down
6 changes: 3 additions & 3 deletions doc/parsing rules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ referenced by:
![subshell](diagram/subshell.png)

```
subshell ::= L_BRACKET pipe_sequence ( ( AND | OR ) pipe_sequence )* R_BRACKET
subshell ::= L_PAREN pipe_sequence ( ( AND | OR ) pipe_sequence )* R_PAREN
```

referenced by:
Expand Down Expand Up @@ -160,7 +160,7 @@ referenced by:

* io_here

##
##
![rr-2.0](diagram/rr-2.0.png) <sup>generated by [RR - Railroad Diagram Generator][RR]</sup>

[RR]: http://bottlecaps.de/rr/ui
[RR]: http://bottlecaps.de/rr/ui
8 changes: 4 additions & 4 deletions include/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ typedef enum e_token_type
T_APPEND,
T_OR,
T_AND,
T_L_BRACKET,
T_R_BRACKET
T_L_PAREN,
T_R_PAREN
} t_tok_typ;

typedef enum e_parsing_table_column
Expand All @@ -209,8 +209,8 @@ typedef enum e_parser_element
P_APPEND,
P_OR,
P_AND,
P_L_BRACKET,
P_R_BRACKET,
P_L_PAREN,
P_R_PAREN,
P_AND_OR = 100,
P_PIPE_SEQ,
P_CMD,
Expand Down
2 changes: 1 addition & 1 deletion include/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ bool handle_word_token(t_list **token_list, t_list_d **cmd_table_list);
bool fill_redirect_by_scenario(
t_list **token_list, t_list_d **cmd_table_list);
void fill_control_op(t_list **token_list, t_list_d **cmd_table_list);
void fill_bracket(t_list **token_list, t_list_d **cmd_table_list);
void fill_parenthesis(t_list **token_list, t_list_d **cmd_table_list);

#endif
2 changes: 1 addition & 1 deletion meta/gen_action_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'RED_IN', 'RED_OUT', 'PIPE',
'HERE_DOC', 'APPEND',
'OR', 'AND',
'L_BRACKET', 'R_BRACKET']
'L_PAREN', 'R_PAREN']

TOKEN_TYPES = {key: i for i, key in enumerate(TOKEN_TYPES)}
TOKEN_TYPES['T_END'] = -2
Expand Down
28 changes: 14 additions & 14 deletions meta/parsing_rule.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ grammar bnf;

start : and_or;
and_or : pipe_sequence | and_or AND pipe_sequence | and_or OR pipe_sequence;
pipe_sequence : command | pipe_sequence PIPE command;
pipe_sequence : command | pipe_sequence PIPE command;
command : simple_command | subshell | subshell redirect_list;
subshell : L_BRACKET and_or R_BRACKET;
simple_command : cmd_prefix cmd_word cmd_suffix | cmd_prefix cmd_word | cmd_prefix | cmd_name cmd_suffix | cmd_name;
cmd_name : WORD;
cmd_word : WORD;
cmd_prefix : io_redirect | cmd_prefix io_redirect | ASSIGNMENT_WORD | cmd_prefix ASSIGNMENT_WORD;
cmd_suffix : io_redirect | cmd_suffix io_redirect | WORD | cmd_suffix WORD;
subshell : L_PAREN and_or R_PAREN;
simple_command : cmd_prefix cmd_word cmd_suffix | cmd_prefix cmd_word | cmd_prefix | cmd_name cmd_suffix | cmd_name;
cmd_name : WORD;
cmd_word : WORD;
cmd_prefix : io_redirect | cmd_prefix io_redirect | ASSIGNMENT_WORD | cmd_prefix ASSIGNMENT_WORD;
cmd_suffix : io_redirect | cmd_suffix io_redirect | WORD | cmd_suffix WORD;
redirect_list : io_redirect | redirect_list io_redirect;
io_redirect : io_file | io_here;
io_file : RED_OUT filename | RED_IN filename | APPEND filename;
filename : WORD;
io_here : HERE_DOC here_end;
here_end : WORD;
io_redirect : io_file | io_here;
io_file : RED_OUT filename | RED_IN filename | APPEND filename;
filename : WORD;
io_here : HERE_DOC here_end;
here_end : WORD;

PIPE : '|';
AND : '&&';
OR : '||';
L_BRACKET : '(';
R_BRACKET : ')';
L_PAREN : '(';
R_PAREN : ')';
WORD : 'abc';
ASSIGNMENT_WORD : '=';
RED_OUT : '>';
Expand Down
24 changes: 12 additions & 12 deletions meta/parsing_rule.output
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Grammar
7 | subshell
8 | subshell redirect_list

9 subshell: L_BRACKET and_or R_BRACKET
9 subshell: L_PAREN and_or R_PAREN

10 simple_command: cmd_prefix cmd_word cmd_suffix
11 | cmd_prefix cmd_word
Expand Down Expand Up @@ -65,8 +65,8 @@ HERE_DOC (263) 33
APPEND (264) 31
AND (265) 2
OR (266) 3
L_BRACKET (267) 9
R_BRACKET (268) 9
L_PAREN (267) 9
R_PAREN (268) 9


Nonterminals, with rules where they appear
Expand Down Expand Up @@ -115,7 +115,7 @@ state 0
RED_OUT shift, and go to state 4
HERE_DOC shift, and go to state 5
APPEND shift, and go to state 6
L_BRACKET shift, and go to state 7
L_PAREN shift, and go to state 7

and_or go to state 8
pipe_sequence go to state 9
Expand Down Expand Up @@ -181,15 +181,15 @@ state 6

state 7

9 subshell: L_BRACKET . and_or R_BRACKET
9 subshell: L_PAREN . and_or R_PAREN

WORD shift, and go to state 1
ASSIGNMENT_WORD shift, and go to state 2
RED_IN shift, and go to state 3
RED_OUT shift, and go to state 4
HERE_DOC shift, and go to state 5
APPEND shift, and go to state 6
L_BRACKET shift, and go to state 7
L_PAREN shift, and go to state 7

and_or go to state 24
pipe_sequence go to state 9
Expand Down Expand Up @@ -365,11 +365,11 @@ state 24

2 and_or: and_or . AND pipe_sequence
3 | and_or . OR pipe_sequence
9 subshell: L_BRACKET and_or . R_BRACKET
9 subshell: L_PAREN and_or . R_PAREN

AND shift, and go to state 26
OR shift, and go to state 27
R_BRACKET shift, and go to state 38
R_PAREN shift, and go to state 38


state 25
Expand All @@ -389,7 +389,7 @@ state 26
RED_OUT shift, and go to state 4
HERE_DOC shift, and go to state 5
APPEND shift, and go to state 6
L_BRACKET shift, and go to state 7
L_PAREN shift, and go to state 7

pipe_sequence go to state 39
command go to state 10
Expand All @@ -412,7 +412,7 @@ state 27
RED_OUT shift, and go to state 4
HERE_DOC shift, and go to state 5
APPEND shift, and go to state 6
L_BRACKET shift, and go to state 7
L_PAREN shift, and go to state 7

pipe_sequence go to state 40
command go to state 10
Expand All @@ -435,7 +435,7 @@ state 28
RED_OUT shift, and go to state 4
HERE_DOC shift, and go to state 5
APPEND shift, and go to state 6
L_BRACKET shift, and go to state 7
L_PAREN shift, and go to state 7

command go to state 41
subshell go to state 11
Expand Down Expand Up @@ -546,7 +546,7 @@ state 37

state 38

9 subshell: L_BRACKET and_or R_BRACKET .
9 subshell: L_PAREN and_or R_PAREN .

$default reduce using rule 9 (subshell)

Expand Down
8 changes: 4 additions & 4 deletions meta/parsing_rule.y
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
/* '>>' */
%token AND OR
/* '&&' '||' */
%token L_BRACKET R_BRACKET
/* '(' ')' */
%token L_PAREN R_PAREN
/* '(' ')' */

%start and_or
%%
Expand All @@ -23,14 +23,14 @@ and_or : pipe_sequence
| and_or AND pipe_sequence
| and_or OR pipe_sequence
;
pipe_sequence : command
pipe_sequence : command
| pipe_sequence PIPE command
;
command : simple_command
| subshell
| subshell redirect_list
;
subshell : L_BRACKET and_or R_BRACKET
subshell : L_PAREN and_or R_PAREN
;
simple_command : cmd_prefix cmd_word cmd_suffix
| cmd_prefix cmd_word
Expand Down
14 changes: 7 additions & 7 deletions meta/parsing_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
| 0 | RED_OUT | shift | 4 | -1 |
| 0 | HERE_DOC | shift | 5 | -1 |
| 0 | APPEND | shift | 6 | -1 |
| 0 | L_BRACKET | shift | 7 | -1 |
| 0 | L_PAREN | shift | 7 | -1 |
| 0 | and_or | goto | 8 | -1 |
| 0 | pipe_sequence | goto | 9 | -1 |
| 0 | command | goto | 10 | -1 |
Expand All @@ -33,7 +33,7 @@
| 7 | RED_OUT | shift | 4 | -1 |
| 7 | HERE_DOC | shift | 5 | -1 |
| 7 | APPEND | shift | 6 | -1 |
| 7 | L_BRACKET | shift | 7 | -1 |
| 7 | L_PAREN | shift | 7 | -1 |
| 7 | and_or | goto | 24 | -1 |
| 7 | pipe_sequence | goto | 9 | -1 |
| 7 | command | goto | 10 | -1 |
Expand Down Expand Up @@ -92,15 +92,15 @@
| 23 | -1 | reduce | io_file | ['APPEND', 'filename'] |
| 24 | AND | shift | 26 | -1 |
| 24 | OR | shift | 27 | -1 |
| 24 | R_BRACKET | shift | 38 | -1 |
| 24 | R_PAREN | shift | 38 | -1 |
| 25 | -1 | accept | None | -1 |
| 26 | WORD | shift | 1 | -1 |
| 26 | ASSIGNMENT_WORD | shift | 2 | -1 |
| 26 | RED_IN | shift | 3 | -1 |
| 26 | RED_OUT | shift | 4 | -1 |
| 26 | HERE_DOC | shift | 5 | -1 |
| 26 | APPEND | shift | 6 | -1 |
| 26 | L_BRACKET | shift | 7 | -1 |
| 26 | L_PAREN | shift | 7 | -1 |
| 26 | pipe_sequence | goto | 39 | -1 |
| 26 | command | goto | 10 | -1 |
| 26 | subshell | goto | 11 | -1 |
Expand All @@ -116,7 +116,7 @@
| 27 | RED_OUT | shift | 4 | -1 |
| 27 | HERE_DOC | shift | 5 | -1 |
| 27 | APPEND | shift | 6 | -1 |
| 27 | L_BRACKET | shift | 7 | -1 |
| 27 | L_PAREN | shift | 7 | -1 |
| 27 | pipe_sequence | goto | 40 | -1 |
| 27 | command | goto | 10 | -1 |
| 27 | subshell | goto | 11 | -1 |
Expand All @@ -132,7 +132,7 @@
| 28 | RED_OUT | shift | 4 | -1 |
| 28 | HERE_DOC | shift | 5 | -1 |
| 28 | APPEND | shift | 6 | -1 |
| 28 | L_BRACKET | shift | 7 | -1 |
| 28 | L_PAREN | shift | 7 | -1 |
| 28 | command | goto | 41 | -1 |
| 28 | subshell | goto | 11 | -1 |
| 28 | simple_command | goto | 12 | -1 |
Expand Down Expand Up @@ -174,7 +174,7 @@
| 36 | io_file | goto | 16 | -1 |
| 36 | io_here | goto | 17 | -1 |
| 37 | -1 | reduce | cmd_prefix | ['cmd_prefix', 'io_redirect'] |
| 38 | -1 | reduce | subshell | ['L_BRACKET', 'and_or', 'R_BRACKET'] |
| 38 | -1 | reduce | subshell | ['L_PAREN', 'and_or', 'R_PAREN'] |
| 39 | PIPE | shift | 28 | -1 |
| 39 | -1 | reduce | and_or | ['and_or', 'AND', 'pipe_sequence'] |
| 40 | PIPE | shift | 28 | -1 |
Expand Down
8 changes: 4 additions & 4 deletions source/debug/print_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ static char *get_token_type_str(t_tok_typ type)
return ("OR");
else if (type == T_AND)
return ("AND");
else if (type == T_L_BRACKET)
return ("L_BRACKET");
else if (type == T_R_BRACKET)
return ("R_BRACKET");
else if (type == T_L_PAREN)
return ("L_PAREN");
else if (type == T_R_PAREN)
return ("R_PAREN");
else if (type == T_END)
return ("END");
return (NULL);
Expand Down
2 changes: 1 addition & 1 deletion source/frontend/lexer/token_list_post_processing.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static void adjust_assignment_word_tokens(t_list *token_list)
{
if (prev_type != T_NONE && prev_type != T_ASSIGNMENT_WORD
&& prev_type != T_PIPE && prev_type != T_OR
&& prev_type != T_AND && prev_type != T_L_BRACKET)
&& prev_type != T_AND && prev_type != T_L_PAREN)
{
token->type = T_WORD;
}
Expand Down
4 changes: 2 additions & 2 deletions source/frontend/lexer/token_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ void set_token_type(t_list *token_list)
else if (ft_strcmp("&&", token_data) == 0)
token->type = T_AND;
else if (*token_data == '(')
token->type = T_L_BRACKET;
token->type = T_L_PAREN;
else if (*token_data == ')')
token->type = T_R_BRACKET;
token->type = T_R_PAREN;
else if (is_assignment_word(token_data))
token->type = T_ASSIGNMENT_WORD;
else
Expand Down
2 changes: 1 addition & 1 deletion source/frontend/parser/cmd_table_symbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bool handle_symbol_token(t_list **token_list, t_list_d **cmd_table_list)
}
else if (is_subshell_symbol(token_type))
{
fill_bracket(token_list, cmd_table_list);
fill_parenthesis(token_list, cmd_table_list);
return (true);
}
return (false);
Expand Down
6 changes: 3 additions & 3 deletions source/frontend/parser/cmd_table_symbol_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ void fill_control_op(t_list **token_list, t_list_d **cmd_table_list)
cmd_table->type = C_PIPE;
}

void fill_bracket(t_list **token_list, t_list_d **cmd_table_list)
void fill_parenthesis(t_list **token_list, t_list_d **cmd_table_list)
{
t_tok *token;
t_ct *cmd_table;

token = get_token_from_list(*token_list);
cmd_table = ft_lstlast_d(*cmd_table_list)->content;
if (token->type == T_L_BRACKET)
if (token->type == T_L_PAREN)
cmd_table->type = C_SUBSHELL_START;
else if (token->type == T_R_BRACKET)
else if (token->type == T_R_PAREN)
cmd_table->type = C_SUBSHELL_END;
}

Expand Down
2 changes: 1 addition & 1 deletion source/utils/token_type_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ bool is_control_op(t_tok_typ token_type)

bool is_subshell_symbol(t_tok_typ token_type)
{
return (token_type == T_L_BRACKET || token_type == T_R_BRACKET);
return (token_type == T_L_PAREN || token_type == T_R_PAREN);
}

0 comments on commit fe968ca

Please sign in to comment.