@@ -231,25 +231,37 @@ fn parse_loop_statement_initial_token(
231231}
232232
233233/// LRM 10.11 Next statement
234- fn parse_next_statement_known_keyword ( stream : & mut TokenStream ) -> ParseResult < NextStatement > {
234+ fn parse_next_statement_known_keyword (
235+ initial : Token ,
236+ stream : & mut TokenStream ,
237+ ) -> ParseResult < WithPos < NextStatement > > {
235238 let loop_label = stream. pop_optional_ident ( ) ?;
236239 let condition = parse_optional ( stream, When , parse_expression) ?;
237- stream. expect_kind ( SemiColon ) ?;
238- Ok ( NextStatement {
239- loop_label : loop_label. map ( WithRef :: new) ,
240- condition,
241- } )
240+ let semi = stream. expect_kind ( SemiColon ) ?;
241+ Ok ( WithPos :: new (
242+ NextStatement {
243+ loop_label : loop_label. map ( WithRef :: new) ,
244+ condition,
245+ } ,
246+ initial. pos . combine_into ( & semi. pos ) ,
247+ ) )
242248}
243249
244250/// LRM 10.12 Exit statement
245- fn parse_exit_statement_known_keyword ( stream : & mut TokenStream ) -> ParseResult < ExitStatement > {
251+ fn parse_exit_statement_known_keyword (
252+ initial : Token ,
253+ stream : & mut TokenStream ,
254+ ) -> ParseResult < WithPos < ExitStatement > > {
246255 let loop_label = stream. pop_optional_ident ( ) ?;
247256 let condition = parse_optional ( stream, When , parse_expression) ?;
248- stream. expect_kind ( SemiColon ) ?;
249- Ok ( ExitStatement {
250- loop_label : loop_label. map ( WithRef :: new) ,
251- condition,
252- } )
257+ let semi = stream. expect_kind ( SemiColon ) ?;
258+ Ok ( WithPos :: new (
259+ ExitStatement {
260+ loop_label : loop_label. map ( WithRef :: new) ,
261+ condition,
262+ } ,
263+ initial. pos . combine_into ( & semi. pos ) ,
264+ ) )
253265}
254266
255267/// LRM 10.13 Return statement
@@ -535,8 +547,8 @@ fn parse_unlabeled_sequential_statement(
535547 For | Loop | While => {
536548 SequentialStatement :: Loop ( parse_loop_statement_initial_token( stream, label, & token, diagnostics) ?)
537549 } ,
538- Next => SequentialStatement :: Next ( parse_next_statement_known_keyword( stream) ?) ,
539- Exit => SequentialStatement :: Exit ( parse_exit_statement_known_keyword( stream) ?) ,
550+ Next => SequentialStatement :: Next ( parse_next_statement_known_keyword( token , stream) ?) ,
551+ Exit => SequentialStatement :: Exit ( parse_exit_statement_known_keyword( token , stream) ?) ,
540552 Return => SequentialStatement :: Return ( parse_return_statement_known_keyword( token, stream) ?) ,
541553 Null => {
542554 stream. expect_kind( SemiColon ) ?;
@@ -1559,15 +1571,18 @@ end loop;
15591571
15601572 #[ test]
15611573 fn parse_next_statement ( ) {
1562- let ( _ , statement) = parse ( "next;" ) ;
1574+ let ( code , statement) = parse ( "next;" ) ;
15631575 assert_eq ! (
15641576 statement,
15651577 with_label(
15661578 None ,
1567- SequentialStatement :: Next ( NextStatement {
1568- loop_label: None ,
1569- condition: None ,
1570- } )
1579+ SequentialStatement :: Next ( WithPos :: new(
1580+ NextStatement {
1581+ loop_label: None ,
1582+ condition: None ,
1583+ } ,
1584+ code. pos( )
1585+ ) , )
15711586 )
15721587 ) ;
15731588 }
@@ -1579,10 +1594,13 @@ end loop;
15791594 statement,
15801595 with_label(
15811596 None ,
1582- SequentialStatement :: Next ( NextStatement {
1583- loop_label: Some ( code. s1( "foo" ) . ident( ) . into_ref( ) ) ,
1584- condition: None ,
1585- } )
1597+ SequentialStatement :: Next ( WithPos :: new(
1598+ NextStatement {
1599+ loop_label: Some ( code. s1( "foo" ) . ident( ) . into_ref( ) ) ,
1600+ condition: None ,
1601+ } ,
1602+ code. pos( )
1603+ ) )
15861604 )
15871605 ) ;
15881606 }
@@ -1594,10 +1612,13 @@ end loop;
15941612 statement,
15951613 with_label(
15961614 None ,
1597- SequentialStatement :: Next ( NextStatement {
1598- loop_label: None ,
1599- condition: Some ( code. s1( "condition" ) . expr( ) ) ,
1600- } )
1615+ SequentialStatement :: Next ( WithPos :: new(
1616+ NextStatement {
1617+ loop_label: None ,
1618+ condition: Some ( code. s1( "condition" ) . expr( ) ) ,
1619+ } ,
1620+ code. pos( )
1621+ ) )
16011622 )
16021623 ) ;
16031624 }
@@ -1609,25 +1630,31 @@ end loop;
16091630 statement,
16101631 with_label(
16111632 None ,
1612- SequentialStatement :: Next ( NextStatement {
1613- loop_label: Some ( code. s1( "foo" ) . ident( ) . into_ref( ) ) ,
1614- condition: Some ( code. s1( "condition" ) . expr( ) ) ,
1615- } )
1633+ SequentialStatement :: Next ( WithPos :: new(
1634+ NextStatement {
1635+ loop_label: Some ( code. s1( "foo" ) . ident( ) . into_ref( ) ) ,
1636+ condition: Some ( code. s1( "condition" ) . expr( ) ) ,
1637+ } ,
1638+ code. pos( )
1639+ ) )
16161640 )
16171641 ) ;
16181642 }
16191643
16201644 #[ test]
16211645 fn parse_exit_statement ( ) {
1622- let ( _ , statement) = parse ( "exit;" ) ;
1646+ let ( code , statement) = parse ( "exit;" ) ;
16231647 assert_eq ! (
16241648 statement,
16251649 with_label(
16261650 None ,
1627- SequentialStatement :: Exit ( ExitStatement {
1628- loop_label: None ,
1629- condition: None ,
1630- } )
1651+ SequentialStatement :: Exit ( WithPos :: new(
1652+ ExitStatement {
1653+ loop_label: None ,
1654+ condition: None ,
1655+ } ,
1656+ code. pos( )
1657+ ) )
16311658 )
16321659 ) ;
16331660 }
@@ -1639,10 +1666,13 @@ end loop;
16391666 statement,
16401667 with_label(
16411668 None ,
1642- SequentialStatement :: Exit ( ExitStatement {
1643- loop_label: Some ( code. s1( "foo" ) . ident( ) . into_ref( ) ) ,
1644- condition: None ,
1645- } )
1669+ SequentialStatement :: Exit ( WithPos :: new(
1670+ ExitStatement {
1671+ loop_label: Some ( code. s1( "foo" ) . ident( ) . into_ref( ) ) ,
1672+ condition: None ,
1673+ } ,
1674+ code. pos( )
1675+ ) )
16461676 )
16471677 ) ;
16481678 }
@@ -1654,10 +1684,13 @@ end loop;
16541684 statement,
16551685 with_label(
16561686 None ,
1657- SequentialStatement :: Exit ( ExitStatement {
1658- loop_label: None ,
1659- condition: Some ( code. s1( "condition" ) . expr( ) ) ,
1660- } )
1687+ SequentialStatement :: Exit ( WithPos :: new(
1688+ ExitStatement {
1689+ loop_label: None ,
1690+ condition: Some ( code. s1( "condition" ) . expr( ) ) ,
1691+ } ,
1692+ code. pos( )
1693+ ) )
16611694 )
16621695 ) ;
16631696 }
@@ -1669,10 +1702,13 @@ end loop;
16691702 statement,
16701703 with_label(
16711704 None ,
1672- SequentialStatement :: Exit ( ExitStatement {
1673- loop_label: Some ( code. s1( "foo" ) . ident( ) . into_ref( ) ) ,
1674- condition: Some ( code. s1( "condition" ) . expr( ) ) ,
1675- } )
1705+ SequentialStatement :: Exit ( WithPos :: new(
1706+ ExitStatement {
1707+ loop_label: Some ( code. s1( "foo" ) . ident( ) . into_ref( ) ) ,
1708+ condition: Some ( code. s1( "condition" ) . expr( ) ) ,
1709+ } ,
1710+ code. pos( )
1711+ ) )
16761712 )
16771713 ) ;
16781714 }
0 commit comments