@@ -1630,13 +1630,17 @@ module.exports = grammar({
1630
1630
) ,
1631
1631
) ,
1632
1632
1633
- interpolated_string_expression : $ =>
1634
- choice (
1635
- seq ( field ( "interpolator" , alias ( $ . _raw_string_start , $ . identifier ) ) , alias ( $ . _raw_string , $ . interpolated_string ) ) ,
1636
- seq ( field ( "interpolator" , $ . identifier ) , $ . interpolated_string ) ,
1633
+ interpolated_string_expression : $ =>
1634
+ choice (
1635
+ seq (
1636
+ field ( "interpolator" , alias ( $ . _raw_string_start , $ . identifier ) ) ,
1637
+ alias ( $ . _raw_string , $ . interpolated_string ) ,
1638
+ ) ,
1639
+ seq ( field ( "interpolator" , $ . identifier ) , $ . interpolated_string ) ,
1637
1640
) ,
1638
1641
1639
- _dollar_escape : $ => alias ( token ( seq ( "$" , choice ( "$" , '"' ) ) ) , $ . escape_sequence ) ,
1642
+ _dollar_escape : $ =>
1643
+ alias ( token ( seq ( "$" , choice ( "$" , '"' ) ) ) , $ . escape_sequence ) ,
1640
1644
1641
1645
_aliased_interpolation_identifier : $ =>
1642
1646
alias ( $ . _interpolation_identifier , $ . identifier ) ,
@@ -1670,14 +1674,14 @@ module.exports = grammar({
1670
1674
) ,
1671
1675
1672
1676
// We need to handle single-line raw strings separately from interpolated strings,
1673
- // because raw strings are not parsed for escape sequences. For example, raw strings
1677
+ // because raw strings are not parsed for escape sequences. For example, raw strings
1674
1678
// are often used for regular expressions, which contain backslashes that would
1675
1679
// be invalid if parsed as escape sequences. We do not special case multiline
1676
1680
// raw strings, because multiline strings do not parse escape sequences anyway.
1677
1681
// Scala handles multiline raw strings identically to other multiline interpolated,
1678
1682
// so we could parse them as interpolated strings, but I think the code is cleaner
1679
1683
// if we maintain the distinction.
1680
- _raw_string : $ =>
1684
+ _raw_string : $ =>
1681
1685
choice (
1682
1686
seq (
1683
1687
$ . _simple_string_start ,
@@ -1689,46 +1693,50 @@ module.exports = grammar({
1689
1693
) ,
1690
1694
) ,
1691
1695
$ . _single_line_string_end ,
1692
- ) ,
1696
+ ) ,
1693
1697
) ,
1694
1698
seq (
1695
1699
$ . _simple_multiline_string_start ,
1696
1700
repeat (
1697
1701
seq (
1698
1702
$ . _raw_string_multiline_middle ,
1699
1703
choice ( $ . _dollar_escape , $ . interpolation ) ,
1700
- )
1704
+ ) ,
1701
1705
) ,
1702
1706
$ . _multiline_string_end ,
1703
1707
) ,
1704
1708
) ,
1705
1709
1706
- escape_sequence : _ => token . immediate ( seq (
1707
- '\\' ,
1708
- choice (
1709
- / [ t b n r f " ' \\ ] / ,
1710
- // The Java spec allows any number of u's and U's at the start of a unicode escape.
1711
- / [ u U ] + [ 0 - 9 a - f A - F ] { 4 } / ,
1712
- // Octals are not allowed in Scala 3, but are allowed in Scala 2. tree-sitter
1713
- // does not have a mechanism for distinguishing between different versions of a
1714
- // language, so I think it makes sense to allow them. Maybe in the future we
1715
- // should move them to a `deprecated` syntax node?
1716
- / [ 0 - 3 ] ? [ 0 - 7 ] { 1 , 2 } / ,
1717
- ) ,
1718
- ) ) ,
1719
-
1720
- string : $ => choice (
1721
- seq (
1722
- $ . _simple_string_start ,
1723
- repeat ( seq ( $ . _simple_string_middle , $ . escape_sequence ) ) ,
1724
- $ . _single_line_string_end ,
1710
+ escape_sequence : _ =>
1711
+ token . immediate (
1712
+ seq (
1713
+ "\\" ,
1714
+ choice (
1715
+ / [ t b n r f " ' \\ ] / ,
1716
+ // The Java spec allows any number of u's and U's at the start of a unicode escape.
1717
+ / [ u U ] + [ 0 - 9 a - f A - F ] { 4 } / ,
1718
+ // Octals are not allowed in Scala 3, but are allowed in Scala 2. tree-sitter
1719
+ // does not have a mechanism for distinguishing between different versions of a
1720
+ // language, so I think it makes sense to allow them. Maybe in the future we
1721
+ // should move them to a `deprecated` syntax node?
1722
+ / [ 0 - 3 ] ? [ 0 - 7 ] { 1 , 2 } / ,
1723
+ ) ,
1724
+ ) ,
1725
1725
) ,
1726
- seq (
1727
- $ . _simple_multiline_string_start ,
1728
- /// Multiline strings ignore escape sequences
1729
- $ . _multiline_string_end ,
1726
+
1727
+ string : $ =>
1728
+ choice (
1729
+ seq (
1730
+ $ . _simple_string_start ,
1731
+ repeat ( seq ( $ . _simple_string_middle , $ . escape_sequence ) ) ,
1732
+ $ . _single_line_string_end ,
1733
+ ) ,
1734
+ seq (
1735
+ $ . _simple_multiline_string_start ,
1736
+ /// Multiline strings ignore escape sequences
1737
+ $ . _multiline_string_end ,
1738
+ ) ,
1730
1739
) ,
1731
- ) ,
1732
1740
1733
1741
_semicolon : $ => choice ( ";" , $ . _automatic_semicolon ) ,
1734
1742
0 commit comments