parse_and_lex_context.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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& inputFile) : inputFileName(inputFile) {}
  16. // Writes a syntax error diagnostic, containing message, for the input file at
  17. // the given line, to standard error.
  18. auto PrintDiagnostic(const std::string& message, int lineNumber) -> void;
  19. // The source range of the token being (or just) lex'd.
  20. yy::location currentTokenPosition;
  21. private:
  22. // A path to the file processed, relative to the current working directory
  23. // when *this is called.
  24. const std::string inputFileName;
  25. };
  26. } // namespace Carbon
  27. // Gives flex the yylex prototype we want.
  28. #define YY_DECL \
  29. yy::parser::symbol_type yylex(Carbon::ParseAndLexContext& context)
  30. // Declares yylex for the parser's sake.
  31. YY_DECL;
  32. #endif // EXECUTABLE_SYNTAX_DRIVER_H_