Skip to content

Commit

Permalink
Fix a scope vs function parsing bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
asoffer committed Nov 17, 2023
1 parent b2d46b5 commit e55d7e2
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions parse/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ void Parser::HandleBracedStatementSequence(ParseTree& tree) {
},
State::Kind::ClosingBrace);
} else {
NTH_UNIMPLEMENTED();
NTH_UNIMPLEMENTED("{}") <<= {current_token().kind()};
}
}

Expand Down Expand Up @@ -629,9 +629,15 @@ void Parser::HandleTryTermSuffix(ParseTree& tree) {
push_state(Expression(tree));
}
return;
case Token::Kind::LeftBrace:
if (state()[state().size() - 3].kind !=
State::Kind::FunctionLiteralBody) {
case Token::Kind::LeftBrace: {
bool in_fn = false;
for (auto iter = state().rbegin();
iter->ambient_precedence != Precedence::Loosest(); ++iter) {
if (iter->ambient_precedence == Precedence::Function()) {
in_fn = true;
}
}
if (not in_fn) {
tree.back().scope_index = PushScope();
tree.append_leaf(ParseNode::Kind::ScopeBodyStart, *iterator_);
tree.append_leaf(ParseNode::Kind::ScopeBlockStart, *iterator_);
Expand All @@ -656,6 +662,7 @@ void Parser::HandleTryTermSuffix(ParseTree& tree) {
} else {
pop_and_discard_state();
}
} break;
break;
default: pop_and_discard_state(); break;
}
Expand All @@ -674,10 +681,11 @@ void Parser::HandleAtom(ParseTree& tree) {
ExpandState(
State{
.kind = State::Kind::FunctionLiteralReturnTypeStart,
.subtree_start = tree.size(),
.ambient_precedence = Precedence::Function(),
.subtree_start = tree.size(),
},
State{
.kind = State::Kind::FunctionLiteralBody,
.kind = State::Kind::FunctionLiteralBody,
.subtree_start = tree.size(),
},
State::Kind::ResolveFunctionLiteral);
Expand All @@ -692,8 +700,9 @@ void Parser::HandleAtom(ParseTree& tree) {
.subtree_start = tree.size(),
},
State{
.kind = State::Kind::FunctionLiteralReturnTypeStart,
.subtree_start = tree.size(),
.kind = State::Kind::FunctionLiteralReturnTypeStart,
.ambient_precedence = Precedence::Function(),
.subtree_start = tree.size(),
},
State{
.kind = State::Kind::FunctionLiteralBody,
Expand Down

0 comments on commit e55d7e2

Please sign in to comment.