parser_handle_call_expression.cpp 1.5 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/parser/parser_context.h"
  5. namespace Carbon {
  6. auto ParserHandleCallExpression(ParserContext& context) -> void {
  7. auto state = context.PopState();
  8. state.state = ParserState::CallExpressionFinish;
  9. context.PushState(state);
  10. context.AddNode(ParseNodeKind::CallExpressionStart, context.Consume(),
  11. state.subtree_start, state.has_error);
  12. if (!context.PositionIs(TokenKind::CloseParen)) {
  13. context.PushState(ParserState::CallExpressionParameterFinish);
  14. context.PushState(ParserState::Expression);
  15. }
  16. }
  17. auto ParserHandleCallExpressionParameterFinish(ParserContext& context) -> void {
  18. auto state = context.PopState();
  19. if (state.has_error) {
  20. context.ReturnErrorOnState();
  21. }
  22. if (context.ConsumeListToken(ParseNodeKind::CallExpressionComma,
  23. TokenKind::CloseParen, state.has_error) ==
  24. ParserContext::ListTokenKind::Comma) {
  25. context.PushState(ParserState::CallExpressionParameterFinish);
  26. context.PushState(ParserState::Expression);
  27. }
  28. }
  29. auto ParserHandleCallExpressionFinish(ParserContext& context) -> void {
  30. auto state = context.PopState();
  31. context.AddNode(ParseNodeKind::CallExpression, context.Consume(),
  32. state.subtree_start, state.has_error);
  33. }
  34. } // namespace Carbon