handle_namespace.cpp 1.1 KB

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