parser_handle_paren_condition.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "toolchain/parser/parser_context.h"
  5. namespace Carbon {
  6. // Handles ParenConditionAs(If|While).
  7. static auto ParserHandleParenCondition(ParserContext& context,
  8. ParseNodeKind start_kind,
  9. ParserState finish_state) -> void {
  10. auto state = context.PopState();
  11. context.ConsumeAndAddOpenParen(state.token, start_kind);
  12. state.state = finish_state;
  13. context.PushState(state);
  14. context.PushState(ParserState::Expression);
  15. }
  16. auto ParserHandleParenConditionAsIf(ParserContext& context) -> void {
  17. ParserHandleParenCondition(context, ParseNodeKind::IfConditionStart,
  18. ParserState::ParenConditionFinishAsIf);
  19. }
  20. auto ParserHandleParenConditionAsWhile(ParserContext& context) -> void {
  21. ParserHandleParenCondition(context, ParseNodeKind::WhileConditionStart,
  22. ParserState::ParenConditionFinishAsWhile);
  23. }
  24. auto ParserHandleParenConditionFinishAsIf(ParserContext& context) -> void {
  25. auto state = context.PopState();
  26. context.ConsumeAndAddCloseParen(state, ParseNodeKind::IfCondition);
  27. }
  28. auto ParserHandleParenConditionFinishAsWhile(ParserContext& context) -> void {
  29. auto state = context.PopState();
  30. context.ConsumeAndAddCloseParen(state, ParseNodeKind::WhileCondition);
  31. }
  32. } // namespace Carbon