feat: toujours les mêmes qui font les pipes. Plus de assert dans ASTs (pour des raisons évidentes de stabilité du code) et nouveaux types (AST_PIPE et AST_NEG), + modifs random dans le parser
This commit is contained in:
parent
07e7d83c60
commit
96626d9850
27 changed files with 238 additions and 86 deletions
|
|
@ -1,13 +1,13 @@
|
|||
#include <stdbool.h>
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
|
||||
#include "grammar_basic.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../utils/lists/lists.h"
|
||||
#include "grammar.h"
|
||||
#include "grammar_advanced.h"
|
||||
#include "grammar_basic.h"
|
||||
|
||||
// === Static functions
|
||||
|
||||
|
|
@ -108,7 +108,42 @@ struct ast *parse_and_or(struct lexer_context *ctx)
|
|||
|
||||
struct ast *parse_pipeline(struct lexer_context *ctx)
|
||||
{
|
||||
return parse_command(ctx);
|
||||
bool negation = false;
|
||||
struct token *token = PEEK_TOKEN();
|
||||
|
||||
// Eventual '!'
|
||||
if (token->type == TOKEN_NEGATION)
|
||||
{
|
||||
negation = true;
|
||||
POP_TOKEN();
|
||||
token = PEEK_TOKEN();
|
||||
}
|
||||
|
||||
// TODO handle negation (new AST type)
|
||||
|
||||
struct ast *left = parse_command(ctx);
|
||||
|
||||
token = PEEK_TOKEN();
|
||||
while (token->type == TOKEN_PIPE)
|
||||
{
|
||||
POP_TOKEN();
|
||||
|
||||
// skip newlines
|
||||
token = PEEK_TOKEN();
|
||||
while (token->type == TOKEN_NEWLINE)
|
||||
{
|
||||
POP_TOKEN();
|
||||
token = PEEK_TOKEN();
|
||||
}
|
||||
|
||||
struct ast *right = parse_command(ctx);
|
||||
|
||||
// Create AST
|
||||
left = ast_create_pipe(left, right);
|
||||
token = PEEK_TOKEN();
|
||||
}
|
||||
|
||||
return left;
|
||||
}
|
||||
|
||||
struct ast *parse_command(struct lexer_context *ctx)
|
||||
|
|
@ -125,7 +160,7 @@ struct ast *parse_command(struct lexer_context *ctx)
|
|||
}
|
||||
else
|
||||
{
|
||||
puts("Syntax error: expected command");
|
||||
puts("Syntax error: unexpected token");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
|
@ -324,7 +359,7 @@ struct ast *parse_compound_list(struct lexer_context *ctx)
|
|||
return NULL;
|
||||
result_list = list_append(result_list, current_cmd);
|
||||
}
|
||||
|
||||
|
||||
token = PEEK_TOKEN();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue