Files
carbon-lang/executable_semantics/syntax/parse_and_lex_context.h
T
Jon Meow b87747306f Add the ability to pipe trace output to a file. (#1183)
Breaks `--trace` into two flags:

- `--parser_debug`, which sets the parser debug level (which I haven't dug into piping with `--trace`, but seemed likely to be troublesome)
- `--trace_file`, which now the type checker and interpreter will use for trace information (note compile errors should use a different channel)

Most of the file edits are just mechanical testdata flag updates: `sed -i 's/--trace/--parser_debug --trace_file=-/' testdata/**/*.carbon`

To explain the output paths:

- parse/compile errors: stderr
- print() calls: stdout
- parser tracing: `--parser_debug` option, stdout (formerly stdout if `--trace`)
- type check/compile tracing: `--trace_file=<file>`, giving `-` uses stdout (formerly stdout if `--trace`)
- return code of executed Carbon code: `--trace_file` if set, stdout if not (formerly stdout always)
2022-04-14 11:20:56 -07:00

66 lines
2.1 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(Nonnull<const std::string*> input_file_name,
bool parser_debug)
: input_file_name_(input_file_name), parser_debug_(parser_debug) {}
// Formats ands records a lexer error. Returns an error token as a
// convenience.
auto RecordSyntaxError(const std::string& message,
bool prefix_with_newline = false)
-> Parser::symbol_type;
auto source_loc() const -> SourceLocation {
return SourceLocation(input_file_name_,
static_cast<int>(current_token_position.begin.line));
}
auto parser_debug() const -> bool { return parser_debug_; }
// The source range of the token being (or just) lex'd.
location current_token_position;
auto error_messages() const -> const std::vector<std::string> {
return error_messages_;
}
private:
// A path to the file processed, relative to the current working directory
// when *this is called.
Nonnull<const std::string*> input_file_name_;
bool parser_debug_;
std::vector<std::string> error_messages_;
};
} // namespace Carbon
// Gives flex the yylex prototype we want.
#define YY_DECL \
auto yylex(Carbon::Nonnull<Carbon::Arena*> arena, yyscan_t yyscanner, \
Carbon::ParseAndLexContext& context) \
->Carbon::Parser::symbol_type
// Declares yylex for the parser's sake.
YY_DECL;
#endif // EXECUTABLE_SYNTAX_DRIVER_H_