@@ -1737,9 +1737,6 @@ object Parsers {
1737
1737
})
1738
1738
else t
1739
1739
1740
- /** The block in a quote or splice */
1741
- def stagedBlock () = inBraces(block(simplify = true ))
1742
-
1743
1740
/** TypeBlock ::= {TypeBlockStat semi} Type
1744
1741
*/
1745
1742
def typeBlock (): Tree =
@@ -1752,7 +1749,7 @@ object Parsers {
1752
1749
while in.token == TYPE do tdefs += typeBlockStat()
1753
1750
tdefs.toList
1754
1751
1755
- /** TypeBlockStat ::= ‘type’ {nl} TypeDcl
1752
+ /** TypeBlockStat ::= ‘type’ {nl} TypeDcl
1756
1753
*/
1757
1754
def typeBlockStat (): Tree =
1758
1755
val mods = defAnnotsMods(BitSet ())
@@ -1761,6 +1758,19 @@ object Parsers {
1761
1758
if in.isNewLine then in.nextToken()
1762
1759
tdef
1763
1760
1761
+ /** Quoted ::= ‘'’ ‘{’ Block ‘}’
1762
+ * | ‘'’ ‘[’ TypeBlock ‘]’
1763
+ */
1764
+ def quote (inPattern : Boolean ): Tree =
1765
+ atSpan(in.skipToken()) {
1766
+ withinStaged(StageKind .Quoted | (if (inPattern) StageKind .QuotedPattern else 0 )) {
1767
+ val body =
1768
+ if (in.token == LBRACKET ) inBrackets(typeBlock())
1769
+ else inBraces(block(simplify = true ))
1770
+ Quote (body, Nil )
1771
+ }
1772
+ }
1773
+
1764
1774
/** ExprSplice ::= ‘$’ spliceId -- if inside quoted block
1765
1775
* | ‘$’ ‘{’ Block ‘}’ -- unless inside quoted pattern
1766
1776
* | ‘$’ ‘{’ Pattern ‘}’ -- when inside quoted pattern
@@ -1775,7 +1785,8 @@ object Parsers {
1775
1785
val expr =
1776
1786
if (in.name.length == 1 ) {
1777
1787
in.nextToken()
1778
- withinStaged(StageKind .Spliced )(if (inPattern) inBraces(pattern()) else stagedBlock())
1788
+ val inPattern = (staged & StageKind .QuotedPattern ) != 0
1789
+ withinStaged(StageKind .Spliced )(inBraces(if inPattern then pattern() else block(simplify = true )))
1779
1790
}
1780
1791
else atSpan(in.offset + 1 ) {
1781
1792
val id = Ident (in.name.drop(1 ))
@@ -2498,14 +2509,7 @@ object Parsers {
2498
2509
canApply = false
2499
2510
blockExpr()
2500
2511
case QUOTE =>
2501
- atSpan(in.skipToken()) {
2502
- withinStaged(StageKind .Quoted | (if (location.inPattern) StageKind .QuotedPattern else 0 )) {
2503
- val body =
2504
- if (in.token == LBRACKET ) inBrackets(typeBlock())
2505
- else stagedBlock()
2506
- Quote (body, Nil )
2507
- }
2508
- }
2512
+ quote(location.inPattern)
2509
2513
case NEW =>
2510
2514
canApply = false
2511
2515
newExpr()
0 commit comments