mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
It's hard to track 2-space indent levels across large vertical gaps, and it can be hard to suppress the instinct to read the dump as if it were preorder. This change introduces a new dump mode that addresses both problems by using box-drawing characters to explicitly represent the parent-child edges of the tree. This new mode is the default, but the old behavior remains available with `--parse-dump-format=yaml-postorder`.
45 lines
1.3 KiB
C++
45 lines
1.3 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 CARBON_TOOLCHAIN_PARSE_PARSE_H_
|
|
#define CARBON_TOOLCHAIN_PARSE_PARSE_H_
|
|
|
|
#include "common/ostream.h"
|
|
#include "toolchain/diagnostics/emitter.h"
|
|
#include "toolchain/lex/tokenized_buffer.h"
|
|
#include "toolchain/parse/tree.h"
|
|
|
|
namespace Carbon::Parse {
|
|
|
|
struct ParseOptions {
|
|
// Options must be set individually, not through initialization.
|
|
explicit ParseOptions() = default;
|
|
|
|
// If set, a consumer for diagnostics. Otherwise, diagnostics go to stderr.
|
|
Diagnostics::Consumer* consumer = nullptr;
|
|
|
|
// If set, enables verbose output.
|
|
llvm::raw_ostream* vlog_stream = nullptr;
|
|
|
|
// If set, the parse tree will be dumped to this.
|
|
llvm::raw_ostream* dump_stream = nullptr;
|
|
|
|
// The format to dump the parse tree in if `dump_stream` is set.
|
|
enum class DumpFormat {
|
|
PrettyPostorder,
|
|
YamlPostorder,
|
|
YamlPreorder,
|
|
};
|
|
DumpFormat dump_format;
|
|
};
|
|
|
|
// Parses the token buffer into a `Tree`.
|
|
//
|
|
// This is the factory function which is used to build parse trees.
|
|
auto Parse(Lex::TokenizedBuffer& tokens, ParseOptions options) -> Tree;
|
|
|
|
} // namespace Carbon::Parse
|
|
|
|
#endif // CARBON_TOOLCHAIN_PARSE_PARSE_H_
|