Fix constructors like True and False not being parsed
This commit is contained in:
parent
1f94b7f799
commit
b6706dd801
5 changed files with 64 additions and 30 deletions
|
@ -707,13 +707,30 @@ namespace bolt {
|
|||
|
||||
};
|
||||
|
||||
class Identifier : public Token {
|
||||
class Symbol : public Token {
|
||||
public:
|
||||
|
||||
inline Symbol(NodeKind Kind, TextLoc StartLoc):
|
||||
Token(Kind, StartLoc) {}
|
||||
|
||||
virtual ByteString getCanonicalText() = 0;
|
||||
|
||||
static bool classof(const Node* N) {
|
||||
return N->getKind() == NodeKind::Identifier
|
||||
|| N->getKind() == NodeKind::IdentifierAlt;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class Identifier : public Symbol {
|
||||
public:
|
||||
|
||||
ByteString Text;
|
||||
|
||||
Identifier(ByteString Text, TextLoc StartLoc):
|
||||
Token(NodeKind::Identifier, StartLoc), Text(Text) {}
|
||||
Symbol(NodeKind::Identifier, StartLoc), Text(Text) {}
|
||||
|
||||
ByteString getCanonicalText() override;
|
||||
|
||||
std::string getText() const override;
|
||||
|
||||
|
@ -725,13 +742,15 @@ namespace bolt {
|
|||
|
||||
};
|
||||
|
||||
class IdentifierAlt : public Token {
|
||||
class IdentifierAlt : public Symbol {
|
||||
public:
|
||||
|
||||
ByteString Text;
|
||||
|
||||
IdentifierAlt(ByteString Text, TextLoc StartLoc):
|
||||
Token(NodeKind::IdentifierAlt, StartLoc), Text(Text) {}
|
||||
Symbol(NodeKind::IdentifierAlt, StartLoc), Text(Text) {}
|
||||
|
||||
ByteString getCanonicalText() override;
|
||||
|
||||
std::string getText() const override;
|
||||
|
||||
|
@ -970,11 +989,11 @@ namespace bolt {
|
|||
public:
|
||||
|
||||
std::vector<std::tuple<IdentifierAlt*, Dot*>> ModulePath;
|
||||
Identifier* Name;
|
||||
Symbol* Name;
|
||||
|
||||
ReferenceExpression(
|
||||
std::vector<std::tuple<IdentifierAlt*, Dot*>> ModulePath,
|
||||
Identifier* Name
|
||||
Symbol* Name
|
||||
): Expression(NodeKind::ReferenceExpression),
|
||||
ModulePath(ModulePath),
|
||||
Name(Name) {}
|
||||
|
@ -1007,7 +1026,6 @@ namespace bolt {
|
|||
|
||||
};
|
||||
|
||||
|
||||
class MatchExpression : public Expression {
|
||||
public:
|
||||
|
||||
|
|
12
src/CST.cc
12
src/CST.cc
|
@ -605,12 +605,20 @@ namespace bolt {
|
|||
return "instance";
|
||||
}
|
||||
|
||||
ByteString Identifier::getCanonicalText() {
|
||||
return Text;
|
||||
}
|
||||
|
||||
ByteString IdentifierAlt::getCanonicalText() {
|
||||
return Text;
|
||||
}
|
||||
|
||||
SymbolPath ReferenceExpression::getSymbolPath() const {
|
||||
std::vector<ByteString> ModuleNames;
|
||||
for (auto [Name, Dot]: ModulePath) {
|
||||
ModuleNames.push_back(Name->Text);
|
||||
ModuleNames.push_back(Name->getCanonicalText());
|
||||
}
|
||||
return SymbolPath { ModuleNames, Name->Text };
|
||||
return SymbolPath { ModuleNames, Name->getCanonicalText() };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -331,8 +331,8 @@ namespace bolt {
|
|||
{
|
||||
auto Class = static_cast<ClassDeclaration*>(X);
|
||||
for (auto TE: Class->TypeVars) {
|
||||
auto TV = createRigidVar(TE->Name->Text);
|
||||
TV->Contexts.emplace(Class->Name->Text);
|
||||
auto TV = createRigidVar(TE->Name->getCanonicalText());
|
||||
TV->Contexts.emplace(Class->Name->getCanonicalText());
|
||||
TE->setType(TV);
|
||||
}
|
||||
for (auto Element: Class->Elements) {
|
||||
|
@ -344,9 +344,9 @@ namespace bolt {
|
|||
case NodeKind::InstanceDeclaration:
|
||||
{
|
||||
auto Decl = static_cast<InstanceDeclaration*>(X);
|
||||
auto Match = InstanceMap.find(Decl->Name->Text);
|
||||
auto Match = InstanceMap.find(Decl->Name->getCanonicalText());
|
||||
if (Match == InstanceMap.end()) {
|
||||
InstanceMap.emplace(Decl->Name->Text, std::vector { Decl });
|
||||
InstanceMap.emplace(Decl->Name->getCanonicalText(), std::vector { Decl });
|
||||
} else {
|
||||
Match->second.push_back(Decl);
|
||||
}
|
||||
|
@ -376,7 +376,7 @@ namespace bolt {
|
|||
auto Decl = static_cast<ClassDeclaration*>(Let->Parent);
|
||||
for (auto TE: Decl->TypeVars) {
|
||||
auto TV = llvm::cast<TVar>(TE->getType());
|
||||
NewCtx->Env.emplace(TE->Name->Text, new Forall(TV));
|
||||
NewCtx->Env.emplace(TE->Name->getCanonicalText(), new Forall(TV));
|
||||
NewCtx->TVs->emplace(TV);
|
||||
}
|
||||
}
|
||||
|
@ -617,7 +617,7 @@ namespace bolt {
|
|||
for (auto TE: D->TEs) {
|
||||
Types.push_back(inferTypeExpression(TE));
|
||||
}
|
||||
return new CClass(D->Name->Text, Types);
|
||||
return new CClass(D->Name->getCanonicalText(), Types);
|
||||
}
|
||||
case NodeKind::EqualityConstraintExpression:
|
||||
{
|
||||
|
@ -636,10 +636,10 @@ namespace bolt {
|
|||
case NodeKind::ReferenceTypeExpression:
|
||||
{
|
||||
auto RefTE = static_cast<ReferenceTypeExpression*>(N);
|
||||
auto Ty = lookupMono(RefTE->Name->Text);
|
||||
auto Ty = lookupMono(RefTE->Name->getCanonicalText());
|
||||
if (Ty == nullptr) {
|
||||
if (Config.typeVarsRequireForall()) {
|
||||
DE.add<BindingNotFoundDiagnostic>(RefTE->Name->Text, RefTE->Name);
|
||||
DE.add<BindingNotFoundDiagnostic>(RefTE->Name->getCanonicalText(), RefTE->Name);
|
||||
}
|
||||
Ty = createTypeVar();
|
||||
}
|
||||
|
@ -650,13 +650,13 @@ namespace bolt {
|
|||
case NodeKind::VarTypeExpression:
|
||||
{
|
||||
auto VarTE = static_cast<VarTypeExpression*>(N);
|
||||
auto Ty = lookupMono(VarTE->Name->Text);
|
||||
auto Ty = lookupMono(VarTE->Name->getCanonicalText());
|
||||
if (Ty == nullptr) {
|
||||
if (Config.typeVarsRequireForall()) {
|
||||
DE.add<BindingNotFoundDiagnostic>(VarTE->Name->Text, VarTE->Name);
|
||||
DE.add<BindingNotFoundDiagnostic>(VarTE->Name->getCanonicalText(), VarTE->Name);
|
||||
}
|
||||
Ty = createRigidVar(VarTE->Name->Text);
|
||||
addBinding(VarTE->Name->Text, new Forall(Ty));
|
||||
Ty = createRigidVar(VarTE->Name->getCanonicalText());
|
||||
addBinding(VarTE->Name->getCanonicalText(), new Forall(Ty));
|
||||
}
|
||||
N->setType(Ty);
|
||||
return Ty;
|
||||
|
@ -725,9 +725,9 @@ namespace bolt {
|
|||
ZEN_ASSERT(Ctx->ReturnType != nullptr);
|
||||
return Ctx->ReturnType;
|
||||
}
|
||||
auto Scm = lookup(Ref->Name->Text);
|
||||
auto Scm = lookup(Ref->Name->getCanonicalText());
|
||||
if (Scm == nullptr) {
|
||||
DE.add<BindingNotFoundDiagnostic>(Ref->Name->Text, Ref->Name);
|
||||
DE.add<BindingNotFoundDiagnostic>(Ref->Name->getCanonicalText(), Ref->Name);
|
||||
return createTypeVar();
|
||||
}
|
||||
auto Ty = instantiate(Scm, X);
|
||||
|
@ -791,7 +791,7 @@ namespace bolt {
|
|||
|
||||
case NodeKind::BindPattern:
|
||||
{
|
||||
addBinding(static_cast<BindPattern*>(Pattern)->Name->Text, new Forall(TVs, Constraints, Type));
|
||||
addBinding(static_cast<BindPattern*>(Pattern)->Name->getCanonicalText(), new Forall(TVs, Constraints, Type));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -813,7 +813,7 @@ namespace bolt {
|
|||
for (auto TE: Class->TypeVars) {
|
||||
Tys.push_back(llvm::cast<TVar>(TE->getType()));
|
||||
}
|
||||
Out.push_back(TypeclassSignature { Class->Name->Text, Tys });
|
||||
Out.push_back(TypeclassSignature { Class->Name->getCanonicalText(), Tys });
|
||||
}
|
||||
if (Decl->TypeAssert != nullptr) {
|
||||
if (llvm::isa<QualifiedTypeExpression>(Decl->TypeAssert->TypeExpression)) {
|
||||
|
@ -827,7 +827,7 @@ namespace bolt {
|
|||
ZEN_ASSERT(llvm::isa<TVar>(TV));
|
||||
Tys.push_back(static_cast<TVar*>(TV));
|
||||
}
|
||||
Out.push_back(TypeclassSignature { TCE->Name->Text, Tys });
|
||||
Out.push_back(TypeclassSignature { TCE->Name->getCanonicalText(), Tys });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,9 @@ namespace bolt {
|
|||
static std::string describe(NodeKind Type) {
|
||||
switch (Type) {
|
||||
case NodeKind::Identifier:
|
||||
return "an identifier";
|
||||
return "an identifier starting with a lowercase letter";
|
||||
case NodeKind::IdentifierAlt:
|
||||
return "an identifier starting with a capital letter";
|
||||
case NodeKind::CustomOperator:
|
||||
return "an operator";
|
||||
case NodeKind::IntegerLiteral:
|
||||
|
|
|
@ -211,18 +211,24 @@ after_constraints:
|
|||
auto T0 = Tokens.peek();
|
||||
switch (T0->getKind()) {
|
||||
case NodeKind::Identifier:
|
||||
case NodeKind::IdentifierAlt:
|
||||
{
|
||||
std::vector<std::tuple<IdentifierAlt*, Dot*>> ModulePath;
|
||||
for (;;) {
|
||||
auto T1 = Tokens.peek();
|
||||
if (T1->getKind() != NodeKind::IdentifierAlt) {
|
||||
auto T1 = Tokens.peek(0);
|
||||
auto T2 = Tokens.peek(1);
|
||||
if (!llvm::isa<IdentifierAlt>(T1) || !llvm::isa<Dot>(T2)) {
|
||||
break;
|
||||
}
|
||||
Tokens.get();
|
||||
auto Dot = expectToken<class Dot>();
|
||||
ModulePath.push_back(std::make_tuple(static_cast<IdentifierAlt*>(T1), Dot));
|
||||
}
|
||||
return new ReferenceExpression(ModulePath, expectToken<Identifier>());
|
||||
auto T3 = Tokens.get();
|
||||
if (!llvm::isa<Symbol>(T3)) {
|
||||
throw UnexpectedTokenDiagnostic(File, T3, { NodeKind::Identifier, NodeKind::IdentifierAlt });
|
||||
}
|
||||
return new ReferenceExpression(ModulePath, static_cast<Symbol*>(T3));
|
||||
}
|
||||
case NodeKind::LParen:
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue