handle_call_expr.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #include "toolchain/parse/handle.h"
  6. namespace Carbon::Parse {
  7. auto HandleCallExpr(Context& context) -> void {
  8. auto state = context.PopState();
  9. context.PushState(state, State::CallExprFinish);
  10. context.AddNode(NodeKind::CallExprStart, context.Consume(), 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.has_error);
  31. }
  32. } // namespace Carbon::Parse