File tree Expand file tree Collapse file tree 2 files changed +19
-7
lines changed
main/scala/scalariform/utils
test/scala/scalariform/parser Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package scalariform.utils
3
3
import java .io .FileOutputStream
4
4
import java .io .FileInputStream
5
5
import java .io .IOException
6
+ import scala .collection .mutable .ListBuffer
6
7
7
8
object Utils {
8
9
@@ -31,14 +32,20 @@ object Utils {
31
32
}
32
33
}
33
34
34
- def groupBy [A ](eq : (A , A ) ⇒ Boolean , lst : List [A ]): List [List [A ]] =
35
- lst match {
36
- case Nil ⇒ Nil
37
- case (x :: xs) ⇒ {
38
- val (ys, zs) = xs span { eq(x, _) }
39
- (x :: ys) :: groupBy(eq, zs)
35
+ def groupBy [A ](eq : (A , A ) ⇒ Boolean , lst : List [A ]): List [List [A ]] = {
36
+ val result = ListBuffer [List [A ]]()
37
+ @ annotation.tailrec def loop (cursor : List [A ]): Unit =
38
+ cursor match {
39
+ case Nil ⇒
40
+ case (x :: xs) ⇒ {
41
+ val (ys, zs) = xs span { eq(x, _) }
42
+ result += x :: ys
43
+ loop(zs)
44
+ }
40
45
}
41
- }
46
+ loop(lst)
47
+ result.toList
48
+ }
42
49
43
50
// File ------------------
44
51
Original file line number Diff line number Diff line change @@ -48,6 +48,11 @@ class ParserTest extends FlatSpec with Matchers {
48
48
""" )
49
49
}
50
50
51
+ // issue #265
52
+ " Parser" should " handle deep complex expressions" in {
53
+ parseExpression(" o.p(a" + (" ,a" * 3000 ) + " )" )
54
+ }
55
+
51
56
private def parser (s : String ) = new ScalaParser (ScalaLexer .tokenise(s).toArray)
52
57
private def parseExpression (s : String ) = parser(s).expr
53
58
private def parseCompilationUnit (s : String ) = parser(s).compilationUnit
You can’t perform that action at this time.
0 commit comments