mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-25 13:40:12 +01:00
With this, only main.cpp instantiates an arena. Maybe we'll want to split that up more later (e.g., so that the runtime interpreter uses its own arena), but given the intent to have type-checking update the AST, I thought this was a reasonable approach for now in order to avoid ownership complexities. Fixes #769
52 lines
1.7 KiB
C++
52 lines
1.7 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/ast.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(Ptr<const std::string> input_file_name)
|
|
: input_file_name(input_file_name) {}
|
|
|
|
// Writes a syntax error diagnostic containing message to standard error.
|
|
auto PrintDiagnostic(const std::string& message) -> void;
|
|
|
|
auto SourceLoc() -> SourceLocation {
|
|
return SourceLocation(input_file_name,
|
|
static_cast<int>(current_token_position.begin.line));
|
|
}
|
|
|
|
// The source range of the token being (or just) lex'd.
|
|
location current_token_position;
|
|
|
|
private:
|
|
// A path to the file processed, relative to the current working directory
|
|
// when *this is called.
|
|
Ptr<const std::string> input_file_name;
|
|
};
|
|
|
|
} // namespace Carbon
|
|
|
|
// Gives flex the yylex prototype we want.
|
|
#define YY_DECL \
|
|
Carbon::Parser::symbol_type yylex(Carbon::Ptr<Carbon::Arena> arena, \
|
|
yyscan_t yyscanner, \
|
|
Carbon::ParseAndLexContext& context)
|
|
|
|
// Declares yylex for the parser's sake.
|
|
YY_DECL;
|
|
|
|
#endif // EXECUTABLE_SYNTAX_DRIVER_H_
|