@@ -1390,14 +1390,99 @@ impl SqlParserEngine {
13901390 let mut scratch_chars = std:: mem:: take ( & mut self . scratch_chars ) ;
13911391 scratch_chars. clear ( ) ;
13921392 scratch_chars. extend ( text. chars ( ) ) ;
1393- let mut on_symbol = |_: & [ char ] , _: usize , _: char , _: Option < char > | { } ;
1394- let mut on_statement_boundary = |_: & [ char ] , _: usize | { } ;
1395- self . process_chars_with_observer (
1396- & scratch_chars,
1397- & mut on_symbol,
1398- & mut on_statement_boundary,
1399- & mut on_lexical_span,
1400- ) ;
1393+ let mut line_start = 0usize ;
1394+
1395+ while line_start < scratch_chars. len ( ) {
1396+ let line_end = scratch_chars[ line_start..]
1397+ . iter ( )
1398+ . position ( |ch| * ch == '\n' )
1399+ . map_or ( scratch_chars. len ( ) , |offset| line_start + offset) ;
1400+ let chunk_end = usize:: from ( line_end < scratch_chars. len ( ) )
1401+ . saturating_add ( line_end)
1402+ . min ( scratch_chars. len ( ) ) ;
1403+ let line: String = scratch_chars[ line_start..line_end] . iter ( ) . collect ( ) ;
1404+ let line_started_with_empty_current = self . current_is_empty ( ) ;
1405+ let current_has_only_sql_comments =
1406+ next_meaningful_word ( self . current . as_str ( ) , 0 ) . is_none ( ) ;
1407+ let current_is_effectively_empty =
1408+ line_started_with_empty_current || current_has_only_sql_comments;
1409+ let line_started_in_with_waiting_main_query =
1410+ self . state . in_with_plsql_declaration ( )
1411+ && self . state . with_clause_waiting_main_query ( )
1412+ && self . state . block_depth ( ) == 0
1413+ && self . state . paren_depth ( ) == 0 ;
1414+ self . state
1415+ . close_foreign_module_source_on_terminator_line ( & line) ;
1416+ let line_boundary_action = self
1417+ . state
1418+ . line_boundary_action_for_line ( & line, current_is_effectively_empty) ;
1419+ if self . apply_line_boundary_action ( line_boundary_action) {
1420+ line_start = chunk_end;
1421+ continue ;
1422+ }
1423+ let line_starts_at_statement_boundary = self . state . is_idle ( )
1424+ && self . state . block_depth ( ) == 0
1425+ && self . state . paren_depth ( ) == 0
1426+ && !self . state . in_with_plsql_declaration ( )
1427+ && current_is_effectively_empty;
1428+ let sqlplus_remark_line = sql_text:: is_sqlplus_remark_comment_line ( & line) ;
1429+ let auto_terminated_tool_command = sqlplus_remark_line
1430+ || ( sql_text:: is_auto_terminated_tool_command ( & line)
1431+ && !self . line_is_mysql_server_statement ( & line) ) ;
1432+
1433+ if ( line_starts_at_statement_boundary
1434+ || ( line_started_in_with_waiting_main_query && self . state . is_idle ( ) ) )
1435+ && auto_terminated_tool_command
1436+ {
1437+ let is_comment_like_tool_line = sql_text:: first_meaningful_word ( & line)
1438+ . is_some_and ( |word| word. eq_ignore_ascii_case ( "PROMPT" ) ) ;
1439+ if is_comment_like_tool_line {
1440+ on_lexical_span (
1441+ & scratch_chars,
1442+ line_start,
1443+ line_end,
1444+ LexicalKind :: LineComment ,
1445+ ) ;
1446+ }
1447+ self . append_current_str ( & line) ;
1448+ if chunk_end > line_end {
1449+ self . append_current_char ( '\n' ) ;
1450+ }
1451+ self . finish_current_statement ( ) ;
1452+ line_start = chunk_end;
1453+ continue ;
1454+ }
1455+
1456+ let mut on_symbol = |_: & [ char ] , _: usize , _: char , _: Option < char > | { } ;
1457+ let mut on_statement_boundary = |_: & [ char ] , _: usize | { } ;
1458+ let mut offset_lexical_span =
1459+ |_: & [ char ] , start : usize , end : usize , kind : LexicalKind | {
1460+ on_lexical_span (
1461+ & scratch_chars,
1462+ line_start. saturating_add ( start) ,
1463+ line_start. saturating_add ( end) ,
1464+ kind,
1465+ ) ;
1466+ } ;
1467+ self . process_chars_with_observer (
1468+ & scratch_chars[ line_start..chunk_end] ,
1469+ & mut on_symbol,
1470+ & mut on_statement_boundary,
1471+ & mut offset_lexical_span,
1472+ ) ;
1473+ self . state . clear_skip_next_end_label_token ( ) ;
1474+
1475+ if ( line_started_with_empty_current || line_started_in_with_waiting_main_query)
1476+ && self . state . is_idle ( )
1477+ && self . state . block_depth ( ) == 0
1478+ && self . state . paren_depth ( ) == 0
1479+ && auto_terminated_tool_command
1480+ {
1481+ self . finish_current_statement ( ) ;
1482+ }
1483+
1484+ line_start = chunk_end;
1485+ }
14011486 self . scratch_chars = scratch_chars;
14021487 }
14031488
0 commit comments