@@ -38,7 +38,7 @@ use crate::ast::{
3838} ;
3939use crate :: dialect:: { Dialect , Precedence } ;
4040use crate :: keywords:: Keyword ;
41- use crate :: parser:: { IsOptional , Parser , ParserError } ;
41+ use crate :: parser:: { parser_err , IsOptional , Parser , ParserError } ;
4242use crate :: tokenizer:: TokenWithSpan ;
4343use crate :: tokenizer:: { Span , Token } ;
4444#[ cfg( not( feature = "std" ) ) ]
@@ -435,7 +435,7 @@ impl Dialect for SnowflakeDialect {
435435 } else if parser. parse_keywords ( & [ Keyword :: TAG ] ) {
436436 Ok ( parse_column_tags ( parser, with) . map ( |p| Some ( ColumnOption :: Tags ( p) ) ) )
437437 } else {
438- Err ( ParserError :: ParserError ( "not found match" . to_string ( ) ) )
438+ parser_err ! ( "not found match" , parser . peek_token_ref ( ) . span )
439439 }
440440 } )
441441 }
@@ -742,9 +742,10 @@ fn parse_file_staging_command(kw: Keyword, parser: &mut Parser) -> Result<Statem
742742 Keyword :: REMOVE | Keyword :: RM => {
743743 Ok ( Statement :: Remove ( FileStagingCommand { stage, pattern } ) )
744744 }
745- _ => Err ( ParserError :: ParserError (
746- "unexpected stage command, expecting LIST, LS, REMOVE or RM" . to_string ( ) ,
747- ) ) ,
745+ _ => parser_err ! (
746+ "unexpected stage command, expecting LIST, LS, REMOVE or RM" ,
747+ parser. get_current_token( ) . span
748+ ) ,
748749 }
749750}
750751
@@ -1092,9 +1093,10 @@ pub fn parse_create_table(
10921093 builder = builder. table_options ( table_options) ;
10931094
10941095 if iceberg && builder. base_location . is_none ( ) {
1095- return Err ( ParserError :: ParserError (
1096- "BASE_LOCATION is required for ICEBERG tables" . to_string ( ) ,
1097- ) ) ;
1096+ return parser_err ! (
1097+ "BASE_LOCATION is required for ICEBERG tables" ,
1098+ parser. peek_token_ref( ) . span
1099+ ) ;
10981100 }
10991101
11001102 Ok ( builder. build ( ) )
@@ -1563,9 +1565,15 @@ fn parse_select_item_for_data_load(
15631565 let next_token = parser. next_token ( ) ;
15641566 match next_token. token {
15651567 Token :: Placeholder ( w) => {
1566- file_col_num = w. to_string ( ) . split_off ( 1 ) . parse :: < i32 > ( ) . map_err ( |e| {
1567- ParserError :: ParserError ( format ! ( "Could not parse '{w}' as i32: {e}" ) )
1568- } ) ?;
1568+ file_col_num = match w. to_string ( ) . split_off ( 1 ) . parse :: < i32 > ( ) {
1569+ Ok ( n) => n,
1570+ Err ( e) => {
1571+ return parser_err ! (
1572+ format!( "Could not parse '{w}' as i32: {e}" ) ,
1573+ next_token. span
1574+ )
1575+ }
1576+ } ;
15691577 Ok ( ( ) )
15701578 }
15711579 Token :: Word ( w) => {
@@ -1581,9 +1589,15 @@ fn parse_select_item_for_data_load(
15811589 let col_num_token = parser. next_token ( ) ;
15821590 match col_num_token. token {
15831591 Token :: Placeholder ( w) => {
1584- file_col_num = w. to_string ( ) . split_off ( 1 ) . parse :: < i32 > ( ) . map_err ( |e| {
1585- ParserError :: ParserError ( format ! ( "Could not parse '{w}' as i32: {e}" ) )
1586- } ) ?;
1592+ file_col_num = match w. to_string ( ) . split_off ( 1 ) . parse :: < i32 > ( ) {
1593+ Ok ( n) => n,
1594+ Err ( e) => {
1595+ return parser_err ! (
1596+ format!( "Could not parse '{w}' as i32: {e}" ) ,
1597+ col_num_token. span
1598+ )
1599+ }
1600+ } ;
15871601 Ok ( ( ) )
15881602 }
15891603 _ => parser. expected ( "file_col_num" , col_num_token) ,
@@ -1730,9 +1744,7 @@ fn parse_session_options(
17301744 }
17311745 }
17321746 if options. is_empty ( ) {
1733- Err ( ParserError :: ParserError (
1734- "expected at least one option" . to_string ( ) ,
1735- ) )
1747+ parser_err ! ( "expected at least one option" , parser. peek_token_ref( ) . span)
17361748 } else {
17371749 Ok ( options)
17381750 }
0 commit comments