Skip to content

Commit

Permalink
Passes all the way to test case t5958.scala
Browse files Browse the repository at this point in the history
  • Loading branch information
Li Haoyi committed Nov 29, 2014
1 parent 38ab174 commit a2e4a07
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 14 deletions.
15 changes: 9 additions & 6 deletions scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif
zeroOrMore(
Check0 ~
Id ~
optional(TypeArgs) ~
Check ~
PrefixExpr
)
Expand Down Expand Up @@ -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 |
Expand Down Expand Up @@ -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 ~ "}"
)
}
Expand Down Expand Up @@ -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) }
Expand All @@ -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 |
Expand Down
11 changes: 4 additions & 7 deletions scalaParser/src/test/resources/test.scala
Original file line number Diff line number Diff line change
@@ -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)
f: A
g(og): B
}
46 changes: 45 additions & 1 deletion scalaParser/src/test/scala/scalaParser/SyntaxTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -768,6 +811,7 @@ object SyntaxTest extends TestSuite{
|
""".stripMargin
)

}
}
def checkFile(path: String) = check(io.Source.fromFile(path).mkString)
Expand Down

0 comments on commit a2e4a07

Please sign in to comment.