Updated grammar file (not code)
This commit is contained in:
parent
c10ce8b165
commit
dcdefc2ac3
3 changed files with 1809 additions and 595 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/17 12:41:56 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/07/01 21:44:49 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/07/02 15:49:56 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -593,13 +593,15 @@ t_error build_sym_program(t_parse_node self, t_const_str input, t_ast_node *out)
|
|||
t_error build_sym_raw_string(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_redirected_statement(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_simple_expansion(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_string_content(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
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_simple_expansion(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_expansion(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
|
||||
|
||||
/* FUNCTION THAT ARE NOT DONE */
|
||||
|
||||
|
|
@ -612,7 +614,6 @@ t_error build_sym_arithmetic_unary_expression(t_parse_node self, t_const_str inp
|
|||
t_error build_sym_arithmetic_expansion(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
|
||||
t_error build_sym_command_substitution(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_expansion(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_expansion_expression(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_expansion_regex(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
|
||||
|
|
|
|||
|
|
@ -42,12 +42,12 @@ module.exports = grammar({
|
|||
[$.redirected_statement, $.command],
|
||||
[$.redirected_statement, $.command_substitution],
|
||||
[$.function_definition, $.command_name],
|
||||
[$._expansion_body, $._expansion_regex],
|
||||
[$.pipeline],
|
||||
],
|
||||
|
||||
inline: $ => [
|
||||
$._statement,
|
||||
// $._terminator,
|
||||
$._literal,
|
||||
$._terminated_statement,
|
||||
$._primary_expression,
|
||||
|
|
@ -100,15 +100,15 @@ module.exports = grammar({
|
|||
_statements: $ => prec(1, seq(
|
||||
repeat(seq(
|
||||
field('stmt', $._statement),
|
||||
field('terminator', $.terminator),
|
||||
field('term', $.terminator),
|
||||
)),
|
||||
field('stmt', $._statement),
|
||||
field('terminator', optional($.terminator)),
|
||||
field('term', optional($.terminator)),
|
||||
)),
|
||||
|
||||
_terminated_statement: $ => repeat1(seq(
|
||||
field('stmt', $._statement),
|
||||
field('terminator', $.terminator)
|
||||
field('term', $.terminator)
|
||||
)),
|
||||
|
||||
// Statements
|
||||
|
|
@ -153,14 +153,14 @@ module.exports = grammar({
|
|||
redirected_statement: $ => prec.dynamic(-1, prec.right(-1, choice(
|
||||
seq(
|
||||
field('body', $._statement),
|
||||
field('redirect', repeat1(choice($.file_redirect, $.heredoc_redirect))),
|
||||
field('redr', repeat1(choice($.file_redirect, $.heredoc_redirect))),
|
||||
),
|
||||
field('redirect', repeat1($.file_redirect)),
|
||||
field('redr', repeat1($.file_redirect)),
|
||||
))),
|
||||
|
||||
for_statement: $ => seq(
|
||||
'for',
|
||||
field('variable', $._simple_variable_name),
|
||||
field('var', $._simple_variable_name),
|
||||
optional(seq(
|
||||
'in',
|
||||
field('value', repeat1($._literal)),
|
||||
|
|
@ -171,7 +171,7 @@ module.exports = grammar({
|
|||
|
||||
while_statement: $ => seq(
|
||||
choice('while', 'until'),
|
||||
field('condition', $._terminated_statement),
|
||||
field('cond', $._terminated_statement),
|
||||
field('body', $.do_group),
|
||||
),
|
||||
|
||||
|
|
@ -183,7 +183,7 @@ module.exports = grammar({
|
|||
|
||||
if_statement: $ => seq(
|
||||
'if',
|
||||
field('condition', alias($._terminated_statement, $.statements)),
|
||||
field('cond', alias($._terminated_statement, $.statements)),
|
||||
'then',
|
||||
field('body', alias(optional($._terminated_statement), $.statements)),
|
||||
field('elif', repeat($.elif_clause)),
|
||||
|
|
@ -193,7 +193,7 @@ module.exports = grammar({
|
|||
|
||||
elif_clause: $ => seq(
|
||||
'elif',
|
||||
field('condition', alias($._terminated_statement, $.statements)),
|
||||
field('cond', alias($._terminated_statement, $.statements)),
|
||||
'then',
|
||||
field('body', alias(optional($._terminated_statement), $.statements)),
|
||||
),
|
||||
|
|
@ -270,7 +270,7 @@ module.exports = grammar({
|
|||
command: $ => prec.left(seq(
|
||||
repeat(choice(
|
||||
$.variable_assignment,
|
||||
field('redirect', $.file_redirect),
|
||||
field('redr', $.file_redirect),
|
||||
)),
|
||||
field('name', $.command_name),
|
||||
choice(
|
||||
|
|
@ -311,7 +311,7 @@ module.exports = grammar({
|
|||
optional(choice(
|
||||
alias($._heredoc_pipeline, $.pipeline),
|
||||
seq(
|
||||
field('redirect', repeat1($.file_redirect)),
|
||||
field('redr', repeat1($.file_redirect)),
|
||||
optional($._heredoc_expression),
|
||||
),
|
||||
$._heredoc_expression,
|
||||
|
|
@ -325,7 +325,7 @@ module.exports = grammar({
|
|||
|
||||
_heredoc_expression: $ => seq(
|
||||
field('op', alias(choice('||', '&&'), $.operator)),
|
||||
field('right', $._statement),
|
||||
field('rhs', $._statement),
|
||||
),
|
||||
|
||||
_heredoc_command: $ => repeat1(field('arg', $._literal)),
|
||||
|
|
@ -403,19 +403,19 @@ module.exports = grammar({
|
|||
|
||||
return choice(...table.map(([operator, precedence]) =>
|
||||
prec.left(precedence, seq(
|
||||
field('left', $._arithmetic_expression),
|
||||
field('lhs', $._arithmetic_expression),
|
||||
field('op', alias(operator, $.operator)),
|
||||
field('right', $._arithmetic_expression),
|
||||
field('rhs', $._arithmetic_expression),
|
||||
))
|
||||
));
|
||||
},
|
||||
|
||||
arithmetic_ternary_expression: $ => prec.left(PREC.TERNARY, seq(
|
||||
field('condition', $._arithmetic_expression),
|
||||
field('cond', $._arithmetic_expression),
|
||||
'?',
|
||||
field('consequence', $._arithmetic_expression),
|
||||
field('then', $._arithmetic_expression),
|
||||
':',
|
||||
field('alternative', $._arithmetic_expression),
|
||||
field('else', $._arithmetic_expression),
|
||||
)),
|
||||
|
||||
arithmetic_unary_expression: $ => choice(
|
||||
|
|
@ -493,67 +493,67 @@ module.exports = grammar({
|
|||
optional($._expansion_body),
|
||||
'}',
|
||||
),
|
||||
|
||||
_expansion_body: $ => seq(
|
||||
field('len', optional(alias('#', $.operator))),
|
||||
field('name', choice($.variable_name, $._simple_variable_name, $._special_variable_name)),
|
||||
field('op', optional(choice($.expansion_expression, $.expansion_regex))),
|
||||
optional(choice($._expansion_expression, $._expansion_regex)),
|
||||
),
|
||||
|
||||
|
||||
expansion_expression: $ => prec(1, seq(
|
||||
_expansion_expression: $ => prec(1, seq(
|
||||
field('op', alias(immediateLiterals(':-', '-', ':=', '=', ':?', '?', ':+', '+'), $.operator)),
|
||||
optional(seq(
|
||||
choice(
|
||||
field('args', optional(choice(
|
||||
alias($._concatenation_in_expansion, $.concatenation),
|
||||
$.word,
|
||||
//alias($._expansion_word, $.word1),
|
||||
alias(prec(10000000, $._word_no_brace), $.word2),
|
||||
$.expansion,
|
||||
$.string,
|
||||
$.raw_string,
|
||||
alias($._expansion_word, $.word),
|
||||
),
|
||||
)),
|
||||
$.string,
|
||||
))),
|
||||
)),
|
||||
|
||||
expansion_regex: $ => seq(
|
||||
_expansion_regex: $ => seq(
|
||||
field('op', alias(choice('#', $._immediate_double_hash, '%', '%%'), $.operator)),
|
||||
repeat(choice(
|
||||
$.regex,
|
||||
alias(')', $.regex),
|
||||
$.string,
|
||||
field('args', repeat(choice(
|
||||
$.raw_string,
|
||||
$.regex,
|
||||
$.string,
|
||||
alias(')', $.regex),
|
||||
alias(/\s+/, $.regex),
|
||||
)),
|
||||
))),
|
||||
),
|
||||
|
||||
|
||||
_concatenation_in_expansion: $ => prec(-2, seq(
|
||||
choice(
|
||||
$.word,
|
||||
alias($._word_no_brace, $.word),
|
||||
alias($._expansion_word, $.word),
|
||||
$.variable_name,
|
||||
$.simple_expansion,
|
||||
$.expansion,
|
||||
$.string,
|
||||
$.raw_string,
|
||||
$.command_substitution,
|
||||
alias($._expansion_word, $.word),
|
||||
),
|
||||
repeat1(seq(
|
||||
choice($._concat, alias(/`\s*`/, '``')),
|
||||
choice(
|
||||
$.word,
|
||||
alias($._word_no_brace, $.word),
|
||||
alias($._expansion_word, $.word),
|
||||
$.variable_name,
|
||||
$.simple_expansion,
|
||||
$.expansion,
|
||||
$.string,
|
||||
$.raw_string,
|
||||
$.command_substitution,
|
||||
alias($._expansion_word, $.word),
|
||||
),
|
||||
)),
|
||||
)),
|
||||
|
||||
command_substitution: $ => choice(
|
||||
seq('$(', $._statements, ')'),
|
||||
seq('$(', field('redirect', $.file_redirect), ')'),
|
||||
seq('$(', field('redr', $.file_redirect), ')'),
|
||||
prec(1, seq('`', $._statements, '`')),
|
||||
),
|
||||
|
||||
|
|
@ -599,6 +599,19 @@ module.exports = grammar({
|
|||
'\\ ',
|
||||
)),
|
||||
)),
|
||||
|
||||
|
||||
_word_no_brace: _ => prec(2, token(seq(
|
||||
choice(
|
||||
noneOf('#', '{', '}', ...SPECIAL_CHARACTERS),
|
||||
seq('\\', noneOf('\\s')),
|
||||
),
|
||||
repeat(choice(
|
||||
noneOf('{', '}', ...SPECIAL_CHARACTERS),
|
||||
seq('\\', noneOf('\\s')),
|
||||
'\\ ',
|
||||
)),
|
||||
))),
|
||||
terminator: _ => choice(';', ';;', /\n/, '&'),
|
||||
},
|
||||
});
|
||||
|
|
|
|||
1200
tree-sitter-sh/src/scanner.c
Normal file
1200
tree-sitter-sh/src/scanner.c
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue