Skip to content

Commit

Permalink
libnixf: diagnose non-associative operators
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc committed Sep 18, 2024
1 parent 28a4190 commit b2b9dcf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions libnixf/src/Basic/diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ class Diagnostic(TypedDict):
"severity": "Error",
"message": "extra `@` for lambda arg",
},
{
"sname": "parse-operator-noassoc",
"cname": "OperatorNotAssociative",
"severity": "Error",
"message": "operator is non-associative",
},
{
"sname": "let-dynamic",
"cname": "LetDynamic",
Expand Down
5 changes: 4 additions & 1 deletion libnixf/src/Parse/ParseOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "Parser.h"

#include "nixf/Basic/Diagnostic.h"
#include "nixf/Basic/Nodes/Op.h"

#include <cassert>
Expand Down Expand Up @@ -115,7 +116,9 @@ std::shared_ptr<Expr> Parser::parseExprOpBP(unsigned LeftRBP) {
if (LeftRBP > LBP)
return Prefix;
if (LeftRBP == LBP) {
// TODO: noassoc
// Report error, operator OP and expr_op is not associative.
Diags.emplace_back(Diagnostic::DK_OperatorNotAssociative,
Tok.range());
}
consume();
assert(LastToken && "consume() should have set LastToken");
Expand Down

0 comments on commit b2b9dcf

Please sign in to comment.