summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
diff options
context:
space:
mode:
authorDen Shabalin <den.shabalin@gmail.com>2013-07-08 20:44:24 +0200
committerEugene Burmako <xeno.by@gmail.com>2013-07-08 21:12:14 +0200
commitcbe5362a62904a88de78e3b068a544612e46c0cc (patch)
tree1f6ebff8e3739751d9c7240678ef366b80f427ab /src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
parentb5f703f145a17c9cdbfede9192189630c2a9829c (diff)
downloadscala-cbe5362a62904a88de78e3b068a544612e46c0cc.tar.gz
scala-cbe5362a62904a88de78e3b068a544612e46c0cc.tar.bz2
scala-cbe5362a62904a88de78e3b068a544612e46c0cc.zip
adds the lookahead routine to the parser
Introduces a scoping operator used to temporarily look into the future. Backs up scanner data before evaluating a block and restores it after. Not used anywhere, only necessary for the upcoming quasiquote patch in order to reliably detect and accordingly process holes in quasiquoted Scala syntax.
Diffstat (limited to 'src/compiler/scala/tools/nsc/ast/parser/Parsers.scala')
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index 40439a5379..a89a994377 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -156,6 +156,17 @@ self =>
def newScanner(): Scanner = new SourceFileScanner(source)
+ /** Scoping operator used to temporarily look into the future.
+ * Backs up scanner data before evaluating a block and restores it after.
+ */
+ def lookingAhead[T](body: => T): T = {
+ val snapshot = (new ScannerData{}).copyFrom(in)
+ in.nextToken()
+ val res = body
+ in copyFrom snapshot
+ res
+ }
+
val in = newScanner()
in.init()