summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2007-07-11 13:45:53 +0000
committermichelou <michelou@epfl.ch>2007-07-11 13:45:53 +0000
commit802a3e3a8f11c7fc41d40f2270154237ca9cc9c1 (patch)
treeb0088e1c2534fac3fc1f020353f79ce00f403a8a /src
parent726eff2779adee5f449a950ca8488cf5759e0af3 (diff)
downloadscala-802a3e3a8f11c7fc41d40f2270154237ca9cc9c1.tar.gz
scala-802a3e3a8f11c7fc41d40f2270154237ca9cc9c1.tar.bz2
scala-802a3e3a8f11c7fc41d40f2270154237ca9cc9c1.zip
removed type aliases, updated scaladoc comments...
removed type aliases, updated scaladoc comments and file headers
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreePrinters.scala70
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala10
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/Opcodes.scala260
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/Primitives.scala138
-rw-r--r--src/library/scala/util/parsing/ast/Binders.scala84
-rw-r--r--src/library/scala/util/parsing/combinator/Parsers.scala92
-rw-r--r--src/library/scala/util/parsing/combinator/lexical/Lexical.scala2
-rw-r--r--src/library/scala/util/parsing/combinator/lexical/Scanners.scala17
-rw-r--r--src/library/scala/util/parsing/combinator/syntactical/BindingParsers.scala91
-rw-r--r--src/library/scala/util/parsing/input/CharArrayPosition.scala24
-rw-r--r--src/library/scala/util/parsing/input/CharArrayReader.scala13
-rw-r--r--src/library/scala/util/parsing/input/NoPosition.scala7
-rw-r--r--src/library/scala/util/parsing/input/Position.scala30
-rw-r--r--src/library/scala/util/parsing/input/Reader.scala12
-rwxr-xr-xsrc/library/scala/util/parsing/input/StreamReader.scala34
15 files changed, 489 insertions, 395 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala
index 71929eb68d..99c4d791d3 100644
--- a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala
@@ -25,7 +25,7 @@ abstract class TreePrinters {
def indent = indentMargin += indentStep
def undent = indentMargin -= indentStep
- def println = {
+ def println {
out.println()
while (indentMargin > indentString.length())
indentString += indentString
@@ -33,49 +33,56 @@ abstract class TreePrinters {
out.write(indentString, 0, indentMargin)
}
- def printSeq[a](ls: List[a])(printelem: a => unit)(printsep: => unit): unit = ls match {
- case List() =>
- case List(x) => printelem(x)
- case x :: rest => printelem(x); printsep; printSeq(rest)(printelem)(printsep)
+ def printSeq[a](ls: List[a])(printelem: a => Unit)(printsep: => Unit) {
+ ls match {
+ case List() =>
+ case List(x) => printelem(x)
+ case x :: rest => printelem(x); printsep; printSeq(rest)(printelem)(printsep)
+ }
}
- def printColumn(ts: List[Tree], start: String, sep: String, end: String): unit = {
+ def printColumn(ts: List[Tree], start: String, sep: String, end: String) {
print(start); indent; println
printSeq(ts){print}{print(sep); println}; undent; println; print(end)
}
- def printRow(ts: List[Tree], start: String, sep: String, end: String): unit = {
+ def printRow(ts: List[Tree], start: String, sep: String, end: String) {
print(start); printSeq(ts){print}{print(sep)}; print(end)
}
- def printRow(ts: List[Tree], sep: String): unit = printRow(ts, "", sep, "")
+ def printRow(ts: List[Tree], sep: String) { printRow(ts, "", sep, "") }
- def printTypeParams(ts: List[TypeDef]): unit =
+ def printTypeParams(ts: List[TypeDef]) {
if (!ts.isEmpty) {
print("["); printSeq(ts){printParam}{print(", ")}; print("]")
}
+ }
- def printValueParams(ts: List[ValDef]): unit = {
+ def printValueParams(ts: List[ValDef]) {
print("(")
if (!ts.isEmpty) printFlags(ts.head.mods.flags & IMPLICIT, "")
printSeq(ts){printParam}{print(", ")}
print(")")
}
- def printParam(tree: Tree): unit = tree match {
- case ValDef(mods, name, tp, rhs) =>
- printAnnotations(tree)
- print(symName(tree, name)); printOpt(": ", tp)
- case TypeDef(mods, name, tparams, rhs) =>
- print(symName(tree, name))
- printTypeParams(tparams); print(rhs)
+ def printParam(tree: Tree) {
+ tree match {
+ case ValDef(mods, name, tp, rhs) =>
+ printAnnotations(tree)
+ print(symName(tree, name)); printOpt(": ", tp)
+ case TypeDef(mods, name, tparams, rhs) =>
+ print(symName(tree, name))
+ printTypeParams(tparams); print(rhs)
+ }
}
- def printBlock(tree: Tree): unit = tree match {
- case Block(_, _) =>
- print(tree)
- case _ =>
- printColumn(List(tree), "{", ";", "}")
+ def printBlock(tree: Tree) {
+ tree match {
+ case Block(_, _) =>
+ print(tree)
+ case _ =>
+ printColumn(List(tree), "{", ";", "}")
+ }
}
def symName(tree: Tree, name: Name): String =
@@ -84,10 +91,11 @@ abstract class TreePrinters {
tree.symbol.nameString)
} else name.toString();
- def printOpt(prefix: String, tree: Tree): unit =
+ def printOpt(prefix: String, tree: Tree) {
if (!tree.isEmpty) { print(prefix); print(tree) }
+ }
- def printModifiers(tree: Tree, mods: Modifiers): unit = {
+ def printModifiers(tree: Tree, mods: Modifiers) {
if (tree.symbol == NoSymbol)
printFlags(mods.flags, mods.privateWithin.toString)
else if (tree.symbol.privateWithin == NoSymbol ||
@@ -97,7 +105,7 @@ abstract class TreePrinters {
printFlags(tree.symbol.flags, tree.symbol.privateWithin.name.toString)
}
- def printFlags(flags: long, privateWithin: String): unit = {
+ def printFlags(flags: long, privateWithin: String) {
var mask: long = if (settings.debug.value) -1L else PrintableFlags
val s = flagsToString(flags & mask, privateWithin.toString)
if (s.length() != 0) print(s + " ")
@@ -114,10 +122,10 @@ abstract class TreePrinters {
}
}
- def print(str: String): unit = out.print(str)
- def print(name: Name): unit = print(name.toString())
+ def print(str: String) { out.print(str) }
+ def print(name: Name) { print(name.toString()) }
- def printRaw(tree: Tree): unit = {
+ def printRaw(tree: Tree) {
tree match {
case EmptyTree =>
print("<empty>")
@@ -340,7 +348,7 @@ abstract class TreePrinters {
}
}
- def print(tree: Tree): unit = {
+ def print(tree: Tree) {
if (settings.Xprintpos.value) print("[" + tree.pos + "]")
printRaw(
if (tree.isDef && tree.symbol != NoSymbol && tree.symbol.isInitialized) {
@@ -381,9 +389,9 @@ abstract class TreePrinters {
* output stream.
*/
object ConsoleWriter extends Writer {
- override def write(str: String): unit = Console.print(str)
+ override def write(str: String) { Console.print(str) }
- def write(cbuf: Array[char], off: int, len: int) {
+ def write(cbuf: Array[Char], off: Int, len: Int) {
val str = new String(cbuf, off, len)
write(str)
}
diff --git a/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala b/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala
index cd2d56fb9e..ee70dd16d3 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala
@@ -21,7 +21,7 @@ trait BasicBlocks {
* either executed all, or none. No jumps
* to/from the "middle" of the basic block are allowed.
*/
- class BasicBlock (theLabel: int, val method: IMethod)
+ class BasicBlock (theLabel: Int, val method: IMethod)
extends AnyRef
with ProgramPoint[BasicBlock] {
@@ -53,7 +53,7 @@ trait BasicBlocks {
private var _lastInstruction: Instruction = null
- private var closed: boolean = false
+ private var closed: Boolean = false
private var instrs: Array[Instruction] = _
private var touched = false
@@ -94,7 +94,7 @@ trait BasicBlocks {
// override def hashCode() = label;
/** Apply a function to all the instructions of the block. */
- def traverse(f: Instruction => unit) = {
+ def traverse(f: Instruction => Unit) = {
if (!closed) {
dump
global.abort("Traversing an open block!: " + label)
@@ -416,9 +416,9 @@ trait BasicBlocks {
override def hashCode = label
// Instead of it, rather use a printer
- def print() : unit = print(java.lang.System.out)
+ def print() { print(java.lang.System.out) }
- def print(out: java.io.PrintStream) : unit = {
+ def print(out: java.io.PrintStream) {
out.println("block #"+label+" :")
toList.foreach(i => out.println(" " + i))
out.print("Successors: ")
diff --git a/src/compiler/scala/tools/nsc/backend/icode/Opcodes.scala b/src/compiler/scala/tools/nsc/backend/icode/Opcodes.scala
index 109c6ef8a9..93941f653a 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/Opcodes.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/Opcodes.scala
@@ -1,15 +1,15 @@
-/* NSC -- new scala compiler
- * Copyright 2005 LAMP/EPFL
+/* NSC -- new Scala compiler
+ * Copyright 2005-2007 LAMP/EPFL
* @author Martin Odersky
*/
// $Id$
-package scala.tools.nsc.backend.icode;
+package scala.tools.nsc.backend.icode
-import scala.tools.nsc.ast._;
-import scala.tools.nsc.util.{Position,NoPosition};
+import scala.tools.nsc.ast._
+import scala.tools.nsc.util.{Position,NoPosition}
/*
A pattern match
@@ -60,22 +60,22 @@ trait Opcodes { self: ICodes =>
abstract class Instruction {
/** This abstract method returns the number of used elements on the stack */
- def consumed : Int = 0;
+ def consumed : Int = 0
/** This abstract method returns the number of produced elements on the stack */
- def produced : Int = 0;
+ def produced : Int = 0
/** This instruction consumes these types from the top of the stack. */
- def consumedTypes: List[TypeKind] = Nil;
+ def consumedTypes: List[TypeKind] = Nil
/** This instruction produces these types on top of the stack. */
- def producedTypes: List[TypeKind] = Nil;
+ def producedTypes: List[TypeKind] = Nil
/** This method returns the difference of size of the stack when the instruction is used */
- def difference = produced-consumed;
+ def difference = produced-consumed
/** The corresponding position in the source file */
- var pos: Position = NoPosition;
+ var pos: Position = NoPosition
/** Used by dead code elimination. */
var useful: Boolean = false
@@ -89,26 +89,26 @@ trait Opcodes { self: ICodes =>
*/
case class THIS(clasz: Symbol) extends Instruction {
/** Returns a string representation of this constant */
- override def toString(): String = "THIS";
+ override def toString(): String = "THIS"
- override def consumed = 0;
- override def produced = 1;
+ override def consumed = 0
+ override def produced = 1
- override def producedTypes = List(REFERENCE(clasz));
+ override def producedTypes = List(REFERENCE(clasz))
}
/** Loads a constant on the stack.
* Stack: ...
* ->: ...:constant
*/
- case class CONSTANT(constant: Constant) extends Instruction{
+ case class CONSTANT(constant: Constant) extends Instruction {
/** Returns a string representation of this constant */
- override def toString(): String = "CONSTANT ("+constant.toString()+")";
+ override def toString(): String = "CONSTANT ("+constant.toString()+")"
- override def consumed = 0;
- override def produced = 1;
+ override def consumed = 0
+ override def produced = 1
- override def producedTypes = List(toTypeKind(constant.tpe));
+ override def producedTypes = List(toTypeKind(constant.tpe))
}
/** Loads an element of an array. The array and the index should
@@ -118,13 +118,13 @@ trait Opcodes { self: ICodes =>
*/
case class LOAD_ARRAY_ITEM(kind: TypeKind) extends Instruction {
/** Returns a string representation of this instruction */
- override def toString(): String = "LOAD_ARRAY_ITEM (" + kind + ")";
+ override def toString(): String = "LOAD_ARRAY_ITEM (" + kind + ")"
- override def consumed = 2;
- override def produced = 1;
+ override def consumed = 2
+ override def produced = 1
- override def consumedTypes = List(ARRAY(kind), INT);
- override def producedTypes = List(kind);
+ override def consumedTypes = List(ARRAY(kind), INT)
+ override def producedTypes = List(kind)
}
/** Load a local variable on the stack. It can be a method argument.
@@ -133,12 +133,12 @@ trait Opcodes { self: ICodes =>
*/
case class LOAD_LOCAL(local: Local) extends Instruction {
/** Returns a string representation of this instruction */
- override def toString(): String = "LOAD_LOCAL "+local.toString(); //+isArgument?" (argument)":"";
+ override def toString(): String = "LOAD_LOCAL "+local.toString() //+isArgument?" (argument)":"";
- override def consumed = 0;
- override def produced = 1;
+ override def consumed = 0
+ override def produced = 1
- override def producedTypes = List(local.kind);
+ override def producedTypes = List(local.kind)
}
/** Load a field on the stack. The object to which it refers should be
@@ -146,13 +146,13 @@ trait Opcodes { self: ICodes =>
* Stack: ...:ref (assuming isStatic = false)
* ->: ...:value
*/
- case class LOAD_FIELD(field: Symbol, isStatic: boolean) extends Instruction {
+ case class LOAD_FIELD(field: Symbol, isStatic: Boolean) extends Instruction {
/** Returns a string representation of this instruction */
override def toString(): String =
"LOAD_FIELD " + (if (isStatic) field.fullNameString else field.toString());
- override def consumed = if(isStatic) 0 else 1;
- override def produced = 1;
+ override def consumed = if (isStatic) 0 else 1
+ override def produced = 1
override def consumedTypes = if (isStatic) Nil else List(REFERENCE(field.owner));
override def producedTypes = List(toTypeKind(field.tpe));
@@ -163,12 +163,12 @@ trait Opcodes { self: ICodes =>
"Invalid module symbol");
/** Returns a string representation of this instruction */
override def toString(): String =
- "LOAD_MODULE " + module.toString();
+ "LOAD_MODULE " + module.toString()
- override def consumed = 0;
- override def produced = 1;
+ override def consumed = 0
+ override def produced = 1
- override def producedTypes = List(REFERENCE(module));
+ override def producedTypes = List(REFERENCE(module))
}
/** Store a value into an array at a specified index.
@@ -177,12 +177,12 @@ trait Opcodes { self: ICodes =>
*/
case class STORE_ARRAY_ITEM(kind: TypeKind) extends Instruction {
/** Returns a string representation of this instruction */
- override def toString(): String = "STORE_ARRAY_ITEM (" + kind + ")";
+ override def toString(): String = "STORE_ARRAY_ITEM (" + kind + ")"
- override def consumed = 3;
- override def produced = 0;
+ override def consumed = 3
+ override def produced = 0
- override def consumedTypes = List(ARRAY(kind), INT, kind);
+ override def consumedTypes = List(ARRAY(kind), INT, kind)
}
/** Store a value into a local variable. It can be an argument.
@@ -193,17 +193,17 @@ trait Opcodes { self: ICodes =>
/** Returns a string representation of this instruction */
override def toString(): String = "STORE_LOCAL "+local.toString(); //+isArgument?" (argument)":"";
- override def consumed = 1;
- override def produced = 0;
+ override def consumed = 1
+ override def produced = 0
- override def consumedTypes = List(local.kind);
+ override def consumedTypes = List(local.kind)
}
/** Store a value into a field.
* Stack: ...:ref:value (assuming isStatic=false)
* ->: ...
*/
- case class STORE_FIELD(field: Symbol, isStatic: boolean) extends Instruction {
+ case class STORE_FIELD(field: Symbol, isStatic: Boolean) extends Instruction {
/** Returns a string representation of this instruction */
override def toString(): String =
"STORE_FIELD "+field.toString() + (if (isStatic) " (static)" else " (dynamic)");
@@ -224,54 +224,54 @@ trait Opcodes { self: ICodes =>
*/
case class CALL_PRIMITIVE(primitive: Primitive) extends Instruction {
/** Returns a string representation of this instruction */
- override def toString(): String ="CALL_PRIMITIVE "+primitive.toString();
+ override def toString(): String ="CALL_PRIMITIVE "+primitive.toString()
override def consumed = primitive match {
- case Negation(_) => 1;
- case Test(_,_,true) => 1;
- case Test(_,_,false) => 2;
- case Comparison(_,_) => 2;
- case Arithmetic(NOT,_) => 1;
- case Arithmetic(_,_) => 2;
- case Logical(_,_) => 2;
- case Shift(_,_) => 2;
- case Conversion(_,_) => 1;
- case ArrayLength(_) => 1;
- case StringConcat(_) => 2;
- case StartConcat => 0;
- case EndConcat => 1;
+ case Negation(_) => 1
+ case Test(_,_, true) => 1
+ case Test(_,_, false) => 2
+ case Comparison(_,_) => 2
+ case Arithmetic(NOT,_) => 1
+ case Arithmetic(_,_) => 2
+ case Logical(_,_) => 2
+ case Shift(_,_) => 2
+ case Conversion(_,_) => 1
+ case ArrayLength(_) => 1
+ case StringConcat(_) => 2
+ case StartConcat => 0
+ case EndConcat => 1
}
- override def produced = 1;
+ override def produced = 1
override def consumedTypes = primitive match {
- case Negation(kind) => List(kind);
- case Test(_, kind, true) => List(kind);
- case Test(_, kind, false) => List(kind, kind);
- case Comparison(_, kind) => List(kind, kind);
- case Arithmetic(NOT, kind) => List(kind);
- case Arithmetic(_, kind) => List(kind, kind);
- case Logical(_, kind) => List(kind, kind);
- case Shift(_, kind) => List(kind, INT);
- case Conversion(from, _) => List(from);
- case ArrayLength(kind) => List(ARRAY(kind));
- case StringConcat(kind) => List(ConcatClass, kind);
- case StartConcat => Nil;
- case EndConcat => List(ConcatClass);
+ case Negation(kind) => List(kind)
+ case Test(_, kind, true) => List(kind)
+ case Test(_, kind, false) => List(kind, kind)
+ case Comparison(_, kind) => List(kind, kind)
+ case Arithmetic(NOT, kind) => List(kind)
+ case Arithmetic(_, kind) => List(kind, kind)
+ case Logical(_, kind) => List(kind, kind)
+ case Shift(_, kind) => List(kind, INT)
+ case Conversion(from, _) => List(from)
+ case ArrayLength(kind) => List(ARRAY(kind))
+ case StringConcat(kind) => List(ConcatClass, kind)
+ case StartConcat => Nil
+ case EndConcat => List(ConcatClass)
}
override def producedTypes = primitive match {
- case Negation(kind) => List(kind);
- case Test(_, _, true) => List(BOOL);
- case Test(_, _, false) => List(BOOL);
- case Comparison(_, _) => List(INT);
- case Arithmetic(_, kind) => List(kind);
- case Logical(_, kind) => List(kind);
- case Shift(_, kind) => List(kind);
- case Conversion(_, to) => List(to);
- case ArrayLength(_) => List(INT);
- case StringConcat(_) => List(ConcatClass);
- case StartConcat => List(ConcatClass);
- case EndConcat => List(REFERENCE(global.definitions.StringClass));
+ case Negation(kind) => List(kind)
+ case Test(_, _, true) => List(BOOL)
+ case Test(_, _, false) => List(BOOL)
+ case Comparison(_, _) => List(INT)
+ case Arithmetic(_, kind) => List(kind)
+ case Logical(_, kind) => List(kind)
+ case Shift(_, kind) => List(kind)
+ case Conversion(_, to) => List(to)
+ case ArrayLength(_) => List(INT)
+ case StringConcat(_) => List(ConcatClass)
+ case StartConcat => List(ConcatClass)
+ case EndConcat => List(REFERENCE(global.definitions.StringClass))
}
}
@@ -379,11 +379,11 @@ trait Opcodes { self: ICodes =>
*/
case class IS_INSTANCE(typ: TypeKind) extends Instruction {
/** Returns a string representation of this instruction */
- override def toString(): String ="IS_INSTANCE "+typ.toString();
+ override def toString(): String ="IS_INSTANCE "+typ.toString()
- override def consumed = 1;
+ override def consumed = 1
override def consumedTypes = AnyRefReference :: Nil
- override def produced = 1;
+ override def produced = 1
}
/** This class represents a CHECK_CAST instruction
@@ -392,10 +392,10 @@ trait Opcodes { self: ICodes =>
*/
case class CHECK_CAST(typ: TypeKind) extends Instruction {
/** Returns a string representation of this instruction */
- override def toString(): String ="CHECK_CAST "+typ.toString();
+ override def toString(): String ="CHECK_CAST "+typ.toString()
- override def consumed = 1;
- override def produced = 1;
+ override def consumed = 1
+ override def produced = 1
override val consumedTypes = List(AnyRefReference)
override def producedTypes = List(typ)
}
@@ -410,10 +410,10 @@ trait Opcodes { self: ICodes =>
*/
case class SWITCH(tags: List[List[Int]], labels: List[BasicBlock]) extends Instruction {
/** Returns a string representation of this instruction */
- override def toString(): String ="SWITCH ...";
+ override def toString(): String ="SWITCH ..."
- override def consumed = 1;
- override def produced = 0;
+ override def consumed = 1
+ override def produced = 0
}
/** This class represents a JUMP instruction
@@ -422,10 +422,10 @@ trait Opcodes { self: ICodes =>
*/
case class JUMP(whereto: BasicBlock) extends Instruction {
/** Returns a string representation of this instruction */
- override def toString(): String ="JUMP "+whereto.label;
+ override def toString(): String ="JUMP "+whereto.label
- override def consumed = 0;
- override def produced = 0;
+ override def consumed = 0
+ override def produced = 0
}
/** This class represents a CJUMP instruction
@@ -445,8 +445,8 @@ trait Opcodes { self: ICodes =>
cond.toString()+" ? "+successBlock.label+" : "+failureBlock.label
);
- override def consumed = 2;
- override def produced = 0;
+ override def consumed = 2
+ override def produced = 0
}
/** This class represents a CZJUMP instruction
@@ -464,8 +464,8 @@ trait Opcodes { self: ICodes =>
cond.toString()+" ? "+successBlock.label+" : "+failureBlock.label
);
- override def consumed = 1;
- override def produced = 0;
+ override def consumed = 1
+ override def produced = 0
}
@@ -475,10 +475,10 @@ trait Opcodes { self: ICodes =>
*/
case class RETURN(kind: TypeKind) extends Instruction {
/** Returns a string representation of this instruction */
- override def toString(): String ="RETURN (" + kind + ")";
+ override def toString(): String ="RETURN (" + kind + ")"
- override def consumed = if(kind == UNIT) 0 else 1;
- override def produced = 0;
+ override def consumed = if (kind == UNIT) 0 else 1
+ override def produced = 0
}
/** This class represents a THROW instruction
@@ -487,10 +487,10 @@ trait Opcodes { self: ICodes =>
*/
case class THROW() extends Instruction {
/** Returns a string representation of this instruction */
- override def toString(): String ="THROW";
+ override def toString(): String ="THROW"
- override def consumed = 1;
- override def produced = 0;
+ override def consumed = 1
+ override def produced = 0
}
/** This class represents a DROP instruction
@@ -499,10 +499,10 @@ trait Opcodes { self: ICodes =>
*/
case class DROP (typ: TypeKind) extends Instruction {
/** Returns a string representation of this instruction */
- override def toString(): String ="DROP "+typ.toString();
+ override def toString(): String ="DROP "+typ.toString()
- override def consumed = 1;
- override def produced = 0;
+ override def consumed = 1
+ override def produced = 0
}
/** This class represents a DUP instruction
@@ -511,10 +511,10 @@ trait Opcodes { self: ICodes =>
*/
case class DUP (typ: TypeKind) extends Instruction {
/** Returns a string representation of this instruction */
- override def toString(): String ="DUP";
+ override def toString(): String ="DUP"
- override def consumed = 1;
- override def produced = 2;
+ override def consumed = 1
+ override def produced = 2
}
/** This class represents a MONITOR_ENTER instruction
@@ -524,10 +524,10 @@ trait Opcodes { self: ICodes =>
case class MONITOR_ENTER() extends Instruction {
/** Returns a string representation of this instruction */
- override def toString(): String ="MONITOR_ENTER";
+ override def toString(): String ="MONITOR_ENTER"
- override def consumed = 1;
- override def produced = 0;
+ override def consumed = 1
+ override def produced = 0
}
/** This class represents a MONITOR_EXIT instruction
@@ -580,14 +580,14 @@ trait Opcodes { self: ICodes =>
/** Is this a dynamic method call? */
def isDynamic: Boolean = this match {
- case Dynamic => true;
- case _ => false;
+ case Dynamic => true
+ case _ => false
}
/** Is this a static method call? */
def isStatic: Boolean = this match {
- case Static(_) => true;
- case _ => false;
+ case Static(_) => true
+ case _ => false
}
def isSuper: Boolean = this match {
@@ -597,31 +597,31 @@ trait Opcodes { self: ICodes =>
/** Is this an instance method call? */
def hasInstance: Boolean = this match {
- case Dynamic => true;
- case Static(onInstance) => onInstance;
- case SuperCall(_) => true;
- case _ => false;
+ case Dynamic => true
+ case Static(onInstance) => onInstance
+ case SuperCall(_) => true
+ case _ => false
}
/** Returns a string representation of this style. */
override def toString(): String = this match {
- case Dynamic => "dynamic";
- case Static(false) => "static-class";
- case Static(true) => "static-instance";
- case SuperCall(mix) => "super(" + mix + ")";
+ case Dynamic => "dynamic"
+ case Static(false) => "static-class"
+ case Static(true) => "static-instance"
+ case SuperCall(mix) => "super(" + mix + ")"
}
}
- case object Dynamic extends InvokeStyle;
+ case object Dynamic extends InvokeStyle
/**
* Special invoke. Static(true) is used for calls to private
* members.
*/
- case class Static(onInstance: Boolean) extends InvokeStyle;
+ case class Static(onInstance: Boolean) extends InvokeStyle
/** Call through super[mix]. */
- case class SuperCall(mix: Name) extends InvokeStyle;
+ case class SuperCall(mix: Name) extends InvokeStyle
}
}
diff --git a/src/compiler/scala/tools/nsc/backend/icode/Primitives.scala b/src/compiler/scala/tools/nsc/backend/icode/Primitives.scala
index 3f07856dce..53b6b4b609 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/Primitives.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/Primitives.scala
@@ -1,5 +1,5 @@
/* NSC -- new scala compiler
- * Copyright 2005 LAMP/EPFL
+ * Copyright 2005-2007 LAMP/EPFL
* @author Martin Odersky
*/
@@ -19,33 +19,33 @@ trait Primitives { self: ICodes =>
// type : (type) => type
// range: type <- { BOOL, Ix, Ux, Rx }
// jvm : {i, l, f, d}neg
- case class Negation(kind: TypeKind) extends Primitive;
+ case class Negation(kind: TypeKind) extends Primitive
// type : zero ? (type) => BOOL : (type,type) => BOOL
// range: type <- { BOOL, Ix, Ux, Rx, REF }
// jvm : if{eq, ne, lt, ge, le, gt}, if{null, nonnull}
// if_icmp{eq, ne, lt, ge, le, gt}, if_acmp{eq,ne}
- case class Test(op: TestOp, kind: TypeKind, zero: boolean) extends Primitive;
+ case class Test(op: TestOp, kind: TypeKind, zero: Boolean) extends Primitive
// type : (type,type) => I4
// range: type <- { Ix, Ux, Rx }
// jvm : lcmp, {f, d}cmp{l, g}
- case class Comparison(op: ComparisonOp, kind: TypeKind) extends Primitive;
+ case class Comparison(op: ComparisonOp, kind: TypeKind) extends Primitive
// type : (type,type) => type
// range: type <- { Ix, Ux, Rx }
// jvm : {i, l, f, d}{add, sub, mul, div, rem}
- case class Arithmetic(op: ArithmeticOp, kind: TypeKind) extends Primitive;
+ case class Arithmetic(op: ArithmeticOp, kind: TypeKind) extends Primitive
// type : (type,type) => type
// range: type <- { BOOL, Ix, Ux }
// jvm : {i, l}{and, or, xor}
- case class Logical(op: LogicalOp, kind: TypeKind) extends Primitive;
+ case class Logical(op: LogicalOp, kind: TypeKind) extends Primitive
// type : (type,I4) => type
// range: type <- { Ix, Ux }
// jvm : {i, l}{shl, ushl, shr}
- case class Shift(op: ShiftOp, kind: TypeKind) extends Primitive;
+ case class Shift(op: ShiftOp, kind: TypeKind) extends Primitive
// type : (src) => dst
// range: src,dst <- { Ix, Ux, Rx }
@@ -60,38 +60,38 @@ trait Primitives { self: ICodes =>
// type : (buf,el) => buf
// range: lf,rg <- { BOOL, Ix, Ux, Rx, REF, STR }
// jvm : It should call the appropiate 'append' method on StringBuffer
- case class StringConcat(el: TypeKind) extends Primitive;
+ case class StringConcat(el: TypeKind) extends Primitive
/** Signals the beginning of a series of concatenations.
* On the JVM platform, it should create a new StringBuffer
*/
- case object StartConcat extends Primitive;
+ case object StartConcat extends Primitive
/**
* type: (buf) => STR
* jvm : It should turn the StringBuffer into a String.
*/
- case object EndConcat extends Primitive;
+ case object EndConcat extends Primitive
/** Pretty printer for primitives */
class PrimitivePrinter(out: PrintWriter) {
def print(s: String): PrimitivePrinter = {
- out.print(s);
+ out.print(s)
this
}
- def print(o: AnyRef): PrimitivePrinter = print(o.toString());
+ def print(o: AnyRef): PrimitivePrinter = print(o.toString())
def printPrimitive(prim: Primitive) = prim match {
case Negation(kind) =>
- print("!");
+ print("!")
case Test(op, kind, zero) =>
- print(op).print(kind);
+ print(op).print(kind)
case Comparison(op, kind) =>
- print(op).print("(").print(kind);
+ print(op).print("(").print(kind)
}
}
@@ -101,21 +101,21 @@ trait Primitives { self: ICodes =>
/** Returns a string representation of this operation. */
override def toString(): String = this match {
- case CMPL => "CMPL";
- case CMP => "CMP";
- case CMPG => "CMPG";
- case _ => throw new RuntimeException("ComparisonOp unknown case");
+ case CMPL => "CMPL"
+ case CMP => "CMP"
+ case CMPG => "CMPG"
+ case _ => throw new RuntimeException("ComparisonOp unknown case")
}
}
/** A comparison operation with -1 default for NaNs */
- case object CMPL extends ComparisonOp;
+ case object CMPL extends ComparisonOp
/** A comparison operation with no default for NaNs */
- case object CMP extends ComparisonOp;
+ case object CMP extends ComparisonOp
/** A comparison operation with +1 default for NaNs */
- case object CMPG extends ComparisonOp;
+ case object CMPG extends ComparisonOp
/** This class represents a test operation. */
@@ -123,117 +123,117 @@ trait Primitives { self: ICodes =>
/** Returns the negation of this operation. */
def negate(): TestOp = this match {
- case EQ => NE;
- case NE => EQ;
- case LT => GE;
- case GE => LT;
- case LE => GT;
- case GT => LE;
- case _ => throw new RuntimeException("TestOp unknown case");
+ case EQ => NE
+ case NE => EQ
+ case LT => GE
+ case GE => LT
+ case LE => GT
+ case GT => LE
+ case _ => throw new RuntimeException("TestOp unknown case")
}
/** Returns a string representation of this operation. */
override def toString(): String = this match {
- case EQ => "EQ";
- case NE => "NE";
- case LT => "LT";
- case GE => "GE";
- case LE => "LE";
- case GT => "GT";
- case _ => throw new RuntimeException("TestOp unknown case");
+ case EQ => "EQ"
+ case NE => "NE"
+ case LT => "LT"
+ case GE => "GE"
+ case LE => "LE"
+ case GT => "GT"
+ case _ => throw new RuntimeException("TestOp unknown case")
}
}
/** An equality test */
- case object EQ extends TestOp;
+ case object EQ extends TestOp
/** A non-equality test */
- case object NE extends TestOp;
+ case object NE extends TestOp
/** A less-than test */
- case object LT extends TestOp;
+ case object LT extends TestOp
/** A greater-than-or-equal test */
- case object GE extends TestOp;
+ case object GE extends TestOp
/** A less-than-or-equal test */
- case object LE extends TestOp;
+ case object LE extends TestOp
/** A greater-than test */
- case object GT extends TestOp;
+ case object GT extends TestOp
/** This class represents an arithmetic operation. */
class ArithmeticOp {
/** Returns a string representation of this operation. */
override def toString(): String = this match {
- case ADD => "ADD";
- case SUB => "SUB";
- case MUL => "MUL";
- case DIV => "DIV";
- case REM => "REM";
- case NOT => "NOT";
- case _ => throw new RuntimeException("ArithmeticOp unknown case");
+ case ADD => "ADD"
+ case SUB => "SUB"
+ case MUL => "MUL"
+ case DIV => "DIV"
+ case REM => "REM"
+ case NOT => "NOT"
+ case _ => throw new RuntimeException("ArithmeticOp unknown case")
}
}
/** An arithmetic addition operation */
- case object ADD extends ArithmeticOp;
+ case object ADD extends ArithmeticOp
/** An arithmetic subtraction operation */
- case object SUB extends ArithmeticOp;
+ case object SUB extends ArithmeticOp
/** An arithmetic multiplication operation */
- case object MUL extends ArithmeticOp;
+ case object MUL extends ArithmeticOp
/** An arithmetic division operation */
- case object DIV extends ArithmeticOp;
+ case object DIV extends ArithmeticOp
/** An arithmetic remainder operation */
- case object REM extends ArithmeticOp;
+ case object REM extends ArithmeticOp
/** Bitwise negation. */
- case object NOT extends ArithmeticOp;
+ case object NOT extends ArithmeticOp
/** This class represents a shift operation. */
class ShiftOp {
/** Returns a string representation of this operation. */
override def toString(): String = this match {
- case LSL => "LSL";
- case ASR => "ASR";
- case LSR => "LSR";
- case _ => throw new RuntimeException("ShitOp unknown case");
+ case LSL => "LSL"
+ case ASR => "ASR"
+ case LSR => "LSR"
+ case _ => throw new RuntimeException("ShitOp unknown case")
}
}
/** A logical shift to the left */
- case object LSL extends ShiftOp;
+ case object LSL extends ShiftOp
/** An arithmetic shift to the right */
- case object ASR extends ShiftOp;
+ case object ASR extends ShiftOp
/** A logical shift to the right */
- case object LSR extends ShiftOp;
+ case object LSR extends ShiftOp
/** This class represents a logical operation. */
class LogicalOp {
/** Returns a string representation of this operation. */
override def toString(): String = this match {
- case AND => return "AND";
- case OR => return "OR";
- case XOR => return "XOR";
- case _ => throw new RuntimeException("LogicalOp unknown case");
+ case AND => return "AND"
+ case OR => return "OR"
+ case XOR => return "XOR"
+ case _ => throw new RuntimeException("LogicalOp unknown case")
}
}
/** A bitwise AND operation */
- case object AND extends LogicalOp;
+ case object AND extends LogicalOp
/** A bitwise OR operation */
- case object OR extends LogicalOp;
+ case object OR extends LogicalOp
/** A bitwise XOR operation */
- case object XOR extends LogicalOp;
+ case object XOR extends LogicalOp
}
diff --git a/src/library/scala/util/parsing/ast/Binders.scala b/src/library/scala/util/parsing/ast/Binders.scala
index 50f9738d52..c1cbead24c 100644
--- a/src/library/scala/util/parsing/ast/Binders.scala
+++ b/src/library/scala/util/parsing/ast/Binders.scala
@@ -1,7 +1,7 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
@@ -15,9 +15,14 @@ import scala.collection.mutable.Map
// TODO: avoid clashes when substituting
// TODO: check binders in the same scope are distinct
-/** This trait provides the core Scrap-Your-Boilerplate abstractions as well as implementations for common datatypes.
- *
- * Based on Ralph Laemmel's SYB papers
+/** <p>
+ * This trait provides the core Scrap-Your-Boilerplate abstractions as
+ * well as implementations for common datatypes.
+ * </p>
+ * <p>
+ * Based on Ralph Laemmel's <a target="_top"
+ * href="http://homepages.cwi.nl/~ralf/publications.html">SYB papers</a>.
+ * </p>
*
* @author Adriaan Moors
*/
@@ -29,32 +34,43 @@ trait Mappable {
we can't require that the type is preserved precisely: a Name may map to e.g., a MethodCall
*/
-
- trait Mappable[t] {
+ trait Mappable[T] {
// one-layer traversal
- def gmap(f: Mapper): t
+ def gmap(f: Mapper): T
// everywhere f x = f (gmapT (everywhere f) x)
- def everywhere(f: Mapper)(implicit c: t => Mappable[t]): t = f(gmap(new Mapper{ def apply[t <% Mappable[t]](x :t): t = x.everywhere(f)}))
+ def everywhere(f: Mapper)(implicit c: T => Mappable[T]): T =
+ f(gmap(new Mapper { def apply[T <% Mappable[T]](x: T): T = x.everywhere(f)}))
}
- implicit def StringIsMappable(s: String): Mappable[String] = new Mappable[String] {
- def gmap(f: Mapper): String = f(s)
- }
- implicit def ListIsMappable[t <% Mappable[t]](xs: List[t]): Mappable[List[t]] = new Mappable[List[t]] {
- def gmap(f: Mapper): List[t] = (for(val x <- xs) yield f(x)).toList
- }
- implicit def OptionIsMappable[t <% Mappable[t]](xs: Option[t]): Mappable[Option[t]] = new Mappable[Option[t]] {
- def gmap(f: Mapper): Option[t] = (for(val x <- xs) yield f(x))
- }
+ implicit def StringIsMappable(s: String): Mappable[String] =
+ new Mappable[String] {
+ def gmap(f: Mapper): String = f(s)
+ }
+
+ implicit def ListIsMappable[t <% Mappable[t]](xs: List[t]): Mappable[List[t]] =
+ new Mappable[List[t]] {
+ def gmap(f: Mapper): List[t] = (for(val x <- xs) yield f(x)).toList
+ }
+
+ implicit def OptionIsMappable[t <% Mappable[t]](xs: Option[t]): Mappable[Option[t]] =
+ new Mappable[Option[t]] {
+ def gmap(f: Mapper): Option[t] = (for(val x <- xs) yield f(x))
+ }
}
-/** This component provides functionality for enforcing variable binding during parse-time.
- *
- * When parsing simple languages, like Featherweight Scala, these parser combinators will fully enforce
- * the binding discipline. When names are allowed to be left unqualified, these mechanisms would have
- * to be complemented by an extra phase that resolves names that couldn't be resolved using the naive
- * binding rules. (Maybe some machinery to model `implicit' binders (e.g., `this' and imported qualifiers)
- * and selection on a binder will suffice?)
+/** <p>
+ * This component provides functionality for enforcing variable binding
+ * during parse-time.
+ * </p>
+ * <p>
+ * When parsing simple languages, like Featherweight Scala, these parser
+ * combinators will fully enforce the binding discipline. When names are
+ * allowed to be left unqualified, these mechanisms would have to be
+ * complemented by an extra phase that resolves names that couldn't be
+ * resolved using the naive binding rules. (Maybe some machinery to
+ * model `implicit' binders (e.g., `this' and imported qualifiers)
+ * and selection on a binder will suffice?)
+ * </p>
*
* @author Adriaan Moors
*/
@@ -160,8 +176,8 @@ trait Binders extends AbstractSyntax with Mappable {
the binding in the returned scope also does, and thus the check that all variables are bound is deferred until this scope is left **/
def nested: Scope[binderType] = this // TODO
- def onEnter = {}
- def onLeft = {}
+ def onEnter {}
+ def onLeft {}
}
@@ -275,7 +291,7 @@ trait Binders extends AbstractSyntax with Mappable {
def UserNameElementIsMappable[t <: NameElement](self: t): Mappable[t]
object UnderBinder {
- def apply[binderType <: NameElement, elementT <% Mappable[elementT]](scope: Scope[binderType], element: elementT) = new UnderBinder(scope, element)
+ def apply[binderType <: NameElement, elementT <% Mappable[elementT]](scope: Scope[binderType], element: elementT) = new UnderBinder(scope, element)
def unit[bt <: NameElement, elementT <% Mappable[elementT]](x: elementT) = UnderBinder(new Scope[bt](), x)
}
@@ -312,8 +328,9 @@ trait Binders extends AbstractSyntax with Mappable {
else BinderEnv.this.apply(w)
}
}
+
object EmptyBinderEnv extends BinderEnv {
- def apply[a <: NameElement](v: a): Option[Scope[a]] = None
+ def apply[A <: NameElement](v: A): Option[Scope[A]] = None
}
/** Returns a given result, but executes the supplied closure before returning.
@@ -324,8 +341,15 @@ trait Binders extends AbstractSyntax with Mappable {
* @param result the result to be returned
* @param block code to be executed, purely for its side-effects
*/
- trait ReturnAndDo[t]{def andDo(block: =>unit):t} // gotta love Smalltalk syntax :-)
- def return_[t](result: t):ReturnAndDo[t] = new ReturnAndDo[t]{val r=result; def andDo(block: =>unit):t = {block; r}}
+ trait ReturnAndDo[T]{
+ def andDo(block: => Unit): T
+ } // gotta love Smalltalk syntax :-)
+
+ def return_[T](result: T): ReturnAndDo[T] =
+ new ReturnAndDo[T] {
+ val r = result
+ def andDo(block: => Unit): T = {block; r}
+ }
private object _Binder {
private var currentId = 0
diff --git a/src/library/scala/util/parsing/combinator/Parsers.scala b/src/library/scala/util/parsing/combinator/Parsers.scala
index c37ef4c288..4628193ba0 100644
--- a/src/library/scala/util/parsing/combinator/Parsers.scala
+++ b/src/library/scala/util/parsing/combinator/Parsers.scala
@@ -1,11 +1,13 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
+// $Id$
+
package scala.util.parsing.combinator
import scala.util.parsing.input._
@@ -14,28 +16,41 @@ import scala.collection.mutable.{Map=>MutableMap}
// TODO: better error handling (labelling like parsec's <?>)
// TODO: memoisation (like packrat parsers?)
-/** `Parsers' is a component that <i>provides</i> generic parser combinators.
- *
- * It <i>requires</i> the type of the elements these parsers should parse
- * (each parser is polymorphic in the type of result it produces).
- *<p>
- * There are two aspects to the result of a parser: (1) success or failure, and (2) the result.
- * A `Parser[T]' provides both kinds of information, but a `UnitParser' only signals success/failure.
- * When composing a `UnitParser' with a normal `Parser', the `UnitParser' only contributes to whether
- * the combined parser is successful (i.e., its result is discarded).</p>
- *<p>
- * The term ``parser combinator'' refers to the fact that these parsers are constructed from primitive
- * parsers and composition operators, such as sequencing, alternation, optionality, repetition,
- * lifting, and so on.</p>
- *<p>
- * A ``primitive parser'' is a parser that accepts or rejects a single piece of input,
- * based on a certain criterion, such as whether the input... <ul>
- * <li> is equal to some given object, </li>
- * <li> satisfies a certain predicate, </li>
- * <li> is in the domain of a given partial function,.... </li></ul></p>
+/** <p>
+ * <code>Parsers</code> is a component that <i>provides</i> generic
+ * parser combinators.
+ * </p>
+ * <p>
+ * It <i>requires</i> the type of the elements these parsers should parse
+ * (each parser is polymorphic in the type of result it produces).
+ * </p>
+ * <p>
+ * There are two aspects to the result of a parser: (1) success or failure,
+ * and (2) the result. A <code>Parser[T]</code> provides both kinds of
+ * information, but a <code>UnitParser</code> only signals success/failure.
+ * When composing a `UnitParser' with a normal <code>Parser</code>, the
+ * <code>UnitParser</code> only contributes to whether the combined parser
+ * is successful (i.e., its result is discarded).
+ * </p>
+ * <p>
+ * The term ``parser combinator'' refers to the fact that these parsers
+ * are constructed from primitive parsers and composition operators, such
+ * as sequencing, alternation, optionality, repetition, lifting, and so on.
+ * </p>
+ * <p>
+ * A ``primitive parser'' is a parser that accepts or rejects a single
+ * piece of input, based on a certain criterion, such as whether the
+ * input...
+ * </p><ul>
+ * <li> is equal to some given object, </li>
+ * <li> satisfies a certain predicate, </li>
+ * <li> is in the domain of a given partial function,.... </li>
+ * </ul>
+ * <p>
+ * Even more primitive parsers always produce the same result, irrespective
+ * of the input.
+ * </p>
*
- *<p> Even more primitive parsers always produce the same result, irrespective of the input. </p>
- *<p>
* @requires Elem the type of elements the provided parsers consume
* (When consuming invidual characters, a parser is typically called a ``scanner'',
* which produces ``tokens'' that are consumed by what is normally called a ``parser''.
@@ -61,8 +76,9 @@ trait Parsers {
type Input = Reader[Elem]
/** A base class for parser results.
- * A result is either successful or not (failure may be fatal, i.e., an Error, or not, i.e., a Failure)
- * On success, provides a result of type `T'.
+ * A result is either successful or not (failure may be fatal, i.e.,
+ * an Error, or not, i.e., a Failure)
+ * On success, provides a result of type <code>T</code>.
*/
sealed abstract class ParseResult[+T] {
/** Functional composition of ParseResults
@@ -360,15 +376,15 @@ trait Parsers {
def ? = opt(this)
}
- /** The root class of special parsers returning the trivial result `unit'
- * These compose differently from normal parsers in that the `unit'
+ /** The root class of special parsers returning the trivial result <code>Unit</code>
+ * These compose differently from normal parsers in that the <code>Unit</code>
* result in a sequential or function composition is dropped.
*/
- abstract class UnitParser extends (Input => ParseResult[unit]) {
+ abstract class UnitParser extends (Input => ParseResult[Unit]) {
/** An unspecified method that defines the behaviour of this parser.
*/
- def apply(in: Input): ParseResult[unit]
+ def apply(in: Input): ParseResult[Unit]
/** A parser combinator for sequential composition
*
@@ -394,7 +410,7 @@ trait Parsers {
* @return a `UnitParser' that fails if either `p' or `q' fails.
*/
def ~ [A <% UnitParser](q: => A): UnitParser = new UnitParser {
- def apply(in: Input): ParseResult[unit] = seq(UnitParser.this, q)((x, y) => y)(in)
+ def apply(in: Input): ParseResult[Unit] = seq(UnitParser.this, q)((x, y) => y)(in)
override def toString = "~"
}
@@ -513,7 +529,7 @@ trait Parsers {
/*trait ElemFun
case class EFCons(hd: Elem => ElemFun, tl: ElemFun) extends ElemFun
- case class EFNil(res: boolean) extends ElemFun*/
+ case class EFNil(res: Boolean) extends ElemFun*/
/** A parser matching input elements that satisfy a given predicate
@@ -524,7 +540,7 @@ trait Parsers {
* @param p A predicate that determines which elements match.
* @return
*/
- def elem(kind: String, p: Elem => boolean) = new Parser[Elem] {
+ def elem(kind: String, p: Elem => Boolean) = new Parser[Elem] {
def apply(in: Input) =
if (p(in.first)) Success(in.first, in.rest)
else Failure(kind+" expected", in)
@@ -829,12 +845,12 @@ trait Parsers {
}
}
- /** `positioned' decorates a unit-parser so that it returns the start position of the input it
- * consumed.
+ /** <code>positioned</code> decorates a unit-parser so that it returns the
+ * start position of the input it consumed.
*
- * @param p a `UnitParser'.
- * @return A parser that has the same behaviour as `p', but which returns the start position of the
- * input it consumed.
+ * @param p a `UnitParser'.
+ * @return A parser that has the same behaviour as `p', but which returns
+ * the start position of the input it consumed.
*/
def positioned(p: UnitParser) = new Parser[Position] {
def apply(in: Input) = p(in) match {
@@ -861,7 +877,7 @@ trait Parsers {
def apply(in: Input): ParseResult[U] = seq(UnitOnceParser.this, commit(q))((x, y) => y)(in)
}
override def ~ [A <% UnitParser](q: => A): UnitParser = new UnitOnceParser {
- def apply(in: Input): ParseResult[unit] = seq(UnitOnceParser.this, commit(q))((x, y) => y)(in)
+ def apply(in: Input): ParseResult[Unit] = seq(UnitOnceParser.this, commit(q))((x, y) => y)(in)
}
}
-} \ No newline at end of file
+}
diff --git a/src/library/scala/util/parsing/combinator/lexical/Lexical.scala b/src/library/scala/util/parsing/combinator/lexical/Lexical.scala
index e2759d1501..d703b89ae8 100644
--- a/src/library/scala/util/parsing/combinator/lexical/Lexical.scala
+++ b/src/library/scala/util/parsing/combinator/lexical/Lexical.scala
@@ -34,7 +34,7 @@ abstract class Lexical extends Scanners with Tokens {
def digit = elem("digit", _.isDigit)
/** A character-parser that matches any character except the ones given in `cs' (and returns it)*/
- def chrExcept(cs: char*) = elem("", ch => (cs forall (ch !=)))
+ def chrExcept(cs: Char*) = elem("", ch => (cs forall (ch !=)))
/** A character-parser that matches a white-space character (and returns it)*/
def whitespaceChar = elem("space char", ch => ch <= ' ' && ch != EofCh)
diff --git a/src/library/scala/util/parsing/combinator/lexical/Scanners.scala b/src/library/scala/util/parsing/combinator/lexical/Scanners.scala
index 53868021db..8585b4d677 100644
--- a/src/library/scala/util/parsing/combinator/lexical/Scanners.scala
+++ b/src/library/scala/util/parsing/combinator/lexical/Scanners.scala
@@ -18,15 +18,16 @@ import scala.util.parsing.input._
* This component provides core functionality for lexical parsers.
* </p>
* <p>
- * See its subclasses {@see Lexical} and -- most interestingly {@see StdLexical},
- * for more functionality.
+ * See its subclasses {@see Lexical} and -- most interestingly
+ * {@see StdLexical}, for more functionality.
* </p>
*
* @requires token a parser that produces a token (from a stream of characters)
* @requires whitespace a unit-parser for white-space
- * @provides Scanner essentially a parser that parses a stream of characters to produce `Token's,
- * which are typically passed to a syntactical parser (which operates on
- * `Token's, not on individual characters)
+ * @provides Scanner essentially a parser that parses a stream of characters
+ * to produce `Token's, which are typically passed to a
+ * syntactical parser (which operates on `Token's, not on
+ * individual characters).
*
* @author Martin Odersky, Adriaan Moors
*/
@@ -41,8 +42,8 @@ trait Scanners extends Parsers with Tokens {
/** <p>
* <code>Scanner</code> is essentially(*) a parser that produces `Token's
- * from a stream of characters. The tokens it produces are typically passed
- * to parsers in <code>TokenParsers</code>.
+ * from a stream of characters. The tokens it produces are typically
+ * passed to parsers in <code>TokenParsers</code>.
* </p>
* <p>
* Note: (*) <code>Scanner</code> is really a `Reader' of `Token's
@@ -59,7 +60,7 @@ trait Scanners extends Parsers with Tokens {
}
case ns: NoSuccess => Triple(errorToken(ns.msg), ns.next, skip(ns.next))
}
- private def skip(in: Reader[char]) = if (in.atEnd) in else in.rest
+ private def skip(in: Reader[Char]) = if (in.atEnd) in else in.rest
def first = tok
def rest = new Scanner(rest2)
diff --git a/src/library/scala/util/parsing/combinator/syntactical/BindingParsers.scala b/src/library/scala/util/parsing/combinator/syntactical/BindingParsers.scala
index c86e7d9755..8ce806f1eb 100644
--- a/src/library/scala/util/parsing/combinator/syntactical/BindingParsers.scala
+++ b/src/library/scala/util/parsing/combinator/syntactical/BindingParsers.scala
@@ -15,32 +15,52 @@ import scala.util.parsing.ast._
// DISCLAIMER: this code is not well-tested -- consider it beta-quality!
-/** This component augments the generic parsers with support for variable binding.
- *
- * Use `bind' to decorate a parser that parses a binder (e.g., the name of a local variable or
- * an argument name in a list of formal arguments): besides the parser, it requires a fresh
- * `Binder' object, which serves as a container for one or more binders with the same scope.
- * The result of the parser is added to the binder's elements. Note that semantic equality (`equals')
- * is used to link a binder to its bound occurrences (along with its scope, of course).
- *
- * For example, here's how you'd write a parser (`p') for a let construct (assuming b: Binder[Name]):
- * "val" ~! bind(name, b) ~ ":" ~ typeP ~ "=" ~ term ~ "in" ~ in(term, b),
- *
- * This can be read as ``The parser that matches `val' (and then does not back-track anymore),
- * a name -- which represents a binder we'll call `b' -- a colon, a type, an equals sign, a term,
- * the keyword `in' and finally a term where `b' is in scope.''
- *
- * The result of this parser is a nested tuple of depth 3, containing a Type, a Term and
- * an UnderBinder[Name, Term]. Note that the binder itself is discarded (the UnderBinder keeps track of it).
- *
- * `newScope' makes an empty scope so that you can use `into' to pass it to a function that makes a parser
- * whose bound variables end up in this scope:
- * In our example, it would be used like this (with `b' free in `p'): <pre>newScope[Name] into { b => p }</pre>
- *
- * Finally, `bound(p)' constructs a parser that checks that the result of `p' is bound by some binder `b'
- * (i.e., `b' has an element which `equals' the result of `p') in the current scope (as delineated by
- * `in(scopeP, b)', where `p' is called during `scopeP'). If scoping is indeed respected, `bound(p)'
- * wraps the result of `p' in a `BoundElement'.
+/** <p>
+ * This component augments the generic parsers with support for variable binding.
+ * </p>
+ * <p>
+ * Use <code>bind</code> to decorate a parser that parses a binder (e.g.,
+ * the name of a local variable or an argument name in a list of formal
+ * arguments): besides the parser, it requires a fresh <code>Binder</code>
+ * object, which serves as a container for one or more binders with the same
+ * scope. The result of the parser is added to the binder's elements. Note
+ * that semantic equality (<code>equals</code>) is used to link a binder to
+ * its bound occurrences (along with its scope, of course).
+ * </p>
+ * <p>
+ * For example, here's how you'd write a parser (<code>p</code>) for a let
+ * construct (assuming <code>b: Binder[Name]</code>):
+ * </p><pre>
+ * "val" ~! bind(name, b) ~ ":" ~ typeP ~ "=" ~ term ~ "in" ~ in(term, b),</pre>
+ * <p>
+ * This can be read as ``The parser that matches <code>val</code> (and then
+ * does not back-track anymore), a name -- which represents a binder we'll
+ * call <code>b</code> -- a colon, a type, an equals sign, a term, the
+ * keyword <code>in</code> and finally a term where `b' is in scope.''
+ * </p>
+ * <p>
+ * The result of this parser is a nested tuple of depth 3, containing a
+ * Type, a <code>Term</code> and an <code>UnderBinder[Name, Term]</code>.
+ * Note that the binder itself is discarded (the <code>UnderBinder</code>
+ * keeps track of it).
+ * </p>
+ * <p>
+ * <code>newScope</code> makes an empty scope so that you can use
+ * <code>into</code> to pass it to a function that makes a parser
+ * whose bound variables end up in this scope:
+ * In our example, it would be used like this (with <code>b</code> free
+ * in <code>p</code>):
+ * </p><pre>
+ * newScope[Name] into { b => p }</pre>
+ * <p>
+ * Finally, <code>bound(p)</code> constructs a parser that checks that the
+ * result of <code>p</code> is bound by some binder <code>b</code> (i.e.,
+ * <code>b</code> has an element which <code>equals</code> the result of
+ * <code>p</code>) in the current scope (as delineated by
+ * <code>in(scopeP, b)</code>, where <code>p</code> is called during
+ * `scopeP'). If scoping is indeed respected, <code>bound(p)</code>
+ * wraps the result of <code>p</code> in a <code>BoundElement</code>.
+ * </p>
*
* @author Adriaan Moors
*/
@@ -51,9 +71,9 @@ trait BindingParsers extends Parsers with Binders {
* <pre>newScope[Name] into { b =>
* "val" ~! bind(name, b) ~ ":" ~ typeP ~ "=" ~ term ~ "in" ~ in(term, b)}</pre>
*/
- def newScope[t <: NameElement] = success(new Scope[t])
+ def newScope[T <: NameElement] = success(new Scope[T])
- def nested[t <: NameElement](s: Scope[t]) = success(s.nested)
+ def nested[T <: NameElement](s: Scope[T]) = success(s.nested)
// TODO: make `bind' and `in' methods of Scope?
@@ -69,15 +89,20 @@ trait BindingParsers extends Parsers with Binders {
* added to `scope' and not returned.
*/
def bind[bt <: NameElement](binderParser: Parser[bt], scope: Scope[bt]) = new UnitParser {
- def apply(in: Input): ParseResult[unit] = {
+ def apply(in: Input): ParseResult[Unit] = {
binderParser(in).map(x => scope.addBinder(x))
}
}
- /** Parse something that is in the scope of the given binders.
- *
- * During the execution of `scopeParser', the binders in `binder' are active:
- * see `bound' for more information. The result of the decorated parser is wrapped in an `UnderBinder'
+ /** <p>
+ * Parse something that is in the scope of the given binders.
+ * </p>
+ * <p>
+ * During the execution of <code>scopeParser</code>, the binders in
+ * <code>binder</code> are active: see <code>bound</code> for more
+ * information. The result of the decorated parser is wrapped in an
+ * <code>UnderBinder</code>.
+ * </p>
*
* @param scopeParser the parser that parses something that is in the scope of `binder'
* @param binder a container of binders, typically populated by `bind'
diff --git a/src/library/scala/util/parsing/input/CharArrayPosition.scala b/src/library/scala/util/parsing/input/CharArrayPosition.scala
index 299f15f067..c3d9f6ea62 100644
--- a/src/library/scala/util/parsing/input/CharArrayPosition.scala
+++ b/src/library/scala/util/parsing/input/CharArrayPosition.scala
@@ -1,15 +1,17 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
+// $Id$
+
package scala.util.parsing.input
-/** `CharArrayPosition' implements the general `Position' class for
- * documents represented by an `Array' of `char's.
+/** <code>CharArrayPosition</code> implements the general <code>Position</code>
+ * class for documents represented by an <code>Array</code> of `char's.
*
* @param source The contents of the document in which this position is contained
* @param line The line number of the position (1-based)
@@ -17,23 +19,23 @@ package scala.util.parsing.input
*
* @author Martin Odersky, Adriaan Moors
*/
-class CharArrayPosition(val source: Array[char], val line: int, val column: int) extends Position {
+class CharArrayPosition(val source: Array[Char], val line: Int, val column: Int) extends Position {
// TODO: this could be implemented more high-level:
- // return the string representation of the sub-array of source that starts after the
- // (lnum-1)'ed '\n' up to (but not including) the (lnum)'ed '\n'
- protected def lineContents(lnum: int) = {
+ // return the string representation of the sub-array of source that starts
+ // after the (lnum-1)'ed '\n' up to (but not including) the (lnum)'ed '\n'
+ protected def lineContents(lnum: Int) = {
var i = 0
var l = 1
while (i < source.length && l < lnum) {
- while (i < source.length && source(i) != '\n') i = i + 1
- i = i + 1
- l = l + 1
+ while (i < source.length && source(i) != '\n') i += 1
+ i += 1
+ l += 1
}
var chars = new StringBuffer
while (i < source.length && source(i) != '\n') {
chars append source(i)
- i = i + 1
+ i += 1
}
chars.toString
}
diff --git a/src/library/scala/util/parsing/input/CharArrayReader.scala b/src/library/scala/util/parsing/input/CharArrayReader.scala
index 4a531a4e53..f1f3240e19 100644
--- a/src/library/scala/util/parsing/input/CharArrayReader.scala
+++ b/src/library/scala/util/parsing/input/CharArrayReader.scala
@@ -1,11 +1,13 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
+// $Id$
+
package scala.util.parsing.input
/** An object encapsulating basic character constants
@@ -27,15 +29,16 @@ object CharArrayReader {
*
* @author Martin Odersky, Adriaan Moors
*/
-class CharArrayReader(source: Array[char], index: int, line: int, column: int) extends Reader[char] {
+class CharArrayReader(source: Array[Char], index: Int, line: Int, column: Int) extends Reader[Char] {
import CharArrayReader._
- /** Construct a `CharArrayReader' with its first element at `source(0)' and position `(1,1)'
+ /** Construct a <code>CharArrayReader</code> with its first element at
+ * <code>source(0)</code> and position <code>(1,1)</code>.
*/
- def this(source: Array[char]) = this(source, 0, 1, 1)
+ def this(source: Array[Char]) = this(source, 0, 1, 1)
private var i = index
- if (i + 1 < source.length && source(i) == CR && source(i + 1) == '\n') i = i + 1
+ if (i + 1 < source.length && source(i) == CR && source(i + 1) == '\n') i += 1
// see `first' in `Reader'
def first = if (i == source.length) EofCh else source(i)
diff --git a/src/library/scala/util/parsing/input/NoPosition.scala b/src/library/scala/util/parsing/input/NoPosition.scala
index ad498d19af..7c11a7c510 100644
--- a/src/library/scala/util/parsing/input/NoPosition.scala
+++ b/src/library/scala/util/parsing/input/NoPosition.scala
@@ -1,11 +1,14 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
+// $Id$
+
+
package scala.util.parsing.input
/** Undefined position
@@ -17,5 +20,5 @@ object NoPosition extends Position {
def column = 0
override def toString = "<undefined position>"
override def longString = toString
- def lineContents(lnum: int) = ""
+ def lineContents(lnum: Int) = ""
}
diff --git a/src/library/scala/util/parsing/input/Position.scala b/src/library/scala/util/parsing/input/Position.scala
index 0908c1fda7..1be14a1211 100644
--- a/src/library/scala/util/parsing/input/Position.scala
+++ b/src/library/scala/util/parsing/input/Position.scala
@@ -1,38 +1,44 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
package scala.util.parsing.input
-/** `Position' is the base class for objects describing a position in a ``document''.
- *<p>
- * It provides functionality for: <ul>
- * <li> generating a visual representation of this position (`longString');
- * <li> comparing two positions (`<').
- * </ul></p>
- *<p>
- * To use this class for a concrete kind of ``document'', implement the `lineContents' method.</p>
+/** <p>
+ * <code>Position</code> is the base class for objects describing a
+ * position in a ``document''.
+ * </p>
+ * <p>
+ * It provides functionality for:
+ * </p><ul>
+ * <li> generating a visual representation of this position (`longString');
+ * <li> comparing two positions (`<').
+ * </ul>
+ * <p>
+ * To use this class for a concrete kind of ``document'', implement the
+ * <code>lineContents</code> method.
+ * </p>
*
* @author Martin Odersky, Adriaan Moors
*/
trait Position {
/** The line number referred to by the position; line numbers start at 1 */
- def line: int
+ def line: Int
/** The column number referred to by the position; column numbers start at 1 */
- def column: int
+ def column: Int
/** The contents of the line numbered `lnum' (must not contain a new-line character).
*
* @param lnum a 1-based integer index into the `document'
* @return the line at `lnum' (not including a newline)
*/
- protected def lineContents(lnum: int): String
+ protected def lineContents(lnum: Int): String
/** Returns a string representation of the `Position', of the form `line.column' */
override def toString = ""+line+"."+column
diff --git a/src/library/scala/util/parsing/input/Reader.scala b/src/library/scala/util/parsing/input/Reader.scala
index 327f4f7aff..3a1021bbd6 100644
--- a/src/library/scala/util/parsing/input/Reader.scala
+++ b/src/library/scala/util/parsing/input/Reader.scala
@@ -1,14 +1,17 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
+// $Id$
+
+
package scala.util.parsing.input
-/** An interface for streams of values that have positions
+/** An interface for streams of values that have positions.
*
* @author Martin Odersky, Adriaan Moors
*/
@@ -20,7 +23,8 @@ abstract class Reader[+T] {
/** Returns an abstract reader consisting of all elements except the first
*
- * @return If `atEnd' is true, the result will be `this'; otherwise, it's a `Reader' containing
+ * @return If <code>atEnd</code> is <code>true</code>, the result will be
+ * <code>this'; otherwise, it's a <code>Reader</code> containing
* more elements.
*/
def rest: Reader[T]
@@ -32,5 +36,5 @@ abstract class Reader[+T] {
/** Whether there are any more elements in this reader besides the first.
* (i.e., whether calling `rest' will yield a `Reader' with more elements)
*/
- def atEnd: boolean
+ def atEnd: Boolean
}
diff --git a/src/library/scala/util/parsing/input/StreamReader.scala b/src/library/scala/util/parsing/input/StreamReader.scala
index c07b85b83d..9522e66650 100755
--- a/src/library/scala/util/parsing/input/StreamReader.scala
+++ b/src/library/scala/util/parsing/input/StreamReader.scala
@@ -1,34 +1,36 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
+// $Id: $
+
package scala.util.parsing.input
import java.io.BufferedReader
-/** An object to create a StreamReader from a java.io.Reader.
+/** An object to create a StreamReader from a <code>java.io.Reader</code>.
*
- * @param in the java.io.Reader that provides the underlying stream of characters for this Reader
+ * @param in the <code>java.io.Reader</code> that provides the underlying
+ * stream of characters for this Reader.
*
* @author Miles Sabin
*/
-object StreamReader
-{
+object StreamReader {
final val EofCh = '\032'
final val CR = '\015'
- def apply(in: java.io.Reader) = {
- val bin = new BufferedReader(in)
+ def apply(in: java.io.Reader): StreamReader = {
+ val bin = new BufferedReader(in)
new StreamReader(bin, bin.readLine, 1, 1)
}
}
-/** A character array reader reads a stream of characters (keeping track of their positions)
- * from an array.
+/** A character array reader reads a stream of characters (keeping track of
+ * their positions) from an array.
*
* @param bin the underlying java.io.BufferedReader
* @param sourceLine the line at column `col' in the stream
@@ -37,22 +39,22 @@ object StreamReader
*
* @author Miles Sabin
*/
-sealed class StreamReader private (bin: java.io.BufferedReader, sourceLine: String, ln: int, col: int) extends Reader[char]
-{
+sealed class StreamReader private (bin: BufferedReader, sourceLine: String, ln: Int, col: Int)
+extends Reader[Char] {
import StreamReader._
def first =
- if(sourceLine == null)
+ if (sourceLine == null)
EofCh
- else if(col > sourceLine.length)
+ else if (col > sourceLine.length)
CR
else
sourceLine(col-1)
def rest: StreamReader =
- if(sourceLine == null)
+ if (sourceLine == null)
this
- else if(col > sourceLine.length)
+ else if (col > sourceLine.length)
new StreamReader(bin, bin.readLine, ln+1, 1)
else
new StreamReader(bin, sourceLine, ln, col+1)
@@ -60,7 +62,7 @@ sealed class StreamReader private (bin: java.io.BufferedReader, sourceLine: Stri
def pos: Position = new Position {
def line = ln
def column = col
- def lineContents(lnum: int) = sourceLine
+ def lineContents(lnum: Int) = sourceLine
}
def atEnd = (sourceLine == null)