summaryrefslogtreecommitdiff
path: root/sources/scala/tools/nsc/ast/parser/Scanners.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2005-12-08 15:15:56 +0000
committerMartin Odersky <odersky@gmail.com>2005-12-08 15:15:56 +0000
commit2d91f011f2ba54bb3ac733f3dcf4a518ea56d50e (patch)
tree956f4cf7f0745cf6916ad67354fcb7c42659969d /sources/scala/tools/nsc/ast/parser/Scanners.scala
parente0d7aeaa9d32afce117d366b179e7a8205586f2e (diff)
downloadscala-2d91f011f2ba54bb3ac733f3dcf4a518ea56d50e.tar.gz
scala-2d91f011f2ba54bb3ac733f3dcf4a518ea56d50e.tar.bz2
scala-2d91f011f2ba54bb3ac733f3dcf4a518ea56d50e.zip
*** empty log message ***
Diffstat (limited to 'sources/scala/tools/nsc/ast/parser/Scanners.scala')
-rwxr-xr-xsources/scala/tools/nsc/ast/parser/Scanners.scala62
1 files changed, 51 insertions, 11 deletions
diff --git a/sources/scala/tools/nsc/ast/parser/Scanners.scala b/sources/scala/tools/nsc/ast/parser/Scanners.scala
index 57f491cab5..b2ba581051 100755
--- a/sources/scala/tools/nsc/ast/parser/Scanners.scala
+++ b/sources/scala/tools/nsc/ast/parser/Scanners.scala
@@ -23,6 +23,9 @@ import scala.tools.nsc.util.CharArrayReader;
/** the token's position */
protected var pos: int = 0;
+ /** the first character position after the previous token */
+ var lastPos: int = 0;
+
def currentPos = pos - 1;
@@ -35,6 +38,7 @@ import scala.tools.nsc.util.CharArrayReader;
def copyFrom(td: TokenData) = {
this.token = td.token;
this.pos = td.pos;
+ this.lastPos = td.lastPos;
this.name = td.name;
this.base = td.base;
}
@@ -82,25 +86,26 @@ import scala.tools.nsc.util.CharArrayReader;
val next = new TokenData();
val prev = new TokenData();
- /** the first character position after the previous token
- */
- var lastpos = 0;
-
/** the last error position
*/
var errpos = -1;
+ /** a stack which indicates whether line-ends can be statement separators
+ */
+ var statSepModes: List[boolean] = List();
+
// Get next token ------------------------------------------------------------
/** read next token and return last position
*/
def skipToken(): int = {
val p = pos; nextToken();
- // XXX: account for off by one error
+ // XXX: account for off by one error //???
p - 1
}
def nextToken(): unit = {
+/*
if (token == RBRACE) {
val prevpos = pos;
fetchToken();
@@ -117,6 +122,16 @@ import scala.tools.nsc.util.CharArrayReader;
}
}
} else {
+*/
+ if (token == LPAREN || token == LBRACKET)
+ statSepModes = false :: statSepModes
+ else if (token == LBRACE)
+ statSepModes = true :: statSepModes
+ else if ((token == RPAREN || token == RBRACKET) && !statSepModes.isEmpty && !statSepModes.head)
+ statSepModes = statSepModes.tail
+ else if (token == RBRACE && !statSepModes.isEmpty && statSepModes.head)
+ statSepModes = statSepModes.tail;
+
if (next.token == EMPTY) {
fetchToken();
} else {
@@ -128,8 +143,10 @@ import scala.tools.nsc.util.CharArrayReader;
fetchToken();
if (token == CLASS) {
token = CASECLASS;
+ lastPos = prev.lastPos;
} else if (token == OBJECT) {
token = CASEOBJECT;
+ lastPos = prev.lastPos;
} else {
next.copyFrom(this);
this.copyFrom(prev);
@@ -143,14 +160,14 @@ import scala.tools.nsc.util.CharArrayReader;
}
}
// Console.println("<" + this + ">");//DEBUG
- }
+// }
}
/** read next token
*/
private def fetchToken(): unit = {
if (token == EOF) return;
- lastpos = in.cpos; // Position.encode(in.cline, in.ccol);
+ lastPos = in.cpos - 1; // Position.encode(in.cline, in.ccol);
//var index = bp;
while (true) {
in.ch match {
@@ -367,18 +384,41 @@ import scala.tools.nsc.util.CharArrayReader;
false
}
+ def isStatSep: boolean = (
+ (token == SEMI) ||
+ afterLineEnd && (statSepModes.isEmpty || statSepModes.head) && inFirstStat(token)
+ );
+
+ def afterLineEnd: boolean = (
+ lastPos < in.lineStartPos &&
+ (in.lineStartPos <= pos ||
+ lastPos < in.lastLineStartPos && in.lastLineStartPos <= pos)
+ );
+
+ def inFirstStat(token: int) = token match {
+ case ELSE | EXTENDS | WITH | YIELD | CATCH | FINALLY |
+ COMMA | SEMI | DOT | COLON | EQUALS | ARROW |
+ LARROW | SUBTYPE | VIEWBOUND | SUPERTYPE | HASH | AT |
+ RPAREN | RBRACKET | RBRACE =>
+ false
+ case _ =>
+ true
+ }
+
// Identifiers ---------------------------------------------------------------
- def isIdentStart(c: char): boolean =
+ def isIdentStart(c: char): boolean = (
('A' <= c && c <= 'Z') ||
('a' <= c && c <= 'a') ||
(c == '_') || (c == '$') ||
- Character.isUnicodeIdentifierStart(c);
+ Character.isUnicodeIdentifierStart(c)
+ );
- def isIdentPart(c: char) =
+ def isIdentPart(c: char) = (
isIdentStart(c) ||
('0' <= c && c <= '9') ||
- Character.isUnicodeIdentifierPart(c);
+ Character.isUnicodeIdentifierPart(c)
+ );
def isSpecial(c: char) = {
val chtp = Character.getType(c);