summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorGilles Dubochet <gilles.dubochet@epfl.ch>2010-04-26 13:11:22 +0000
committerGilles Dubochet <gilles.dubochet@epfl.ch>2010-04-26 13:11:22 +0000
commitaed5acd72568c1a9bbad254374921ca2fcf835cd (patch)
tree061a061f9b71644f1249620c428cebb3da17a5f7 /src/library
parent8b58d4360a9bca0f9695a1ac325a6c4baf04787a (diff)
downloadscala-aed5acd72568c1a9bbad254374921ca2fcf835cd.tar.gz
scala-aed5acd72568c1a9bbad254374921ca2fcf835cd.tar.bz2
scala-aed5acd72568c1a9bbad254374921ca2fcf835cd.zip
Better positioned regular expression parser, co...
Better positioned regular expression parser, contributed by "asloane" (#3254). No review.
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/util/parsing/combinator/RegexParsers.scala19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/library/scala/util/parsing/combinator/RegexParsers.scala b/src/library/scala/util/parsing/combinator/RegexParsers.scala
index 89c5050431..fd8ee60db0 100644
--- a/src/library/scala/util/parsing/combinator/RegexParsers.scala
+++ b/src/library/scala/util/parsing/combinator/RegexParsers.scala
@@ -67,6 +67,25 @@ trait RegexParsers extends Parsers {
}
}
+ /** `positioned' decorates a parser's result with the start position of the input it consumed.
+ * If whitespace is being skipped, then it is skipped before the start position is recorded.
+ *
+ * @param p a `Parser' whose result conforms to `Positional'.
+ * @return A parser that has the same behaviour as `p', but which marks its result with the
+ * start position of the input it consumed after whitespace has been skipped, if it
+ * didn't already have a position.
+ */
+ override def positioned[T <: Positional](p: => Parser[T]): Parser[T] = {
+ val pp = super.positioned(p)
+ new Parser[T] {
+ def apply(in: Input) = {
+ val offset = in.offset
+ val start = handleWhiteSpace(in.source, offset)
+ pp(in.drop (start - offset))
+ }
+ }
+ }
+
override def phrase[T](p: Parser[T]): Parser[T] =
super.phrase(p <~ opt("""\z""".r))