From c29231a690ad20dc754f16d0aa8e63a7c97fb5e6 Mon Sep 17 00:00:00 2001 From: iphydf Date: Mon, 22 Jan 2024 12:02:12 +0000 Subject: [PATCH] fix: Add error message for constant inside compound-expr. --- src/Language/Cimple/DescribeAst.hs | 1 + test/Language/Cimple/DescribeAstSpec.hs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/Language/Cimple/DescribeAst.hs b/src/Language/Cimple/DescribeAst.hs index 0a59dfb..0ba3edc 100644 --- a/src/Language/Cimple/DescribeAst.hs +++ b/src/Language/Cimple/DescribeAst.hs @@ -148,6 +148,7 @@ describeExpected options | wants ["ID_FUNC_TYPE", "non_null", "static", "'#include'"] = "top-level declaration or definition" | options == ["ID_STD_TYPE", "ID_SUE_TYPE", "struct", "void"] = "type specifier" | options == ["ID_STD_TYPE", "ID_SUE_TYPE", "const", "struct", "void"] = "type specifier" + | options == ["ID_CONST", "ID_VAR", "LIT_CHAR", "LIT_FALSE", "LIT_INTEGER", "'{'"] = "constant or literal" | ["ID_FUNC_TYPE", "ID_STD_TYPE", "ID_SUE_TYPE", "ID_VAR"] `isPrefixOf` options = "type specifier or variable name" | ["ID_FUNC_TYPE", "ID_STD_TYPE", "ID_SUE_TYPE", "const"] `isPrefixOf` options = "type specifier" | ["ID_CONST", "sizeof", "LIT_CHAR", "LIT_FALSE", "LIT_TRUE", "LIT_INTEGER"] `isPrefixOf` options = "constant expression" diff --git a/test/Language/Cimple/DescribeAstSpec.hs b/test/Language/Cimple/DescribeAstSpec.hs index f9c8c48..2aa1efc 100644 --- a/test/Language/Cimple/DescribeAstSpec.hs +++ b/test/Language/Cimple/DescribeAstSpec.hs @@ -36,6 +36,9 @@ spec = do expected parseText "int a() { int }" `shouldBe` "expected variable name" + expected parseStmt "(int){" `shouldBe` + "expected constant or literal" + it "has suggestions for any sequence of tokens in top level" $ do property $ \tokens -> expected parseText (Text.intercalate " " (map sampleToken tokens)) `shouldNotContain`