summaryrefslogtreecommitdiff
path: root/src/library
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/library
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/library')
-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
11 files changed, 246 insertions, 160 deletions
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)