@@ -983,7 +983,7 @@ object Parsers {
983
983
}
984
984
else
985
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 ))
986
+ if ! isType && in.token == MATCH then recur(matchClause(t))
987
987
else t
988
988
989
989
recur(first)
@@ -1027,8 +1027,7 @@ object Parsers {
1027
1027
/** Accept identifier or match clause acting as a selector on given tree `t` */
1028
1028
def selector (t : Tree ): Tree =
1029
1029
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())
1032
1031
}
1033
1032
1034
1033
/** Selectors ::= id { `.' id }
@@ -1736,11 +1735,10 @@ object Parsers {
1736
1735
* | HkTypeParamClause ‘=>’ Expr
1737
1736
* | [SimpleExpr `.'] id `=' Expr
1738
1737
* | SimpleExpr1 ArgumentExprs `=' Expr
1739
- * | Expr2
1740
- * | [ ‘inline’] Expr2 `match' (`{' CaseClauses `}' | CaseClause)
1738
+ * | PostfixExpr [Ascription]
1739
+ * | ‘inline’ InfixExpr MatchClause
1741
1740
* Bindings ::= `(' [Binding {`,' Binding}] `)'
1742
1741
* Binding ::= (id | `_') [`:' Type]
1743
- * Expr2 ::= PostfixExpr [Ascription]
1744
1742
* Ascription ::= `:' InfixType
1745
1743
* | `:' Annotation {Annotation}
1746
1744
* | `:' `_' `*'
@@ -1779,7 +1777,7 @@ object Parsers {
1779
1777
}
1780
1778
}
1781
1779
1782
- def expr1 (location : Location .Value = Location .ElseWhere ): Tree = in.token match {
1780
+ def expr1 (location : Location .Value = Location .ElseWhere ): Tree = in.token match
1783
1781
case IF =>
1784
1782
in.endMarkerScope(IF ) { ifExpr(in.offset, If ) }
1785
1783
case WHILE =>
@@ -1876,7 +1874,7 @@ object Parsers {
1876
1874
}
1877
1875
}
1878
1876
case _ =>
1879
- if isIdent(nme.inline) // TODO: drop this clause
1877
+ if isIdent(nme.inline)
1880
1878
&& ! in.inModifierPosition()
1881
1879
&& in.lookaheadIn(in.canStartExprTokens)
1882
1880
then
@@ -1885,13 +1883,14 @@ object Parsers {
1885
1883
case IF =>
1886
1884
ifExpr(start, InlineIf )
1887
1885
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
1893
1892
else expr1Rest(postfixExpr(), location)
1894
- }
1893
+ end expr1
1895
1894
1896
1895
def expr1Rest (t : Tree , location : Location .Value ): Tree = in.token match
1897
1896
case EQUALS =>
@@ -1933,14 +1932,11 @@ object Parsers {
1933
1932
}
1934
1933
}
1935
1934
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]
1938
1937
*/
1939
- def ifExpr (start : Offset , mkIf0 : (Tree , Tree , Tree ) => If ): If =
1938
+ def ifExpr (start : Offset , mkIf : (Tree , Tree , Tree ) => If ): If =
1940
1939
atSpan(start, in.skipToken()) {
1941
- val mkIf =
1942
- if isIdent(nme.inline) then { in.nextToken(); InlineIf }
1943
- else mkIf0
1944
1940
val cond = condExpr(THEN )
1945
1941
newLinesOpt()
1946
1942
val thenp = subExpr()
@@ -1951,13 +1947,10 @@ object Parsers {
1951
1947
1952
1948
/** MatchClause ::= `match' [‘inline’] `{' CaseClauses `}'
1953
1949
*/
1954
- def matchClause (t : Tree , start : Offset , mkMatch0 : ( Tree , List [ CaseDef ]) => Match ) =
1950
+ def matchClause (t : Tree ) : Match =
1955
1951
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)))
1961
1954
}
1962
1955
}
1963
1956
0 commit comments