Add CST definitions for record expressions and rename StructDeclaration
This commit is contained in:
parent
4a501c1f77
commit
4acb76159f
3 changed files with 108 additions and 28 deletions
|
@ -137,6 +137,8 @@ namespace bolt {
|
|||
CallExpression,
|
||||
InfixExpression,
|
||||
PrefixExpression,
|
||||
RecordExpressionField,
|
||||
RecordExpression,
|
||||
ExpressionStatement,
|
||||
ReturnStatement,
|
||||
IfStatement,
|
||||
|
@ -146,8 +148,8 @@ namespace bolt {
|
|||
LetBlockBody,
|
||||
LetExprBody,
|
||||
LetDeclaration,
|
||||
StructDeclarationField,
|
||||
StructDeclaration,
|
||||
RecordDeclarationField,
|
||||
RecordDeclaration,
|
||||
ClassDeclaration,
|
||||
InstanceDeclaration,
|
||||
SourceFile,
|
||||
|
@ -1366,6 +1368,49 @@ namespace bolt {
|
|||
|
||||
};
|
||||
|
||||
class RecordExpressionField : public Node {
|
||||
public:
|
||||
|
||||
Identifier* Name;
|
||||
Equals* Equals;
|
||||
Expression* E;
|
||||
|
||||
inline RecordExpressionField(
|
||||
Identifier* Name,
|
||||
class Equals* Equals,
|
||||
Expression* E
|
||||
): Node(NodeKind::RecordExpressionField),
|
||||
Name(Name),
|
||||
Equals(Equals),
|
||||
E(E) {}
|
||||
|
||||
Token* getFirstToken() const override;
|
||||
Token* getLastToken() const override;
|
||||
|
||||
inline Expression* getExpression() const {
|
||||
return E;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class RecordExpression : public Expression {
|
||||
public:
|
||||
|
||||
LBrace* LBrace;
|
||||
std::vector<std::tuple<RecordExpressionField*, Comma*>> Fields;
|
||||
RBrace* RBrace;
|
||||
|
||||
inline RecordExpression(
|
||||
class LBrace* LBrace,
|
||||
std::vector<std::tuple<RecordExpressionField*, Comma*>> Fields,
|
||||
class RBrace* RBrace
|
||||
): Expression(NodeKind::RecordExpression),
|
||||
LBrace(LBrace),
|
||||
Fields(Fields),
|
||||
RBrace(RBrace) {}
|
||||
|
||||
};
|
||||
|
||||
class Statement : public Node {
|
||||
protected:
|
||||
|
||||
|
@ -1640,14 +1685,14 @@ namespace bolt {
|
|||
|
||||
};
|
||||
|
||||
class StructDeclarationField : public Node {
|
||||
class RecordDeclarationField : public Node {
|
||||
public:
|
||||
|
||||
StructDeclarationField(
|
||||
RecordDeclarationField(
|
||||
Identifier* Name,
|
||||
class Colon* Colon,
|
||||
class TypeExpression* TypeExpression
|
||||
): Node(NodeKind::StructDeclarationField),
|
||||
): Node(NodeKind::RecordDeclarationField),
|
||||
Name(Name),
|
||||
Colon(Colon),
|
||||
TypeExpression(TypeExpression) {}
|
||||
|
@ -1661,22 +1706,22 @@ namespace bolt {
|
|||
|
||||
};
|
||||
|
||||
class StructDeclaration : public Node {
|
||||
class RecordDeclaration : public Node {
|
||||
public:
|
||||
|
||||
class PubKeyword* PubKeyword;
|
||||
class StructKeyword* StructKeyword;
|
||||
Identifier* Name;
|
||||
class BlockStart* BlockStart;
|
||||
std::vector<StructDeclarationField*> Fields;
|
||||
std::vector<RecordDeclarationField*> Fields;
|
||||
|
||||
StructDeclaration(
|
||||
RecordDeclaration(
|
||||
class PubKeyword* PubKeyword,
|
||||
class StructKeyword* StructKeyword,
|
||||
Identifier* Name,
|
||||
class BlockStart* BlockStart,
|
||||
std::vector<StructDeclarationField*> Fields
|
||||
): Node(NodeKind::StructDeclaration),
|
||||
std::vector<RecordDeclarationField*> Fields
|
||||
): Node(NodeKind::RecordDeclaration),
|
||||
PubKeyword(PubKeyword),
|
||||
StructKeyword(StructKeyword),
|
||||
Name(Name),
|
||||
|
@ -1780,8 +1825,8 @@ namespace bolt {
|
|||
template<> inline NodeKind getNodeType<LetBlockBody>() { return NodeKind::LetBlockBody; }
|
||||
template<> inline NodeKind getNodeType<LetExprBody>() { return NodeKind::LetExprBody; }
|
||||
template<> inline NodeKind getNodeType<LetDeclaration>() { return NodeKind::LetDeclaration; }
|
||||
template<> inline NodeKind getNodeType<StructDeclarationField>() { return NodeKind::StructDeclarationField; }
|
||||
template<> inline NodeKind getNodeType<StructDeclaration>() { return NodeKind::StructDeclaration; }
|
||||
template<> inline NodeKind getNodeType<RecordDeclarationField>() { return NodeKind::RecordDeclarationField; }
|
||||
template<> inline NodeKind getNodeType<RecordDeclaration>() { return NodeKind::RecordDeclaration; }
|
||||
template<> inline NodeKind getNodeType<ClassDeclaration>() { return NodeKind::ClassDeclaration; }
|
||||
template<> inline NodeKind getNodeType<InstanceDeclaration>() { return NodeKind::InstanceDeclaration; }
|
||||
template<> inline NodeKind getNodeType<SourceFile>() { return NodeKind::SourceFile; }
|
||||
|
|
|
@ -127,6 +127,10 @@ namespace bolt {
|
|||
return static_cast<D*>(this)->visitInfixExpression(static_cast<InfixExpression*>(N));
|
||||
case NodeKind::PrefixExpression:
|
||||
return static_cast<D*>(this)->visitPrefixExpression(static_cast<PrefixExpression*>(N));
|
||||
case NodeKind::RecordExpressionField:
|
||||
return static_cast<D*>(this)->visitRecordExpressionField(static_cast<RecordExpressionField*>(N));
|
||||
case NodeKind::RecordExpression:
|
||||
return static_cast<D*>(this)->visitRecordExpression(static_cast<RecordExpression*>(N));
|
||||
case NodeKind::ExpressionStatement:
|
||||
return static_cast<D*>(this)->visitExpressionStatement(static_cast<ExpressionStatement*>(N));
|
||||
case NodeKind::ReturnStatement:
|
||||
|
@ -145,10 +149,10 @@ namespace bolt {
|
|||
return static_cast<D*>(this)->visitLetExprBody(static_cast<LetExprBody*>(N));
|
||||
case NodeKind::LetDeclaration:
|
||||
return static_cast<D*>(this)->visitLetDeclaration(static_cast<LetDeclaration*>(N));
|
||||
case NodeKind::StructDeclarationField:
|
||||
return static_cast<D*>(this)->visitStructDeclarationField(static_cast<StructDeclarationField*>(N));
|
||||
case NodeKind::StructDeclaration:
|
||||
return static_cast<D*>(this)->visitStructDeclaration(static_cast<StructDeclaration*>(N));
|
||||
case NodeKind::RecordDeclarationField:
|
||||
return static_cast<D*>(this)->visitStructDeclarationField(static_cast<RecordDeclarationField*>(N));
|
||||
case NodeKind::RecordDeclaration:
|
||||
return static_cast<D*>(this)->visitStructDeclaration(static_cast<RecordDeclaration*>(N));
|
||||
case NodeKind::ClassDeclaration:
|
||||
return static_cast<D*>(this)->visitClassDeclaration(static_cast<ClassDeclaration*>(N));
|
||||
case NodeKind::InstanceDeclaration:
|
||||
|
@ -416,6 +420,14 @@ namespace bolt {
|
|||
visitExpression(N);
|
||||
}
|
||||
|
||||
void visitRecordExpressionField(RecordExpressionField* N) {
|
||||
visitNode(N);
|
||||
}
|
||||
|
||||
void visitRecordExpression(RecordExpression* N) {
|
||||
visitExpression(N);
|
||||
}
|
||||
|
||||
void visitStatement(Statement* N) {
|
||||
visitNode(N);
|
||||
}
|
||||
|
@ -460,11 +472,11 @@ namespace bolt {
|
|||
visitNode(N);
|
||||
}
|
||||
|
||||
void visitStructDeclarationField(StructDeclarationField* N) {
|
||||
void visitStructDeclarationField(RecordDeclarationField* N) {
|
||||
visitNode(N);
|
||||
}
|
||||
|
||||
void visitStructDeclaration(StructDeclaration* N) {
|
||||
void visitStructDeclaration(RecordDeclaration* N) {
|
||||
visitNode(N);
|
||||
}
|
||||
|
||||
|
@ -658,6 +670,12 @@ namespace bolt {
|
|||
case NodeKind::PrefixExpression:
|
||||
visitEachChild(static_cast<PrefixExpression*>(N));
|
||||
break;
|
||||
case NodeKind::RecordExpressionField:
|
||||
visitEachChild(static_cast<RecordExpressionField*>(N));
|
||||
break;
|
||||
case NodeKind::RecordExpression:
|
||||
visitEachChild(static_cast<RecordExpression*>(N));
|
||||
break;
|
||||
case NodeKind::ExpressionStatement:
|
||||
visitEachChild(static_cast<ExpressionStatement*>(N));
|
||||
break;
|
||||
|
@ -685,11 +703,11 @@ namespace bolt {
|
|||
case NodeKind::LetDeclaration:
|
||||
visitEachChild(static_cast<LetDeclaration*>(N));
|
||||
break;
|
||||
case NodeKind::StructDeclaration:
|
||||
visitEachChild(static_cast<StructDeclaration*>(N));
|
||||
case NodeKind::RecordDeclaration:
|
||||
visitEachChild(static_cast<RecordDeclaration*>(N));
|
||||
break;
|
||||
case NodeKind::StructDeclarationField:
|
||||
visitEachChild(static_cast<StructDeclarationField*>(N));
|
||||
case NodeKind::RecordDeclarationField:
|
||||
visitEachChild(static_cast<RecordDeclarationField*>(N));
|
||||
break;
|
||||
case NodeKind::ClassDeclaration:
|
||||
visitEachChild(static_cast<ClassDeclaration*>(N));
|
||||
|
@ -959,6 +977,23 @@ namespace bolt {
|
|||
BOLT_VISIT(N->Argument);
|
||||
}
|
||||
|
||||
void visitEachChild(RecordExpressionField* N) {
|
||||
BOLT_VISIT(N->Name);
|
||||
BOLT_VISIT(N->Equals);
|
||||
BOLT_VISIT(N->E);
|
||||
}
|
||||
|
||||
void visitEachChild(RecordExpression* N) {
|
||||
BOLT_VISIT(N->LBrace);
|
||||
for (auto [Field, Comma]: N->Fields) {
|
||||
BOLT_VISIT(Field);
|
||||
if (Comma) {
|
||||
BOLT_VISIT(Comma);
|
||||
}
|
||||
}
|
||||
BOLT_VISIT(N->RBrace);
|
||||
}
|
||||
|
||||
void visitEachChild(ExpressionStatement* N) {
|
||||
BOLT_VISIT(N->Expression);
|
||||
}
|
||||
|
@ -1029,13 +1064,13 @@ namespace bolt {
|
|||
}
|
||||
}
|
||||
|
||||
void visitEachChild(StructDeclarationField* N) {
|
||||
void visitEachChild(RecordDeclarationField* N) {
|
||||
BOLT_VISIT(N->Name);
|
||||
BOLT_VISIT(N->Colon);
|
||||
BOLT_VISIT(N->TypeExpression);
|
||||
}
|
||||
|
||||
void visitEachChild(StructDeclaration* N) {
|
||||
void visitEachChild(RecordDeclaration* N) {
|
||||
if (N->PubKeyword) {
|
||||
BOLT_VISIT(N->PubKeyword);
|
||||
}
|
||||
|
|
|
@ -514,22 +514,22 @@ namespace bolt {
|
|||
return Pattern->getLastToken();
|
||||
}
|
||||
|
||||
Token* StructDeclarationField::getFirstToken() const {
|
||||
Token* RecordDeclarationField::getFirstToken() const {
|
||||
return Name;
|
||||
}
|
||||
|
||||
Token* StructDeclarationField::getLastToken() const {
|
||||
Token* RecordDeclarationField::getLastToken() const {
|
||||
return TypeExpression->getLastToken();
|
||||
}
|
||||
|
||||
Token* StructDeclaration::getFirstToken() const {
|
||||
Token* RecordDeclaration::getFirstToken() const {
|
||||
if (PubKeyword) {
|
||||
return PubKeyword;
|
||||
}
|
||||
return StructKeyword;
|
||||
}
|
||||
|
||||
Token* StructDeclaration::getLastToken() const {
|
||||
Token* RecordDeclaration::getLastToken() const {
|
||||
if (Fields.size()) {
|
||||
Fields.back()->getLastToken();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue