handle_call_expr.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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/parse/context.h"
  5. namespace Carbon::Parse {
  6. auto HandleCallExpr(Context& context) -> void {
  7. auto state = context.PopState();
  8. context.PushState(state, State::CallExprFinish);
  9. context.AddNode(NodeKind::CallExprStart, context.Consume(),
  10. state.subtree_start, state.has_error);
  11. if (!context.PositionIs(Lex::TokenKind::CloseParen)) {
  12. context.PushState(State::CallExprParamFinish);
  13. context.PushState(State::Expr);
  14. }
  15. }
  16. auto HandleCallExprParamFinish(Context& context) -> void {
  17. auto state = context.PopState();
  18. if (state.has_error) {
  19. context.ReturnErrorOnState();
  20. }
  21. if (context.ConsumeListToken(NodeKind::CallExprComma,
  22. Lex::TokenKind::CloseParen, state.has_error) ==
  23. Context::ListTokenKind::Comma) {
  24. context.PushState(State::CallExprParamFinish);
  25. context.PushState(State::Expr);
  26. }
  27. }
  28. auto HandleCallExprFinish(Context& context) -> void {
  29. auto state = context.PopState();
  30. context.AddNode(NodeKind::CallExpr, context.Consume(), state.subtree_start,
  31. state.has_error);
  32. }
  33. } // namespace Carbon::Parse