mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Model var as a pattern operator (#4720)
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
co-authored by
Richard Smith
parent
6572da7314
commit
13434f0e8a
@@ -16,6 +16,9 @@ static auto HandleVar(Context& context, State finish_state,
|
||||
// The finished variable declaration will start at the `var` or `returned`.
|
||||
context.PushState(state, finish_state);
|
||||
|
||||
// TODO: is there a cleaner way to give VarAfterPattern access to the `var`
|
||||
// token?
|
||||
state.token = *(context.position() - 1);
|
||||
context.PushState(state, State::VarAfterPattern);
|
||||
|
||||
if (returned_token.is_valid()) {
|
||||
@@ -66,6 +69,8 @@ auto HandleVarAfterPattern(Context& context) -> void {
|
||||
}
|
||||
}
|
||||
|
||||
context.AddNode(NodeKind::VariablePattern, state.token, state.has_error);
|
||||
|
||||
if (context.PositionIs(Lex::TokenKind::Equal)) {
|
||||
context.AddLeafNode(NodeKind::VariableInitializer,
|
||||
context.ConsumeChecked(Lex::TokenKind::Equal));
|
||||
@@ -91,6 +96,8 @@ auto HandleVarFinishAsDecl(Context& context) -> void {
|
||||
auto HandleVarFinishAsFor(Context& context) -> void {
|
||||
auto state = context.PopState();
|
||||
|
||||
context.AddNode(NodeKind::VariablePattern, state.token, state.has_error);
|
||||
|
||||
auto end_token = state.token;
|
||||
if (context.PositionIs(Lex::TokenKind::In)) {
|
||||
end_token = context.Consume();
|
||||
|
||||
Reference in New Issue
Block a user