aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/parsing/Parsers.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-11-17 18:35:08 +0100
committerMartin Odersky <odersky@gmail.com>2016-11-24 16:43:59 +0100
commit18eea6b3159e8caaffc1e415ce69301b64d566d4 (patch)
tree7bcee19a189ca2f08a63d630631b2f53c5f1af15 /compiler/src/dotty/tools/dotc/parsing/Parsers.scala
parent40c1913dd539beb4b6184b37d87e48d98803a465 (diff)
downloaddotty-18eea6b3159e8caaffc1e415ce69301b64d566d4.tar.gz
dotty-18eea6b3159e8caaffc1e415ce69301b64d566d4.tar.bz2
dotty-18eea6b3159e8caaffc1e415ce69301b64d566d4.zip
Rename ...Pos to ...Offset and add pointOffset
Diffstat (limited to 'compiler/src/dotty/tools/dotc/parsing/Parsers.scala')
-rw-r--r--compiler/src/dotty/tools/dotc/parsing/Parsers.scala73
1 files changed, 37 insertions, 36 deletions
diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala
index 838f7514c..51dafc928 100644
--- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala
+++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala
@@ -83,12 +83,13 @@ object Parsers {
def atPos[T <: Positioned](start: Offset)(t: T): T =
atPos(start, start)(t)
- /** Defensive version of Position#start */
- def startPos(t: Positioned): Int =
+ def startOffset(t: Positioned): Int =
if (t.pos.exists) t.pos.start else in.offset
- /** Defensive version of Position#end */
- def endPos(t: Positioned): Int =
+ def pointOffset(t: Positioned): Int =
+ if (t.pos.exists) t.pos.point else in.offset
+
+ def endOffset(t: Positioned): Int =
if (t.pos.exists) t.pos.end else in.lastOffset
def nameStart: Offset =
@@ -456,7 +457,7 @@ object Parsers {
val topInfo = opStack.head
opStack = opStack.tail
val od = reduceStack(base, topInfo.operand, 0, true)
- return atPos(startPos(od), topInfo.offset) {
+ return atPos(startOffset(od), topInfo.offset) {
PostfixOp(od, topInfo.operator)
}
}
@@ -500,7 +501,7 @@ object Parsers {
/** Accept identifier acting as a selector on given tree `t`. */
def selector(t: Tree): Tree =
- atPos(startPos(t), in.offset) { Select(t, ident()) }
+ atPos(startOffset(t), in.offset) { Select(t, ident()) }
/** Selectors ::= ident { `.' ident()
*
@@ -736,7 +737,7 @@ object Parsers {
def refinedTypeRest(t: Tree): Tree = {
newLineOptWhenFollowedBy(LBRACE)
- if (in.token == LBRACE) refinedTypeRest(atPos(startPos(t)) { RefinedTypeTree(t, refinement()) })
+ if (in.token == LBRACE) refinedTypeRest(atPos(startOffset(t)) { RefinedTypeTree(t, refinement()) })
else t
}
@@ -757,7 +758,7 @@ object Parsers {
def annotType(): Tree = annotTypeRest(simpleType())
def annotTypeRest(t: Tree): Tree =
- if (in.token == AT) annotTypeRest(atPos(startPos(t)) { Annotated(t, annot()) })
+ if (in.token == AT) annotTypeRest(atPos(startOffset(t)) { Annotated(t, annot()) })
else t
/** SimpleType ::= SimpleType TypeArgs
@@ -788,19 +789,19 @@ object Parsers {
val handleSingletonType: Tree => Tree = t =>
if (in.token == TYPE) {
in.nextToken()
- atPos(startPos(t)) { SingletonTypeTree(t) }
+ atPos(startOffset(t)) { SingletonTypeTree(t) }
} else t
private def simpleTypeRest(t: Tree): Tree = in.token match {
case HASH => simpleTypeRest(typeProjection(t))
- case LBRACKET => simpleTypeRest(atPos(startPos(t)) { AppliedTypeTree(t, typeArgs(namedOK = true)) })
+ case LBRACKET => simpleTypeRest(atPos(startOffset(t)) { AppliedTypeTree(t, typeArgs(namedOK = true)) })
case _ => t
}
private def typeProjection(t: Tree): Tree = {
accept(HASH)
val id = typeIdent()
- atPos(startPos(t), startPos(id)) { Select(t, id.name) }
+ atPos(startOffset(t), startOffset(id)) { Select(t, id.name) }
}
/** NamedTypeArg ::= id `=' Type
@@ -854,7 +855,7 @@ object Parsers {
val t = toplevelTyp()
if (isIdent(nme.raw.STAR)) {
in.nextToken()
- atPos(startPos(t)) { PostfixOp(t, nme.raw.STAR) }
+ atPos(startOffset(t)) { PostfixOp(t, nme.raw.STAR) }
} else t
}
@@ -979,7 +980,7 @@ object Parsers {
val t = expr1(location)
if (in.token == ARROW) {
placeholderParams = saved
- closureRest(startPos(t), location, convertToParams(t))
+ closureRest(startOffset(t), location, convertToParams(t))
}
else if (isWildcard(t)) {
placeholderParams = placeholderParams ::: saved
@@ -1033,7 +1034,7 @@ object Parsers {
assert(handlerStart != -1)
syntaxError(
new EmptyCatchBlock(body),
- Position(handlerStart, endPos(handler))
+ Position(handlerStart, endOffset(handler))
)
case _ =>
}
@@ -1043,7 +1044,7 @@ object Parsers {
else {
if (handler.isEmpty) warning(
EmptyCatchAndFinallyBlock(body),
- source atPos Position(tryOffset, endPos(body))
+ source atPos Position(tryOffset, endOffset(body))
)
EmptyTree
}
@@ -1065,21 +1066,21 @@ object Parsers {
case EQUALS =>
t match {
case Ident(_) | Select(_, _) | Apply(_, _) =>
- atPos(startPos(t), in.skipToken()) { Assign(t, expr()) }
+ atPos(startOffset(t), in.skipToken()) { Assign(t, expr()) }
case _ =>
t
}
case COLON =>
ascription(t, location)
case MATCH =>
- atPos(startPos(t), in.skipToken()) {
+ atPos(startOffset(t), in.skipToken()) {
inBraces(Match(t, caseClauses()))
}
case _ =>
t
}
- def ascription(t: Tree, location: Location.Value) = atPos(startPos(t), in.skipToken()) {
+ def ascription(t: Tree, location: Location.Value) = atPos(startOffset(t), in.skipToken()) {
in.token match {
case USCORE =>
val uscoreStart = in.skipToken()
@@ -1113,7 +1114,7 @@ object Parsers {
val id = termIdent()
val paramExpr =
if (location == Location.InBlock && in.token == COLON)
- atPos(startPos(id), in.skipToken()) { Typed(id, infixType()) }
+ atPos(startOffset(id), in.skipToken()) { Typed(id, infixType()) }
else
id
closureRest(start, location, convertToParam(paramExpr, mods) :: Nil)
@@ -1202,13 +1203,13 @@ object Parsers {
in.nextToken()
simpleExprRest(selector(t), canApply = true)
case LBRACKET =>
- val tapp = atPos(startPos(t), in.offset) { TypeApply(t, typeArgs(namedOK = true)) }
+ val tapp = atPos(startOffset(t), in.offset) { TypeApply(t, typeArgs(namedOK = true)) }
simpleExprRest(tapp, canApply = true)
case LPAREN | LBRACE if canApply =>
- val app = atPos(startPos(t), in.offset) { Apply(t, argumentExprs()) }
+ val app = atPos(startOffset(t), in.offset) { Apply(t, argumentExprs()) }
simpleExprRest(app, canApply = true)
case USCORE =>
- atPos(startPos(t), in.skipToken()) { PostfixOp(t, nme.WILDCARD) }
+ atPos(startOffset(t), in.skipToken()) { PostfixOp(t, nme.WILDCARD) }
case _ =>
t
}
@@ -1292,7 +1293,7 @@ object Parsers {
if (in.token == IF) guard()
else {
val pat = pattern1()
- if (in.token == EQUALS) atPos(startPos(pat), in.skipToken()) { GenAlias(pat, expr()) }
+ if (in.token == EQUALS) atPos(startOffset(pat), in.skipToken()) { GenAlias(pat, expr()) }
else generatorRest(pat)
}
@@ -1301,7 +1302,7 @@ object Parsers {
def generator(): Tree = generatorRest(pattern1())
def generatorRest(pat: Tree) =
- atPos(startPos(pat), accept(LARROW)) { GenFrom(pat, expr()) }
+ atPos(startOffset(pat), accept(LARROW)) { GenFrom(pat, expr()) }
/** ForExpr ::= `for' (`(' Enumerators `)' | `{' Enumerators `}')
* {nl} [`yield'] Expr
@@ -1365,7 +1366,7 @@ object Parsers {
val pattern = () => {
val pat = pattern1()
if (isIdent(nme.raw.BAR))
- atPos(startPos(pat)) { Alternative(pat :: patternAlts()) }
+ atPos(startOffset(pat)) { Alternative(pat :: patternAlts()) }
else pat
}
@@ -1391,15 +1392,15 @@ object Parsers {
// compatibility for Scala2 `x @ _*` syntax
infixPattern() match {
case pt @ Ident(tpnme.WILDCARD_STAR) =>
- migrationWarningOrError("The syntax `x @ _*' is no longer supported; use `x : _*' instead", startPos(p))
- atPos(startPos(p), offset) { Typed(p, pt) }
+ migrationWarningOrError("The syntax `x @ _*' is no longer supported; use `x : _*' instead", startOffset(p))
+ atPos(startOffset(p), offset) { Typed(p, pt) }
case p =>
- atPos(startPos(p), offset) { Bind(name, p) }
+ atPos(startOffset(p), offset) { Bind(name, p) }
}
case p @ Ident(tpnme.WILDCARD_STAR) =>
// compatibility for Scala2 `_*` syntax
- migrationWarningOrError("The syntax `_*' is no longer supported; use `x : _*' instead", startPos(p))
- atPos(startPos(p)) { Typed(Ident(nme.WILDCARD), p) }
+ migrationWarningOrError("The syntax `_*' is no longer supported; use `x : _*' instead", startOffset(p))
+ atPos(startOffset(p)) { Typed(Ident(nme.WILDCARD), p) }
case p =>
p
}
@@ -1423,7 +1424,7 @@ object Parsers {
val simplePattern = () => in.token match {
case IDENTIFIER | BACKQUOTED_IDENT | THIS =>
path(thisOK = true) match {
- case id @ Ident(nme.raw.MINUS) if isNumericLit => literal(startPos(id))
+ case id @ Ident(nme.raw.MINUS) if isNumericLit => literal(startOffset(id))
case t => simplePatternRest(t)
}
case USCORE =>
@@ -1453,9 +1454,9 @@ object Parsers {
def simplePatternRest(t: Tree): Tree = {
var p = t
if (in.token == LBRACKET)
- p = atPos(startPos(t), in.offset) { TypeApply(p, typeArgs()) }
+ p = atPos(startOffset(t), in.offset) { TypeApply(p, typeArgs()) }
if (in.token == LPAREN)
- p = atPos(startPos(t), in.offset) { Apply(p, argumentPatterns()) }
+ p = atPos(startOffset(t), in.offset) { Apply(p, argumentPatterns()) }
p
}
@@ -1780,7 +1781,7 @@ object Parsers {
case imp: Import =>
imp
case sel @ Select(qual, name) =>
- val selector = atPos(sel.pos.point) { Ident(name) }
+ val selector = atPos(pointOffset(sel)) { Ident(name) }
cpy.Import(sel)(qual, selector :: Nil)
case t =>
accept(DOT)
@@ -1813,7 +1814,7 @@ object Parsers {
def importSelector(): Tree = {
val from = termIdentOrWildcard()
if (from.name != nme.WILDCARD && in.token == ARROW)
- atPos(startPos(from), in.skipToken()) {
+ atPos(startOffset(from), in.skipToken()) {
Thicket(from, termIdentOrWildcard())
}
else from
@@ -2094,7 +2095,7 @@ object Parsers {
/** Create a tree representing a packaging */
def makePackaging(start: Int, pkg: Tree, stats: List[Tree]): PackageDef = pkg match {
- case x: RefTree => atPos(start, pkg.pos.point)(PackageDef(x, stats))
+ case x: RefTree => atPos(start, pointOffset(pkg))(PackageDef(x, stats))
}
/** Packaging ::= package QualId [nl] `{' TopStatSeq `}'