Class StatementSeparation

java.lang.Object
dev.frostlake.parser.StatementSeparation

public final class StatementSeparation extends Object
The SEMICOLON between two statements, which live REQUIRES and this grammar leaves optional.

Every statement rule carries its own trailing SEMI? and the script rule adds another, so two statements written with nothing between them parse happily as two — SELECT 1 SELECT 2 answered 1 here where live refuses it. Making the separator mandatory in the grammar is not available: the statements consume it themselves, so the script rule never sees one to require. It is checked here instead, over the parse tree and the token stream, once per parse.

★ TWO REFUSALS, AND WHICH ONE DEPENDS ON THE FIRST STATEMENT. A bare BEGIN — no WORK, no TRANSACTION, no name — is BOTH a transaction start and the opening of a scripting block, and live reads it as the block whenever anything follows it. So a block that loses an END is not "two statements without a separator" to live; it is one block that ran out of input:

   BEGIN BEGIN RETURN 42; END;        unexpected '<EOF>'   the outer block never closes
   BEGIN SELECT 1;                    unexpected '<EOF>'   same shape, any body
   BEGIN TRANSACTION BEGIN … END;     unexpected 'BEGIN'   an explicit transaction cannot open one
   SELECT 1 SELECT 2                  unexpected 'SELECT'  the ordinary missing separator
 

★ THE EOF ANCHOR IS THE INPUT'S OWN END — the line and column one PAST the last character, which for text ending in a newline is column 0 of the following line. Live-verified across a one-line block, four-line blocks with and without a trailing newline, and a DECLARE section.

★ WHAT STAYS LEGAL: a bare BEGIN that IS the whole statement (live accepts it, and BEGIN TRANSACTION / BEGIN WORK / BEGIN NAME t with or without a semicolon), every multi-statement script whose statements DO carry their semicolons, and a doubled ;.

  • Method Details

    • requireSeparators

      public static void requireSeparators(FrostlakeParser.SqlScriptContext script, org.antlr.v4.runtime.TokenStream tokens, String sql)
      Refuse a script whose statements are not separated by semicolons.
      Parameters:
      script - the parsed script
      tokens - the token stream it was parsed from
      sql - the script's source text