@@ -20,6 +20,7 @@ import StdNames._
2020import util .Positions ._
2121import Constants ._
2222import ScriptParsers ._
23+ import Decorators ._
2324import scala .annotation .{tailrec , switch }
2425import rewrites .Rewrites .patch
2526
@@ -1127,7 +1128,8 @@ object Parsers {
11271128 val start = in.offset
11281129 if (in.token == IMPLICIT || in.token == ERASED ) {
11291130 val imods = modifiers(funArgMods)
1130- implicitClosure(start, location, imods)
1131+ if (in.token == MATCH ) implicitMatch(start, imods)
1132+ else implicitClosure(start, location, imods)
11311133 } else {
11321134 val saved = placeholderParams
11331135 placeholderParams = Nil
@@ -1207,7 +1209,21 @@ object Parsers {
12071209 case FOR =>
12081210 forExpr()
12091211 case _ =>
1210- expr1Rest(postfixExpr(), location)
1212+ if (isIdent(nme.inline) && ! in.inModifierPosition() && in.lookaheadIn(canStartExpressionTokens)) {
1213+ val start = in.skipToken()
1214+ in.token match {
1215+ case IF =>
1216+ ifExpr(start, InlineIf )
1217+ case _ =>
1218+ val t = postfixExpr()
1219+ if (in.token == MATCH ) matchExpr(t, start, InlineMatch )
1220+ else {
1221+ syntaxErrorOrIncomplete(i " `match` or `if` expected but ${in.token} found " )
1222+ t
1223+ }
1224+ }
1225+ }
1226+ else expr1Rest(postfixExpr(), location)
12111227 }
12121228
12131229 def expr1Rest (t : Tree , location : Location .Value ): Tree = in.token match {
@@ -1221,7 +1237,7 @@ object Parsers {
12211237 case COLON =>
12221238 ascription(t, location)
12231239 case MATCH =>
1224- matchExpr(t, startOffset(t))
1240+ matchExpr(t, startOffset(t), Match )
12251241 case _ =>
12261242 t
12271243 }
@@ -1266,13 +1282,36 @@ object Parsers {
12661282 }
12671283
12681284 /** `match' { CaseClauses }
1269- * `match' { ImplicitCaseClauses }
12701285 */
1271- def matchExpr (t : Tree , start : Offset ) : Match =
1286+ def matchExpr (t : Tree , start : Offset , mkMatch : ( Tree , List [ CaseDef ]) => Match ) =
12721287 atPos(start, in.skipToken()) {
1273- inBraces(Match (t, caseClauses(caseClause)))
1288+ inBraces(mkMatch (t, caseClauses(caseClause)))
12741289 }
12751290
1291+ /** `match' { ImplicitCaseClauses }
1292+ */
1293+ def implicitMatch (start : Int , imods : Modifiers ) = {
1294+ def markFirstIllegal (mods : List [Mod ]) = mods match {
1295+ case mod :: _ => syntaxError(em " illegal modifier for implicit match " , mod.pos)
1296+ case _ =>
1297+ }
1298+ imods.mods match {
1299+ case Mod .Implicit () :: mods => markFirstIllegal(mods)
1300+ case mods => markFirstIllegal(mods)
1301+ }
1302+ val result @ Match (t, cases) =
1303+ matchExpr(EmptyTree , start, InlineMatch )
1304+ for (CaseDef (pat, _, _) <- cases) {
1305+ def isImplicitPattern (pat : Tree ) = pat match {
1306+ case Typed (pat1, _) => isVarPattern(pat1)
1307+ case pat => isVarPattern(pat)
1308+ }
1309+ if (! isImplicitPattern(pat))
1310+ syntaxError(em " not a legal pattern for an implicit match " , pat.pos)
1311+ }
1312+ result
1313+ }
1314+
12761315 /** `match' { TypeCaseClauses }
12771316 */
12781317 def matchType (bound : Tree , t : Tree ): MatchTypeTree =
@@ -2620,6 +2659,8 @@ object Parsers {
26202659 var imods = modifiers(funArgMods)
26212660 if (isBindingIntro)
26222661 stats += implicitClosure(start, Location .InBlock , imods)
2662+ else if (in.token == MATCH )
2663+ stats += implicitMatch(start, imods)
26232664 else
26242665 stats +++= localDef(start, imods)
26252666 } else {
0 commit comments