From b2b9dcff4a1403f6192ad0376674be8c993a8d39 Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Wed, 18 Sep 2024 13:41:18 +0800 Subject: [PATCH] libnixf: diagnose non-associative operators --- libnixf/src/Basic/diagnostic.py | 6 ++++++ libnixf/src/Parse/ParseOp.cpp | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libnixf/src/Basic/diagnostic.py b/libnixf/src/Basic/diagnostic.py index 8261d8548..58f82e9cc 100644 --- a/libnixf/src/Basic/diagnostic.py +++ b/libnixf/src/Basic/diagnostic.py @@ -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", diff --git a/libnixf/src/Parse/ParseOp.cpp b/libnixf/src/Parse/ParseOp.cpp index 45e7f0b77..0e842bb32 100644 --- a/libnixf/src/Parse/ParseOp.cpp +++ b/libnixf/src/Parse/ParseOp.cpp @@ -3,6 +3,7 @@ #include "Parser.h" +#include "nixf/Basic/Diagnostic.h" #include "nixf/Basic/Nodes/Op.h" #include @@ -115,7 +116,9 @@ std::shared_ptr 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");