@@ -655,12 +655,6 @@ where
655
655
// Detect indentation levels
656
656
if self . at_begin_of_line {
657
657
self . handle_indentations ( ) ?;
658
- if self . mode == Mode :: Jupyter
659
- // https://github.com/ipython/ipython/blob/635815e8f1ded5b764d66cacc80bbe25e9e2587f/IPython/core/inputtransformer2.py#L345
660
- && matches ! ( self . window[ 0 ] , Some ( '%' | '!' | '?' | '/' | ';' | ',' ) )
661
- {
662
- self . lex_and_emit_magic_command ( ) ;
663
- }
664
658
}
665
659
666
660
self . consume_normal ( ) ?;
@@ -709,6 +703,10 @@ where
709
703
spaces = 0 ;
710
704
tabs = 0 ;
711
705
}
706
+ // https://github.com/ipython/ipython/blob/635815e8f1ded5b764d66cacc80bbe25e9e2587f/IPython/core/inputtransformer2.py#L345
707
+ Some ( '%' | '!' | '?' | '/' | ';' | ',' ) if self . mode == Mode :: Jupyter => {
708
+ self . lex_and_emit_magic_command ( ) ;
709
+ }
712
710
Some ( '\x0C' ) => {
713
711
// Form feed character!
714
712
// Reset indentation for the Emacs user.
@@ -1487,13 +1485,10 @@ mod tests {
1487
1485
let tokens = lex_jupyter_source ( & source) ;
1488
1486
assert_eq ! (
1489
1487
tokens,
1490
- vec![
1491
- Tok :: MagicCommand {
1492
- value: "matplotlib --inline" . to_string( ) ,
1493
- kind: MagicKind :: Magic
1494
- } ,
1495
- Tok :: Newline
1496
- ]
1488
+ vec![ Tok :: MagicCommand {
1489
+ value: "matplotlib --inline" . to_string( ) ,
1490
+ kind: MagicKind :: Magic
1491
+ } , ]
1497
1492
)
1498
1493
}
1499
1494
@@ -1517,13 +1512,10 @@ mod tests {
1517
1512
let tokens = lex_jupyter_source ( & source) ;
1518
1513
assert_eq ! (
1519
1514
tokens,
1520
- vec![
1521
- Tok :: MagicCommand {
1522
- value: "matplotlib " . to_string( ) ,
1523
- kind: MagicKind :: Magic
1524
- } ,
1525
- Tok :: Newline
1526
- ]
1515
+ vec![ Tok :: MagicCommand {
1516
+ value: "matplotlib " . to_string( ) ,
1517
+ kind: MagicKind :: Magic
1518
+ } , ]
1527
1519
)
1528
1520
}
1529
1521
@@ -1553,47 +1545,54 @@ mod tests {
1553
1545
value: "" . to_string( ) ,
1554
1546
kind: MagicKind :: Magic ,
1555
1547
} ,
1556
- Tok :: Newline ,
1548
+ #[ cfg( feature = "full-lexer" ) ]
1549
+ Tok :: NonLogicalNewline ,
1557
1550
Tok :: MagicCommand {
1558
1551
value: "" . to_string( ) ,
1559
1552
kind: MagicKind :: Magic2 ,
1560
1553
} ,
1561
- Tok :: Newline ,
1554
+ #[ cfg( feature = "full-lexer" ) ]
1555
+ Tok :: NonLogicalNewline ,
1562
1556
Tok :: MagicCommand {
1563
1557
value: "" . to_string( ) ,
1564
1558
kind: MagicKind :: Shell ,
1565
1559
} ,
1566
- Tok :: Newline ,
1560
+ #[ cfg( feature = "full-lexer" ) ]
1561
+ Tok :: NonLogicalNewline ,
1567
1562
Tok :: MagicCommand {
1568
1563
value: "" . to_string( ) ,
1569
1564
kind: MagicKind :: ShCap ,
1570
1565
} ,
1571
- Tok :: Newline ,
1566
+ #[ cfg( feature = "full-lexer" ) ]
1567
+ Tok :: NonLogicalNewline ,
1572
1568
Tok :: MagicCommand {
1573
1569
value: "" . to_string( ) ,
1574
1570
kind: MagicKind :: Help ,
1575
1571
} ,
1576
- Tok :: Newline ,
1572
+ #[ cfg( feature = "full-lexer" ) ]
1573
+ Tok :: NonLogicalNewline ,
1577
1574
Tok :: MagicCommand {
1578
1575
value: "" . to_string( ) ,
1579
1576
kind: MagicKind :: Help2 ,
1580
1577
} ,
1581
- Tok :: Newline ,
1578
+ #[ cfg( feature = "full-lexer" ) ]
1579
+ Tok :: NonLogicalNewline ,
1582
1580
Tok :: MagicCommand {
1583
1581
value: "" . to_string( ) ,
1584
1582
kind: MagicKind :: Paren ,
1585
1583
} ,
1586
- Tok :: Newline ,
1584
+ #[ cfg( feature = "full-lexer" ) ]
1585
+ Tok :: NonLogicalNewline ,
1587
1586
Tok :: MagicCommand {
1588
1587
value: "" . to_string( ) ,
1589
1588
kind: MagicKind :: Quote ,
1590
1589
} ,
1591
- Tok :: Newline ,
1590
+ #[ cfg( feature = "full-lexer" ) ]
1591
+ Tok :: NonLogicalNewline ,
1592
1592
Tok :: MagicCommand {
1593
1593
value: "" . to_string( ) ,
1594
1594
kind: MagicKind :: Quote2 ,
1595
1595
} ,
1596
- Tok :: Newline ,
1597
1596
]
1598
1597
)
1599
1598
}
@@ -1612,8 +1611,10 @@ mod tests {
1612
1611
!!cd /Users/foo/Library/Application\ Support/
1613
1612
/foo 1 2
1614
1613
,foo 1 2
1615
- ;foo 1 2"
1616
- . trim ( ) ;
1614
+ ;foo 1 2
1615
+ !ls
1616
+ "
1617
+ . trim ( ) ;
1617
1618
let tokens = lex_jupyter_source ( source) ;
1618
1619
assert_eq ! (
1619
1620
tokens,
@@ -1622,78 +1623,66 @@ mod tests {
1622
1623
value: "foo" . to_string( ) ,
1623
1624
kind: MagicKind :: Help ,
1624
1625
} ,
1625
- Tok :: Newline ,
1626
+ #[ cfg( feature = "full-lexer" ) ]
1627
+ Tok :: NonLogicalNewline ,
1626
1628
Tok :: MagicCommand {
1627
1629
value: "foo" . to_string( ) ,
1628
1630
kind: MagicKind :: Help2 ,
1629
1631
} ,
1630
- Tok :: Newline ,
1632
+ #[ cfg( feature = "full-lexer" ) ]
1633
+ Tok :: NonLogicalNewline ,
1631
1634
Tok :: MagicCommand {
1632
1635
value: "timeit a = b" . to_string( ) ,
1633
1636
kind: MagicKind :: Magic ,
1634
1637
} ,
1635
- Tok :: Newline ,
1638
+ #[ cfg( feature = "full-lexer" ) ]
1639
+ Tok :: NonLogicalNewline ,
1636
1640
Tok :: MagicCommand {
1637
1641
value: "timeit a % 3" . to_string( ) ,
1638
1642
kind: MagicKind :: Magic ,
1639
1643
} ,
1640
- Tok :: Newline ,
1644
+ #[ cfg( feature = "full-lexer" ) ]
1645
+ Tok :: NonLogicalNewline ,
1641
1646
Tok :: MagicCommand {
1642
1647
value: "matplotlib --inline" . to_string( ) ,
1643
1648
kind: MagicKind :: Magic ,
1644
1649
} ,
1645
- Tok :: Newline ,
1650
+ #[ cfg( feature = "full-lexer" ) ]
1651
+ Tok :: NonLogicalNewline ,
1646
1652
Tok :: MagicCommand {
1647
1653
value: "pwd && ls -a | sed 's/^/\\ \\ /'" . to_string( ) ,
1648
1654
kind: MagicKind :: Shell ,
1649
1655
} ,
1650
- Tok :: Newline ,
1656
+ #[ cfg( feature = "full-lexer" ) ]
1657
+ Tok :: NonLogicalNewline ,
1651
1658
Tok :: MagicCommand {
1652
1659
value: "cd /Users/foo/Library/Application\\ Support/" . to_string( ) ,
1653
1660
kind: MagicKind :: ShCap ,
1654
1661
} ,
1655
- Tok :: Newline ,
1662
+ #[ cfg( feature = "full-lexer" ) ]
1663
+ Tok :: NonLogicalNewline ,
1656
1664
Tok :: MagicCommand {
1657
1665
value: "foo 1 2" . to_string( ) ,
1658
1666
kind: MagicKind :: Paren ,
1659
1667
} ,
1660
- Tok :: Newline ,
1668
+ #[ cfg( feature = "full-lexer" ) ]
1669
+ Tok :: NonLogicalNewline ,
1661
1670
Tok :: MagicCommand {
1662
1671
value: "foo 1 2" . to_string( ) ,
1663
1672
kind: MagicKind :: Quote ,
1664
1673
} ,
1665
- Tok :: Newline ,
1674
+ #[ cfg( feature = "full-lexer" ) ]
1675
+ Tok :: NonLogicalNewline ,
1666
1676
Tok :: MagicCommand {
1667
1677
value: "foo 1 2" . to_string( ) ,
1668
1678
kind: MagicKind :: Quote2 ,
1669
1679
} ,
1670
- Tok :: Newline ,
1671
- ]
1672
- )
1673
- }
1674
-
1675
- #[ test]
1676
- fn test_jupyter_magic_indentation ( ) {
1677
- let source = r"
1678
- if True:
1679
- %matplotlib \
1680
- --inline"
1681
- . trim ( ) ;
1682
- let tokens = lex_jupyter_source ( source) ;
1683
- assert_eq ! (
1684
- tokens,
1685
- vec![
1686
- Tok :: If ,
1687
- Tok :: True ,
1688
- Tok :: Colon ,
1689
- Tok :: Newline ,
1690
- Tok :: Indent ,
1680
+ #[ cfg( feature = "full-lexer" ) ]
1681
+ Tok :: NonLogicalNewline ,
1691
1682
Tok :: MagicCommand {
1692
- value: "matplotlib --inline " . to_string( ) ,
1693
- kind: MagicKind :: Magic ,
1683
+ value: "ls " . to_string( ) ,
1684
+ kind: MagicKind :: Shell ,
1694
1685
} ,
1695
- Tok :: Newline ,
1696
- Tok :: Dedent ,
1697
1686
]
1698
1687
)
1699
1688
}
0 commit comments