Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ba02b78
Fix `OpAssign` locations
amomchilov Oct 28, 2025
3a8870c
Include `end` in `elsif` location
amomchilov Oct 29, 2025
6dd3a0f
Fix location of regular Super with a block
amomchilov Oct 29, 2025
e371f7c
Unused `getFirstAndLast()` helper
amomchilov Oct 29, 2025
6c83468
Fix `LVarLHS` locations for dynamic const assign
amomchilov Oct 30, 2025
0412feb
`rescue` checkpoint
amomchilov Nov 3, 2025
1dcf3ea
Fix `Ensure` node locations
amomchilov Nov 3, 2025
240692d
Refactor `translateRescue` to take `begin` node
amomchilov Nov 3, 2025
d866e3d
wip fixed `bazel-bin/test/prism_regression/rescue_location_test`
amomchilov Nov 3, 2025
85f83c9
Improve `begin`/`rescue`/`ensure` tests
amomchilov Nov 3, 2025
9f63706
[Improve me] Fix locations of rescue exception clauses
amomchilov Nov 3, 2025
69ae86e
[FIXME] test improvements
amomchilov Nov 3, 2025
e8f11f3
Fix `NumParams` location for blocks
amomchilov Nov 3, 2025
5235694
[checkpoint] Fix `NumParams` location for lambdas
amomchilov Nov 3, 2025
29d9c23
checkpoint
amomchilov Nov 3, 2025
d4d7328
Fix NumParam LVar decls in legacy parser
amomchilov Nov 3, 2025
cbd7c46
Add test for ConstPatterns
amomchilov Nov 6, 2025
33a707a
Fix ArrayPattern locations
amomchilov Oct 29, 2025
57f4289
Fix HashPattern locations
amomchilov Nov 6, 2025
5a446e9
Fix locations for index expressions
amomchilov Oct 28, 2025
24403a7
Un-skip fixed tests
amomchilov Nov 7, 2025
033d1c2
Fix `IfGuard`/`UnlessGuard` locations
amomchilov Oct 29, 2025
3020207
F lambda locations
amomchilov Oct 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions parser/Builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ class Builder::Impl {

auto raw_numparam_stack = driver_->numparam_stack.stackCopy();

auto opening_token = raw_numparam_stack.back().opening_token;

// ignore current block scope
raw_numparam_stack.pop_back();

Expand All @@ -226,7 +228,11 @@ class Builder::Impl {
}

driver_->lex.declare(name_str);
auto intro = make_unique<LVar>(node->loc, id->name);

// The LVar's location matches the non-zero length NumParams node. See `numparams()` for details.
core::LocOffsets loc = tokLoc(opening_token).copyEndWithZeroLength();
auto intro = make_unique<LVar>(loc, id->name);

auto decls = driver_->alloc.node_list();
decls->emplace_back(toForeign(std::move(intro)));
driver_->numparam_stack.regis(name_str[1] - '0', std::move(decls));
Expand Down Expand Up @@ -1348,7 +1354,7 @@ class Builder::Impl {
// `tok` is the opening token:
// - for blocks, it's opening `do` or `{`
// - for lambdas, it's the `->`
// We use it to set the location of the numparams to a zero-length loc just after, as if you had written:
// We use it to set the location of the NumParams to a zero-length loc just after, as if you had written:
// - `do|_1, _2| ... end`
// - `{|_1, _2| ... }`
// - `->(_1, _2) { ... }`
Expand Down
28 changes: 17 additions & 11 deletions parser/parser/cc/grammars/typedruby.ypp
Original file line number Diff line number Diff line change
Expand Up @@ -2155,27 +2155,29 @@ array_premature_end: eof
DIAGCHECK();
}
| lambda
| kIF expr_value then compstmt if_tail kend_or_eof
| kIF expr_value then compstmt if_tail
{
auto &else_ = $5;
auto end_t = else_ ? else_->tok : nullptr;
$$ = driver.build.condition(self, $1, $2, $3, $4->body,
else_ ? else_->tok : nullptr,
else_ ? else_->nod : nullptr, $6);
driver.rewind_if_dedented($1, $6);
nullptr,
else_ ? else_->nod : nullptr, end_t);
driver.rewind_if_dedented($1, end_t);
}
| kIF error
{
auto err = driver.build.error_node(self, @1.endPos(), @2.beginPos());
$$ = driver.build.condition(self, $1, err, nullptr, nullptr, nullptr, nullptr, nullptr);
driver.replace_last_diagnostic(dlevel::ERROR, dclass::UnexpectedToken, $1, driver.token_name($1->type()));
}
| kIF strings kDO compstmt if_tail kEND
| kIF strings kDO compstmt if_tail
{
driver.diagnostics.emplace_back(dlevel::ERROR, dclass::IfInsteadOfItForTest, diagnostic::range(@1.beginPos(), @1.endPos()));
auto &else_ = $5;
auto end_t = else_ ? else_->tok : nullptr;
$$ = driver.build.condition(self, $1, $2, $3, $4->body,
else_ ? else_->tok : nullptr,
else_ ? else_->nod : nullptr, $6);
nullptr,
else_ ? else_->nod : nullptr, end_t);
}
| kUNLESS expr_value then compstmt opt_else kend_or_eof
{
Expand Down Expand Up @@ -2461,16 +2463,20 @@ array_premature_end: eof
do: term
| kDO_COND

if_tail: opt_else
if_tail: opt_else kend_or_eof
{
$$ = driver.alloc.node_with_token($2, $1 ? $1->nod : nullptr);
}
| kELSIF expr_value then compstmt if_tail
{
auto elsif_t = $1;
auto &else_ = $5;
$$ = driver.alloc.node_with_token(elsif_t,
auto end_t = else_ ? else_->tok : nullptr;
$$ = driver.alloc.node_with_token(end_t,
driver.build.condition(self,
elsif_t, $2, $3, $4->body,
else_ ? else_->tok : nullptr,
else_ ? else_->nod : nullptr, nullptr)
nullptr,
else_ ? else_->nod : nullptr, end_t)
);
}

Expand Down
Loading
Loading