@@ -1498,6 +1498,155 @@ fn look_ahead_non_outermost_stream() {
1498
1498
} ) ;
1499
1499
}
1500
1500
1501
+ // FIXME(nnethercote) All the output is currently wrong.
1502
+ #[ test]
1503
+ fn debug_lookahead ( ) {
1504
+ create_default_session_globals_then ( || {
1505
+ let psess = psess ( ) ;
1506
+ let mut p = string_to_parser ( & psess, "fn f(x: u32) { x } struct S;" . to_string ( ) ) ;
1507
+
1508
+ // Current position is the `fn`.
1509
+ assert_eq ! (
1510
+ & format!( "{:#?}" , p. debug_lookahead( 0 ) ) ,
1511
+ "Parser {
1512
+ prev_token: Token {
1513
+ kind: Question,
1514
+ span: Span {
1515
+ lo: BytePos(
1516
+ 0,
1517
+ ),
1518
+ hi: BytePos(
1519
+ 0,
1520
+ ),
1521
+ ctxt: #0,
1522
+ },
1523
+ },
1524
+ tokens: [],
1525
+ approx_token_stream_pos: 1,
1526
+ ..
1527
+ }"
1528
+ ) ;
1529
+ assert_eq ! (
1530
+ & format!( "{:#?}" , p. debug_lookahead( 7 ) ) ,
1531
+ "Parser {
1532
+ prev_token: Token {
1533
+ kind: Question,
1534
+ span: Span {
1535
+ lo: BytePos(
1536
+ 0,
1537
+ ),
1538
+ hi: BytePos(
1539
+ 0,
1540
+ ),
1541
+ ctxt: #0,
1542
+ },
1543
+ },
1544
+ tokens: [],
1545
+ approx_token_stream_pos: 1,
1546
+ ..
1547
+ }"
1548
+ ) ;
1549
+ assert_eq ! (
1550
+ & format!( "{:#?}" , p. debug_lookahead( 15 ) ) ,
1551
+ "Parser {
1552
+ prev_token: Token {
1553
+ kind: Question,
1554
+ span: Span {
1555
+ lo: BytePos(
1556
+ 0,
1557
+ ),
1558
+ hi: BytePos(
1559
+ 0,
1560
+ ),
1561
+ ctxt: #0,
1562
+ },
1563
+ },
1564
+ tokens: [],
1565
+ approx_token_stream_pos: 1,
1566
+ ..
1567
+ }"
1568
+ ) ;
1569
+
1570
+ // Move forward to the second `x`.
1571
+ for _ in 0 ..8 {
1572
+ p. bump ( ) ;
1573
+ }
1574
+ assert_eq ! (
1575
+ & format!( "{:#?}" , p. debug_lookahead( 1 ) ) ,
1576
+ "Parser {
1577
+ prev_token: Token {
1578
+ kind: OpenDelim(
1579
+ Brace,
1580
+ ),
1581
+ span: Span {
1582
+ lo: BytePos(
1583
+ 13,
1584
+ ),
1585
+ hi: BytePos(
1586
+ 14,
1587
+ ),
1588
+ ctxt: #0,
1589
+ },
1590
+ },
1591
+ tokens: [],
1592
+ approx_token_stream_pos: 9,
1593
+ ..
1594
+ }"
1595
+ ) ;
1596
+ assert_eq ! (
1597
+ & format!( "{:#?}" , p. debug_lookahead( 4 ) ) ,
1598
+ "Parser {
1599
+ prev_token: Token {
1600
+ kind: OpenDelim(
1601
+ Brace,
1602
+ ),
1603
+ span: Span {
1604
+ lo: BytePos(
1605
+ 13,
1606
+ ),
1607
+ hi: BytePos(
1608
+ 14,
1609
+ ),
1610
+ ctxt: #0,
1611
+ },
1612
+ },
1613
+ tokens: [],
1614
+ approx_token_stream_pos: 9,
1615
+ ..
1616
+ }"
1617
+ ) ;
1618
+
1619
+ // Move two past the final token (the `;`).
1620
+ for _ in 0 ..6 {
1621
+ p. bump ( ) ;
1622
+ }
1623
+ assert_eq ! (
1624
+ & format!( "{:#?}" , p. debug_lookahead( 3 ) ) ,
1625
+ "Parser {
1626
+ prev_token: Token {
1627
+ kind: Eof,
1628
+ span: Span {
1629
+ lo: BytePos(
1630
+ 27,
1631
+ ),
1632
+ hi: BytePos(
1633
+ 28,
1634
+ ),
1635
+ ctxt: #0,
1636
+ },
1637
+ },
1638
+ tokens: [
1639
+ Eof,
1640
+ Eof,
1641
+ Eof,
1642
+ ],
1643
+ approx_token_stream_pos: 15,
1644
+ ..
1645
+ }"
1646
+ ) ;
1647
+ } ) ;
1648
+ }
1649
+
1501
1650
// This tests that when parsing a string (rather than a file) we don't try
1502
1651
// and read in a file for a module declaration and just parse a stub.
1503
1652
// See `recurse_into_file_modules` in the parser.
0 commit comments