summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2007-08-20 10:57:43 +0000
committerMartin Odersky <odersky@gmail.com>2007-08-20 10:57:43 +0000
commit102aadc5f56f6f297b8643563eeb49557e36dd41 (patch)
treed5be00898604457f1145e2a44bbbcf6c005fbe90 /src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
parent5eadca1408d20df1484459309206f97aefc1688d (diff)
downloadscala-102aadc5f56f6f297b8643563eeb49557e36dd41.tar.gz
scala-102aadc5f56f6f297b8643563eeb49557e36dd41.tar.bz2
scala-102aadc5f56f6f297b8643563eeb49557e36dd41.zip
fixed some bugs related to existentials.
fixed unboxing bug fixed ByNameFunction problem some cleanups in parser
Diffstat (limited to 'src/compiler/scala/tools/nsc/ast/parser/Parsers.scala')
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala66
1 files changed, 34 insertions, 32 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index 5c2ff33243..88ab6bae1c 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -652,24 +652,24 @@ trait Parsers {
/** Types ::= Type {`,' Type}
* (also eats trailing comma if it finds one)
*/
- def types(isPattern: Boolean): List[Tree] = {
- val ts = new ListBuffer[Tree] + argType(isPattern)
+ def types(isPattern: Boolean, isTypeApply: Boolean): List[Tree] = {
+ val ts = new ListBuffer[Tree] + argType(isPattern, isTypeApply)
while (inToken == COMMA) {
inNextToken
if (inToken == RPAREN) {
in.deprecationWarning(in.pos, "Trailing commas have been deprecated")
return ts.toList
} else {
- ts += argType(isPattern)
+ ts += argType(isPattern, isTypeApply)
}
}
ts.toList
}
/** modes for infix types */
- private final val FirstOp = 0 // first operand
- private final val LeftOp = 1 // left associative
- private final val RightOp = 2 // right associative
+ object InfixMode extends Enumeration {
+ val FirstOp, LeftOp, RightOp = Value
+ }
/** Type ::= InfixType `=>' Type
* | `(' [`=>' Type] `)' `=>' Type
@@ -691,13 +691,13 @@ trait Parsers {
accept(RPAREN)
atPos(accept(ARROW)) { makeByNameFunctionTypeTree(t0, typ()) }
} else {
- val ts = types(false)
+ val ts = types(false, false)
accept(RPAREN)
if (inToken == ARROW) atPos(inSkipToken) { makeFunctionTypeTree(ts, typ()) }
- else infixTypeRest(pos, annotTypeRest(pos, false, makeTupleType(ts, true)), false, FirstOp)
+ else infixTypeRest(pos, annotTypeRest(pos, false, makeTupleType(ts, true)), false, InfixMode.FirstOp)
}
} else {
- infixType(false, FirstOp)
+ infixType(false, InfixMode.FirstOp)
}
if (inToken == ARROW)
atPos(inSkipToken) {
@@ -721,26 +721,26 @@ trait Parsers {
/** InfixType ::= CompoundType {id [nl] CompoundType}
*/
- def infixType(isPattern: Boolean, mode: Int): Tree =
+ def infixType(isPattern: Boolean, mode: InfixMode.Value): Tree =
infixTypeRest(inCurrentPos, infixTypeFirst(isPattern), isPattern, mode)
- def infixTypeFirst(isPattern: boolean) =
+ def infixTypeFirst(isPattern: Boolean) =
if (inToken == LBRACE) scalaAnyRefConstr else annotType(isPattern)
- def infixTypeRest(pos: ScanPosition, t0: Tree, isPattern: Boolean, mode: Int): Tree = {
+ def infixTypeRest(pos: ScanPosition, t0: Tree, isPattern: Boolean, mode: InfixMode.Value): Tree = {
val t = compoundTypeRest(pos, t0, isPattern)
if (isIdent && inName != nme.STAR) {
val opPos = inCurrentPos
val leftAssoc = treeInfo.isLeftAssoc(inName)
- if (mode == LeftOp) checkAssoc(opPos, inName, true)
- else if (mode == RightOp) checkAssoc(opPos, inName, false)
+ if (mode == InfixMode.LeftOp) checkAssoc(opPos, inName, true)
+ else if (mode == InfixMode.RightOp) checkAssoc(opPos, inName, false)
val op = ident()
newLineOptWhenFollowing(isTypeIntroToken)
def mkOp(t1: Tree) = atPos(opPos) { AppliedTypeTree(Ident(op.toTypeName), List(t, t1)) }
if (leftAssoc)
- infixTypeRest(inCurrentPos, mkOp(compoundType(isPattern)), isPattern, LeftOp)
+ infixTypeRest(inCurrentPos, mkOp(compoundType(isPattern)), isPattern, InfixMode.LeftOp)
else
- mkOp(infixType(isPattern, RightOp))
+ mkOp(infixType(isPattern, InfixMode.RightOp))
} else t
}
@@ -757,9 +757,10 @@ trait Parsers {
}
newLineOptWhenFollowedBy(LBRACE)
atPos(pos) {
- if (inToken == LBRACE && !isPattern)
+ if (inToken == LBRACE)
CompoundTypeTree(Template(ts.toList, emptyValDef, refinement()))
- else makeIntersectionTypeTree(ts.toList)
+ else
+ makeIntersectionTypeTree(ts.toList)
}
}
@@ -778,7 +779,7 @@ trait Parsers {
val t: Tree = annotTypeRest(pos, isPattern,
if (inToken == LPAREN) {
inNextToken
- val ts = types(isPattern)
+ val ts = types(isPattern, false)
accept(RPAREN)
atPos(pos) { makeTupleType(ts, true) }
} else if (inToken == USCORE) {
@@ -800,7 +801,7 @@ trait Parsers {
if (inToken == HASH)
annotTypeRest(pos, isPattern, atPos(inSkipToken) { SelectFromTypeTree(t, ident().toTypeName) })
else if (inToken == LBRACKET)
- annotTypeRest(pos, isPattern, atPos(pos) { AppliedTypeTree(t, typeArgs(isPattern)) })
+ annotTypeRest(pos, isPattern, atPos(pos) { AppliedTypeTree(t, typeArgs(isPattern, false)) })
else
t
@@ -814,20 +815,17 @@ trait Parsers {
}
/** TypeArgs ::= `[' ArgType {`,' ArgType} `]'
- * TypePatArgs ::= `[' TypePatArg {`,' TypePatArg} `]'
*/
- def typeArgs(isPattern: Boolean): List[Tree] = {
+ def typeArgs(isPattern: Boolean, isTypeApply: Boolean): List[Tree] = {
accept(LBRACKET)
- val ts = types(isPattern)
+ val ts = types(isPattern, isTypeApply)
accept(RBRACKET)
ts
}
/** ArgType ::= Type
- * TypePatArg ::= `_'
- * | varid
*/
- def argType(isPattern: Boolean): Tree =
+ def argType(isPattern: Boolean, isTypeApply: Boolean): Tree =
if (isPattern) {
if (inToken == USCORE)
if (inToken == SUBTYPE || inToken == SUPERTYPE) wildcardType(inSkipToken)
@@ -839,7 +837,11 @@ trait Parsers {
else {
typ()
}
- } else typ()
+ } else if (isTypeApply) {
+ placeholderTypeBoundary(typ())
+ } else {
+ typ()
+ }
//////// EXPRESSIONS ////////////////////////////////////////////////////////
@@ -1195,7 +1197,7 @@ trait Parsers {
val t1 = stripParens(t)
t1 match {
case Ident(_) | Select(_, _) =>
- simpleExprRest(atPos(inCurrentPos) { TypeApply(t1, typeArgs(false)) }, true)
+ simpleExprRest(atPos(inCurrentPos) { TypeApply(t1, typeArgs(false, true)) }, true)
case _ =>
t1
}
@@ -1412,14 +1414,14 @@ trait Parsers {
* | `_'
* | literal
* | XmlPattern
- * | StableId [TypePatArgs] [`(' [SeqPatterns [`,']] `)']
+ * | StableId [TypeArgs] [`(' [SeqPatterns [`,']] `)']
* | `(' [Patterns [`,']] `)'
* SimpleSeqPattern ::= varid
* | `_'
* | literal
* | XmlPattern
* | `<' xLiteralPattern
- * | StableId [TypePatArgs] [`(' [SeqPatterns [`,']] `)']
+ * | StableId [TypeArgs] [`(' [SeqPatterns [`,']] `)']
* | `(' [SeqPatterns [`,']] `)'
*
* XXX: Hook for IDE
@@ -1439,7 +1441,7 @@ trait Parsers {
/* not yet
if (inToken == LBRACKET)
atPos(inCurrentPos) {
- val ts = typeArgs(true)
+ val ts = typeArgs(true, false)
accept(LPAREN)
val ps = if (inToken == RPAREN) List() else patterns(true, false)
accept(RPAREN)
@@ -1622,7 +1624,7 @@ trait Parsers {
val pos = inCurrentPos
var t: Tree = convertToTypeId(stableId())
if (inToken == LBRACKET)
- t = atPos(inCurrentPos)(AppliedTypeTree(t, typeArgs(false)))
+ t = atPos(inCurrentPos)(AppliedTypeTree(t, typeArgs(false, false)))
val args = if (inToken == LPAREN) argumentExprs() else List()
newLineOptWhenFollowedBy(LBRACE)
val nameValuePairs: List[Tree] = if (inToken == LBRACE) {