MiniDevil As beautiful as a shell
parser_pipeline.c
Go to the documentation of this file.
1 /* ************************************************************************** */
2 /* */
3 /* ::: :::::::: */
4 /* parser_pipeline.c :+: :+: :+: */
5 /* +:+ +:+ +:+ */
6 /* By: baelgadi <baelgadi@student.42.fr> +#+ +:+ +#+ */
7 /* +#+#+#+#+#+ +#+ */
8 /* Created: 2025/12/07 22:35:25 by zotaj-di #+# #+# */
9 /* Updated: 2026/03/04 04:46:44 by baelgadi ### ########.fr */
10 /* */
11 /* ************************************************************************** */
12 
13 #include "parser.h"
14 #include "ast.h"
15 #include <stddef.h>
16 
26 {
27  t_ast *left;
28  t_ast *right;
29 
30  left = parse_command(tokens);
31  if (!left)
32  return (NULL);
33  while (*tokens && (*tokens)->type == TOKEN_PIPE)
34  {
35  *tokens = (*tokens)->next;
36  right = parse_command(tokens);
37  if (!right)
38  {
39  free_ast(left);
40  return (NULL);
41  }
42  left = create_pipe_node(left, right);
43  if (!left)
44  return (NULL);
45  }
46  return (left);
47 }
t_ast * create_pipe_node(t_ast *left, t_ast *right)
Create a pipe AST node connecting 2 subtrees.
Definition: ast.c:43
AST node creation and destruction prototypes.
void free_ast(t_ast *node)
Recursively free an entire AST tree.
Definition: ast_utils.c:46
Parser entry point & sub parser prototypes.
t_ast * parse_pipeline(t_token **tokens)
Parse a pipeline of commands connected by pipes.
t_ast * parse_command(t_token **tokens)
Parse a command with all its redirections.
Definition: parser_redir.c:134
@ TOKEN_PIPE
Definition: structs.h:26
AST node (union based ↑)
Definition: structs.h:151
Lexer token (singly linked list)
Definition: structs.h:71
t_token_type type
Token type (word, pipe, redir)
Definition: structs.h:72
struct s_token * next
Next token.
Definition: structs.h:76