Files
carbon-lang/executable_semantics/syntax/parse_and_lex_context.h
T
Dave Abrahams 436a9dda79 [executable semantics] Minimal cxx parser (#363)
Makes a minimal transition to using C++ in the parser.
2021-03-09 20:46:52 -08:00

44 lines
1.4 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef EXECUTABLE_SEMANTICS_SYNTAX_DRIVER_H_
#define EXECUTABLE_SEMANTICS_SYNTAX_DRIVER_H_
#include <variant>
#include "executable_semantics/ast/abstract_syntax_tree.h"
#include "executable_semantics/syntax/parser.h" // from parser.ypp
namespace Carbon {
// The state and functionality that is threaded "globally" through the
// lexing/parsing process.
class ParseAndLexContext {
public:
// Creates an instance analyzing the given input file.
ParseAndLexContext(const std::string& inputFile) : inputFileName(inputFile) {}
// Writes a syntax error diagnostic, containing message, for the input file at
// the given line, to standard error.
auto PrintDiagnostic(const std::string& message, int lineNumber) -> void;
private:
// A path to the file processed, relative to the current working directory
// when *this is called.
const std::string inputFileName;
};
} // namespace Carbon
// Gives flex the yylex prototype we want.
#define YY_DECL \
int yylex(yy::parser::semantic_type* yylval, \
yy::parser::location_type* sourceLocation, \
Carbon::ParseAndLexContext& context)
// Declares yylex for the parser's sake.
YY_DECL;
#endif // EXECUTABLE_SYNTAX_DRIVER_H_