Add support for _ placeholder. (#661)

Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
This commit is contained in:
Geoff Romer
2021-07-19 10:33:06 -07:00
committed by GitHub
co-authored by Jon Meow
parent c3c89a77a4
commit def98d1182
15 changed files with 88 additions and 20 deletions
+5 -2
View File
@@ -5,6 +5,7 @@
#ifndef EXECUTABLE_SEMANTICS_AST_EXPRESSION_H_
#define EXECUTABLE_SEMANTICS_AST_EXPRESSION_H_
#include <optional>
#include <string>
#include <variant>
#include <vector>
@@ -74,7 +75,8 @@ struct IndexExpression {
struct BindingExpression {
static constexpr ExpressionKind Kind = ExpressionKind::BindingExpression;
std::string name;
// nullopt represents the `_` placeholder.
std::optional<std::string> name;
const Expression* type;
};
@@ -136,7 +138,8 @@ struct TypeTypeLiteral {
struct Expression {
static auto MakeIdentifierExpression(int line_num, std::string var)
-> const Expression*;
static auto MakeBindingExpression(int line_num, std::string var,
static auto MakeBindingExpression(int line_num,
std::optional<std::string> var,
const Expression* type)
-> const Expression*;
static auto MakeIntLiteral(int line_num, int i) -> const Expression*;