parse_and_lex_context.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. #ifndef EXECUTABLE_SEMANTICS_SYNTAX_DRIVER_H_
  5. #define EXECUTABLE_SEMANTICS_SYNTAX_DRIVER_H_
  6. #include <variant>
  7. #include "executable_semantics/ast/abstract_syntax_tree.h"
  8. #include "executable_semantics/syntax/parser.h" // from parser.ypp
  9. namespace Carbon {
  10. // The state and functionality that is threaded "globally" through the
  11. // lexing/parsing process.
  12. class ParseAndLexContext {
  13. public:
  14. // Creates an instance analyzing the given input file.
  15. ParseAndLexContext(const std::string& input_file)
  16. : input_file_name(input_file) {}
  17. // Writes a syntax error diagnostic, containing message, for the input file at
  18. // the given line, to standard error.
  19. auto PrintDiagnostic(const std::string& message, int line_number) -> void;
  20. // The source range of the token being (or just) lex'd.
  21. yy::location current_token_position;
  22. private:
  23. // A path to the file processed, relative to the current working directory
  24. // when *this is called.
  25. const std::string input_file_name;
  26. };
  27. } // namespace Carbon
  28. // Gives flex the yylex prototype we want.
  29. #define YY_DECL \
  30. yy::parser::symbol_type yylex(Carbon::ParseAndLexContext& context)
  31. // Declares yylex for the parser's sake.
  32. YY_DECL;
  33. #endif // EXECUTABLE_SYNTAX_DRIVER_H_