Skip to content

Commit e1fe02e

Browse files
committed
Enable parsing comma lists without semicolons
1 parent 366c7bb commit e1fe02e

File tree

2 files changed

+128
-1
lines changed

2 files changed

+128
-1
lines changed

src/parser/mod.rs

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

4638+
if end_token == Token::SemiColon
4639+
&& self
4640+
.dialect
4641+
.supports_statements_without_semicolon_delimiter()
4642+
{
4643+
if let Token::Word(ref kw) = self.peek_token().token {
4644+
if kw.keyword != Keyword::NoKeyword {
4645+
return Ok(vec![]);
4646+
}
4647+
}
4648+
}
4649+
46384650
if self.options.trailing_commas && self.peek_tokens() == [Token::Comma, end_token] {
46394651
let _ = self.consume_token(&Token::Comma);
46404652
return Ok(vec![]);

tests/sqlparser_mssql.rs

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2536,7 +2536,6 @@ DECLARE @Y AS NVARCHAR(MAX)='y'
25362536
#[test]
25372537
fn test_supports_statements_without_semicolon_delimiter() {
25382538
use sqlparser::ast::Ident;
2539-
25402539
use sqlparser::tokenizer::Location;
25412540

25422541
fn parse_n_statements(n: usize, sql: &str) -> Vec<Statement> {
@@ -2846,4 +2845,120 @@ fn test_supports_statements_without_semicolon_delimiter() {
28462845
},
28472846
}
28482847
);
2848+
2849+
let exec_then_update = "\
2850+
EXEC my_sp \
2851+
UPDATE my_table SET col = 1 \
2852+
";
2853+
assert_eq!(
2854+
parse_n_statements(2, exec_then_update),
2855+
vec![
2856+
Statement::Execute {
2857+
name: Some(ObjectName::from(vec![Ident::new("my_sp")])),
2858+
parameters: vec![],
2859+
has_parentheses: false,
2860+
immediate: false,
2861+
into: vec![],
2862+
using: vec![],
2863+
output: false,
2864+
default: false,
2865+
},
2866+
Statement::Update {
2867+
table: TableWithJoins {
2868+
relation: TableFactor::Table {
2869+
name: ObjectName::from(vec![Ident::new("my_table")]),
2870+
alias: None,
2871+
with_hints: vec![],
2872+
args: None,
2873+
version: None,
2874+
with_ordinality: false,
2875+
partitions: vec![],
2876+
json_path: None,
2877+
sample: None,
2878+
index_hints: vec![]
2879+
},
2880+
joins: vec![],
2881+
},
2882+
assignments: vec![Assignment {
2883+
value: Expr::Value(
2884+
number("1")
2885+
.with_span(Span::new(Location::new(3, 16), Location::new(3, 17)))
2886+
),
2887+
target: AssignmentTarget::ColumnName(ObjectName::from(vec![Ident::new("col")])),
2888+
},],
2889+
selection: None,
2890+
returning: None,
2891+
from: None,
2892+
or: None,
2893+
limit: None,
2894+
},
2895+
]
2896+
);
2897+
2898+
let exec_params_then_update = "\
2899+
EXEC my_sp 1, 2 \
2900+
UPDATE my_table SET col = 1 \
2901+
";
2902+
assert_eq!(
2903+
parse_n_statements(2, exec_params_then_update),
2904+
vec![
2905+
Statement::Execute {
2906+
name: Some(ObjectName::from(vec![Ident::with_span(
2907+
Span::new(Location::new(1, 6), Location::new(1, 11)),
2908+
"my_sp"
2909+
)])),
2910+
parameters: vec![
2911+
Expr::Value(
2912+
number("1")
2913+
.with_span(Span::new(Location::new(1, 12), Location::new(1, 13)))
2914+
),
2915+
Expr::Value(
2916+
number("2")
2917+
.with_span(Span::new(Location::new(1, 15), Location::new(1, 17)))
2918+
),
2919+
],
2920+
has_parentheses: false,
2921+
immediate: false,
2922+
into: vec![],
2923+
using: vec![],
2924+
output: false,
2925+
default: false,
2926+
},
2927+
Statement::Update {
2928+
table: TableWithJoins {
2929+
relation: TableFactor::Table {
2930+
name: ObjectName::from(vec![Ident::with_span(
2931+
Span::new(Location::new(1, 24), Location::new(1, 32)),
2932+
"my_table"
2933+
)]),
2934+
alias: None,
2935+
with_hints: vec![],
2936+
args: None,
2937+
version: None,
2938+
with_ordinality: false,
2939+
partitions: vec![],
2940+
json_path: None,
2941+
sample: None,
2942+
index_hints: vec![]
2943+
},
2944+
joins: vec![],
2945+
},
2946+
assignments: vec![Assignment {
2947+
value: Expr::Value(
2948+
number("1")
2949+
.with_span(Span::new(Location::new(3, 16), Location::new(3, 17)))
2950+
),
2951+
target: AssignmentTarget::ColumnName(ObjectName::from(vec![Ident::with_span(
2952+
Span::new(Location::new(1, 37), Location::new(1, 40)),
2953+
"col"
2954+
)])),
2955+
},],
2956+
selection: None,
2957+
returning: None,
2958+
from: None,
2959+
or: None,
2960+
limit: None,
2961+
},
2962+
]
2963+
);
28492964
}

0 commit comments

Comments
 (0)