Skip to content

Commit

Permalink
Do not expose func_body node
Browse files Browse the repository at this point in the history
This node has no additional semantic meaning beyond the `stmt_list` it
wraps.
  • Loading branch information
bbannier committed Feb 10, 2023
1 parent d7e9920 commit aea2ff1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
40 changes: 18 additions & 22 deletions corpus/test
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,15 @@ function foo()
(func_decl
(id)
(func_params)
(func_body
(stmt_list
(var_decl
(id)
(initializer
(init_class)
(init
(expr
(constant
(integer))))))))))
(stmt_list
(var_decl
(id)
(initializer
(init_class)
(init
(expr
(constant
(integer)))))))))

================================================================================
Record fields
Expand Down Expand Up @@ -158,29 +157,26 @@ redef event foo(x: count)
(formal_arg
(id)
(type))))
(func_body
(stmt_list
(expr
(id)))))
(stmt_list
(expr
(id))))
(hook_decl
(id)
(func_params
(formal_args
(formal_arg
(id)
(type))))
(func_body
(stmt_list
(expr
(id)))))
(stmt_list
(expr
(id))))
(event_decl
(id)
(func_params
(formal_args
(formal_arg
(id)
(type))))
(func_body
(stmt_list
(expr
(id))))))
(stmt_list
(expr
(id)))))
12 changes: 6 additions & 6 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ module.exports = grammar({
prec_r(3, seq($.expr, '+=', $.expr)),

prec(2, seq('$', $.id, '=', $.expr)),
prec(2, seq('$', $.id, $.begin_lambda, '=', $.func_body)),
prec(2, seq('$', $.id, $.begin_lambda, '=', $._func_body)),

prec_l(1, seq('[', optional($.expr_list), ']')),
prec_l(1, seq('record', '(', $.expr_list, ')')),
Expand All @@ -261,7 +261,7 @@ module.exports = grammar({
seq('copy', '(', $.expr, ')'),
prec_r(seq('hook', $.expr)),
seq('schedule', $.expr, '{', $.event_hdr, '}'),
seq('function', $.begin_lambda, $.func_body),
seq('function', $.begin_lambda, $._func_body),

// Lower precedence here to favor local-variable statements
prec_r(-1, seq('local', $.id, '=', $.expr)),
Expand All @@ -287,11 +287,11 @@ module.exports = grammar({
),

// Precedences here are to avoid ambiguity with related expressions
func_decl: $ => prec(1, seq('function', $.id, $.func_params, optional($.attr_list), $.func_body)),
hook_decl: $ => prec(1, seq('hook', $.id, $.func_params, optional($.attr_list), $.func_body)),
event_decl: $ => seq(optional('redef'), 'event', $.id, $.func_params, optional($.attr_list), $.func_body),
func_decl: $ => prec(1, seq('function', $.id, $.func_params, optional($.attr_list), $._func_body)),
hook_decl: $ => prec(1, seq('hook', $.id, $.func_params, optional($.attr_list), $._func_body)),
event_decl: $ => seq(optional('redef'), 'event', $.id, $.func_params, optional($.attr_list), $._func_body),

func_body: $ => seq('{', optional($.stmt_list), '}'),
_func_body: $ => seq('{', optional($.stmt_list), '}'),

// Precedence here is to disambiguate other interpretations of the colon
// and type, arising in expressions.
Expand Down

0 comments on commit aea2ff1

Please sign in to comment.