mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Closes #3063 --------- Co-authored-by: Richard Smith <richard@metafoo.co.uk>
49 lines
1.6 KiB
C++
49 lines
1.6 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/parser/parser_context.h"
|
|
|
|
namespace Carbon {
|
|
|
|
// Handles ParenConditionAs(If|While).
|
|
static auto ParserHandleParenCondition(ParserContext& context,
|
|
ParseNodeKind start_kind,
|
|
ParserState finish_state) -> void {
|
|
auto state = context.PopState();
|
|
|
|
context.ConsumeAndAddOpenParen(state.token, start_kind);
|
|
|
|
state.state = finish_state;
|
|
context.PushState(state);
|
|
context.PushState(ParserState::Expression);
|
|
}
|
|
|
|
auto ParserHandleParenConditionAsIf(ParserContext& context) -> void {
|
|
ParserHandleParenCondition(context, ParseNodeKind::IfConditionStart,
|
|
ParserState::ParenConditionFinishAsIf);
|
|
}
|
|
|
|
auto ParserHandleParenConditionAsWhile(ParserContext& context) -> void {
|
|
ParserHandleParenCondition(context, ParseNodeKind::WhileConditionStart,
|
|
ParserState::ParenConditionFinishAsWhile);
|
|
}
|
|
|
|
auto ParserHandleParenConditionFinishAsIf(ParserContext& context) -> void {
|
|
auto state = context.PopState();
|
|
|
|
context.ConsumeAndAddCloseSymbol(
|
|
*(TokenizedBuffer::TokenIterator(state.token) + 1), state,
|
|
ParseNodeKind::IfCondition);
|
|
}
|
|
|
|
auto ParserHandleParenConditionFinishAsWhile(ParserContext& context) -> void {
|
|
auto state = context.PopState();
|
|
|
|
context.ConsumeAndAddCloseSymbol(
|
|
*(TokenizedBuffer::TokenIterator(state.token) + 1), state,
|
|
ParseNodeKind::WhileCondition);
|
|
}
|
|
|
|
} // namespace Carbon
|