diff options
author | Martin Odersky <odersky@gmail.com> | 2005-12-23 18:12:51 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2005-12-23 18:12:51 +0000 |
commit | 35915d3420ae6a7ffa53be40f2c14b0ba97a1be7 (patch) | |
tree | 6adac77f2deb01c16ad8da7b2673c6fb84568ac3 /src/compiler/scala/tools/nsc/ast/parser/Scanners.scala | |
parent | 2ec5c0424495224a0e28b62f3e78a65e304d2504 (diff) | |
download | scala-35915d3420ae6a7ffa53be40f2c14b0ba97a1be7.tar.gz scala-35915d3420ae6a7ffa53be40f2c14b0ba97a1be7.tar.bz2 scala-35915d3420ae6a7ffa53be40f2c14b0ba97a1be7.zip |
Diffstat (limited to 'src/compiler/scala/tools/nsc/ast/parser/Scanners.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Scanners.scala | 614 |
1 files changed, 307 insertions, 307 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala index 5fbf54834e..091a4faa05 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala @@ -3,44 +3,44 @@ * @author Martin Odersky */ // $Id$ -package scala.tools.nsc.ast.parser; +package scala.tools.nsc.ast.parser -import Tokens._; +import Tokens._ import scala.tools.nsc.util.{Position, SourceFile} import SourceFile.{LF, FF, CR, SU} -import scala.tools.nsc.util.CharArrayReader; +import scala.tools.nsc.util.CharArrayReader [_trait_] abstract class Scanners: SyntaxAnalyzer { - import global._; + import global._ /** A class for representing a token's data. */ class TokenData { /** the next token */ - var token: int = EMPTY; + var token: int = EMPTY /** the token's position */ - protected var pos: int = 0; + protected var pos: int = 0 /** the first character position after the previous token */ - var lastPos: int = 0; + var lastPos: int = 0 - def currentPos = pos - 1; + def currentPos = pos - 1 /** the name of an identifier or token */ - var name: Name = null; + var name: Name = null /** the base of a number */ - var base: int = 0; + var base: int = 0 def copyFrom(td: TokenData) = { - this.token = td.token; - this.pos = td.pos; - this.lastPos = td.lastPos; - this.name = td.name; - this.base = td.base; + this.token = td.token + this.pos = td.pos + this.lastPos = td.lastPos + this.name = td.name + this.base = td.base } } @@ -51,48 +51,48 @@ import scala.tools.nsc.util.CharArrayReader; */ class Scanner(unit: CompilationUnit) extends TokenData { - import Tokens._; + import Tokens._ import java.lang.{Integer, Long, Float, Double, Character} /** Character input reader */ - val in = new CharArrayReader(unit.source.getContent(), true, syntaxError); + val in = new CharArrayReader(unit.source.getContent(), true, syntaxError) /** character buffer for literals */ - val cbuf = new StringBuffer(); + val cbuf = new StringBuffer() /** append Unicode character to "lit" buffer */ - protected def putChar(c: char) = cbuf.append(c); + protected def putChar(c: char) = cbuf.append(c) /** Clear buffer and set name */ private def setName = { - name = newTermName(cbuf.toString()); + name = newTermName(cbuf.toString()) cbuf.setLength(0) } /** buffer for the documentation comment */ - var docBuffer: StringBuffer = null; + var docBuffer: StringBuffer = null /** add the given character to the documentation buffer */ protected def putDocChar(c: char): unit = - if (docBuffer != null) docBuffer.append(c); + if (docBuffer != null) docBuffer.append(c) /** we need one token lookahead */ - val next = new TokenData(); - val prev = new TokenData(); + val next = new TokenData() + val prev = new TokenData() /** the last error position */ - var errpos = -1; + var errpos = -1 /** a stack which indicates whether line-ends can be statement separators */ - var sepRegions: List[int] = List(); + var sepRegions: List[int] = List() // Get next token ------------------------------------------------------------ @@ -115,7 +115,7 @@ import scala.tools.nsc.util.CharArrayReader; sepRegions = ARROW :: sepRegions } else if (token == RBRACE) { while (!sepRegions.isEmpty && sepRegions.head != RBRACE) - sepRegions = sepRegions.tail; + sepRegions = sepRegions.tail if (!sepRegions.isEmpty) sepRegions = sepRegions.tail } else if (token == RBRACKET || token == RPAREN || token == ARROW) { @@ -123,45 +123,45 @@ import scala.tools.nsc.util.CharArrayReader; sepRegions = sepRegions.tail } - val lastToken = token; + val lastToken = token if (next.token == EMPTY) { - fetchToken(); + fetchToken() } else { - this.copyFrom(next); + this.copyFrom(next) next.token = EMPTY } if (token == CASE) { - prev.copyFrom(this); - fetchToken(); + prev.copyFrom(this) + fetchToken() if (token == CLASS) { - token = CASECLASS; - lastPos = prev.lastPos; + token = CASECLASS + lastPos = prev.lastPos } else if (token == OBJECT) { - token = CASEOBJECT; - lastPos = prev.lastPos; + token = CASEOBJECT + lastPos = prev.lastPos } else { - next.copyFrom(this); - this.copyFrom(prev); + next.copyFrom(this) + this.copyFrom(prev) } } else if (token == SEMI) { - prev.copyFrom(this); - fetchToken(); + prev.copyFrom(this) + fetchToken() if (token != ELSE) { - next.copyFrom(this); - this.copyFrom(prev); + next.copyFrom(this) + this.copyFrom(prev) } } if (afterLineEnd() && inLastOfStat(lastToken) && inFirstOfStat(token) && (sepRegions.isEmpty || sepRegions.head == RBRACE)) { - next.copyFrom(this); - pos = in.lineStartPos; + next.copyFrom(this) + pos = in.lineStartPos token = NEWLINE /* } else if (lastToken == RBRACE) { System.out.println("failing to insert NL after RBRACE: " + sepRegions + " " + - lastPos + " " + in.lineStartPos + " " + pos); + lastPos + " " + in.lineStartPos + " " + pos) */ } // System.out.println("token: " + toString());//DEBUG @@ -171,24 +171,24 @@ import scala.tools.nsc.util.CharArrayReader; lastPos < in.lineStartPos && (in.lineStartPos <= pos || lastPos < in.lastLineStartPos && in.lastLineStartPos <= pos) - ); + ) /** read next token */ private def fetchToken(): unit = { - if (token == EOF) return; - lastPos = in.cpos - 1; // Position.encode(in.cline, in.ccol); - //var index = bp; + if (token == EOF) return + lastPos = in.cpos - 1; // Position.encode(in.cline, in.ccol) + //var index = bp while (true) { in.ch match { case ' ' | '\t' | CR | LF | FF => - in.next; + in.next case _ => - pos = in.cpos; // Position.encode(in.cline, in.ccol); + pos = in.cpos; // Position.encode(in.cline, in.ccol) in.ch match { case '\u21D2' => - in.next; token = ARROW; - return; + in.next; token = ARROW + return case 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | @@ -201,65 +201,65 @@ import scala.tools.nsc.util.CharArrayReader; 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | // scala-mode: need to understand multi-line case patterns 'z' => - putChar(in.ch); - in.next; + putChar(in.ch) + in.next getIdentRest; // scala-mode: wrong indent for multi-line case blocks return; case '<' => // is XMLSTART? - val last = in.last; - in.next; + val last = in.last + in.next last match { case ' '|'\t'|'\n'|'{'|'('|'>' if xml.Parsing.isNameStart(in.ch) => - token = XMLSTART; + token = XMLSTART case _ => // Console.println("found '<', but last is '"+in.last+"'"); // DEBUG - putChar('<'); - getOperatorRest; + putChar('<') + getOperatorRest } - return; + return case '~' | '!' | '@' | '#' | '%' | '^' | '*' | '+' | '-' | /*'<' | */ '>' | '?' | ':' | '=' | '&' | '|' | '\\' => - putChar(in.ch); - in.next; + putChar(in.ch) + in.next getOperatorRest; // XXX - return; + return case '/' => - in.next; + in.next if (!skipComment()) { - putChar('/'); - getOperatorRest; - return; + putChar('/') + getOperatorRest + return } case '0' => - putChar(in.ch); - in.next; + putChar(in.ch) + in.next if (in.ch == 'x' || in.ch == 'X') { - in.next; + in.next base = 16 } else { - base = 8; + base = 8 } - getNumber; + getNumber return; // scala-mode: return is a keyword case '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' => - base = 10; - getNumber; - return; + base = 10 + getNumber + return case '`' => //" scala-mode: need to understand literals - getStringLit('`'); - token = IDENTIFIER; - return; + getStringLit('`') + token = IDENTIFIER + return case '\"' => //" scala-mode: need to understand literals - getStringLit('\"'); - return; + getStringLit('\"') + return case '\'' => - in.next; + in.next in.ch match { case 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | @@ -273,86 +273,86 @@ import scala.tools.nsc.util.CharArrayReader; 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z' => - putChar(in.ch); - in.next; + putChar(in.ch) + in.next if (in.ch != '\'') { - getIdentRest; - token = SYMBOLLIT; - return; + getIdentRest + token = SYMBOLLIT + return } case _ => if (Character.isUnicodeIdentifierStart(in.ch)) { - putChar(in.ch); - in.next; + putChar(in.ch) + in.next if (in.ch != '\'') { - getIdentRest; - token = SYMBOLLIT; - return; + getIdentRest + token = SYMBOLLIT + return } } else { getlitch() } } if (in.ch == '\'') { - in.next; - token = CHARLIT; + in.next + token = CHARLIT setName } else { - syntaxError("unclosed character literal"); + syntaxError("unclosed character literal") } - return; + return case '.' => in.next; if ('0' <= in.ch && in.ch <= '9') { - putChar('.'); getFraction; + putChar('.'); getFraction } else { token = DOT } - return; + return case ';' => - in.next; token = SEMI; - return; + in.next; token = SEMI + return case ',' => - in.next; token = COMMA; - return; + in.next; token = COMMA + return case '(' => //scala-mode: need to understand character quotes in.next; token = LPAREN; - return; + return case '{' => - in.next; token = LBRACE; - return; + in.next; token = LBRACE + return case ')' => - in.next; token = RPAREN; - return; + in.next; token = RPAREN + return case '}' => - in.next; token = RBRACE; - return; + in.next; token = RBRACE + return case '[' => - in.next; token = LBRACKET; - return; + in.next; token = LBRACKET + return case ']' => - in.next; token = RBRACKET; - return; + in.next; token = RBRACKET + return case SU => - if (!in.hasNext) token = EOF; + if (!in.hasNext) token = EOF else { syntaxError("illegal character"); in.next } - return; + return case _ => if (Character.isUnicodeIdentifierStart(in.ch)) { - putChar(in.ch); - in.next; - getIdentRest; + putChar(in.ch) + in.next + getIdentRest } else if (isSpecial(in.ch)) { - putChar(in.ch); - getOperatorRest; + putChar(in.ch) + getOperatorRest } else { syntaxError("illegal character"); - in.next; + in.next } - return; + return } } } @@ -361,33 +361,33 @@ import scala.tools.nsc.util.CharArrayReader; private def skipComment(): boolean = if (in.ch == '/') { do { - in.next; - } while ((in.ch != CR) && (in.ch != LF) && (in.ch != SU)); + in.next + } while ((in.ch != CR) && (in.ch != LF) && (in.ch != SU)) true } else if (in.ch == '*') { - docBuffer = null; - var openComments = 1; - in.next; - if (in.ch == '*') docBuffer = new StringBuffer("/**"); + docBuffer = null + var openComments = 1 + in.next + if (in.ch == '*') docBuffer = new StringBuffer("/**") while (openComments > 0) { do { do { if (in.ch == '/') { - in.next; putDocChar(in.ch); + in.next; putDocChar(in.ch) if (in.ch == '*') { - in.next; putDocChar(in.ch); - openComments = openComments + 1; + in.next; putDocChar(in.ch) + openComments = openComments + 1 } } - in.next; putDocChar(in.ch); - } while (in.ch != '*' && in.ch != SU); + in.next; putDocChar(in.ch) + } while (in.ch != '*' && in.ch != SU) while (in.ch == '*') { - in.next; putDocChar(in.ch); + in.next; putDocChar(in.ch) } - } while (in.ch != '/' && in.ch != SU); - if (in.ch == '/') in.next; - else syntaxError("unclosed comment"); - openComments = openComments - 1; + } while (in.ch != '/' && in.ch != SU) + if (in.ch == '/') in.next + else syntaxError("unclosed comment") + openComments = openComments - 1 } true } else { @@ -395,8 +395,8 @@ import scala.tools.nsc.util.CharArrayReader; } def inFirstOfStat(token: int) = token match { - case EOF | ELSE | CASE | EXTENDS | WITH | YIELD | CATCH | FINALLY | MATCH | - REQUIRES | COMMA | SEMI | NEWLINE | DOT | USCORE | COLON | EQUALS | ARROW | + case EOF | CASE | CATCH | ELSE | EXTENDS | FINALLY | MATCH | REQUIRES | WITH | YIELD | + COMMA | SEMI | NEWLINE | DOT | USCORE | COLON | EQUALS | ARROW | LARROW | SUBTYPE | VIEWBOUND | SUPERTYPE | HASH | AT | RPAREN | RBRACKET | RBRACE => false @@ -420,17 +420,17 @@ import scala.tools.nsc.util.CharArrayReader; ('a' <= c && c <= 'a') || (c == '_') || (c == '$') || Character.isUnicodeIdentifierStart(c) - ); + ) def isIdentPart(c: char) = ( isIdentStart(c) || ('0' <= c && c <= '9') || Character.isUnicodeIdentifierPart(c) - ); + ) def isSpecial(c: char) = { - val chtp = Character.getType(c); - chtp == Character.MATH_SYMBOL || chtp == Character.OTHER_SYMBOL; + val chtp = Character.getType(c) + chtp == Character.MATH_SYMBOL || chtp == Character.OTHER_SYMBOL } private def getIdentRest: unit = @@ -450,24 +450,24 @@ import scala.tools.nsc.util.CharArrayReader; 'z' | '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' => - putChar(in.ch); - in.next; + putChar(in.ch) + in.next case '_' => - putChar(in.ch); - in.next; - getIdentOrOperatorRest; - return; + putChar(in.ch) + in.next + getIdentOrOperatorRest + return case SU => - setName; - token = name2token(name); - return; + setName + token = name2token(name) + return case _ => if(java.lang.Character.isUnicodeIdentifierPart(in.ch)) { - putChar(in.ch); + putChar(in.ch) in.next } else { - setName; - token = name2token(name); + setName + token = name2token(name) return } } @@ -480,25 +480,25 @@ import scala.tools.nsc.util.CharArrayReader; '^' | '*' | '+' | '-' | '<' | '>' | '?' | ':' | '=' | '&' | '|' | '\\' => - putChar(in.ch); + putChar(in.ch) in.next case '/' => - in.next; + in.next if (skipComment()) { - setName; - token = name2token(name); - return; + setName + token = name2token(name) + return } else { - putChar('/'); + putChar('/') } case _ => if (isSpecial(in.ch)) { - putChar(in.ch); - in.next; + putChar(in.ch) + in.next } else { - setName; - token = name2token(name); - return; + setName + token = name2token(name) + return } } } @@ -511,26 +511,26 @@ import scala.tools.nsc.util.CharArrayReader; '^' | '*' | '+' | '-' | '<' | '>' | '?' | ':' | '=' | '&' | '|' | '\\' | '/' => - getOperatorRest; + getOperatorRest case _ => if (isSpecial(in.ch)) getOperatorRest else { - setName; + setName token = name2token(name) } } private def getStringLit(delimiter: char): unit = { - in.next; + in.next while (in.ch != delimiter && (in.isUnicode || in.ch != CR && in.ch != LF && in.ch != SU)) { - getlitch(); + getlitch() } if (in.ch == delimiter) { - token = STRINGLIT; - setName; + token = STRINGLIT + setName in.next } else { - syntaxError("unclosed string literal"); + syntaxError("unclosed string literal") } } @@ -540,20 +540,20 @@ import scala.tools.nsc.util.CharArrayReader; */ protected def getlitch() = if (in.ch == '\\') { - in.next; + in.next if ('0' <= in.ch && in.ch <= '7') { - val leadch: char = in.ch; - var oct: int = in.digit2int(in.ch, 8); - in.next; + val leadch: char = in.ch + var oct: int = in.digit2int(in.ch, 8) + in.next if ('0' <= in.ch && in.ch <= '7') { - oct = oct * 8 + in.digit2int(in.ch, 8); - in.next; + oct = oct * 8 + in.digit2int(in.ch, 8) + in.next if (leadch <= '3' && '0' <= in.ch && in.ch <= '7') { - oct = oct * 8 + in.digit2int(in.ch, 8); - in.next; + oct = oct * 8 + in.digit2int(in.ch, 8) + in.next } } - putChar(oct.asInstanceOf[char]); + putChar(oct.asInstanceOf[char]) } else { in.ch match { case 'b' => putChar('\b') @@ -566,53 +566,53 @@ import scala.tools.nsc.util.CharArrayReader; case '\\' => putChar('\\') case _ => syntaxError(in.cpos - 1, // Position.encode(in.cline, in.ccol - 1), - "invalid escape character"); - putChar(in.ch); + "invalid escape character") + putChar(in.ch) } in.next } } else { - putChar(in.ch); - in.next; + putChar(in.ch) + in.next } /** read fractional part and exponent of floating point number * if one is present. */ protected def getFraction = { - token = DOUBLELIT; + token = DOUBLELIT while ('0' <= in.ch && in.ch <= '9') { - putChar(in.ch); - in.next; + putChar(in.ch) + in.next } if (in.ch == 'e' || in.ch == 'E') { - val lookahead = in.copy; - lookahead.next; + val lookahead = in.copy + lookahead.next if (lookahead.ch == '+' || lookahead.ch == '-') { - lookahead.next; + lookahead.next } if ('0' <= lookahead.ch && lookahead.ch <= '9') { - putChar(in.ch); - in.next; + putChar(in.ch) + in.next if (in.ch == '+' || in.ch == '-') { - putChar(in.ch); - in.next; + putChar(in.ch) + in.next } while ('0' <= in.ch && in.ch <= '9') { - putChar(in.ch); - in.next; + putChar(in.ch) + in.next } } - token = DOUBLELIT; + token = DOUBLELIT } if ((in.ch == 'd') || (in.ch == 'D')) { - putChar(in.ch); - in.next; - token = DOUBLELIT; + putChar(in.ch) + in.next + token = DOUBLELIT } else if ((in.ch == 'f') || (in.ch == 'F')) { - putChar(in.ch); - in.next; - token = FLOATLIT; + putChar(in.ch) + in.next + token = FLOATLIT } setName } @@ -623,74 +623,74 @@ import scala.tools.nsc.util.CharArrayReader; if (token == CHARLIT && !negated) { if (name.length > 0) name(0) else 0 } else { - var value: long = 0; - val divider = if (base == 10) 1 else 2; + var value: long = 0 + val divider = if (base == 10) 1 else 2 val limit: long = - if (token == LONGLIT) Long.MAX_VALUE else Integer.MAX_VALUE; - var i = 0; - val len = name.length; + if (token == LONGLIT) Long.MAX_VALUE else Integer.MAX_VALUE + var i = 0 + val len = name.length while (i < len) { - val d = in.digit2int(name(i), base); + val d = in.digit2int(name(i), base) if (d < 0) { - syntaxError("malformed integer number"); - return 0; + syntaxError("malformed integer number") + return 0 } if (value < 0 || limit / (base / divider) < value || limit - (d / divider) < value * (base / divider) && !(negated && limit == value * base - 1 + d)) { - syntaxError("integer number too large"); - return 0; + syntaxError("integer number too large") + return 0 } - value = value * base + d; - i = i + 1; + value = value * base + d + i = i + 1 } if (negated) -value else value } } - def intVal: long = intVal(false); + def intVal: long = intVal(false) /** convert name, base to double value */ def floatVal(negated: boolean): double = { val limit: double = - if (token == DOUBLELIT) Double.MAX_VALUE else Float.MAX_VALUE; + if (token == DOUBLELIT) Double.MAX_VALUE else Float.MAX_VALUE try { - val value = Double.valueOf(name.toString()).doubleValue(); + val value = Double.valueOf(name.toString()).doubleValue() if (value > limit) - syntaxError("floating point number too large"); + syntaxError("floating point number too large") if (negated) -value else value } catch { case _: NumberFormatException => - syntaxError("malformed floating point number"); + syntaxError("malformed floating point number") 0.0 } } - def floatVal: double = floatVal(false); + def floatVal: double = floatVal(false) /** read a number into name and set base */ protected def getNumber:unit = { while (in.digit2int(in.ch, if (base < 10) 10 else base) >= 0) { - putChar(in.ch); - in.next; + putChar(in.ch) + in.next } - token = INTLIT; + token = INTLIT if (base <= 10 && in.ch == '.') { - val lookahead = in.copy; - lookahead.next; + val lookahead = in.copy + lookahead.next lookahead.ch match { case '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | 'd' | 'D' | 'e' | 'E' | 'f' | 'F' => - putChar(in.ch); - in.next; + putChar(in.ch) + in.next return getFraction case _ => if (!isIdentStart(lookahead.ch)) { - putChar(in.ch); - in.next; + putChar(in.ch) + in.next return getFraction } } @@ -701,18 +701,18 @@ import scala.tools.nsc.util.CharArrayReader; in.ch == 'd' || in.ch == 'D')) { return getFraction } - setName; + setName if (in.ch == 'l' || in.ch == 'L') { - in.next; - token = LONGLIT; + in.next + token = LONGLIT } } // XML lexing---------------------------------------------------------------- def xSync = { token = NEWLINE; // avoid getting NEWLINE from nextToken if last was RBRACE - //in.next; - nextToken(); + //in.next + nextToken() } // Errors ----------------------------------------------------------------- @@ -720,95 +720,95 @@ import scala.tools.nsc.util.CharArrayReader; /** generate an error at the given position */ def syntaxError(pos: int, msg: String): unit = { - unit.error(pos, msg); - token = ERROR; - errpos = pos; + unit.error(pos, msg) + token = ERROR + errpos = pos } /** generate an error at the current token position */ - def syntaxError(msg: String): unit = syntaxError(pos, msg); + def syntaxError(msg: String): unit = syntaxError(pos, msg) // Keywords ----------------------------------------------------------------- /** Keyword array; maps from name indices to tokens */ - private var key: Array[byte] = _; - private var maxKey = 0; - private var tokenName = new Array[Name](128); + private var key: Array[byte] = _ + private var maxKey = 0 + private var tokenName = new Array[Name](128) { - var tokenCount = 0; + var tokenCount = 0 // Enter keywords def enterKeyword(n: Name, tokenId: int): unit = { while (tokenId >= tokenName.length) { - val newTokName = new Array[Name](tokenName.length * 2); - System.arraycopy(tokenName, 0, newTokName, 0, newTokName.length); - tokenName = newTokName; + val newTokName = new Array[Name](tokenName.length * 2) + System.arraycopy(tokenName, 0, newTokName, 0, newTokName.length) + tokenName = newTokName } - tokenName(tokenId) = n; - if (n.start > maxKey) maxKey = n.start; - if (tokenId >= tokenCount) tokenCount = tokenId + 1; + tokenName(tokenId) = n + if (n.start > maxKey) maxKey = n.start + if (tokenId >= tokenCount) tokenCount = tokenId + 1 } - enterKeyword(nme.ABSTRACTkw, ABSTRACT); - enterKeyword(nme.CASEkw, CASE); - enterKeyword(nme.CATCHkw, CATCH); - enterKeyword(nme.CLASSkw, CLASS); - enterKeyword(nme.DEFkw, DEF); - enterKeyword(nme.DOkw, DO); - enterKeyword(nme.ELSEkw, ELSE); - enterKeyword(nme.EXTENDSkw, EXTENDS); - enterKeyword(nme.FALSEkw, FALSE); - enterKeyword(nme.FINALkw, FINAL); - enterKeyword(nme.FINALLYkw, FINALLY); - enterKeyword(nme.FORkw, FOR); - enterKeyword(nme.IFkw, IF); - enterKeyword(nme.IMPLICITkw, IMPLICIT); - enterKeyword(nme.IMPORTkw, IMPORT); - enterKeyword(nme.MATCHkw, MATCH); - enterKeyword(nme.REQUIRESkw, REQUIRES); - enterKeyword(nme.NEWkw, NEW); - enterKeyword(nme.NULLkw, NULL); - enterKeyword(nme.OBJECTkw, OBJECT); - enterKeyword(nme.OVERRIDEkw, OVERRIDE); - enterKeyword(nme.PACKAGEkw, PACKAGE); - enterKeyword(nme.PRIVATEkw, PRIVATE); - enterKeyword(nme.PROTECTEDkw, PROTECTED); - enterKeyword(nme.RETURNkw, RETURN); - enterKeyword(nme.SEALEDkw, SEALED); - enterKeyword(nme.SUPERkw, SUPER); - enterKeyword(nme.THISkw, THIS); - enterKeyword(nme.THROWkw, THROW); - enterKeyword(nme.TRAITkw, TRAIT); - enterKeyword(nme.TRUEkw, TRUE); - enterKeyword(nme.TRYkw, TRY); - enterKeyword(nme.TYPEkw, TYPE); - enterKeyword(nme.VALkw, VAL); - enterKeyword(nme.VARkw, VAR); - enterKeyword(nme.WHILEkw, WHILE); - enterKeyword(nme.WITHkw, WITH); - enterKeyword(nme.YIELDkw, YIELD); - enterKeyword(nme.DOTkw, DOT); - enterKeyword(nme.USCOREkw, USCORE); - enterKeyword(nme.COLONkw, COLON); - enterKeyword(nme.EQUALSkw, EQUALS); - enterKeyword(nme.ARROWkw, ARROW); - enterKeyword(nme.LARROWkw, LARROW); - enterKeyword(nme.SUBTYPEkw, SUBTYPE); - enterKeyword(nme.VIEWBOUNDkw, VIEWBOUND); - enterKeyword(nme.SUPERTYPEkw, SUPERTYPE); - enterKeyword(nme.HASHkw, HASH); - enterKeyword(nme.ATkw, AT); + enterKeyword(nme.ABSTRACTkw, ABSTRACT) + enterKeyword(nme.CASEkw, CASE) + enterKeyword(nme.CATCHkw, CATCH) + enterKeyword(nme.CLASSkw, CLASS) + enterKeyword(nme.DEFkw, DEF) + enterKeyword(nme.DOkw, DO) + enterKeyword(nme.ELSEkw, ELSE) + enterKeyword(nme.EXTENDSkw, EXTENDS) + enterKeyword(nme.FALSEkw, FALSE) + enterKeyword(nme.FINALkw, FINAL) + enterKeyword(nme.FINALLYkw, FINALLY) + enterKeyword(nme.FORkw, FOR) + enterKeyword(nme.IFkw, IF) + enterKeyword(nme.IMPLICITkw, IMPLICIT) + enterKeyword(nme.IMPORTkw, IMPORT) + enterKeyword(nme.MATCHkw, MATCH) + enterKeyword(nme.REQUIRESkw, REQUIRES) + enterKeyword(nme.NEWkw, NEW) + enterKeyword(nme.NULLkw, NULL) + enterKeyword(nme.OBJECTkw, OBJECT) + enterKeyword(nme.OVERRIDEkw, OVERRIDE) + enterKeyword(nme.PACKAGEkw, PACKAGE) + enterKeyword(nme.PRIVATEkw, PRIVATE) + enterKeyword(nme.PROTECTEDkw, PROTECTED) + enterKeyword(nme.RETURNkw, RETURN) + enterKeyword(nme.SEALEDkw, SEALED) + enterKeyword(nme.SUPERkw, SUPER) + enterKeyword(nme.THISkw, THIS) + enterKeyword(nme.THROWkw, THROW) + enterKeyword(nme.TRAITkw, TRAIT) + enterKeyword(nme.TRUEkw, TRUE) + enterKeyword(nme.TRYkw, TRY) + enterKeyword(nme.TYPEkw, TYPE) + enterKeyword(nme.VALkw, VAL) + enterKeyword(nme.VARkw, VAR) + enterKeyword(nme.WHILEkw, WHILE) + enterKeyword(nme.WITHkw, WITH) + enterKeyword(nme.YIELDkw, YIELD) + enterKeyword(nme.DOTkw, DOT) + enterKeyword(nme.USCOREkw, USCORE) + enterKeyword(nme.COLONkw, COLON) + enterKeyword(nme.EQUALSkw, EQUALS) + enterKeyword(nme.ARROWkw, ARROW) + enterKeyword(nme.LARROWkw, LARROW) + enterKeyword(nme.SUBTYPEkw, SUBTYPE) + enterKeyword(nme.VIEWBOUNDkw, VIEWBOUND) + enterKeyword(nme.SUPERTYPEkw, SUPERTYPE) + enterKeyword(nme.HASHkw, HASH) + enterKeyword(nme.ATkw, AT) // Build keyword array - key = new Array[byte](maxKey+1); + key = new Array[byte](maxKey+1) for (val i <- Iterator.range(0, maxKey + 1)) - key(i) = IDENTIFIER; + key(i) = IDENTIFIER for (val j <- Iterator.range(0, tokenCount)) if (tokenName(j) != null) - key(tokenName(j).start) = j.asInstanceOf[byte]; + key(tokenName(j).start) = j.asInstanceOf[byte] } @@ -816,7 +816,7 @@ import scala.tools.nsc.util.CharArrayReader; /** Convert name to token */ def name2token(name: Name): int = - if (name.start <= maxKey) key(name.start) else IDENTIFIER; + if (name.start <= maxKey) key(name.start) else IDENTIFIER /** Returns the string representation of given token. */ def token2string(token: int): String = token match { @@ -902,7 +902,7 @@ import scala.tools.nsc.util.CharArrayReader; /** INIT: read lookahead character and token. */ - in.next; - nextToken(); + in.next + nextToken() } } |