parse_and_lex_context.cpp 1.1 KB

1234567891011121314151617181920212223242526
  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 "executable_semantics/syntax/parse_and_lex_context.h"
  5. namespace Carbon {
  6. auto ParseAndLexContext::RecordSyntaxError(const std::string& message,
  7. bool prefix_with_newline)
  8. -> Parser::symbol_type {
  9. // Optionally adds a newline in trace mode because trace prints an incomplete
  10. // line "Reading a token: " which can prevent LIT from finding expected
  11. // patterns.
  12. // TODO: support formatting of `SourceLocation` instances with formatv().
  13. std::string full_message;
  14. llvm::raw_string_ostream(full_message)
  15. << (prefix_with_newline && parser_debug() ? "\n" : "")
  16. << "COMPILATION ERROR: " << source_loc() << ": " << message;
  17. error_messages_.push_back(full_message);
  18. // TODO: use `YYerror` token once bison is upgraded to at least 3.5.
  19. return Parser::make_END_OF_FILE(current_token_position);
  20. }
  21. } // namespace Carbon