@@ -52,6 +52,9 @@ object Parsers {
5252 enum ParamOwner :
5353 case Class , Type , TypeParam , Def
5454
55+ enum ParseKind :
56+ case Expr , Type , Pattern
57+
5558 type StageKind = Int
5659 object StageKind {
5760 val None = 0
@@ -939,18 +942,19 @@ object Parsers {
939942 def infixOps (
940943 first : Tree , canStartOperand : Token => Boolean , operand : Location => Tree ,
941944 location : Location ,
942- isType : Boolean ,
943- isOperator : => Boolean ,
944- maybePostfix : Boolean = false ): Tree = {
945+ kind : ParseKind ,
946+ isOperator : => Boolean ): Tree =
945947 val base = opStack
946948
947949 def recur (top : Tree ): Tree =
950+ val isType = kind == ParseKind .Type
948951 if (isIdent && isOperator) {
949- val op = if ( isType) typeIdent() else termIdent()
952+ val op = if isType then typeIdent() else termIdent()
950953 val top1 = reduceStack(base, top, precedence(op.name), ! op.name.isRightAssocOperatorName, op.name, isType)
951954 opStack = OpInfo (top1, op, in.offset) :: opStack
952955 colonAtEOLOpt()
953956 newLineOptWhenFollowing(canStartOperand)
957+ val maybePostfix = kind == ParseKind .Expr && in.postfixOpsEnabled
954958 if (maybePostfix && ! canStartOperand(in.token)) {
955959 val topInfo = opStack.head
956960 opStack = opStack.tail
@@ -973,7 +977,7 @@ object Parsers {
973977 else top
974978
975979 recur(first)
976- }
980+ end infixOps
977981
978982/* -------- IDENTIFIERS AND LITERALS ------------------------------------------- */
979983
@@ -1525,8 +1529,7 @@ object Parsers {
15251529 def infixType (): Tree = infixTypeRest(refinedType())
15261530
15271531 def infixTypeRest (t : Tree ): Tree =
1528- infixOps(t, canStartTypeTokens, refinedTypeFn, Location .ElseWhere ,
1529- isType = true ,
1532+ infixOps(t, canStartTypeTokens, refinedTypeFn, Location .ElseWhere , ParseKind .Type ,
15301533 isOperator = ! followingIsVararg())
15311534
15321535 /** RefinedType ::= WithType {[nl] Refinement}
@@ -2218,10 +2221,8 @@ object Parsers {
22182221 t
22192222
22202223 def postfixExprRest (t : Tree , location : Location ): Tree =
2221- infixOps(t, in.canStartExprTokens, prefixExpr, location,
2222- isType = false ,
2223- isOperator = ! (location.inArgs && followingIsVararg()),
2224- maybePostfix = true )
2224+ infixOps(t, in.canStartExprTokens, prefixExpr, location, ParseKind .Expr ,
2225+ isOperator = ! (location.inArgs && followingIsVararg()))
22252226
22262227 /** PrefixExpr ::= [PrefixOperator'] SimpleExpr
22272228 * PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’
@@ -2708,8 +2709,8 @@ object Parsers {
27082709 /** InfixPattern ::= SimplePattern {id [nl] SimplePattern}
27092710 */
27102711 def infixPattern (): Tree =
2711- infixOps(simplePattern(), in.canStartExprTokens, simplePatternFn, Location . InPattern ,
2712- isType = false ,
2712+ infixOps(
2713+ simplePattern(), in.canStartExprTokens, simplePatternFn, Location . InPattern , ParseKind . Pattern ,
27132714 isOperator = in.name != nme.raw.BAR && ! followingIsVararg())
27142715
27152716 /** SimplePattern ::= PatVar
0 commit comments