• Sergei Golubchik's avatar
    MDEV-6899 extra semicolon in show create event syntax · 3988dfff
    Sergei Golubchik authored
    to detect the end of SP definition correctly we need to know where
    the parser stopped parsing the SP. lip->get_cpp_ptr() shows the
    current parsing position, lip->get_cpp_tok_start() shows the start of
    the last parsed token. The actual value depends on whether
    the parser has performed a look-ahead. For example, in
    
      CREATE PROCEDURE ... BEGIN ... END ;
    
    the parser reads 'END' and knows that this ends the procedure definition,
    it does not need to read the next token for this. But in
    
      CREATE PROCEDURE ... SELECT 1 ;
    
    the parser cannot know that the procedure ends at '1'. It has to read
    the semicolon first (it could be '1 + 2' for example).
    
    In the first case, the "current parsing position" is after END, before
    the semicolon, in the second case it's *after* the semicolon. Note that
    SP definition in both cases ends before the semicolon.
    
    To be able to detect the end of SP deterministically, we need the parser
    to do the look-ahead always or never.
    
    The bug fix introduces a new parser token FORCE_LOOKAHEAD. Lexer never
    returns it, so this token can never match. But the parser cannot know
    it so it will have to perform a look-ahead to determine that the next
    token is not FORCE_LOOKAHEAD. This way we deterministically end
    SP parsing with a look-ahead.
    3988dfff
parser.test 40.2 KB