Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-19996

Bison grammar: turn singe-character operators into <kwd>

    XMLWordPrintable

Details

    • Task
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.4.7
    • Parser
    • None

    Description

      The rule remember_tok_start in the bison grammar may cause shift/reduce conflicts.
      In order to fix MDEV-19956 easier, lets get rid of remember_tok_start gradually.

      As the first step let's change the token type for the following single-character operators from <NONE> to <kwd>.

      %type <kwd>
              '-' '+' '*' '/' '%' '(' ')'
              ',' '!' '{' '}' '&' '|'
      

      and replace remember_tok_start to token positions in with_list_element (to prove the conceipt), as follows:

      @@ -15262,16 +15262,16 @@ with_list_element:
                     MYSQL_YYABORT;
                   Lex->with_column_list.empty();
                 }
      -          AS '(' remember_tok_start query_expression remember_tok_end ')'
      +          AS '(' query_expression ')'
                {
                   LEX *lex= thd->lex;
                   const char *query_start= lex->sphead ? lex->sphead->m_tmp_query
                                                        : thd->query();
      -            char *spec_start= $6 + 1;
      -            With_element *elem= new With_element($1, *$2, $7);
      +            const char *spec_start= $5.pos() + 1;
      +            With_element *elem= new With_element($1, *$2, $6);
                  if (elem == NULL || Lex->curr_with_clause->add_with_element(elem))
                    MYSQL_YYABORT;
      -            if (elem->set_unparsed_spec(thd, spec_start, $8,
      +            if (elem->set_unparsed_spec(thd, spec_start, $7.pos(),
                                               spec_start - query_start))
                     MYSQL_YYABORT;
                }
      

      Lex_input_stream::lex_one_token() will be changed to assign positions to the mentioned tokens, like this:

      --- a/sql/sql_lex.cc
      +++ b/sql/sql_lex.cc
      @@ -1510,6 +1510,7 @@ int Lex_input_stream::lex_one_token(YYSTYPE *yylval, THD *thd)
           case MY_LEX_SKIP:                          // This should not happen
             if (c != ')')
               next_state= MY_LEX_START;         // Allow signed numbers
      +      yylval->kwd.set_keyword(m_tok_start, 1);
             return((int) c);
       
           case MY_LEX_MINUS_OR_COMMENT:
      

      Note, this change will not immediately resolve any conflicts.

      Conflicts should be resolved in a separate patch by effectively replacing remember_tok_start to token positions in these grammar rules:

      parenthesized_expr:
                remember_tok_start
                query_expression
                {
                  if (!($$= Lex->create_item_query_expression(thd, $1, $2)))
                    MYSQL_YYABORT;
                }
      

      subselect:
                remember_tok_start
                query_expression
                {
                  if (!($$= Lex->parsed_subselect($2, $1)))
                    YYABORT;
                }
              ;
      

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.