Add parsing support for function expressions and format Parser.cc
This commit is contained in:
parent
d0ead42daa
commit
556fc28eb7
6 changed files with 964 additions and 253 deletions
|
@ -10,6 +10,7 @@
|
|||
#include <optional>
|
||||
|
||||
#include "zen/config.hpp"
|
||||
#include "zen/range.hpp"
|
||||
|
||||
#include "bolt/Common.hpp"
|
||||
#include "bolt/Integer.hpp"
|
||||
|
@ -92,6 +93,7 @@ enum class NodeKind {
|
|||
// Plain tokens
|
||||
Assignment,
|
||||
At,
|
||||
Backslash,
|
||||
Colon,
|
||||
Comma,
|
||||
CustomOperator,
|
||||
|
@ -150,14 +152,14 @@ enum class NodeKind {
|
|||
TypeclassConstraintExpression,
|
||||
EqualityConstraintExpression,
|
||||
|
||||
RecordTypeExpression,
|
||||
RecordTypeExpressionField,
|
||||
|
||||
// Type expressions
|
||||
AppTypeExpression,
|
||||
ArrowTypeExpression,
|
||||
NestedTypeExpression,
|
||||
QualifiedTypeExpression,
|
||||
RecordTypeExpressionField,
|
||||
RecordTypeExpression,
|
||||
ReferenceTypeExpression,
|
||||
TupleTypeExpression,
|
||||
VarTypeExpression,
|
||||
|
@ -181,6 +183,7 @@ enum class NodeKind {
|
|||
// Expressions
|
||||
BlockExpression,
|
||||
CallExpression,
|
||||
FunctionExpression,
|
||||
IfExpression,
|
||||
InfixExpression,
|
||||
LiteralExpression,
|
||||
|
@ -471,6 +474,18 @@ public:
|
|||
|
||||
};
|
||||
|
||||
class Backslash : public Token {
|
||||
public:
|
||||
|
||||
inline Backslash(TextLoc StartLoc):
|
||||
Token(NodeKind::Backslash, StartLoc) {}
|
||||
|
||||
std::string getText() const override;
|
||||
|
||||
static constexpr const NodeKind Kind = NodeKind::Backslash;
|
||||
|
||||
};
|
||||
|
||||
class DoKeyword : public Token {
|
||||
public:
|
||||
|
||||
|
@ -1747,6 +1762,7 @@ public:
|
|||
return N->getKind() == NodeKind::ReferenceExpression
|
||||
|| N->getKind() == NodeKind::NestedExpression
|
||||
|| N->getKind() == NodeKind::CallExpression
|
||||
|| N->getKind() == NodeKind::FunctionExpression
|
||||
|| N->getKind() == NodeKind::TupleExpression
|
||||
|| N->getKind() == NodeKind::InfixExpression
|
||||
|| N->getKind() == NodeKind::RecordExpression
|
||||
|
@ -2043,6 +2059,53 @@ public:
|
|||
|
||||
};
|
||||
|
||||
class FunctionExpression : public Expression {
|
||||
|
||||
public:
|
||||
|
||||
Backslash* Backslash;
|
||||
std::vector<Pattern*> Params;
|
||||
RArrow* RArrow;
|
||||
Expression* E;
|
||||
|
||||
inline FunctionExpression(
|
||||
std::vector<Annotation*> Annotations,
|
||||
class Backslash* Backslash,
|
||||
std::vector<Pattern*> Params,
|
||||
class RArrow* RArrow,
|
||||
class Expression* E
|
||||
): Expression(NodeKind::FunctionExpression, Annotations),
|
||||
Backslash(Backslash),
|
||||
Params(Params),
|
||||
RArrow(RArrow),
|
||||
E(E) {}
|
||||
|
||||
inline FunctionExpression(
|
||||
class Backslash* Backslash,
|
||||
std::vector<Pattern*> Params,
|
||||
class RArrow* RArrow,
|
||||
class Expression* Expression
|
||||
): FunctionExpression({}, Backslash, Params, RArrow, Expression) {}
|
||||
|
||||
std::size_t countParams() {
|
||||
return Params.size();
|
||||
}
|
||||
|
||||
auto getParameters() {
|
||||
return zen::make_iterator_range(Params);
|
||||
}
|
||||
|
||||
Expression* getExpression() const {
|
||||
return E;
|
||||
}
|
||||
|
||||
Token* getFirstToken() const override;
|
||||
Token* getLastToken() const override;
|
||||
|
||||
static constexpr const NodeKind Kind = NodeKind::FunctionExpression;
|
||||
|
||||
};
|
||||
|
||||
class InfixExpression : public Expression {
|
||||
public:
|
||||
|
||||
|
|
|
@ -20,106 +20,108 @@ public:
|
|||
#define BOLT_VISIT_OPERATOR(node) static_cast<D*>(this)->dispatchOperator(node)
|
||||
|
||||
switch (N->getKind()) {
|
||||
BOLT_GEN_CASE(VBar)
|
||||
BOLT_GEN_CASE(Equals)
|
||||
BOLT_GEN_CASE(AppTypeExpression)
|
||||
BOLT_GEN_CASE(ArrowTypeExpression)
|
||||
BOLT_GEN_CASE(Assignment)
|
||||
BOLT_GEN_CASE(At)
|
||||
BOLT_GEN_CASE(Backslash)
|
||||
BOLT_GEN_CASE(BindPattern)
|
||||
BOLT_GEN_CASE(BlockEnd)
|
||||
BOLT_GEN_CASE(BlockExpression)
|
||||
BOLT_GEN_CASE(BlockStart)
|
||||
BOLT_GEN_CASE(CallExpression)
|
||||
BOLT_GEN_CASE(ClassDeclaration)
|
||||
BOLT_GEN_CASE(ClassKeyword)
|
||||
BOLT_GEN_CASE(Colon)
|
||||
BOLT_GEN_CASE(Comma)
|
||||
BOLT_GEN_CASE(CustomOperator)
|
||||
BOLT_GEN_CASE(DoKeyword)
|
||||
BOLT_GEN_CASE(Dot)
|
||||
BOLT_GEN_CASE(DotDot)
|
||||
BOLT_GEN_CASE(Tilde)
|
||||
BOLT_GEN_CASE(At)
|
||||
BOLT_GEN_CASE(DoKeyword)
|
||||
BOLT_GEN_CASE(LParen)
|
||||
BOLT_GEN_CASE(RParen)
|
||||
BOLT_GEN_CASE(LBracket)
|
||||
BOLT_GEN_CASE(RBracket)
|
||||
BOLT_GEN_CASE(LBrace)
|
||||
BOLT_GEN_CASE(RBrace)
|
||||
BOLT_GEN_CASE(RArrow)
|
||||
BOLT_GEN_CASE(RArrowAlt)
|
||||
BOLT_GEN_CASE(LetKeyword)
|
||||
BOLT_GEN_CASE(ForeignKeyword)
|
||||
BOLT_GEN_CASE(MutKeyword)
|
||||
BOLT_GEN_CASE(PubKeyword)
|
||||
BOLT_GEN_CASE(TypeKeyword)
|
||||
BOLT_GEN_CASE(ReturnKeyword)
|
||||
BOLT_GEN_CASE(ModKeyword)
|
||||
BOLT_GEN_CASE(StructKeyword)
|
||||
BOLT_GEN_CASE(EnumKeyword)
|
||||
BOLT_GEN_CASE(FnKeyword)
|
||||
BOLT_GEN_CASE(ClassKeyword)
|
||||
BOLT_GEN_CASE(InstanceKeyword)
|
||||
BOLT_GEN_CASE(ElifKeyword)
|
||||
BOLT_GEN_CASE(IfKeyword)
|
||||
BOLT_GEN_CASE(ElseKeyword)
|
||||
BOLT_GEN_CASE(MatchKeyword)
|
||||
BOLT_GEN_CASE(Invalid)
|
||||
BOLT_GEN_CASE(EndOfFile)
|
||||
BOLT_GEN_CASE(BlockStart)
|
||||
BOLT_GEN_CASE(BlockEnd)
|
||||
BOLT_GEN_CASE(LineFoldEnd)
|
||||
BOLT_GEN_CASE(CustomOperator)
|
||||
BOLT_GEN_CASE(Assignment)
|
||||
BOLT_GEN_CASE(EnumKeyword)
|
||||
BOLT_GEN_CASE(EqualityConstraintExpression)
|
||||
BOLT_GEN_CASE(Equals)
|
||||
BOLT_GEN_CASE(ExpressionAnnotation)
|
||||
BOLT_GEN_CASE(FnKeyword)
|
||||
BOLT_GEN_CASE(ForeignKeyword)
|
||||
BOLT_GEN_CASE(FunctionExpression)
|
||||
BOLT_GEN_CASE(Identifier)
|
||||
BOLT_GEN_CASE(IdentifierAlt)
|
||||
BOLT_GEN_CASE(WrappedOperator)
|
||||
BOLT_GEN_CASE(StringLiteral)
|
||||
BOLT_GEN_CASE(IntegerLiteral)
|
||||
BOLT_GEN_CASE(ExpressionAnnotation)
|
||||
BOLT_GEN_CASE(TypeAssertAnnotation)
|
||||
BOLT_GEN_CASE(TypeclassConstraintExpression)
|
||||
BOLT_GEN_CASE(EqualityConstraintExpression)
|
||||
BOLT_GEN_CASE(RecordTypeExpressionField)
|
||||
BOLT_GEN_CASE(RecordTypeExpression)
|
||||
BOLT_GEN_CASE(QualifiedTypeExpression)
|
||||
BOLT_GEN_CASE(ReferenceTypeExpression)
|
||||
BOLT_GEN_CASE(ArrowTypeExpression)
|
||||
BOLT_GEN_CASE(AppTypeExpression)
|
||||
BOLT_GEN_CASE(VarTypeExpression)
|
||||
BOLT_GEN_CASE(NestedTypeExpression)
|
||||
BOLT_GEN_CASE(TupleTypeExpression)
|
||||
BOLT_GEN_CASE(BindPattern)
|
||||
BOLT_GEN_CASE(LiteralPattern)
|
||||
BOLT_GEN_CASE(RecordPatternField)
|
||||
BOLT_GEN_CASE(RecordPattern)
|
||||
BOLT_GEN_CASE(NamedRecordPattern)
|
||||
BOLT_GEN_CASE(NamedTuplePattern)
|
||||
BOLT_GEN_CASE(TuplePattern)
|
||||
BOLT_GEN_CASE(NestedPattern)
|
||||
BOLT_GEN_CASE(ListPattern)
|
||||
BOLT_GEN_CASE(ReferenceExpression)
|
||||
BOLT_GEN_CASE(MatchCase)
|
||||
BOLT_GEN_CASE(MatchExpression)
|
||||
BOLT_GEN_CASE(BlockExpression)
|
||||
BOLT_GEN_CASE(MemberExpression)
|
||||
BOLT_GEN_CASE(TupleExpression)
|
||||
BOLT_GEN_CASE(NestedExpression)
|
||||
BOLT_GEN_CASE(LiteralExpression)
|
||||
BOLT_GEN_CASE(CallExpression)
|
||||
BOLT_GEN_CASE(InfixExpression)
|
||||
BOLT_GEN_CASE(PrefixExpression)
|
||||
BOLT_GEN_CASE(RecordExpressionField)
|
||||
BOLT_GEN_CASE(RecordExpression)
|
||||
BOLT_GEN_CASE(ReturnExpression)
|
||||
BOLT_GEN_CASE(IfExpression)
|
||||
BOLT_GEN_CASE(IfExpressionPart)
|
||||
BOLT_GEN_CASE(TypeAssert)
|
||||
BOLT_GEN_CASE(Parameter)
|
||||
BOLT_GEN_CASE(IfKeyword)
|
||||
BOLT_GEN_CASE(InfixExpression)
|
||||
BOLT_GEN_CASE(InfixFunctionDeclaration)
|
||||
BOLT_GEN_CASE(InstanceDeclaration)
|
||||
BOLT_GEN_CASE(InstanceKeyword)
|
||||
BOLT_GEN_CASE(IntegerLiteral)
|
||||
BOLT_GEN_CASE(Invalid)
|
||||
BOLT_GEN_CASE(LBrace)
|
||||
BOLT_GEN_CASE(LBracket)
|
||||
BOLT_GEN_CASE(LParen)
|
||||
BOLT_GEN_CASE(LetBlockBody)
|
||||
BOLT_GEN_CASE(LetExprBody)
|
||||
BOLT_GEN_CASE(PrefixFunctionDeclaration)
|
||||
BOLT_GEN_CASE(InfixFunctionDeclaration)
|
||||
BOLT_GEN_CASE(SuffixFunctionDeclaration)
|
||||
BOLT_GEN_CASE(LetKeyword)
|
||||
BOLT_GEN_CASE(LineFoldEnd)
|
||||
BOLT_GEN_CASE(ListPattern)
|
||||
BOLT_GEN_CASE(LiteralExpression)
|
||||
BOLT_GEN_CASE(LiteralPattern)
|
||||
BOLT_GEN_CASE(MatchCase)
|
||||
BOLT_GEN_CASE(MatchExpression)
|
||||
BOLT_GEN_CASE(MatchKeyword)
|
||||
BOLT_GEN_CASE(MemberExpression)
|
||||
BOLT_GEN_CASE(ModKeyword)
|
||||
BOLT_GEN_CASE(MutKeyword)
|
||||
BOLT_GEN_CASE(NamedFunctionDeclaration)
|
||||
BOLT_GEN_CASE(VariableDeclaration)
|
||||
BOLT_GEN_CASE(NamedRecordPattern)
|
||||
BOLT_GEN_CASE(NamedTuplePattern)
|
||||
BOLT_GEN_CASE(NestedExpression)
|
||||
BOLT_GEN_CASE(NestedPattern)
|
||||
BOLT_GEN_CASE(NestedTypeExpression)
|
||||
BOLT_GEN_CASE(Parameter)
|
||||
BOLT_GEN_CASE(PrefixExpression)
|
||||
BOLT_GEN_CASE(PrefixFunctionDeclaration)
|
||||
BOLT_GEN_CASE(PubKeyword)
|
||||
BOLT_GEN_CASE(QualifiedTypeExpression)
|
||||
BOLT_GEN_CASE(RArrow)
|
||||
BOLT_GEN_CASE(RArrowAlt)
|
||||
BOLT_GEN_CASE(RBrace)
|
||||
BOLT_GEN_CASE(RBracket)
|
||||
BOLT_GEN_CASE(RParen)
|
||||
BOLT_GEN_CASE(RecordDeclaration)
|
||||
BOLT_GEN_CASE(RecordDeclarationField)
|
||||
BOLT_GEN_CASE(VariantDeclaration)
|
||||
BOLT_GEN_CASE(TupleVariantDeclarationMember)
|
||||
BOLT_GEN_CASE(RecordExpression)
|
||||
BOLT_GEN_CASE(RecordExpressionField)
|
||||
BOLT_GEN_CASE(RecordPattern)
|
||||
BOLT_GEN_CASE(RecordPatternField)
|
||||
BOLT_GEN_CASE(RecordTypeExpression)
|
||||
BOLT_GEN_CASE(RecordTypeExpressionField)
|
||||
BOLT_GEN_CASE(RecordVariantDeclarationMember)
|
||||
BOLT_GEN_CASE(ClassDeclaration)
|
||||
BOLT_GEN_CASE(InstanceDeclaration)
|
||||
BOLT_GEN_CASE(ReferenceExpression)
|
||||
BOLT_GEN_CASE(ReferenceTypeExpression)
|
||||
BOLT_GEN_CASE(ReturnExpression)
|
||||
BOLT_GEN_CASE(ReturnKeyword)
|
||||
BOLT_GEN_CASE(SourceFile)
|
||||
BOLT_GEN_CASE(StringLiteral)
|
||||
BOLT_GEN_CASE(StructKeyword)
|
||||
BOLT_GEN_CASE(SuffixFunctionDeclaration)
|
||||
BOLT_GEN_CASE(Tilde)
|
||||
BOLT_GEN_CASE(TupleExpression)
|
||||
BOLT_GEN_CASE(TuplePattern)
|
||||
BOLT_GEN_CASE(TupleTypeExpression)
|
||||
BOLT_GEN_CASE(TupleVariantDeclarationMember)
|
||||
BOLT_GEN_CASE(TypeAssert)
|
||||
BOLT_GEN_CASE(TypeAssertAnnotation)
|
||||
BOLT_GEN_CASE(TypeKeyword)
|
||||
BOLT_GEN_CASE(TypeclassConstraintExpression)
|
||||
BOLT_GEN_CASE(VBar)
|
||||
BOLT_GEN_CASE(VarTypeExpression)
|
||||
BOLT_GEN_CASE(VariableDeclaration)
|
||||
BOLT_GEN_CASE(VariantDeclaration)
|
||||
BOLT_GEN_CASE(WrappedOperator)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -194,6 +196,10 @@ protected:
|
|||
static_cast<D*>(this)->visitToken(N);
|
||||
}
|
||||
|
||||
void visitBackslash(Backslash* N) {
|
||||
static_cast<D*>(this)->visitToken(N);
|
||||
}
|
||||
|
||||
void visitDoKeyword(DoKeyword* N) {
|
||||
static_cast<D*>(this)->visitToken(N);
|
||||
}
|
||||
|
@ -486,6 +492,10 @@ protected:
|
|||
static_cast<D*>(this)->visitExpression(N);
|
||||
}
|
||||
|
||||
void visitFunctionExpression(FunctionExpression* N) {
|
||||
static_cast<D*>(this)->visitExpression(N);
|
||||
}
|
||||
|
||||
void visitInfixExpression(InfixExpression* N) {
|
||||
static_cast<D*>(this)->visitExpression(N);
|
||||
}
|
||||
|
@ -604,106 +614,108 @@ public:
|
|||
break;
|
||||
|
||||
switch (N->getKind()) {
|
||||
BOLT_GEN_CHILD_CASE(VBar)
|
||||
BOLT_GEN_CHILD_CASE(Equals)
|
||||
BOLT_GEN_CHILD_CASE(AppTypeExpression)
|
||||
BOLT_GEN_CHILD_CASE(ArrowTypeExpression)
|
||||
BOLT_GEN_CHILD_CASE(Assignment)
|
||||
BOLT_GEN_CHILD_CASE(At)
|
||||
BOLT_GEN_CHILD_CASE(Backslash)
|
||||
BOLT_GEN_CHILD_CASE(BindPattern)
|
||||
BOLT_GEN_CHILD_CASE(BlockEnd)
|
||||
BOLT_GEN_CHILD_CASE(BlockExpression)
|
||||
BOLT_GEN_CHILD_CASE(BlockStart)
|
||||
BOLT_GEN_CHILD_CASE(CallExpression)
|
||||
BOLT_GEN_CHILD_CASE(ClassDeclaration)
|
||||
BOLT_GEN_CHILD_CASE(ClassKeyword)
|
||||
BOLT_GEN_CHILD_CASE(Colon)
|
||||
BOLT_GEN_CHILD_CASE(Comma)
|
||||
BOLT_GEN_CHILD_CASE(CustomOperator)
|
||||
BOLT_GEN_CHILD_CASE(DoKeyword)
|
||||
BOLT_GEN_CHILD_CASE(Dot)
|
||||
BOLT_GEN_CHILD_CASE(DotDot)
|
||||
BOLT_GEN_CHILD_CASE(Tilde)
|
||||
BOLT_GEN_CHILD_CASE(At)
|
||||
BOLT_GEN_CHILD_CASE(DoKeyword)
|
||||
BOLT_GEN_CHILD_CASE(LParen)
|
||||
BOLT_GEN_CHILD_CASE(RParen)
|
||||
BOLT_GEN_CHILD_CASE(LBracket)
|
||||
BOLT_GEN_CHILD_CASE(RBracket)
|
||||
BOLT_GEN_CHILD_CASE(LBrace)
|
||||
BOLT_GEN_CHILD_CASE(RBrace)
|
||||
BOLT_GEN_CHILD_CASE(RArrow)
|
||||
BOLT_GEN_CHILD_CASE(RArrowAlt)
|
||||
BOLT_GEN_CHILD_CASE(LetKeyword)
|
||||
BOLT_GEN_CHILD_CASE(ForeignKeyword)
|
||||
BOLT_GEN_CHILD_CASE(MutKeyword)
|
||||
BOLT_GEN_CHILD_CASE(PubKeyword)
|
||||
BOLT_GEN_CHILD_CASE(TypeKeyword)
|
||||
BOLT_GEN_CHILD_CASE(ReturnKeyword)
|
||||
BOLT_GEN_CHILD_CASE(ModKeyword)
|
||||
BOLT_GEN_CHILD_CASE(StructKeyword)
|
||||
BOLT_GEN_CHILD_CASE(EnumKeyword)
|
||||
BOLT_GEN_CHILD_CASE(FnKeyword)
|
||||
BOLT_GEN_CHILD_CASE(ClassKeyword)
|
||||
BOLT_GEN_CHILD_CASE(InstanceKeyword)
|
||||
BOLT_GEN_CHILD_CASE(ElifKeyword)
|
||||
BOLT_GEN_CHILD_CASE(IfKeyword)
|
||||
BOLT_GEN_CHILD_CASE(ElseKeyword)
|
||||
BOLT_GEN_CHILD_CASE(MatchKeyword)
|
||||
BOLT_GEN_CHILD_CASE(Invalid)
|
||||
BOLT_GEN_CHILD_CASE(EndOfFile)
|
||||
BOLT_GEN_CHILD_CASE(BlockStart)
|
||||
BOLT_GEN_CHILD_CASE(BlockEnd)
|
||||
BOLT_GEN_CHILD_CASE(LineFoldEnd)
|
||||
BOLT_GEN_CHILD_CASE(CustomOperator)
|
||||
BOLT_GEN_CHILD_CASE(Assignment)
|
||||
BOLT_GEN_CHILD_CASE(EnumKeyword)
|
||||
BOLT_GEN_CHILD_CASE(EqualityConstraintExpression)
|
||||
BOLT_GEN_CHILD_CASE(Equals)
|
||||
BOLT_GEN_CHILD_CASE(ExpressionAnnotation)
|
||||
BOLT_GEN_CHILD_CASE(FnKeyword)
|
||||
BOLT_GEN_CHILD_CASE(ForeignKeyword)
|
||||
BOLT_GEN_CHILD_CASE(FunctionExpression)
|
||||
BOLT_GEN_CHILD_CASE(Identifier)
|
||||
BOLT_GEN_CHILD_CASE(IdentifierAlt)
|
||||
BOLT_GEN_CHILD_CASE(WrappedOperator)
|
||||
BOLT_GEN_CHILD_CASE(StringLiteral)
|
||||
BOLT_GEN_CHILD_CASE(IntegerLiteral)
|
||||
BOLT_GEN_CHILD_CASE(ExpressionAnnotation)
|
||||
BOLT_GEN_CHILD_CASE(TypeAssertAnnotation)
|
||||
BOLT_GEN_CHILD_CASE(TypeclassConstraintExpression)
|
||||
BOLT_GEN_CHILD_CASE(EqualityConstraintExpression)
|
||||
BOLT_GEN_CHILD_CASE(RecordTypeExpressionField)
|
||||
BOLT_GEN_CHILD_CASE(RecordTypeExpression)
|
||||
BOLT_GEN_CHILD_CASE(QualifiedTypeExpression)
|
||||
BOLT_GEN_CHILD_CASE(ReferenceTypeExpression)
|
||||
BOLT_GEN_CHILD_CASE(ArrowTypeExpression)
|
||||
BOLT_GEN_CHILD_CASE(AppTypeExpression)
|
||||
BOLT_GEN_CHILD_CASE(VarTypeExpression)
|
||||
BOLT_GEN_CHILD_CASE(NestedTypeExpression)
|
||||
BOLT_GEN_CHILD_CASE(TupleTypeExpression)
|
||||
BOLT_GEN_CHILD_CASE(BindPattern)
|
||||
BOLT_GEN_CHILD_CASE(LiteralPattern)
|
||||
BOLT_GEN_CHILD_CASE(RecordPatternField)
|
||||
BOLT_GEN_CHILD_CASE(RecordPattern)
|
||||
BOLT_GEN_CHILD_CASE(NamedRecordPattern)
|
||||
BOLT_GEN_CHILD_CASE(NamedTuplePattern)
|
||||
BOLT_GEN_CHILD_CASE(TuplePattern)
|
||||
BOLT_GEN_CHILD_CASE(NestedPattern)
|
||||
BOLT_GEN_CHILD_CASE(ListPattern)
|
||||
BOLT_GEN_CHILD_CASE(ReferenceExpression)
|
||||
BOLT_GEN_CHILD_CASE(MatchCase)
|
||||
BOLT_GEN_CHILD_CASE(MatchExpression)
|
||||
BOLT_GEN_CHILD_CASE(BlockExpression)
|
||||
BOLT_GEN_CHILD_CASE(MemberExpression)
|
||||
BOLT_GEN_CHILD_CASE(TupleExpression)
|
||||
BOLT_GEN_CHILD_CASE(NestedExpression)
|
||||
BOLT_GEN_CHILD_CASE(LiteralExpression)
|
||||
BOLT_GEN_CHILD_CASE(CallExpression)
|
||||
BOLT_GEN_CHILD_CASE(InfixExpression)
|
||||
BOLT_GEN_CHILD_CASE(PrefixExpression)
|
||||
BOLT_GEN_CHILD_CASE(RecordExpressionField)
|
||||
BOLT_GEN_CHILD_CASE(RecordExpression)
|
||||
BOLT_GEN_CHILD_CASE(ReturnExpression)
|
||||
BOLT_GEN_CHILD_CASE(IfExpression)
|
||||
BOLT_GEN_CHILD_CASE(IfExpressionPart)
|
||||
BOLT_GEN_CHILD_CASE(TypeAssert)
|
||||
BOLT_GEN_CHILD_CASE(Parameter)
|
||||
BOLT_GEN_CHILD_CASE(IfKeyword)
|
||||
BOLT_GEN_CHILD_CASE(InfixExpression)
|
||||
BOLT_GEN_CHILD_CASE(InfixFunctionDeclaration)
|
||||
BOLT_GEN_CHILD_CASE(InstanceDeclaration)
|
||||
BOLT_GEN_CHILD_CASE(InstanceKeyword)
|
||||
BOLT_GEN_CHILD_CASE(IntegerLiteral)
|
||||
BOLT_GEN_CHILD_CASE(Invalid)
|
||||
BOLT_GEN_CHILD_CASE(LBrace)
|
||||
BOLT_GEN_CHILD_CASE(LBracket)
|
||||
BOLT_GEN_CHILD_CASE(LParen)
|
||||
BOLT_GEN_CHILD_CASE(LetBlockBody)
|
||||
BOLT_GEN_CHILD_CASE(LetExprBody)
|
||||
BOLT_GEN_CHILD_CASE(PrefixFunctionDeclaration)
|
||||
BOLT_GEN_CHILD_CASE(InfixFunctionDeclaration)
|
||||
BOLT_GEN_CHILD_CASE(SuffixFunctionDeclaration)
|
||||
BOLT_GEN_CHILD_CASE(LetKeyword)
|
||||
BOLT_GEN_CHILD_CASE(LineFoldEnd)
|
||||
BOLT_GEN_CHILD_CASE(ListPattern)
|
||||
BOLT_GEN_CHILD_CASE(LiteralExpression)
|
||||
BOLT_GEN_CHILD_CASE(LiteralPattern)
|
||||
BOLT_GEN_CHILD_CASE(MatchCase)
|
||||
BOLT_GEN_CHILD_CASE(MatchExpression)
|
||||
BOLT_GEN_CHILD_CASE(MatchKeyword)
|
||||
BOLT_GEN_CHILD_CASE(MemberExpression)
|
||||
BOLT_GEN_CHILD_CASE(ModKeyword)
|
||||
BOLT_GEN_CHILD_CASE(MutKeyword)
|
||||
BOLT_GEN_CHILD_CASE(NamedFunctionDeclaration)
|
||||
BOLT_GEN_CHILD_CASE(VariableDeclaration)
|
||||
BOLT_GEN_CHILD_CASE(NamedRecordPattern)
|
||||
BOLT_GEN_CHILD_CASE(NamedTuplePattern)
|
||||
BOLT_GEN_CHILD_CASE(NestedExpression)
|
||||
BOLT_GEN_CHILD_CASE(NestedPattern)
|
||||
BOLT_GEN_CHILD_CASE(NestedTypeExpression)
|
||||
BOLT_GEN_CHILD_CASE(Parameter)
|
||||
BOLT_GEN_CHILD_CASE(PrefixExpression)
|
||||
BOLT_GEN_CHILD_CASE(PrefixFunctionDeclaration)
|
||||
BOLT_GEN_CHILD_CASE(PubKeyword)
|
||||
BOLT_GEN_CHILD_CASE(QualifiedTypeExpression)
|
||||
BOLT_GEN_CHILD_CASE(RArrow)
|
||||
BOLT_GEN_CHILD_CASE(RArrowAlt)
|
||||
BOLT_GEN_CHILD_CASE(RBrace)
|
||||
BOLT_GEN_CHILD_CASE(RBracket)
|
||||
BOLT_GEN_CHILD_CASE(RParen)
|
||||
BOLT_GEN_CHILD_CASE(RecordDeclaration)
|
||||
BOLT_GEN_CHILD_CASE(RecordDeclarationField)
|
||||
BOLT_GEN_CHILD_CASE(VariantDeclaration)
|
||||
BOLT_GEN_CHILD_CASE(TupleVariantDeclarationMember)
|
||||
BOLT_GEN_CHILD_CASE(RecordExpression)
|
||||
BOLT_GEN_CHILD_CASE(RecordExpressionField)
|
||||
BOLT_GEN_CHILD_CASE(RecordPattern)
|
||||
BOLT_GEN_CHILD_CASE(RecordPatternField)
|
||||
BOLT_GEN_CHILD_CASE(RecordTypeExpression)
|
||||
BOLT_GEN_CHILD_CASE(RecordTypeExpressionField)
|
||||
BOLT_GEN_CHILD_CASE(RecordVariantDeclarationMember)
|
||||
BOLT_GEN_CHILD_CASE(ClassDeclaration)
|
||||
BOLT_GEN_CHILD_CASE(InstanceDeclaration)
|
||||
BOLT_GEN_CHILD_CASE(ReferenceExpression)
|
||||
BOLT_GEN_CHILD_CASE(ReferenceTypeExpression)
|
||||
BOLT_GEN_CHILD_CASE(ReturnExpression)
|
||||
BOLT_GEN_CHILD_CASE(ReturnKeyword)
|
||||
BOLT_GEN_CHILD_CASE(SourceFile)
|
||||
BOLT_GEN_CHILD_CASE(StringLiteral)
|
||||
BOLT_GEN_CHILD_CASE(StructKeyword)
|
||||
BOLT_GEN_CHILD_CASE(SuffixFunctionDeclaration)
|
||||
BOLT_GEN_CHILD_CASE(Tilde)
|
||||
BOLT_GEN_CHILD_CASE(TupleExpression)
|
||||
BOLT_GEN_CHILD_CASE(TuplePattern)
|
||||
BOLT_GEN_CHILD_CASE(TupleTypeExpression)
|
||||
BOLT_GEN_CHILD_CASE(TupleVariantDeclarationMember)
|
||||
BOLT_GEN_CHILD_CASE(TypeAssert)
|
||||
BOLT_GEN_CHILD_CASE(TypeAssertAnnotation)
|
||||
BOLT_GEN_CHILD_CASE(TypeKeyword)
|
||||
BOLT_GEN_CHILD_CASE(TypeclassConstraintExpression)
|
||||
BOLT_GEN_CHILD_CASE(VBar)
|
||||
BOLT_GEN_CHILD_CASE(VarTypeExpression)
|
||||
BOLT_GEN_CHILD_CASE(VariableDeclaration)
|
||||
BOLT_GEN_CHILD_CASE(VariantDeclaration)
|
||||
BOLT_GEN_CHILD_CASE(WrappedOperator)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -731,6 +743,9 @@ public:
|
|||
void visitEachChildImpl(At* N) {
|
||||
}
|
||||
|
||||
void visitEachChildImpl(Backslash* N) {
|
||||
}
|
||||
|
||||
void visitEachChildImpl(DoKeyword* N) {
|
||||
}
|
||||
|
||||
|
@ -1125,6 +1140,18 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void visitEachChildImpl(FunctionExpression* N) {
|
||||
for (auto A: N->Annotations) {
|
||||
BOLT_VISIT(A);
|
||||
}
|
||||
BOLT_VISIT(N->Backslash);
|
||||
for (auto P: N->getParameters()) {
|
||||
BOLT_VISIT(P);
|
||||
}
|
||||
BOLT_VISIT(N->RArrow);
|
||||
BOLT_VISIT(N->getExpression());
|
||||
}
|
||||
|
||||
void visitEachChildImpl(InfixExpression* N) {
|
||||
for (auto A: N->Annotations) {
|
||||
BOLT_VISIT(A);
|
||||
|
|
|
@ -72,7 +72,7 @@ class Parser {
|
|||
Token* expectToken(NodeKind Ty);
|
||||
|
||||
std::vector<RecordDeclarationField*> parseRecordDeclarationFields();
|
||||
std::optional<std::vector<std::tuple<RecordPatternField*, Comma*>>> parseRecordPatternFields();
|
||||
std::vector<std::tuple<RecordPatternField*, Comma*>> parseRecordPatternFields();
|
||||
|
||||
template<typename T>
|
||||
T* expectToken();
|
||||
|
@ -112,6 +112,7 @@ public:
|
|||
|
||||
Parameter* parseParam();
|
||||
|
||||
FunctionExpression* parseFunctionExpression();
|
||||
ReferenceExpression* parseReferenceExpression();
|
||||
Expression* parseUnaryExpression();
|
||||
Expression* parseExpression();
|
||||
|
|
12
src/CST.cc
12
src/CST.cc
|
@ -492,6 +492,14 @@ Token* CallExpression::getLastToken() const {
|
|||
return Function->getLastToken();
|
||||
}
|
||||
|
||||
Token* FunctionExpression::getFirstToken() const {
|
||||
return Backslash;
|
||||
}
|
||||
|
||||
Token* FunctionExpression::getLastToken() const {
|
||||
return E->getLastToken();
|
||||
}
|
||||
|
||||
Token* InfixExpression::getFirstToken() const {
|
||||
return Left->getFirstToken();
|
||||
}
|
||||
|
@ -775,6 +783,10 @@ Token* SourceFile::getLastToken() const {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
std::string Backslash::getText() const {
|
||||
return "\\";
|
||||
}
|
||||
|
||||
std::string VBar::getText() const {
|
||||
return "|";
|
||||
}
|
||||
|
|
749
src/Parser.cc
749
src/Parser.cc
File diff suppressed because it is too large
Load diff
|
@ -344,6 +344,9 @@ after_string_contents:
|
|||
return new StringLiteral(Text, StartLoc);
|
||||
}
|
||||
|
||||
case '\\':
|
||||
return new Backslash { getCurrentLoc() };
|
||||
|
||||
case '.':
|
||||
{
|
||||
auto C1 = peekChar();
|
||||
|
|
Loading…
Reference in a new issue