MiniDevil As beautiful as a shell
parser_grammar.c File Reference

Syntax validation: validates pipe / redirection positions. More...

#include "parser.h"
+ Include dependency graph for parser_grammar.c:

Detailed Description

Syntax validation: validates pipe / redirection positions.

Definition in file parser_grammar.c.

Functions

static int validate_empty (t_token *tokens)
 Validate that the token list isn't empty. More...
 
static int validate_pipe_position (t_token *tokens)
 Validate pipe positions (not at start nor end and no consecutive pipe) More...
 
static int validate_redir_syntax (t_token *tokens)
 Validate that every redirection is followed by a word token. More...
 
int validate_syntax (t_token *tokens)
 Run all validation checks on a token list. More...
 

Function Documentation

◆ validate_empty()

static int validate_empty ( t_token tokens)
static

Validate that the token list isn't empty.

Parameters
tokensToken list
Returns
0 if not empty and -1 on error

Definition at line 21 of file parser_grammar.c.

References ERR_EMPTY_INPUT, and print_syntax_error().

Referenced by validate_syntax().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validate_pipe_position()

static int validate_pipe_position ( t_token tokens)
static

Validate pipe positions (not at start nor end and no consecutive pipe)

Parameters
tokensToken list
Returns
0 if valid and -1 on error

Definition at line 34 of file parser_grammar.c.

References ERR_PIPE_DOUBLE, ERR_PIPE_END, ERR_PIPE_START, t_token::next, print_syntax_error(), TOKEN_PIPE, and t_token::type.

Referenced by validate_syntax().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validate_redir_syntax()

static int validate_redir_syntax ( t_token tokens)
static

Validate that every redirection is followed by a word token.

Parameters
tokensToken list
Returns
0 if valid and -1 on error

Definition at line 63 of file parser_grammar.c.

References ERR_REDIR_NO_FILE, is_redirection(), t_token::next, print_syntax_error(), TOKEN_WORD, and t_token::type.

Referenced by validate_syntax().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validate_syntax()

int validate_syntax ( t_token tokens)

Run all validation checks on a token list.

Parameters
tokensToken list to validate
Returns
0 if valid and -1 on error (with message printed to STDERR)

Definition at line 88 of file parser_grammar.c.

References validate_empty(), validate_pipe_position(), and validate_redir_syntax().

Referenced by parse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Go to the source code of this file.