handle_index_expression.cpp 935 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/lex/token_kind.h"
  5. #include "toolchain/parse/context.h"
  6. namespace Carbon::Parse {
  7. auto HandleIndexExpression(Context& context) -> void {
  8. auto state = context.PopState();
  9. state.state = State::IndexExpressionFinish;
  10. context.PushState(state);
  11. context.AddNode(NodeKind::IndexExpressionStart,
  12. context.ConsumeChecked(Lex::TokenKind::OpenSquareBracket),
  13. state.subtree_start, state.has_error);
  14. context.PushState(State::Expression);
  15. }
  16. auto HandleIndexExpressionFinish(Context& context) -> void {
  17. auto state = context.PopState();
  18. context.ConsumeAndAddCloseSymbol(state.token, state,
  19. NodeKind::IndexExpression);
  20. }
  21. } // namespace Carbon::Parse