parser_handle_index_expression.cpp 972 B

123456789101112131415161718192021222324252627
  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/lexer/token_kind.h"
  5. #include "toolchain/parser/parser_context.h"
  6. namespace Carbon {
  7. auto ParserHandleIndexExpression(ParserContext& context) -> void {
  8. auto state = context.PopState();
  9. state.state = ParserState::IndexExpressionFinish;
  10. context.PushState(state);
  11. context.AddNode(ParseNodeKind::IndexExpressionStart,
  12. context.ConsumeChecked(TokenKind::OpenSquareBracket),
  13. state.subtree_start, state.has_error);
  14. context.PushState(ParserState::Expression);
  15. }
  16. auto ParserHandleIndexExpressionFinish(ParserContext& context) -> void {
  17. auto state = context.PopState();
  18. context.ConsumeAndAddCloseSymbol(state.token, state,
  19. ParseNodeKind::IndexExpression);
  20. }
  21. } // namespace Carbon