@@ -951,7 +951,7 @@ object Parsers {
951951 recur(top)
952952 }
953953
954- /** operand { infixop operand | ‘given’ (operand | ParArgumentExprs) } [postfixop],
954+ /** operand { infixop operand | MatchClause } [postfixop],
955955 *
956956 * respecting rules of associativity and precedence.
957957 * @param isOperator the current token counts as an operator.
@@ -981,18 +981,14 @@ object Parsers {
981981 }
982982 else recur(operand())
983983 }
984- else reduceStack(base, top, minPrec, leftAssoc = true , in.name, isType)
984+ else
985+ val t = reduceStack(base, top, minPrec, leftAssoc = true , in.name, isType)
986+ if ! isType && in.token == MATCH then recur(matchClause(t, t.span.start, Match ))
987+ else t
985988
986989 recur(first)
987990 }
988991
989- def applyGiven (t : Tree , operand : () => Tree ): Tree =
990- atSpan(startOffset(t), in.offset) {
991- in.nextToken()
992- val args = if (in.token == LPAREN ) parArgumentExprs()._1 else operand() :: Nil
993- Apply (t, args)
994- }.setGivenApply()
995-
996992/* -------- IDENTIFIERS AND LITERALS ------------------------------------------- */
997993
998994 /** Accept identifier and return its name as a term name. */
@@ -1028,9 +1024,12 @@ object Parsers {
10281024 def wildcardIdent (): Ident =
10291025 atSpan(accept(USCORE )) { Ident (nme.WILDCARD ) }
10301026
1031- /** Accept identifier acting as a selector on given tree `t`. */
1027+ /** Accept identifier or match clause acting as a selector on given tree `t` */
10321028 def selector (t : Tree ): Tree =
1033- atSpan(startOffset(t), in.offset) { Select (t, ident()) }
1029+ atSpan(startOffset(t), in.offset) {
1030+ if in.token == MATCH then matchClause(t, t.span.start, Match )
1031+ else Select (t, ident())
1032+ }
10341033
10351034 /** Selectors ::= id { `.' id }
10361035 *
@@ -1877,7 +1876,7 @@ object Parsers {
18771876 }
18781877 }
18791878 case _ =>
1880- if isIdent(nme.inline)
1879+ if isIdent(nme.inline) // TODO: drop this clause
18811880 && ! in.inModifierPosition()
18821881 && in.lookaheadIn(in.canStartExprTokens)
18831882 then
@@ -1886,31 +1885,27 @@ object Parsers {
18861885 case IF =>
18871886 ifExpr(start, InlineIf )
18881887 case _ =>
1889- val t = postfixExpr ()
1890- if (in.token == MATCH ) matchExpr (t, start, InlineMatch )
1888+ val t = prefixExpr ()
1889+ if (in.token == MATCH ) matchClause (t, start, InlineMatch )
18911890 else
1892- syntaxErrorOrIncomplete(i " `match` or `if` expected but ${in.token } found " )
1891+ syntaxErrorOrIncomplete(i " `match` or `if` expected but ${in} found " )
18931892 t
18941893 else expr1Rest(postfixExpr(), location)
18951894 }
18961895
1897- def expr1Rest (t : Tree , location : Location .Value ): Tree = in.token match {
1896+ def expr1Rest (t : Tree , location : Location .Value ): Tree = in.token match
18981897 case EQUALS =>
1899- t match {
1900- case Ident (_) | Select (_, _) | Apply (_, _) =>
1901- atSpan(startOffset(t), in.skipToken()) { Assign (t, subExpr()) }
1902- case _ =>
1903- t
1904- }
1898+ t match
1899+ case Ident (_) | Select (_, _) | Apply (_, _) =>
1900+ atSpan(startOffset(t), in.skipToken()) { Assign (t, subExpr()) }
1901+ case _ =>
1902+ t
19051903 case COLON =>
19061904 in.nextToken()
1907- val t1 = ascription(t, location)
1908- if (in.token == MATCH ) expr1Rest(t1, location) else t1
1909- case MATCH =>
1910- matchExpr(t, startOffset(t), Match )
1905+ ascription(t, location)
19111906 case _ =>
19121907 t
1913- }
1908+ end expr1Rest
19141909
19151910 def ascription (t : Tree , location : Location .Value ): Tree = atSpan(startOffset(t)) {
19161911 in.token match {
@@ -1938,11 +1933,14 @@ object Parsers {
19381933 }
19391934 }
19401935
1941- /** `if' `(' Expr `)' {nl} Expr [[semi] else Expr]
1942- * `if' Expr `then' Expr [[semi] else Expr]
1936+ /** `if' [‘inline’] `(' Expr `)' {nl} Expr [[semi] else Expr]
1937+ * `if' [‘inline’] Expr `then' Expr [[semi] else Expr]
19431938 */
1944- def ifExpr (start : Offset , mkIf : (Tree , Tree , Tree ) => If ): If =
1939+ def ifExpr (start : Offset , mkIf0 : (Tree , Tree , Tree ) => If ): If =
19451940 atSpan(start, in.skipToken()) {
1941+ val mkIf =
1942+ if isIdent(nme.inline) then { in.nextToken(); InlineIf }
1943+ else mkIf0
19461944 val cond = condExpr(THEN )
19471945 newLinesOpt()
19481946 val thenp = subExpr()
@@ -1951,11 +1949,14 @@ object Parsers {
19511949 mkIf(cond, thenp, elsep)
19521950 }
19531951
1954- /** `match' `{' CaseClauses `}'
1952+ /** MatchClause ::= `match' [‘inline’] `{' CaseClauses `}'
19551953 */
1956- def matchExpr (t : Tree , start : Offset , mkMatch : (Tree , List [CaseDef ]) => Match ) =
1954+ def matchClause (t : Tree , start : Offset , mkMatch0 : (Tree , List [CaseDef ]) => Match ) =
19571955 in.endMarkerScope(MATCH ) {
19581956 atSpan(start, in.skipToken()) {
1957+ val mkMatch =
1958+ if isIdent(nme.inline) then { in.nextToken(); InlineMatch }
1959+ else mkMatch0
19591960 mkMatch(t, inBracesOrIndented(caseClauses(caseClause)))
19601961 }
19611962 }
@@ -2032,7 +2033,7 @@ object Parsers {
20322033 /** PostfixExpr ::= InfixExpr [id [nl]]
20332034 * InfixExpr ::= PrefixExpr
20342035 * | InfixExpr id [nl] InfixExpr
2035- * | InfixExpr ‘given’ (InfixExpr | ParArgumentExprs)
2036+ * | InfixExpr MatchClause
20362037 */
20372038 def postfixExpr (): Tree = postfixExprRest(prefixExpr())
20382039
@@ -2063,6 +2064,7 @@ object Parsers {
20632064 * | Path
20642065 * | `(' [ExprsInParens] `)'
20652066 * | SimpleExpr `.' id
2067+ * | SimpleExpr `.' MatchClause
20662068 * | SimpleExpr (TypeArgs | NamedTypeArgs)
20672069 * | SimpleExpr1 ArgumentExprs
20682070 * Quoted ::= ‘'’ ‘{’ Block ‘}’
0 commit comments