Restructure handling of paren expressions (#417)

* Move nontrivial logic out of `parser.ypp` into `FieldList`, rename it to `ParenContents`, make it a class, and add tests
* Use a `FieldInitializer` struct instead of `std::pair<std::string, Expression*>` to represent the fields of a tuple
This commit is contained in:
Geoff Romer
2021-04-05 10:49:25 -07:00
committed by GitHub
parent 98a6477233
commit 80f035874d
9 changed files with 251 additions and 105 deletions
-7
View File
@@ -27,13 +27,6 @@ cc_library(
hdrs = ["expression.h"],
)
cc_library(
name = "field_list",
srcs = ["field_list.cpp"],
hdrs = ["field_list.h"],
deps = [":expression"],
)
cc_library(
name = "function_definition",
srcs = ["function_definition.cpp"],
-29
View File
@@ -1,29 +0,0 @@
// 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
#include "executable_semantics/ast/field_list.h"
namespace Carbon {
auto MakeFieldList(std::list<std::pair<std::string, Expression*>>* fields)
-> FieldList* {
auto e = new FieldList();
e->fields = fields;
return e;
}
auto MakeConsField(FieldList* e1, FieldList* e2) -> FieldList* {
auto fields = new std::list<std::pair<std::string, Expression*>>();
for (auto& field : *e1->fields) {
fields->push_back(field);
}
for (auto& field : *e2->fields) {
fields->push_back(field);
}
auto result = MakeFieldList(fields);
result->has_explicit_comma = true;
return result;
}
} // namespace Carbon
-26
View File
@@ -1,26 +0,0 @@
// 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_AST_FIELD_LIST_H_
#define EXECUTABLE_SEMANTICS_AST_FIELD_LIST_H_
#include <list>
#include "executable_semantics/ast/expression.h"
namespace Carbon {
// This is used in the parsing of tuples and parenthesized expressions.
struct FieldList {
std::list<std::pair<std::string, Expression*>>* fields;
bool has_explicit_comma = false;
};
auto MakeFieldList(std::list<std::pair<std::string, Expression*>>* fields)
-> FieldList*;
auto MakeConsField(FieldList* e1, FieldList* e2) -> FieldList*;
} // namespace Carbon
#endif // EXECUTABLE_SEMANTICS_AST_FIELD_LIST_H_