From c0be73f506d02dc0c442cdfe8f4e5e0dc36a55d7 Mon Sep 17 00:00:00 2001 From: Kunlin Yu Date: Tue, 31 Dec 2024 10:47:51 +0800 Subject: [PATCH] Use arrayList to make the rules about array better Signed-off-by: Kunlin Yu --- CMakeLists.txt | 2 +- src/cql2_parser.y | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f69ba8..1d5ec16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,7 @@ set(BISON_FILE ${CMAKE_SOURCE_DIR}/src/cql2_parser.y) set(BISON_OUTPUT ${CMAKE_BINARY_DIR}/cql2_parser_base.cc) add_custom_command( OUTPUT ${BISON_OUTPUT} - COMMAND bison -v -d -o ${BISON_OUTPUT} ${BISON_FILE} + COMMAND bison -v -d -o ${BISON_OUTPUT} ${BISON_FILE} -W -Wcounterexamples DEPENDS ${BISON_FILE} COMMENT "Generating ${BISON_OUTPUT} from ${BISON_FILE} using bison" ) diff --git a/src/cql2_parser.y b/src/cql2_parser.y index 56f6167..402688d 100644 --- a/src/cql2_parser.y +++ b/src/cql2_parser.y @@ -96,6 +96,7 @@ void cql2cpp::Cql2ParserBase::error(const std::string& msg) { %type arrayExpression %type array %type arrayElement +%type arrayList %type function %type argumentList %type argument @@ -108,7 +109,6 @@ void cql2cpp::Cql2ParserBase::error(const std::string& msg) { %left PLUS MINUS %left MULT DIV -%left NOT AND OR %define parse.trace %% @@ -223,21 +223,24 @@ arrayPredicate: arrayFunction LPT arrayExpression COMMA arrayExpression RPT { $$ = new AstNode(ArrayPred, NameOp.at($1), {$3, $5}); } arrayExpression: - LPT RPT { $$ = new AstNode(Array, NullOp, {}); } + array | propertyName | function - | LPT array RPT { $$ = $2; } array: + LPT RPT { $$ = new AstNode(Array, NullOp, {}); } + | LPT arrayList RPT { $$ = $2; } + +arrayList: arrayElement { $$ = new AstNode(Array, NullOp, {$1}); } - | array COMMA arrayElement { $1->append($3); $$ = $1; } + | arrayList COMMA arrayElement { $1->append($3); $$ = $1; } arrayElement: characterClause | numericLiteral // | temporalInstance | spatialInstance - // | array // shift/reduce conflict + | array // shift/reduce conflict // | arithmeticExpression | booleanExpression | propertyName