Skip to content

Commit 8f37686

Browse files
oderskynicolasstucki
authored andcommitted
Quote patterns: syntax and parsing
1 parent 72883e9 commit 8f37686

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,9 +1478,8 @@ object Parsers {
14781478

14791479
/** SimpleExpr ::= ‘new’ (ConstrApp [TemplateBody] | TemplateBody)
14801480
* | BlockExpr
1481-
* | ‘'’ ‘{’ Block ‘}’
1482-
* | ‘'’ ‘[’ Type ‘]’
14831481
* | ‘$’ ‘{’ Block ‘}’
1482+
* | Quoted
14841483
* | quoteId
14851484
* | SimpleExpr1 [`_']
14861485
* SimpleExpr1 ::= literal
@@ -1490,6 +1489,8 @@ object Parsers {
14901489
* | SimpleExpr `.' id
14911490
* | SimpleExpr (TypeArgs | NamedTypeArgs)
14921491
* | SimpleExpr1 ArgumentExprs
1492+
* Quoted ::= ‘'’ ‘{’ Block ‘}’
1493+
* | ‘'’ ‘[’ Type ‘]’
14931494
*/
14941495
def simpleExpr(): Tree = {
14951496
var canApply = true
@@ -1827,6 +1828,7 @@ object Parsers {
18271828

18281829
/** SimplePattern ::= PatVar
18291830
* | Literal
1831+
* | Quoted
18301832
* | XmlPattern
18311833
* | `(' [Patterns] `)'
18321834
* | SimplePattern1 [TypeArgs] [ArgumentPatterns]
@@ -1853,6 +1855,8 @@ object Parsers {
18531855
} else wildIndent
18541856
case LPAREN =>
18551857
atSpan(in.offset) { makeTupleOrParens(inParens(patternsOpt())) }
1858+
case QUOTE =>
1859+
simpleExpr()
18561860
case XMLSTART =>
18571861
xmlLiteralPattern()
18581862
case _ =>

docs/docs/internals/syntax.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,8 @@ InfixExpr ::= PrefixExpr
209209
PrefixExpr ::= [‘-’ | ‘+’ | ‘~’ | ‘!’] SimpleExpr PrefixOp(expr, op)
210210
SimpleExpr ::= ‘new’ (ConstrApp [TemplateBody] | TemplateBody) New(constr | templ)
211211
| BlockExpr
212-
| ‘'’ ‘{’ Block ‘}’
213-
| ‘'’ ‘[’ Type ‘]’
214212
| ‘$’ ‘{’ Block ‘}’
213+
| Quoted
215214
| quoteId // only inside splices
216215
| SimpleExpr1 [‘_’] PostfixOp(expr, _)
217216
SimpleExpr1 ::= Literal
@@ -222,6 +221,8 @@ SimpleExpr1 ::= Literal
222221
| SimpleExpr (TypeArgs | NamedTypeArgs) TypeApply(expr, args)
223222
| SimpleExpr1 ArgumentExprs Apply(expr, args)
224223
| XmlExpr
224+
Quoted ::= ‘'’ ‘{’ Block ‘}’
225+
| ‘'’ ‘[’ Type ‘]’
225226
ExprsInParens ::= ExprInParens {‘,’ ExprInParens}
226227
ExprInParens ::= PostfixExpr ‘:’ Type
227228
| Expr
@@ -261,6 +262,7 @@ InfixPattern ::= SimplePattern { id [nl] SimplePattern }
261262
SimplePattern ::= PatVar Ident(wildcard)
262263
| Literal Bind(name, Ident(wildcard))
263264
| ‘(’ [Patterns] ‘)’ Parens(pats) Tuple(pats)
265+
| Quoted
264266
| XmlPattern
265267
| SimplePattern1 [TypeArgs] [ArgumentPatterns]
266268
SimplePattern1 ::= Path

0 commit comments

Comments
 (0)