diff options
author | Li Haoyi <haoyi@dropbox.com> | 2014-11-28 05:38:35 -0800 |
---|---|---|
committer | Li Haoyi <haoyi@dropbox.com> | 2014-11-28 05:38:35 -0800 |
commit | 3dc34955b3f8287178339a28f7ba3772a27ae08a (patch) | |
tree | b36430c5c5e11eaeacf09878d7286280832a5f22 | |
parent | 5ef6a1dd630764a1ffa6c3b68fff1649c9d89934 (diff) | |
download | hands-on-scala-js-3dc34955b3f8287178339a28f7ba3772a27ae08a.tar.gz hands-on-scala-js-3dc34955b3f8287178339a28f7ba3772a27ae08a.tar.bz2 hands-on-scala-js-3dc34955b3f8287178339a28f7ba3772a27ae08a.zip |
"omg" goes down to java.net.URI
-rw-r--r-- | scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala | 20 | ||||
-rw-r--r-- | scalaParser/src/test/resources/test.scala | 7 | ||||
-rw-r--r-- | scalaParser/src/test/scala/scalaParser/SyntaxTest.scala | 29 |
3 files changed, 43 insertions, 13 deletions
diff --git a/scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala b/scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala index fe30606..c2a6ce1 100644 --- a/scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala +++ b/scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala @@ -82,11 +82,13 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif Id ~ zeroOrMore('.' ~ Id) } } - + def ExistentialDcl = rule { K.W("type") ~ TypeDcl | K.W("val") ~ ValDcl } + def ExistentialClause = rule { + "forSome" ~ '{' ~ oneOrMore(ExistentialDcl).separatedBy(Semi) ~ '}' + } def Type: R0 = { def WildcardType: R0 = rule{ K.W("_") } - def ExistentialDcl = rule { K.W("type") ~ TypeDcl | K.W("val") ~ ValDcl } - def ExistentialClause = rule { "forSome" ~ '{' ~ oneOrMore(ExistentialDcl).separatedBy(Semi) } + def FunctionArgTypes = rule { InfixType | '(' ~ optional(oneOrMore(ParamType) separatedBy ',') ~ ')' } @@ -110,7 +112,7 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif } } def AnnotType = rule { - SimpleType ~ zeroOrMore(Annotation) + SimpleType ~ zeroOrMore(Annotation) } def SimpleType: R0 = { def BasicType: R0 = rule { @@ -131,7 +133,7 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif def TypePat = rule { CompoundType } def Ascription = rule { - ":" ~ ("_" ~ "*" | InfixType | oneOrMore(Annotation)) + ":" ~ ("_" ~ "*" | InfixType | oneOrMore(Annotation)) } def ParamType = rule { K.O("=>") ~ Type | Type ~ "*" | Type } @@ -145,7 +147,7 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif ( Bindings | optional(K.W("implicit")) ~ Id ~ optional(Ascription) | - "_" ~ optional(Ascription) + K.W("_") ~ optional(Ascription) ) ~ K.O("=>") } @@ -216,13 +218,13 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif BlockExpr | Literal | Path | - K.W("_") | + NotNewline ~ K.W("_") | '(' ~ optional(Exprs) ~ ")" } rule { SimpleExpr1 ~ zeroOrMore('.' ~ Id | TypeArgs | ArgumentExprs) ~ - optional( "_") + optional(K.W("_")) } } @@ -302,7 +304,7 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif def VariantTypeParam: R0 = rule { zeroOrMore(Annotation) ~ optional(anyOf("+-")) ~ TypeParam } rule { '[' ~ oneOrMore(VariantTypeParam).separatedBy(',') ~ ']' } } - def FunTypeParamClause: R0 = rule { '[' ~ oneOrMore(TypeParam).separatedBy(',') ~ ']' } + def FunTypeParamClause: R0 = rule { '[' ~ oneOrMore(zeroOrMore(Annotation) ~ TypeParam).separatedBy(',') ~ ']' } def TypeBounds: R0 = rule{ optional(K.O(">:") ~ Type) ~ optional(K.O("<:") ~ Type) diff --git a/scalaParser/src/test/resources/test.scala b/scalaParser/src/test/resources/test.scala index a0e847e..55e43c2 100644 --- a/scalaParser/src/test/resources/test.scala +++ b/scalaParser/src/test/resources/test.scala @@ -1,4 +1,3 @@ - -object System { - def a[@b T] = 1 -} +class A { + null: T forSome { type T <: V } +}
\ 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 0f9b734..90a08e2 100644 --- a/scalaParser/src/test/scala/scalaParser/SyntaxTest.scala +++ b/scalaParser/src/test/scala/scalaParser/SyntaxTest.scala @@ -538,6 +538,27 @@ object SyntaxTest extends TestSuite{ """class Runtime private """.stripMargin ) + * - check( + """ + |object System { + | def a[@b T[@b V]] = 1 + |} + | + """.stripMargin + ) + * - check( + """class A { + | null: T forSome { type T <: V } + |} + """.stripMargin + ) + * - check( + """object U{ + | private val _fragment = fld(Fragment) + | _fld = null + |} + """.stripMargin + ) } 'neg{ * - checkNeg( @@ -573,6 +594,14 @@ object SyntaxTest extends TestSuite{ |} """.stripMargin ) + * - checkNeg( + """ + |object System { + | def a[@b T[V @b]] = 1 + |} + | + """.stripMargin + ) } } def checkFile(path: String) = check(io.Source.fromFile(path).mkString) |