Set up a 'Parse' namespace. (#3161)

Continuing on #3070.

I moved ParseTree::Node to just Parse::Node, versus Parse::Tree::Node.
Other name changes are just removing "Parse" or "Parser" prefixes.

In EnumBase, I'm directly defining operator<< because the ostream.h
approach just isn't working, not for either of Parse::State nor
Parse::NodeKind. Errors look like:

```toolchain/parser/parser_context.cpp:449:34: error: invalid operands to binary expression ('llvm::raw_ostream' and 'const Carbon::Parse::State')
    output << "\t" << i << ".\t" << entry.state;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~
```

The expected template in `Carbon::` is not in the error list; I only see
the:

```
./common/ostream.h:112:6: note: candidate template ignored: requirement 'std::is_base_of_v<std::ostream, llvm::raw_ostream>' was not satisfied [with S = llvm::raw_ostream, T = Carbon::Parse::State]
auto operator<<(S& standard_out, const T& value) -> S& {
     ^
```

I'm still prodding at this, but not seeing an obvious fix.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
Jon Ross-PerkinsandRichard Smith authored and GitHub committed 2023-08-28 21:58:38 +00:00
1 parent 64687aa7d1
commit 7157445f97
75 files changed
+1181 -1277

No files matched your search

+10 -9
View File
@@ -18,9 +18,10 @@
namespace Carbon::Testing {
namespace {
using Parse::Tree;
using ::testing::ElementsAre;
class ParseTreeTest : public ::testing::Test {
class TreeTest : public ::testing::Test {
protected:
auto GetSourceBuffer(llvm::StringRef t) -> SourceBuffer& {
CARBON_CHECK(fs.addFile("test.carbon", /*ModificationTime=*/0,
@@ -42,15 +43,15 @@ class ParseTreeTest : public ::testing::Test {
DiagnosticConsumer& consumer = ConsoleDiagnosticConsumer();
};
TEST_F(ParseTreeTest, IsValid) {
TEST_F(TreeTest, IsValid) {
TokenizedBuffer tokens = GetTokenizedBuffer("");
ParseTree tree = ParseTree::Parse(tokens, consumer, /*vlog_stream=*/nullptr);
Tree tree = Tree::Parse(tokens, consumer, /*vlog_stream=*/nullptr);
EXPECT_TRUE((*tree.postorder().begin()).is_valid());
}
TEST_F(ParseTreeTest, PrintPostorderAsYAML) {
TEST_F(TreeTest, PrintPostorderAsYAML) {
TokenizedBuffer tokens = GetTokenizedBuffer("fn F();");
ParseTree tree = ParseTree::Parse(tokens, consumer, /*vlog_stream=*/nullptr);
Tree tree = Tree::Parse(tokens, consumer, /*vlog_stream=*/nullptr);
EXPECT_FALSE(tree.has_errors());
TestRawOstream print_stream;
tree.Print(print_stream);
@@ -70,9 +71,9 @@ TEST_F(ParseTreeTest, PrintPostorderAsYAML) {
EXPECT_THAT(Yaml::Value::FromText(print_stream.TakeStr()), ElementsAre(file));
}
TEST_F(ParseTreeTest, PrintPreorderAsYAML) {
TEST_F(TreeTest, PrintPreorderAsYAML) {
TokenizedBuffer tokens = GetTokenizedBuffer("fn F();");
ParseTree tree = ParseTree::Parse(tokens, consumer, /*vlog_stream=*/nullptr);
Tree tree = Tree::Parse(tokens, consumer, /*vlog_stream=*/nullptr);
EXPECT_FALSE(tree.has_errors());
TestRawOstream print_stream;
tree.Print(print_stream, /*preorder=*/true);
@@ -106,7 +107,7 @@ TEST_F(ParseTreeTest, PrintPreorderAsYAML) {
EXPECT_THAT(Yaml::Value::FromText(print_stream.TakeStr()), ElementsAre(file));
}
TEST_F(ParseTreeTest, HighRecursion) {
TEST_F(TreeTest, HighRecursion) {
std::string code = "fn Foo() { return ";
code.append(10000, '(');
code.append(10000, ')');
@@ -114,7 +115,7 @@ TEST_F(ParseTreeTest, HighRecursion) {
TokenizedBuffer tokens = GetTokenizedBuffer(code);
ASSERT_FALSE(tokens.has_errors());
Testing::MockDiagnosticConsumer consumer;
ParseTree tree = ParseTree::Parse(tokens, consumer, /*vlog_stream=*/nullptr);
Tree tree = Tree::Parse(tokens, consumer, /*vlog_stream=*/nullptr);
EXPECT_FALSE(tree.has_errors());
}