summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Haoyi <haoyi@dropbox.com>2014-11-28 17:01:50 -0800
committerLi Haoyi <haoyi@dropbox.com>2014-11-28 17:01:50 -0800
commita2e4a074271890889e8fbafff25010449c06a190 (patch)
treea355fcd257d6764bae7fb8de5981a73eb59ec3ef
parent38ab174bada21b0ad1b8487481baa87578547eae (diff)
downloadhands-on-scala-js-a2e4a074271890889e8fbafff25010449c06a190.tar.gz
hands-on-scala-js-a2e4a074271890889e8fbafff25010449c06a190.tar.bz2
hands-on-scala-js-a2e4a074271890889e8fbafff25010449c06a190.zip
Passes all the way to test case t5958.scala
-rw-r--r--scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala15
-rw-r--r--scalaParser/src/test/resources/test.scala11
-rw-r--r--scalaParser/src/test/scala/scalaParser/SyntaxTest.scala46
3 files changed, 58 insertions, 14 deletions
diff --git a/scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala b/scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala
index 9c0511f..cb008c9 100644
--- a/scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala
+++ b/scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala
@@ -222,6 +222,7 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif
zeroOrMore(
Check0 ~
Id ~
+ optional(TypeArgs) ~
Check ~
PrefixExpr
)
@@ -260,7 +261,7 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif
def BlockStats: R0 = {
def Template: R0 = rule{
zeroOrMore(Annotation) ~
- (optional(`implicit` | K.W("lazy")) ~ Def | zeroOrMore(LocalModifier) ~ TmplDef)
+ (optional(`implicit`) ~ optional(K.W("lazy")) ~ Def | zeroOrMore(LocalModifier) ~ TmplDef)
}
def BlockStat: R0 = rule {
Import |
@@ -405,8 +406,8 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif
def ConstrExpr: R0 = rule { ConstrBlock | SelfInvocation }
def FunDef: R0 = rule {
`this` ~ ParamClause ~ ParamClauses ~ (`=` ~ ConstrExpr | OneNewlineMax ~ ConstrBlock) |
- FunSig ~ (
- optional(`:` ~ Type) ~ `=` ~ optional(K.W("macro")) ~ Expr0(true) |
+ FunSig ~ optional(`:` ~ Type) ~ (
+ `=` ~ optional(K.W("macro")) ~ Expr0(true) |
OneNewlineMax ~ '{' ~ Block ~ "}"
)
}
@@ -471,7 +472,7 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif
def ClassTemplate: R0 = {
def ClassParents: R0 = {
- def Constr: R0 = rule{ AnnotType ~ zeroOrMore(ArgumentExprs) }
+ def Constr: R0 = rule{ AnnotType ~ zeroOrMore(NotNewline ~ ArgumentExprs) }
rule{ Constr ~ zeroOrMore(`with` ~ AnnotType) }
}
rule{ optional(EarlyDefs) ~ ClassParents ~ optional(TemplateBody) }
@@ -484,12 +485,14 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif
rule{ '{' ~ optional(oneOrMore(EarlyDef).separatedBy(Semis)) ~ '}' ~ `with` }
}
- def ConstrBlock: R0 = rule { '{' ~ SelfInvocation ~ optional(Semis ~ BlockStats) ~ '}' }
+ def ConstrBlock: R0 = rule { '{' ~ SelfInvocation ~ optional(Semis ~ BlockStats) ~ optional(Semis) ~ '}' }
def SelfInvocation: R0 = rule { `this` ~ oneOrMore(ArgumentExprs) }
def TopStatSeq: R0 = {
def PackageObject: R0 = rule { `package` ~ `object` ~ ObjectDef }
- def Packaging: R0 = rule { `package` ~ QualId ~ '{' ~ TopStatSeq ~ WL ~ '}' }
+ def Packaging: R0 = rule {
+ `package` ~ QualId ~ '{' ~ optional(TopStatSeq) ~ WL ~ '}'
+ }
def TopStat: R0 = rule {
Packaging |
PackageObject |
diff --git a/scalaParser/src/test/resources/test.scala b/scalaParser/src/test/resources/test.scala
index 191933e..2313257 100644
--- a/scalaParser/src/test/resources/test.scala
+++ b/scalaParser/src/test/resources/test.scala
@@ -1,8 +1,5 @@
-class A {
- def fn1 = List apply 1
- def fn2 = List apply[Int] 2
+class Test {
- def g1: Char = "g1" toList 0
- def g2: Char = "g2" apply 1
-
- def h1 = List apply[List[Int]] (List(1), List(2)) mapConserve[List[Any]] (x => x) \ No newline at end of file
+ f: A
+ g(og): B
+} \ No newline at end of file
diff --git a/scalaParser/src/test/scala/scalaParser/SyntaxTest.scala b/scalaParser/src/test/scala/scalaParser/SyntaxTest.scala
index 8a4affb..072fc7b 100644
--- a/scalaParser/src/test/scala/scalaParser/SyntaxTest.scala
+++ b/scalaParser/src/test/scala/scalaParser/SyntaxTest.scala
@@ -724,7 +724,50 @@ object SyntaxTest extends TestSuite{
|}
""".stripMargin
)
-
+ * - check(
+ """package `dmacro` {
+ |}
+ """.stripMargin
+ )
+ * - check(
+ """class A {
+ | def fn1 = List apply 1
+ | def fn2 = List apply[Int] 2
+ |}
+ """.stripMargin
+ )
+ * - check(
+ """class C {
+ | def this(x: Int) = {
+ | this();
+ | class D;
+ | }
+ |}
+ """.stripMargin
+ )
+ * - check(
+ """trait B[T] {
+ | def f1(a: T): Unit { }
+ |}
+ """.stripMargin
+ )
+ * - check(
+ """object test {
+ | case object Int16 extends SampleFormat1
+ | (1) match {
+ | case _ => 1
+ | }
+ |}
+ """.stripMargin
+ )
+ * - check(
+ """object A {
+ | def x {
+ | implicit lazy val e: Int = 0
+ | }
+ |}
+ """.stripMargin
+ )
}
'neg{
* - checkNeg(
@@ -768,6 +811,7 @@ object SyntaxTest extends TestSuite{
|
""".stripMargin
)
+
}
}
def checkFile(path: String) = check(io.Source.fromFile(path).mkString)