Files
carbon-lang/toolchain/parse/handle_pattern.cpp
T
Burak EmirandDana Jansens fec6ce2f9f Implement "unused pattern bindings" p2022 - parsing (#6460)
This implements proposal #2022, with changes from #3763 and leads
answers on #6448

Detection of unusedness is happening in
~~`toolchain/check/dataflow_analysis.cpp`~~ next PR. See
[here](https://github.com/burakemir/carbon-lang/tree/unused_pattern_bindings_p2022_impl_part2)
for preview.

~~All test cases with unused bindings were updated in order to avoid
polluting test output.~~

---------

Co-authored-by: Dana Jansens <danakj@orodu.net>
2025-12-17 15:40:20 +00:00

37 lines
1.3 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "toolchain/parse/context.h"
#include "toolchain/parse/handle.h"
namespace Carbon::Parse {
auto HandlePattern(Context& context) -> void {
auto state = context.PopState();
switch (context.PositionKind()) {
case Lex::TokenKind::OpenParen:
context.PushStateForPattern(StateKind::PatternListAsTuple,
state.in_var_pattern,
state.in_unused_pattern);
break;
case Lex::TokenKind::Var:
context.PushStateForPattern(StateKind::VariablePattern,
state.in_var_pattern,
state.in_unused_pattern);
break;
case Lex::TokenKind::Unused:
context.PushStateForPattern(StateKind::UnusedPattern,
state.in_var_pattern,
state.in_unused_pattern);
break;
default:
context.PushStateForPattern(StateKind::BindingPattern,
state.in_var_pattern,
state.in_unused_pattern);
break;
}
}
} // namespace Carbon::Parse