handle_call_expr.cpp 1.3 KB

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