Change keyword statements to bracket arguments. (#2394)

This changes `return`, `break`, and `continue` to treat the keyword as the "start" and semicolon as the "parent", essentially bracketing the keyword.

Pragmatically this is focusing on making `return` work with only one ParseNodeKind: because `return` and `;` now bracket the expression, we can tightly determine whether the `return` has arguments without looking at subtree size. However, it's possible that `break` and `continue` may in the future take some kind of label as an argument, so the consistency seems beneficial there too.

Note this eliminates the StatementEnd ParseNodeKind, as it's obsolete with this change.
This commit is contained in:
Jon Ross-Perkins
2022-11-15 22:42:54 -08:00
committed by GitHub
parent ed654c1aa8
commit b914f46ec5
13 changed files with 174 additions and 83 deletions
@@ -12,9 +12,9 @@
// CHECK:STDOUT: {kind: 'Literal', text: 'f64'},
// CHECK:STDOUT: {kind: 'ReturnType', text: '->', subtree_size: 2},
// CHECK:STDOUT: {kind: 'FunctionDefinitionStart', text: '{', subtree_size: 7},
// CHECK:STDOUT: {kind: 'ReturnStatementStart', text: 'return'},
// CHECK:STDOUT: {kind: 'Literal', text: '42'},
// CHECK:STDOUT: {kind: 'StatementEnd', text: ';'},
// CHECK:STDOUT: {kind: 'ReturnStatement', text: 'return', subtree_size: 3},
// CHECK:STDOUT: {kind: 'ReturnStatement', text: ';', subtree_size: 3},
// CHECK:STDOUT: {kind: 'FunctionDefinition', text: '}', subtree_size: 11},
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]