This repository was archived by the owner on Nov 3, 2025. It is now read-only.
Simplify embedded_braced_expression #29
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR removes custom call, subscript, and selection expressions used in
$.embedded_brace_expressionand replaces them with their main alternatives.We also rename
$.embedded_brace_expressionto$.embedded_braced_expressionto matchhh_parsenode name. This was my intention originally, but didn't notice the difference in tenses. This also matches the node name$.braced_expression.Finally, we add more tests for
$.embedded_braced_expression.Issue
@frankeld found an issue with embedded braced expression (#26 (comment)) in heredocs where nested
$.selection_expressions were matched on the tail of the nest instead of the head (like the non-embedded version of$.selection_expression).Using @frankeld's example,
"{$var->fun->yum}";would approximately result ininstead of what we expect in the non-embedded case
Change
Duplicate call, subscript, and selection expressions
The child expressions for
$.embedded_brace_expressionwere originally re-written specifically for$.embedded_brace_expressionso that only expressions starting with a$.variablewere allowed and only expressions with no whitespace between the opening{brace and$were matched as embedded brace expressions.For example,
func(),var_const["key"], andvar_const->func()are valid$.call_expression,$.subscript_expression, and$.selection_expressionrespectively, but are not allowed inside$.embedded_brace_expression.Duplicates not necessary
While looking into the ordering issue of
$._embedded_brace_selection_expressionI realized that because tree-sitter-hack's heredoc scanner specifically looks for the sequence/\{\$[a-zA-Z_\x80-\xff]/to release control back to the parser, the parser will only match expressions that start with a$.variableand don't have whitespace between{and$. The parser never gets a chance to match expressions that don't start with$.variable.If there is whitespace between
{and$like say{ $var, the scanner matches{as part of$.heredoc_bodyand the parser doesn't get a chance to match an embedded braced expression.In the case of an expression that starts with an identifier like
{var->func(), the scanner matches{vas part of$.heredoc_body(as well as the rest of the string), so the parser again doesn't get a chance to match an embedded braced expression.