handle_namespace.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  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 HandleNamespace(Context& context) -> void {
  7. auto state = context.PopState();
  8. context.PushState(state, State::NamespaceFinish);
  9. context.PushState(State::DeclNameAndParamsAsNone, state.token);
  10. }
  11. auto HandleNamespaceFinish(Context& context) -> void {
  12. auto state = context.PopState();
  13. if (state.has_error) {
  14. context.RecoverFromDeclError(state, NodeKind::Namespace,
  15. /*skip_past_likely_end=*/true);
  16. return;
  17. }
  18. if (auto semi = context.ConsumeIf(Lex::TokenKind::Semi)) {
  19. context.AddNode(NodeKind::Namespace, *semi, state.subtree_start,
  20. state.has_error);
  21. } else {
  22. context.EmitExpectedDeclSemi(Lex::TokenKind::Namespace);
  23. context.RecoverFromDeclError(state, NodeKind::Namespace,
  24. /*skip_past_likely_end=*/true);
  25. }
  26. }
  27. } // namespace Carbon::Parse