diff options
Diffstat (limited to 'src/compiler/scala/tools/nsc/ast/parser/Scanners.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Scanners.scala | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala index 4f564c5d0b..79f0bcf149 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala @@ -113,6 +113,11 @@ trait Scanners extends ScannersCommon { cbuf.append(c) } + /** Determines whether this scanner should emit identifier deprecation warnings, + * e.g. when seeing `macro` or `then`, which are planned to become keywords in future versions of Scala. + */ + protected def emitIdentifierDeprecationWarnings = true + /** Clear buffer and set name and token */ private def finishNamed(idtoken: Int = IDENTIFIER) { name = newTermName(cbuf.toString) @@ -122,7 +127,7 @@ trait Scanners extends ScannersCommon { val idx = name.start - kwOffset if (idx >= 0 && idx < kwArray.length) { token = kwArray(idx) - if (token == IDENTIFIER && allowIdent != name) + if (token == IDENTIFIER && allowIdent != name && emitIdentifierDeprecationWarnings) deprecationWarning(name+" is now a reserved word; usage as an identifier is deprecated") } } @@ -283,10 +288,16 @@ trait Scanners extends ScannersCommon { prev copyFrom this val nextLastOffset = charOffset - 1 fetchToken() + def resetOffset() { + offset = prev.offset + lastOffset = prev.lastOffset + } if (token == CLASS) { token = CASECLASS + resetOffset() } else if (token == OBJECT) { token = CASEOBJECT + resetOffset() } else { lastOffset = nextLastOffset next copyFrom this @@ -607,7 +618,10 @@ trait Scanners extends ScannersCommon { if (ch == '`') { nextChar() finishNamed(BACKQUOTED_IDENT) - if (name.length == 0) syntaxError("empty quoted identifier") + if (name.length == 0) + syntaxError("empty quoted identifier") + else if (name == nme.WILDCARD) + syntaxError("wildcard invalid as backquoted identifier") } else syntaxError("unclosed quoted identifier") } @@ -1488,6 +1502,10 @@ trait Scanners extends ScannersCommon { def improves(patches1: List[BracePatch]): Boolean = imbalanceMeasure > new ParensAnalyzer(unit, patches1).imbalanceMeasure + // don't emit deprecation warnings about identifiers like `macro` or `then` + // when skimming through the source file trying to heal braces + override def emitIdentifierDeprecationWarnings = false + override def error(offset: Int, msg: String) {} } } |