Updated Grammar

This commit is contained in:
Maieul BOYER 2024-07-01 12:57:51 +02:00
parent 74d642f297
commit 175efe0f2f
No known key found for this signature in database
1246 changed files with 109558 additions and 114993 deletions

View file

@ -41,6 +41,8 @@ enum e_ast_node_kind
AST_STRING = S_AST_NONE | 0x000B,
AST_WORD = S_AST_NONE | 0x000C,
AST_VARIABLE_ASSIGNMENT = S_AST_NONE | 0x000E,
AST_EXTGLOB = S_AST_NONE | 0x001A,
AST_REGEX = S_AST_NONE | 0x001B,
AST_FILE_REDIRECTION = S_AST_REDIRECT | 0x000F,
AST_HEREDOC_REDIRECTION = S_AST_REDIRECT | 0x0010,
@ -84,6 +86,8 @@ union u_ast_node_data {
t_ast_variable_assignment variable_assignment;
t_ast_while while_;
t_ast_word word;
t_ast_extglob extglob;
t_ast_regex regex;
};
struct s_ast_node

View file

@ -18,6 +18,7 @@ typedef enum e_ast_word_kind t_ast_word_kind;
typedef enum e_ast_list_kind t_ast_list_kind;
typedef enum e_ast_expansion_operator t_ast_expansion_operator;
typedef enum e_ast_terminator_kind t_ast_terminator_kind;
typedef enum e_ast_redirection_kind t_ast_redirection_kind;
typedef union u_ast_node_data t_ast_node_data;
@ -33,6 +34,7 @@ typedef struct s_ast_elif t_ast_elif;
typedef struct s_ast_else t_ast_else;
typedef struct s_ast_empty t_ast_empty;
typedef struct s_ast_expansion t_ast_expansion;
typedef struct s_ast_extglob t_ast_extglob;
typedef struct s_ast_file_redirection t_ast_file_redirection;
typedef struct s_ast_for t_ast_for;
typedef struct s_ast_function_definition t_ast_function_definition;
@ -48,6 +50,7 @@ typedef struct s_ast_until t_ast_until;
typedef struct s_ast_variable_assignment t_ast_variable_assignment;
typedef struct s_ast_while t_ast_while;
typedef struct s_ast_word t_ast_word;
typedef struct s_ast_regex t_ast_regex;
/*
t_ast_arithmetic_expansion arithmetic_expansion;

View file

@ -58,6 +58,18 @@ enum e_ast_expansion_operator
E_OP_LARGEST_SUFFIX, // ${var%%pattern}
};
enum e_ast_redirection_kind
{
AST_REDIR_INPUT, // <
AST_REDIR_OUTPUT, // >
AST_REDIR_APPEND, // >>
AST_REDIR_HEREDOC, // <<
AST_REDIR_HEREDOC_INDENT, // <<-
AST_REDIR_DUP_INPUT, // <&
AST_REDIR_DUP_OUTPUT, // >&
AST_REDIR_DUP_ERROR, // &>
};
struct s_ast_empty
{
};
@ -306,6 +318,7 @@ struct s_ast_variable_assignment
struct s_ast_file_redirection
{
t_ast_node output;
t_ast_redirection_kind op;
t_ast_node input;
};
@ -318,6 +331,7 @@ struct s_ast_file_redirection
struct s_ast_heredoc_redirection
{
t_ast_node output;
t_ast_redirection_kind op;
t_ast_node delimiter;
};
@ -357,4 +371,26 @@ struct s_ast_command_substitution
t_ast_node cmd;
};
/// Extended Globbing
/// ```shell
/// !(pattern)
/// ?(pattern)
/// *(pattern)
/// +(pattern)
/// @(pattern)
/// ```
struct s_ast_extglob
{
t_str pattern;
};
/// Regex
/// ```shell
/// ~pattern
/// ```
struct s_ast_regex
{
t_str pattern;
};
#endif /* AST_RAW_STRUCTS_H */

View file

@ -205,6 +205,14 @@ void ast_free(t_ast_node elem)
{
vec_ast_free(elem->data.word.inner);
}
if (elem->kind == AST_EXTGLOB)
{
mem_free(elem->data.extglob.pattern);
}
if (elem->kind == AST_REGEX)
{
mem_free(elem->data.regex.pattern);
}
mem_free(elem);
}
@ -357,6 +365,14 @@ t_ast_node ast_alloc(t_ast_node_kind kind)
ret->data.word.inner = vec_ast_new(16, ast_free);
ret->data.word.kind = AST_WORD_NO_QUOTE;
}
if (kind == AST_EXTGLOB)
{
ret->data.extglob.pattern = NULL;
}
if (kind == AST_REGEX)
{
ret->data.regex.pattern = NULL;
}
return (ret);
}
@ -452,13 +468,13 @@ t_ast_terminator_kind _select_term(t_parse_node node)
t_symbol symbol;
symbol = ts_node_grammar_symbol(node);
printf("term_symbol = %hu\n", symbol);
if (symbol == anon_sym_AMP)
return (AST_TERM_FORK);
if (symbol == anon_sym_SEMI)
return (AST_TERM_SEMI);
if (symbol == anon_sym_SEMI_SEMI)
return (AST_TERM_DOUBLE_SEMI);
printf("unknown term symbol %d\n", symbol);
return (AST_TERM_NONE);
}
@ -466,9 +482,7 @@ t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out);
/* FUNCTION THAT ARE DONE */
t_error build_sym__bare_dollar(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_case_item(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym__case_item_last(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_case_statement(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_command(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_command_name(t_parse_node self, t_const_str input, t_ast_node *out);
@ -476,6 +490,7 @@ t_error build_sym_comment(t_parse_node self, t_const_str input, t_ast_node *out)
t_error build_sym_compound_statement(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_elif_clause(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_else_clause(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_extglob_pattern(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_for_statement(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_function_definition(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_if_statement(t_parse_node self, t_const_str input, t_ast_node *out);
@ -490,6 +505,8 @@ t_error build_sym_subshell(t_parse_node self, t_const_str input, t_ast_node *out
t_error build_sym_variable_assignment(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_while_statement(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_word(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_regex(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_file_redirect(t_parse_node self, t_const_str input, t_ast_node *out);
/* FUNCTION THAT ARE NOT DONE */
@ -507,13 +524,10 @@ t_error build_sym_expansion_expression(t_parse_node self, t_const_str input, t_a
t_error build_sym_expansion_regex(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_simple_expansion(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_heredoc_redirect(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_file_redirect(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_extglob_pattern(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_file_descriptor(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_number(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_regex(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_heredoc_redirect(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_simple_heredoc_body(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_heredoc_body(t_parse_node self, t_const_str input, t_ast_node *out);
@ -523,6 +537,38 @@ t_error build_sym_heredoc_start(t_parse_node self, t_const_str input, t_ast_node
#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 = str_substring(input, ts_node_start_byte(self), ts_node_end_byte(self) - ts_node_start_byte(self));
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 = str_substring(input, ts_node_start_byte(self), ts_node_end_byte(self) - ts_node_start_byte(self));
return (*out = ret, NO_ERROR);
}
t_error build_sym_function_definition(t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
@ -534,7 +580,7 @@ t_error build_sym_function_definition(t_parse_node self, t_const_str input, t_as
(void)(self);
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_function_definition)
if (ts_node_symbol(self) != sym_function_definition)
return (ERROR);
ret = ast_alloc(AST_FUNCTION_DEFINITION);
i = 0;
@ -571,7 +617,7 @@ t_error build_sym_case_statement(t_parse_node self, t_const_str input, t_ast_nod
(void)(self);
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_case_statement)
if (ts_node_symbol(self) != sym_case_statement)
return (ERROR);
ret = ast_alloc(AST_CASE);
i = 0;
@ -607,7 +653,7 @@ t_error build_sym__case_item_last(t_parse_node self, t_const_str input, t_ast_no
(void)(self);
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym__case_item_last)
if (ts_node_symbol(self) != sym__case_item_last)
return (ERROR);
ret = ast_alloc(AST_CASE_ITEM);
i = 0;
@ -643,7 +689,7 @@ t_error build_sym_case_item(t_parse_node self, t_const_str input, t_ast_node *ou
(void)(self);
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_case_item)
if (ts_node_symbol(self) != sym_case_item)
return (ERROR);
ret = ast_alloc(AST_CASE_ITEM);
i = 0;
@ -680,7 +726,7 @@ t_error build_sym_if_statement(t_parse_node self, t_const_str input, t_ast_node
(void)(self);
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_if_statement)
if (ts_node_symbol(self) != sym_if_statement)
return (ERROR);
ret = ast_alloc(AST_IF);
i = 0;
@ -729,7 +775,7 @@ t_error build_sym_elif_clause(t_parse_node self, t_const_str input, t_ast_node *
(void)(self);
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_elif_clause)
if (ts_node_symbol(self) != sym_elif_clause)
return (ERROR);
ret = ast_alloc(AST_ELIF);
i = 0;
@ -766,7 +812,7 @@ t_error build_sym_else_clause(t_parse_node self, t_const_str input, t_ast_node *
(void)(self);
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_else_clause)
if (ts_node_symbol(self) != sym_else_clause)
return (ERROR);
ret = ast_alloc(AST_ELSE);
i = 0;
@ -797,7 +843,7 @@ t_error build_sym_for_statement(t_parse_node self, t_const_str input, t_ast_node
(void)(self);
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_for_statement)
if (ts_node_symbol(self) != sym_for_statement)
return (ERROR);
ret = ast_alloc(AST_FOR);
i = 0;
@ -840,7 +886,7 @@ t_error build_sym_pipeline(t_parse_node self, t_const_str input, t_ast_node *out
(void)(self);
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_pipeline)
if (ts_node_symbol(self) != sym_pipeline)
return (ERROR);
ret = ast_alloc(AST_PIPELINE);
i = 0;
@ -868,12 +914,18 @@ t_error build_sym_do_group(t_parse_node self, t_const_str input, t_ast_node *out
(void)(self);
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_do_group)
if (ts_node_symbol(self) != sym_do_group)
return (ERROR);
ret = ast_alloc(AST_COMPOUND_STATEMENT);
i = 0;
while (i < ts_node_child_count(self))
{
if (ts_node_symbol(ts_node_child(self, i)) == anon_sym_do || ts_node_symbol(ts_node_child(self, i)) == anon_sym_done)
{
i++;
continue;
}
if (ts_node_field_id_for_child(self, i) == field_terminator && ret->data.compound_statement.body.len != 0)
{
term = _select_term(ts_node_child(self, i));
@ -902,7 +954,7 @@ t_error build_sym_subshell(t_parse_node self, t_const_str input, t_ast_node *out
(void)(self);
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_subshell)
if (ts_node_symbol(self) != sym_subshell)
return (ERROR);
ret = ast_alloc(AST_SUBSHELL);
i = 0;
@ -940,12 +992,12 @@ t_error build_sym_while_statement(t_parse_node self, t_const_str input, t_ast_no
(void)(self);
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_while_statement)
if (ts_node_symbol(self) != sym_while_statement)
return (ERROR);
i = 0;
if (ts_node_grammar_symbol(ts_node_child(self, 0)) == anon_sym_until)
if (ts_node_symbol(ts_node_child(self, 0)) == anon_sym_until)
ret = ast_alloc(AST_UNTIL);
else if (ts_node_grammar_symbol(ts_node_child(self, 0)) == anon_sym_while)
else if (ts_node_symbol(ts_node_child(self, 0)) == anon_sym_while)
ret = ast_alloc(AST_WHILE);
else
return (ERROR);
@ -954,15 +1006,17 @@ t_error build_sym_while_statement(t_parse_node self, t_const_str input, t_ast_no
child = ts_node_child(self, i);
if (!ts_node_is_named(child) && (i++, true))
continue;
if (ast_from_node(child, input, &tmp))
return (ast_free(ret), ERROR);
if (ts_node_field_id_for_child(self, i) == field_stmt)
vec_ast_push(&ret->data.while_.condition, tmp);
if (ts_node_field_id_for_child(self, i) == field_terminator)
{
term = _select_term(ts_node_child(self, i));
ast_set_term(&ret->data.while_.condition.buffer[ret->data.while_.condition.len - 1], term);
i++;
continue;
}
if (ast_from_node(child, input, &tmp))
return (ast_free(ret), ERROR);
if (ts_node_field_id_for_child(self, i) == field_stmt)
vec_ast_push(&ret->data.while_.condition, tmp);
if (ts_node_field_id_for_child(self, i) == field_body)
vec_ast_push(&ret->data.while_.do_, tmp);
i++;
@ -970,8 +1024,11 @@ t_error build_sym_while_statement(t_parse_node self, t_const_str input, t_ast_no
return (*out = ret, NO_ERROR);
}
// t_error buildw
t_error build_sym_redirected_statement(t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret_tmp;
t_ast_node ret;
t_ast_node tmp;
t_usize i;
@ -981,22 +1038,28 @@ t_error build_sym_redirected_statement(t_parse_node self, t_const_str input, t_a
(void)(self);
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_negated_command)
return (ERROR);
if (ts_node_child_count(self) != 1)
if (ts_node_symbol(self) != sym_redirected_statement)
return (ERROR);
i = 0;
if (ast_from_node(ts_node_child(self, i++), input, &ret))
return (ERROR);
ret = ast_alloc(AST_COMMAND);
ret_tmp = ret;
while (i < ts_node_child_count(self))
{
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
continue;
if (!(ts_node_symbol(ts_node_child(self, i)) == sym_file_redirect ||
ts_node_symbol(ts_node_child(self, i)) == sym_heredoc_redirect))
{
if (ast_from_node(ts_node_child(self, i++), input, &ret))
return (ast_free(ret_tmp), ERROR);
else
ret_tmp = NULL;
}
if (ast_from_node(ts_node_child(self, i++), input, &tmp))
return (ast_free(ret), ERROR);
return ((void)!((ret != ret_tmp) && (ast_free(ret_tmp), true)), ast_free(ret), ERROR);
_append_redirection(ret, tmp);
}
return (*out = ret, NO_ERROR);
return ((void)!((ret != ret_tmp) && (ast_free(ret_tmp), true)), *out = ret, NO_ERROR);
}
t_error build_sym_negated_command(t_parse_node self, t_const_str input, t_ast_node *out)
@ -1011,7 +1074,7 @@ t_error build_sym_negated_command(t_parse_node self, t_const_str input, t_ast_no
(void)(self);
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_negated_command)
if (ts_node_symbol(self) != sym_negated_command)
return (ERROR);
if (ts_node_child_count(self) != 1)
return (ERROR);
@ -1033,7 +1096,7 @@ t_error build_sym_compound_statement(t_parse_node self, t_const_str input, t_ast
(void)(self);
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_compound_statement)
if (ts_node_symbol(self) != sym_compound_statement)
return (ERROR);
ret = ast_alloc(AST_COMPOUND_STATEMENT);
i = 0;
@ -1058,41 +1121,6 @@ t_error build_sym_compound_statement(t_parse_node self, t_const_str input, t_ast
return (*out = ret, NO_ERROR);
}
// t_error build_sym_subshell(t_parse_node self, t_const_str input, t_ast_node *out)
// {
// t_ast_node ret;
// t_ast_node tmp;
// t_usize i;
// t_ast_terminator_kind term;
//
// (void)(out);
// (void)(input);
// (void)(self);
// if (out == NULL)
// return (ERROR);
// if (ts_node_grammar_symbol(self) != sym_subshell)
// return (ERROR);
// ret = ast_alloc(AST_SUBSHELL);
// // ret->data.subshell.body
// i = 0;
// while (i < ts_node_child_count(self))
// {
// if (ts_node_field_id_for_child(self, i) == field_terminator && ret->data.subshell.body.len != 0)
// {
// term = _select_term(input, ts_node_start_byte(ts_node_child(self, i)), ts_node_end_byte(ts_node_child(self, i)));
//
// ast_set_term(&ret->data.subshell.body.buffer[ret->data.subshell.body.len - 1], term);
// }
// else
// {
// if (ast_from_node(ts_node_child(self, i), input, &tmp))
// return (ast_free(ret), ERROR);
// vec_ast_push(&ret->data.subshell.body, tmp);
// }
// i++;
// }
// return (*out = ret, NO_ERROR);
// }
t_error build_sym_comment(t_parse_node self, t_const_str input, t_ast_node *out)
{
(void)(out);
@ -1100,7 +1128,7 @@ t_error build_sym_comment(t_parse_node self, t_const_str input, t_ast_node *out)
(void)(self);
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_comment)
if (ts_node_symbol(self) != sym_comment)
return (ERROR);
*out = ast_alloc(AST_EMPTY);
return (NO_ERROR);
@ -1116,14 +1144,14 @@ t_error build_sym_variable_assignment(t_parse_node self, t_const_str input, t_as
(void)(out);
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_variable_assignment)
if (ts_node_symbol(self) != sym_variable_assignment)
return (ERROR);
ret = ast_alloc(AST_VARIABLE_ASSIGNMENT);
// temp_str = str_substring(input, ts_node_start_byte(self), ts_node_end_byte(self) - ts_node_start_byte(self));
if (ts_node_child_count(self) >= 2)
{
temp_ast = ts_node_child(self, 0);
if (ts_node_grammar_symbol(temp_ast) != sym_variable_name)
if (ts_node_symbol(temp_ast) != sym_variable_name)
return (ast_free(ret), ERROR);
ret->data.variable_assignment.name =
str_substring(input, ts_node_start_byte(temp_ast), ts_node_end_byte(temp_ast) - ts_node_start_byte(temp_ast));
@ -1136,22 +1164,6 @@ t_error build_sym_variable_assignment(t_parse_node self, t_const_str input, t_as
return (*out = ret, NO_ERROR);
}
t_error build_sym__bare_dollar(t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_str temp_str;
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym__bare_dollar)
return (ERROR);
ret = ast_alloc(AST_RAW_STRING);
temp_str = str_substring(input, ts_node_start_byte(self), ts_node_end_byte(self) - ts_node_start_byte(self));
ret->data.raw_string.str = temp_str;
ret->data.raw_string.len = str_len(temp_str);
return (*out = ret, NO_ERROR);
}
t_error build_sym_string(t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
@ -1163,7 +1175,7 @@ t_error build_sym_string(t_parse_node self, t_const_str input, t_ast_node *out)
(void)(out);
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_string)
if (ts_node_symbol(self) != sym_string)
return (ERROR);
ret = ast_alloc(AST_WORD);
ret->data.word.kind = AST_WORD_DOUBLE_QUOTE;
@ -1191,7 +1203,7 @@ t_error build_sym_concatenation(t_parse_node self, t_const_str input, t_ast_node
(void)(out);
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_concatenation)
if (ts_node_symbol(self) != sym_concatenation)
return (ERROR);
ret = ast_alloc(AST_WORD);
ret->data.word.kind = AST_WORD_NO_QUOTE;
@ -1214,7 +1226,7 @@ t_error build_sym_string_content(t_parse_node self, t_const_str input, t_ast_nod
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_string_content)
if (ts_node_symbol(self) != sym_string_content)
return (ERROR);
ret = ast_alloc(AST_RAW_STRING);
temp_str = str_substring(input, ts_node_start_byte(self), ts_node_end_byte(self) - ts_node_start_byte(self));
@ -1231,7 +1243,7 @@ t_error build_sym_raw_string(t_parse_node self, t_const_str input, t_ast_node *o
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_raw_string)
if (ts_node_symbol(self) != sym_raw_string)
return (ERROR);
ret = ast_alloc(AST_WORD);
temp = ast_alloc(AST_RAW_STRING);
@ -1251,7 +1263,7 @@ t_error build_sym_program(t_parse_node self, t_const_str input, t_ast_node *out)
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_program)
if (ts_node_symbol(self) != sym_program)
return (ERROR);
ret = ast_alloc(AST_PROGRAM);
i = 0;
@ -1280,7 +1292,7 @@ t_error build_sym_command_name(t_parse_node self, t_const_str input, t_ast_node
{
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_command_name)
if (ts_node_symbol(self) != sym_command_name)
return (ERROR);
return (ast_from_node(ts_node_child(self, 0), input, out));
}
@ -1293,7 +1305,7 @@ t_error build_sym_word(t_parse_node self, t_const_str input, t_ast_node *out)
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_word)
if (ts_node_symbol(self) != sym_word)
return (ERROR);
ret = ast_alloc(AST_WORD);
ret->data.word.kind = AST_WORD_NO_QUOTE;
@ -1314,7 +1326,7 @@ t_error build_sym_command(t_parse_node self, t_const_str input, t_ast_node *out)
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_command)
if (ts_node_symbol(self) != sym_command)
return (ERROR);
ret = ast_alloc(AST_COMMAND);
i = 0;
@ -1354,7 +1366,7 @@ t_error build_sym_list(t_parse_node self, t_const_str input, t_ast_node *out)
}
else if (ts_node_field_id_for_child(self, i) == field_op)
{
temp = ts_node_grammar_symbol(ts_node_child(self, i));
temp = ts_node_symbol(ts_node_child(self, i));
if (temp == anon_sym_PIPE_PIPE)
ret->data.list.op = AST_LIST_OR;
if (temp == anon_sym_AMP_AMP)
@ -1444,106 +1456,102 @@ t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out)
{
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(node) == sym_arithmetic_binary_expression)
if (ts_node_symbol(node) == sym_arithmetic_binary_expression)
return (build_sym_arithmetic_binary_expression(node, input, out));
if (ts_node_grammar_symbol(node) == sym_arithmetic_expansion)
if (ts_node_symbol(node) == sym_arithmetic_expansion)
return (build_sym_arithmetic_expansion(node, input, out));
if (ts_node_grammar_symbol(node) == sym_arithmetic_literal)
if (ts_node_symbol(node) == sym_arithmetic_literal)
return (build_sym_arithmetic_literal(node, input, out));
if (ts_node_grammar_symbol(node) == sym_arithmetic_parenthesized_expression)
if (ts_node_symbol(node) == sym_arithmetic_parenthesized_expression)
return (build_sym_arithmetic_parenthesized_expression(node, input, out));
if (ts_node_grammar_symbol(node) == sym_arithmetic_postfix_expression)
if (ts_node_symbol(node) == sym_arithmetic_postfix_expression)
return (build_sym_arithmetic_postfix_expression(node, input, out));
if (ts_node_grammar_symbol(node) == sym_arithmetic_ternary_expression)
if (ts_node_symbol(node) == sym_arithmetic_ternary_expression)
return (build_sym_arithmetic_ternary_expression(node, input, out));
if (ts_node_grammar_symbol(node) == sym_arithmetic_unary_expression)
if (ts_node_symbol(node) == sym_arithmetic_unary_expression)
return (build_sym_arithmetic_unary_expression(node, input, out));
if (ts_node_grammar_symbol(node) == sym_case_item)
if (ts_node_symbol(node) == sym_case_item)
return (build_sym_case_item(node, input, out));
if (ts_node_grammar_symbol(node) == sym__case_item_last)
return (build_sym__case_item_last(node, input, out));
if (ts_node_grammar_symbol(node) == sym_case_statement)
if (ts_node_symbol(node) == sym_case_statement)
return (build_sym_case_statement(node, input, out));
if (ts_node_grammar_symbol(node) == sym_command)
if (ts_node_symbol(node) == sym_command)
return (build_sym_command(node, input, out));
if (ts_node_grammar_symbol(node) == sym_command_name)
if (ts_node_symbol(node) == sym_command_name)
return (build_sym_command_name(node, input, out));
if (ts_node_grammar_symbol(node) == sym_command_substitution)
if (ts_node_symbol(node) == sym_command_substitution)
return (build_sym_command_substitution(node, input, out));
if (ts_node_grammar_symbol(node) == sym_comment)
if (ts_node_symbol(node) == sym_comment)
return (build_sym_comment(node, input, out));
if (ts_node_grammar_symbol(node) == sym_compound_statement)
if (ts_node_symbol(node) == sym_compound_statement)
return (build_sym_compound_statement(node, input, out));
if (ts_node_grammar_symbol(node) == sym_concatenation)
if (ts_node_symbol(node) == sym_concatenation)
return (build_sym_concatenation(node, input, out));
if (ts_node_grammar_symbol(node) == sym_do_group)
if (ts_node_symbol(node) == sym_do_group)
return (build_sym_do_group(node, input, out));
if (ts_node_grammar_symbol(node) == sym_elif_clause)
if (ts_node_symbol(node) == sym_elif_clause)
return (build_sym_elif_clause(node, input, out));
if (ts_node_grammar_symbol(node) == sym_else_clause)
if (ts_node_symbol(node) == sym_else_clause)
return (build_sym_else_clause(node, input, out));
if (ts_node_grammar_symbol(node) == sym_expansion)
if (ts_node_symbol(node) == sym_expansion)
return (build_sym_expansion(node, input, out));
if (ts_node_grammar_symbol(node) == sym_expansion_expression)
if (ts_node_symbol(node) == sym_expansion_expression)
return (build_sym_expansion_expression(node, input, out));
if (ts_node_grammar_symbol(node) == sym_expansion_regex)
if (ts_node_symbol(node) == sym_expansion_regex)
return (build_sym_expansion_regex(node, input, out));
if (ts_node_grammar_symbol(node) == sym_extglob_pattern)
if (ts_node_symbol(node) == sym_extglob_pattern)
return (build_sym_extglob_pattern(node, input, out));
if (ts_node_grammar_symbol(node) == sym_file_descriptor)
if (ts_node_symbol(node) == sym_file_descriptor)
return (build_sym_file_descriptor(node, input, out));
if (ts_node_grammar_symbol(node) == sym_file_redirect)
if (ts_node_symbol(node) == sym_file_redirect)
return (build_sym_file_redirect(node, input, out));
if (ts_node_grammar_symbol(node) == sym_for_statement)
if (ts_node_symbol(node) == sym_for_statement)
return (build_sym_for_statement(node, input, out));
if (ts_node_grammar_symbol(node) == sym_function_definition)
if (ts_node_symbol(node) == sym_function_definition)
return (build_sym_function_definition(node, input, out));
if (ts_node_grammar_symbol(node) == sym_heredoc_body)
if (ts_node_symbol(node) == sym_heredoc_body)
return (build_sym_heredoc_body(node, input, out));
if (ts_node_grammar_symbol(node) == sym_heredoc_content)
if (ts_node_symbol(node) == sym_heredoc_content)
return (build_sym_heredoc_content(node, input, out));
if (ts_node_grammar_symbol(node) == sym_heredoc_end)
if (ts_node_symbol(node) == sym_heredoc_end)
return (build_sym_heredoc_end(node, input, out));
if (ts_node_grammar_symbol(node) == sym_heredoc_redirect)
if (ts_node_symbol(node) == sym_heredoc_redirect)
return (build_sym_heredoc_redirect(node, input, out));
if (ts_node_grammar_symbol(node) == sym_heredoc_start)
if (ts_node_symbol(node) == sym_heredoc_start)
return (build_sym_heredoc_start(node, input, out));
if (ts_node_grammar_symbol(node) == sym_if_statement)
if (ts_node_symbol(node) == sym_if_statement)
return (build_sym_if_statement(node, input, out));
if (ts_node_grammar_symbol(node) == sym_list)
if (ts_node_symbol(node) == sym_list)
return (build_sym_list(node, input, out));
if (ts_node_grammar_symbol(node) == sym_negated_command)
if (ts_node_symbol(node) == sym_negated_command)
return (build_sym_negated_command(node, input, out));
if (ts_node_grammar_symbol(node) == sym_number)
if (ts_node_symbol(node) == sym_number)
return (build_sym_number(node, input, out));
if (ts_node_grammar_symbol(node) == sym_pipeline)
if (ts_node_symbol(node) == sym_pipeline)
return (build_sym_pipeline(node, input, out));
if (ts_node_grammar_symbol(node) == sym_program)
if (ts_node_symbol(node) == sym_program)
return (build_sym_program(node, input, out));
if (ts_node_grammar_symbol(node) == sym_raw_string)
if (ts_node_symbol(node) == sym_raw_string)
return (build_sym_raw_string(node, input, out));
if (ts_node_grammar_symbol(node) == sym_redirected_statement)
if (ts_node_symbol(node) == sym_redirected_statement)
return (build_sym_redirected_statement(node, input, out));
if (ts_node_grammar_symbol(node) == sym_regex)
if (ts_node_symbol(node) == sym_regex)
return (build_sym_regex(node, input, out));
if (ts_node_grammar_symbol(node) == sym_simple_expansion)
if (ts_node_symbol(node) == sym_simple_expansion)
return (build_sym_simple_expansion(node, input, out));
if (ts_node_grammar_symbol(node) == sym_simple_heredoc_body)
if (ts_node_symbol(node) == sym_simple_heredoc_body)
return (build_sym_simple_heredoc_body(node, input, out));
if (ts_node_grammar_symbol(node) == sym_string)
if (ts_node_symbol(node) == sym_string)
return (build_sym_string(node, input, out));
if (ts_node_grammar_symbol(node) == sym_string_content)
if (ts_node_symbol(node) == sym_string_content)
return (build_sym_string_content(node, input, out));
if (ts_node_grammar_symbol(node) == sym_subshell)
if (ts_node_symbol(node) == sym_subshell)
return (build_sym_subshell(node, input, out));
if (ts_node_grammar_symbol(node) == sym_variable_assignment)
if (ts_node_symbol(node) == sym_variable_assignment)
return (build_sym_variable_assignment(node, input, out));
if (ts_node_grammar_symbol(node) == sym_while_statement)
if (ts_node_symbol(node) == sym_while_statement)
return (build_sym_while_statement(node, input, out));
if (ts_node_grammar_symbol(node) == sym_word)
if (ts_node_symbol(node) == sym_word)
return (build_sym_word(node, input, out));
if (ts_node_grammar_symbol(node) == sym__bare_dollar)
return (build_sym__bare_dollar(node, input, out));
printf("UNKNOWN KIND = [%d]%s\n", ts_node_grammar_symbol(node), ts_node_grammar_type(node));
printf("UNKNOWN KIND = [%d]%s\n", ts_node_symbol(node), ts_node_type(node));
return (ERROR);
}