summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorBurak Emir <emir@epfl.ch>2006-02-24 19:23:24 +0000
committerBurak Emir <emir@epfl.ch>2006-02-24 19:23:24 +0000
commit45371e87920d3a68dc5cc3c20d4408f6127700f1 (patch)
treed37ad5bd71ae4a6394c0da19ec4e83b806224d92 /src/compiler
parentad5e5a343d84e45e8410cb764c5963486a38641c (diff)
downloadscala-45371e87920d3a68dc5cc3c20d4408f6127700f1.tar.gz
scala-45371e87920d3a68dc5cc3c20d4408f6127700f1.tar.bz2
scala-45371e87920d3a68dc5cc3c20d4408f6127700f1.zip
ok, poor man regexp matching works now for righ...
ok, poor man regexp matching works now for right-ignoring patterns
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/matching/TransMatcher.scala30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/matching/TransMatcher.scala b/src/compiler/scala/tools/nsc/matching/TransMatcher.scala
index d68302694f..f8d213013d 100644
--- a/src/compiler/scala/tools/nsc/matching/TransMatcher.scala
+++ b/src/compiler/scala/tools/nsc/matching/TransMatcher.scala
@@ -128,6 +128,33 @@ with RightTracers {
generatedVars;
}
+ /** a casedef with sequence subpatterns like
+ *
+ * case ..x @ ().. => body
+ *
+ * should be replaced straight away with
+ *
+ * case .. () .. => val x = Nil; body
+ */
+
+ def isRegularPattern(pat: Tree): Boolean = pat match {
+ case Alternative(trees) =>
+ trees exists { isRegularPattern };
+ case Star(t) => true
+ case Ident(_) => false
+ case Bind( n, pat1 ) => isRegularPattern( pat1 );
+ case Sequence( trees ) => true // cause there are ArrayValues now
+ case ArrayValue( tt, trees ) =>
+ trees exists { isRegularPattern };
+ case Apply( fn, List(Sequence(List()))) =>
+ false
+ case Apply( fn, trees ) =>
+ trees exists { isRegularPattern };
+ case Literal(_) => false
+ case Select(_,_) => false
+ case Typed(_,_) => false
+ }
+
protected def isDefault(p: Tree): Boolean = p match {
case Bind(_,q) => isDefault(q);
case Ident(nme.WILDCARD) => true
@@ -145,7 +172,8 @@ with RightTracers {
case ArrayValue(s,trees) =>
val it = trees.elements;
var c: Tree = null;
- while(it.hasNext && {c = it.next; isDefault(c)}) {}
+ while(it.hasNext && {c = it.next; //Console.println("isReg?("+c+" = "+isRegularPattern(c)); // DEBUG
+!isRegularPattern(c)}) {}
(!it.hasNext) && isDefaultStar(c)
}