Skip to content

Commit f51bfa6

Browse files
committed
Enable parsing comma lists without semicolons
1 parent f328a3b commit f51bfa6

File tree

2 files changed

+122
-1
lines changed

2 files changed

+122
-1
lines changed

src/parser/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4536,6 +4536,18 @@ impl<'a> Parser<'a> {
45364536
return Ok(vec![]);
45374537
}
45384538

4539+
if end_token == Token::SemiColon
4540+
&& self
4541+
.dialect
4542+
.supports_statements_without_semicolon_delimiter()
4543+
{
4544+
if let Token::Word(ref kw) = self.peek_token().token {
4545+
if kw.keyword != Keyword::NoKeyword {
4546+
return Ok(vec![]);
4547+
}
4548+
}
4549+
}
4550+
45394551
if self.options.trailing_commas && self.peek_tokens() == [Token::Comma, end_token] {
45404552
let _ = self.consume_token(&Token::Comma);
45414553
return Ok(vec![]);

tests/sqlparser_mssql.rs

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2520,7 +2520,6 @@ DECLARE @Y AS NVARCHAR(MAX)='y'
25202520
#[test]
25212521
fn test_supports_statements_without_semicolon_delimiter() {
25222522
use sqlparser::ast::Ident;
2523-
25242523
use sqlparser::tokenizer::Location;
25252524

25262525
fn parse_n_statements(n: usize, sql: &str) -> Vec<Statement> {
@@ -2831,4 +2830,114 @@ fn test_supports_statements_without_semicolon_delimiter() {
28312830
},
28322831
}
28332832
);
2833+
2834+
let exec_then_update = "\
2835+
EXEC my_sp \
2836+
UPDATE my_table SET col = 1 \
2837+
";
2838+
assert_eq!(
2839+
parse_n_statements(2, exec_then_update),
2840+
vec![
2841+
Statement::Execute {
2842+
name: Some(ObjectName::from(vec![Ident::new("my_sp")])),
2843+
parameters: vec![],
2844+
has_parentheses: false,
2845+
immediate: false,
2846+
into: vec![],
2847+
using: vec![],
2848+
},
2849+
Statement::Update {
2850+
table: TableWithJoins {
2851+
relation: TableFactor::Table {
2852+
name: ObjectName::from(vec![Ident::new("my_table")]),
2853+
alias: None,
2854+
with_hints: vec![],
2855+
args: None,
2856+
version: None,
2857+
with_ordinality: false,
2858+
partitions: vec![],
2859+
json_path: None,
2860+
sample: None,
2861+
index_hints: vec![]
2862+
},
2863+
joins: vec![],
2864+
},
2865+
assignments: vec![Assignment {
2866+
value: Expr::Value(
2867+
number("1")
2868+
.with_span(Span::new(Location::new(3, 16), Location::new(3, 17)))
2869+
),
2870+
target: AssignmentTarget::ColumnName(ObjectName::from(vec![Ident::new("col")])),
2871+
},],
2872+
selection: None,
2873+
returning: None,
2874+
from: None,
2875+
or: None
2876+
},
2877+
]
2878+
);
2879+
2880+
let exec_params_then_update = "\
2881+
EXEC my_sp 1, 2 \
2882+
UPDATE my_table SET col = 1 \
2883+
";
2884+
assert_eq!(
2885+
parse_n_statements(2, exec_params_then_update),
2886+
vec![
2887+
Statement::Execute {
2888+
name: Some(ObjectName::from(vec![Ident::with_span(
2889+
Span::new(Location::new(1, 6), Location::new(1, 11)),
2890+
"my_sp"
2891+
)])),
2892+
parameters: vec![
2893+
Expr::Value(
2894+
number("1")
2895+
.with_span(Span::new(Location::new(1, 12), Location::new(1, 13)))
2896+
),
2897+
Expr::Value(
2898+
number("2")
2899+
.with_span(Span::new(Location::new(1, 15), Location::new(1, 17)))
2900+
),
2901+
],
2902+
has_parentheses: false,
2903+
immediate: false,
2904+
into: vec![],
2905+
using: vec![],
2906+
},
2907+
Statement::Update {
2908+
table: TableWithJoins {
2909+
relation: TableFactor::Table {
2910+
name: ObjectName::from(vec![Ident::with_span(
2911+
Span::new(Location::new(1, 24), Location::new(1, 32)),
2912+
"my_table"
2913+
)]),
2914+
alias: None,
2915+
with_hints: vec![],
2916+
args: None,
2917+
version: None,
2918+
with_ordinality: false,
2919+
partitions: vec![],
2920+
json_path: None,
2921+
sample: None,
2922+
index_hints: vec![]
2923+
},
2924+
joins: vec![],
2925+
},
2926+
assignments: vec![Assignment {
2927+
value: Expr::Value(
2928+
number("1")
2929+
.with_span(Span::new(Location::new(3, 16), Location::new(3, 17)))
2930+
),
2931+
target: AssignmentTarget::ColumnName(ObjectName::from(vec![Ident::with_span(
2932+
Span::new(Location::new(1, 37), Location::new(1, 40)),
2933+
"col"
2934+
)])),
2935+
},],
2936+
selection: None,
2937+
returning: None,
2938+
from: None,
2939+
or: None
2940+
},
2941+
]
2942+
);
28342943
}

0 commit comments

Comments
 (0)