@@ -983,7 +983,7 @@ object Parsers {
983983 }
984984 else
985985 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 ))
986+ if ! isType && in.token == MATCH then recur(matchClause(t))
987987 else t
988988
989989 recur(first)
@@ -1027,8 +1027,7 @@ object Parsers {
10271027 /** Accept identifier or match clause acting as a selector on given tree `t` */
10281028 def selector (t : Tree ): Tree =
10291029 atSpan(startOffset(t), in.offset) {
1030- if in.token == MATCH then matchClause(t, t.span.start, Match )
1031- else Select (t, ident())
1030+ if in.token == MATCH then matchClause(t) else Select (t, ident())
10321031 }
10331032
10341033 /** Selectors ::= id { `.' id }
@@ -1736,11 +1735,10 @@ object Parsers {
17361735 * | HkTypeParamClause ‘=>’ Expr
17371736 * | [SimpleExpr `.'] id `=' Expr
17381737 * | SimpleExpr1 ArgumentExprs `=' Expr
1739- * | Expr2
1740- * | [ ‘inline’] Expr2 `match' (`{' CaseClauses `}' | CaseClause)
1738+ * | PostfixExpr [Ascription]
1739+ * | ‘inline’ InfixExpr MatchClause
17411740 * Bindings ::= `(' [Binding {`,' Binding}] `)'
17421741 * Binding ::= (id | `_') [`:' Type]
1743- * Expr2 ::= PostfixExpr [Ascription]
17441742 * Ascription ::= `:' InfixType
17451743 * | `:' Annotation {Annotation}
17461744 * | `:' `_' `*'
@@ -1779,7 +1777,7 @@ object Parsers {
17791777 }
17801778 }
17811779
1782- def expr1 (location : Location .Value = Location .ElseWhere ): Tree = in.token match {
1780+ def expr1 (location : Location .Value = Location .ElseWhere ): Tree = in.token match
17831781 case IF =>
17841782 in.endMarkerScope(IF ) { ifExpr(in.offset, If ) }
17851783 case WHILE =>
@@ -1876,7 +1874,7 @@ object Parsers {
18761874 }
18771875 }
18781876 case _ =>
1879- if isIdent(nme.inline) // TODO: drop this clause
1877+ if isIdent(nme.inline)
18801878 && ! in.inModifierPosition()
18811879 && in.lookaheadIn(in.canStartExprTokens)
18821880 then
@@ -1885,13 +1883,14 @@ object Parsers {
18851883 case IF =>
18861884 ifExpr(start, InlineIf )
18871885 case _ =>
1888- val t = prefixExpr()
1889- if (in.token == MATCH ) matchClause(t, start, InlineMatch )
1890- else
1891- syntaxErrorOrIncomplete(i " `match` or `if` expected but ${in} found " )
1892- t
1886+ postfixExpr() match
1887+ case t @ Match (scrut, cases) =>
1888+ InlineMatch (scrut, cases).withSpan(t.span)
1889+ case t =>
1890+ syntaxError(em " `inline` must be followed by an `if` or a `match` " , start)
1891+ t
18931892 else expr1Rest(postfixExpr(), location)
1894- }
1893+ end expr1
18951894
18961895 def expr1Rest (t : Tree , location : Location .Value ): Tree = in.token match
18971896 case EQUALS =>
@@ -1933,14 +1932,11 @@ object Parsers {
19331932 }
19341933 }
19351934
1936- /** `if' [‘inline’] `(' Expr `)' {nl} Expr [[semi] else Expr]
1937- * `if' [‘inline’] Expr `then' Expr [[semi] else Expr]
1935+ /** `if' `(' Expr `)' {nl} Expr [[semi] else Expr]
1936+ * `if' Expr `then' Expr [[semi] else Expr]
19381937 */
1939- def ifExpr (start : Offset , mkIf0 : (Tree , Tree , Tree ) => If ): If =
1938+ def ifExpr (start : Offset , mkIf : (Tree , Tree , Tree ) => If ): If =
19401939 atSpan(start, in.skipToken()) {
1941- val mkIf =
1942- if isIdent(nme.inline) then { in.nextToken(); InlineIf }
1943- else mkIf0
19441940 val cond = condExpr(THEN )
19451941 newLinesOpt()
19461942 val thenp = subExpr()
@@ -1951,13 +1947,10 @@ object Parsers {
19511947
19521948 /** MatchClause ::= `match' [‘inline’] `{' CaseClauses `}'
19531949 */
1954- def matchClause (t : Tree , start : Offset , mkMatch0 : ( Tree , List [ CaseDef ]) => Match ) =
1950+ def matchClause (t : Tree ) : Match =
19551951 in.endMarkerScope(MATCH ) {
1956- atSpan(start, in.skipToken()) {
1957- val mkMatch =
1958- if isIdent(nme.inline) then { in.nextToken(); InlineMatch }
1959- else mkMatch0
1960- mkMatch(t, inBracesOrIndented(caseClauses(caseClause)))
1952+ atSpan(t.span.start, in.skipToken()) {
1953+ Match (t, inBracesOrIndented(caseClauses(caseClause)))
19611954 }
19621955 }
19631956
0 commit comments