Adding for the norm
This commit is contained in:
parent
4f5cf3cf10
commit
84b7e3e1e9
12 changed files with 873 additions and 591 deletions
123
ast/src/from_node/expansion_node.c
Normal file
123
ast/src/from_node/expansion_node.c
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* expansion_node.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/06 18:26:15 by rparodi #+# #+# */
|
||||
/* Updated: 2024/08/06 18:31:32 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ast/_from_node.h"
|
||||
#include "ast/ast.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/symbols.h"
|
||||
#include "gmr/symbols.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_ast.h"
|
||||
#include "parser/api.h"
|
||||
#include <stdio.h>
|
||||
|
||||
t_error build_sym_regex(\
|
||||
t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
|
||||
(void)(out);
|
||||
(void)(input);
|
||||
(void)(self);
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_regex)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_REGEX);
|
||||
ret->data.regex.pattern = _extract_str(self, input);
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_extglob_pattern(\
|
||||
t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
|
||||
(void)(out);
|
||||
(void)(input);
|
||||
(void)(self);
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_extglob_pattern)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_EXTGLOB);
|
||||
ret->data.extglob.pattern = _extract_str(self, input);
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_expansion(\
|
||||
t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_ast_node tmp;
|
||||
t_usize i;
|
||||
|
||||
(void)(out);
|
||||
(void)(input);
|
||||
(void)(self);
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_expansion)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_EXPANSION);
|
||||
ret->data.expansion.kind = E_OP_NONE;
|
||||
i = 0;
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
|
||||
continue ;
|
||||
if (ts_node_field_id_for_child(self, i) == field_len)
|
||||
ret->data.expansion.len_operator = true;
|
||||
if (ts_node_field_id_for_child(self, i) == field_name)
|
||||
ret->data.expansion.var_name = \
|
||||
_extract_str(ts_node_child(self, i), input);
|
||||
if (ts_node_field_id_for_child(self, i) == field_op)
|
||||
ret->data.expansion.kind = _extract_exp_op(ts_node_child(self, i));
|
||||
if (ts_node_field_id_for_child(self, i) == field_args)
|
||||
{
|
||||
if (ast_from_node(ts_node_child(self, i), input, &tmp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(&ret->data.expansion.args, tmp);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_simple_expansion(\
|
||||
t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_usize i;
|
||||
|
||||
(void)(out);
|
||||
(void)(input);
|
||||
(void)(self);
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_simple_expansion)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_EXPANSION);
|
||||
ret->data.expansion.kind = E_OP_NONE;
|
||||
i = 0;
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
|
||||
continue ;
|
||||
ret->data.expansion.var_name = \
|
||||
_extract_str(ts_node_child(self, i), input);
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue