From d3b3b73f6dfd29274d8075b7fae578de03328b22 Mon Sep 17 00:00:00 2001 From: Daehyun Kim <18080546+vimkim@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:24:22 +0900 Subject: [PATCH] [CUBVEC-12] Add VECTOR to Lexer and Parser (#5693) http://jira.cubrid.org/browse/CUBVEC-12 * feat(parser): add VECTOR token and PT_TYPE_VECTOR to parser Create Table succeeds * feat(csql_grammar.y): can create vector table with arguments * fix(csql_grammar.y): remove unnecessary container initialization for readability * fix(csql_grammar): get rid of obscure TODO and pass vector options to parent rule * Update src/parser/csql_grammar.y Co-authored-by: joonmin83 * docs(csql_grammar): todo: dim and type validation later --------- Co-authored-by: joonmin83 --- src/parser/csql_grammar.y | 43 +++++++++++++++++++++++++++++++++++++++ src/parser/csql_lexer.l | 1 + src/parser/parse_tree.h | 1 + 3 files changed, 45 insertions(+) diff --git a/src/parser/csql_grammar.y b/src/parser/csql_grammar.y index d60cd82076b..7545ecdaaa0 100644 --- a/src/parser/csql_grammar.y +++ b/src/parser/csql_grammar.y @@ -1101,6 +1101,7 @@ static int g_plcsql_text_pos; %type class_name_with_server_name %type opt_index_with_clause %type index_with_item_list +%type opt_vector_args /*}}}*/ @@ -1468,6 +1469,7 @@ static int g_plcsql_text_pos; %token VARIABLE_ %token VARYING %token VCLASS +%token VECTOR %token VIEW %token WHEN %token WHENEVER @@ -22119,8 +22121,49 @@ primitive_type $$ = ctn; DBG_PRINT}} + | VECTOR opt_vector_args + {{ DBG_TRACE_GRAMMAR(data_type, | vector_type); + + container_2 ctn; + SET_CONTAINER_2 (ctn, FROM_NUMBER (PT_TYPE_VECTOR), NULL); + $$ = ctn; + + // TODO: The opt_vector_args are not covered in this milestone. + // Dimension and type validation for VECTOR arguments must be included + // in the milestone that checks user input for correctness. + + + DBG_PRINT}} ; +opt_vector_args + : /* empty */ + {{ DBG_TRACE_GRAMMAR(opt_vector_args, : ); + + container_2 ctn; + SET_CONTAINER_2 (ctn, NULL, NULL); + $$ = ctn; + + DBG_PRINT}} + | '(' unsigned_integer ')' + {{ DBG_TRACE_GRAMMAR(opt_vector_args, | '(' unsigned_integer ')' ); + + container_2 ctn; + SET_CONTAINER_2 (ctn, $2, NULL); + $$ = ctn; + + DBG_PRINT}} + | '(' unsigned_integer ',' FLOAT_ ')' + {{ DBG_TRACE_GRAMMAR(opt_vector_args, | '(' unsigned_integer ',' FLOAT_ ')' ); + + container_2 ctn; + SET_CONTAINER_2 (ctn, $2, FROM_NUMBER(PT_TYPE_FLOAT)); + $$ = ctn; + + DBG_PRINT}} + ; + + opt_internal_external : /* empty */ {{ DBG_TRACE_GRAMMAR(opt_internal_external, : ); diff --git a/src/parser/csql_lexer.l b/src/parser/csql_lexer.l index 55c0b4505d1..c4d1544c9b5 100644 --- a/src/parser/csql_lexer.l +++ b/src/parser/csql_lexer.l @@ -1063,6 +1063,7 @@ IDL [a-zA-Z0-9_] return VARIANCE; } [vV][aA][rR][yY][iI][nN][gG] { begin_token(yytext); return VARYING; } [vV][cC][lL][aA][sS][sS] { begin_token(yytext); return VCLASS; } +[vV][eE][cC][tT][oO][rR] { begin_token(yytext); return VECTOR; } [vV][iI][eE][wW] { begin_token(yytext); return VIEW; } [vV][iI][sS][iI][bB][lL][eE] { begin_token(yytext); csql_yylval.cptr = pt_makename(yytext); diff --git a/src/parser/parse_tree.h b/src/parser/parse_tree.h index bdc1e739ce0..97c469fbf2d 100644 --- a/src/parser/parse_tree.h +++ b/src/parser/parse_tree.h @@ -1125,6 +1125,7 @@ enum pt_type_enum PT_TYPE_LOGICAL, PT_TYPE_MAYBE, PT_TYPE_JSON, + PT_TYPE_VECTOR, /* special values */ PT_TYPE_NA, /* in SELECT NA */