diff options
author | Li Haoyi <haoyi@dropbox.com> | 2014-11-28 07:48:48 -0800 |
---|---|---|
committer | Li Haoyi <haoyi@dropbox.com> | 2014-11-28 07:48:48 -0800 |
commit | 2fdf34a0177cc8eb0a7334007fa2a804946f6629 (patch) | |
tree | 9ee6f90f26b06b1363c615240089693783432a2c | |
parent | d6a356156c1f9e8d8f9207b70731cb917fb38ee9 (diff) | |
download | hands-on-scala-js-2fdf34a0177cc8eb0a7334007fa2a804946f6629.tar.gz hands-on-scala-js-2fdf34a0177cc8eb0a7334007fa2a804946f6629.tar.bz2 hands-on-scala-js-2fdf34a0177cc8eb0a7334007fa2a804946f6629.zip |
Lots of fixes, now at scala.collection.generic.Growable
4 files changed, 120 insertions, 23 deletions
diff --git a/scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala b/scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala index ef5eb4a..39d57eb 100644 --- a/scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala +++ b/scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala @@ -74,7 +74,17 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif def Ids = rule { oneOrMore(Id) separatedBy ',' } def NotNewline: R0 = rule{ &( WS ~ noneOf("\n") )} - def OneNewlineMax: R0 = rule{ WS ~ optional(Basic.Newline) ~ NotNewline} + def OneNewlineMax: R0 = rule{ + WS ~ + optional(Basic.Newline) ~ + zeroOrMore( + zeroOrMore(Basic.WhitespaceChar) ~ + Literals.Comment ~ + zeroOrMore(Basic.WhitespaceChar) ~ + Basic.Newline + ) ~ + NotNewline + } def StableId: R0 = { def ClassQualifier = rule { '[' ~ Id ~ ']' } rule { @@ -123,8 +133,7 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif } rule { BasicType ~ - optional('#' ~ Id) ~ - optional(TypeArgs) + zeroOrMore(TypeArgs | '#' ~ Id) } } @@ -164,12 +173,14 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif def Expr = Expr0() def ExprSensitive = Expr0(true) def Expr0(G: Boolean = false): R0 = { - def IfCFlow = rule { "if" ~ '(' ~ Expr ~ ')' ~ Expr0(G) ~ optional(optional(Semi) ~ K.W("else") ~ Expr0(G)) } + def IfCFlow = rule { + "if" ~ '(' ~ Expr ~ ')' ~ Expr0(G) ~ optional(optional(Semi) ~ K.W("else") ~ Expr0(G)) + } def WhileCFlow = rule { "while" ~ '(' ~ Expr ~ ')' ~ Expr0(G) } def TryCFlow = rule { K.W("try") ~ Expr0(G) ~ - optional(K.W("catch") ~ Expr0(G)) ~ - optional(K.W("finally") ~ Expr0(G)) + optional(K.W("catch") ~ Expr0(G)) ~ + optional(K.W("finally") ~ Expr0(G)) } def DoWhileCFlow = rule { K.W("do") ~ Expr0(G) ~ optional(Semi) ~ "while" ~ '(' ~ Expr ~ ")" } @@ -228,7 +239,7 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif } rule { SimpleExpr1 ~ - zeroOrMore('.' ~ Id | TypeArgs | ArgumentExprs) ~ + zeroOrMore('.' ~ Id | TypeArgs | NotNewline ~ ArgumentExprs) ~ optional(K.W("_")) } } @@ -363,7 +374,10 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif Expr0(true) } - def SelfType: R0 = rule { K.W("this") ~ K.O(":") ~ Type ~ K.O("=>") | Id ~ optional(K.O(":") ~ Type) ~ K.O("=>") } + def SelfType: R0 = rule { + K.W("this") ~ K.O(":") ~ InfixType ~ K.O("=>") | + (Id | K.W("_")) ~ optional(K.O(":") ~ InfixType) ~ K.O("=>") + } def Import: R0 = { def ImportExpr: R0 = rule { @@ -403,11 +417,10 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif def ConstrExpr: R0 = rule { ConstrBlock | SelfInvocation } def FunDef: R0 = rule { K.W("this") ~ ParamClause ~ ParamClauses ~ (K.O("=") ~ ConstrExpr | OneNewlineMax ~ ConstrBlock) | - FunSig ~ - ( - optional(K.O(":") ~ Type) ~ K.O("=") ~ optional(K.W("macro")) ~ Expr | - OneNewlineMax ~ '{' ~ Block ~ "}" - ) + FunSig ~ ( + optional(K.O(":") ~ Type) ~ K.O("=") ~ optional(K.W("macro")) ~ Expr0(true) | + OneNewlineMax ~ '{' ~ Block ~ "}" + ) } rule { K.W("def") ~ FunDef | K.W("type") ~ TypeDef | PatVarDef | TmplDef } } diff --git a/scalaParser/src/main/scala/scalaParser/syntax/Literals.scala b/scalaParser/src/main/scala/scalaParser/syntax/Literals.scala index f854671..703c793 100644 --- a/scalaParser/src/main/scala/scalaParser/syntax/Literals.scala +++ b/scalaParser/src/main/scala/scalaParser/syntax/Literals.scala @@ -4,7 +4,8 @@ import acyclic.file import org.parboiled2._ trait Literals { self: Parser with Basic with Identifiers => - def Expr: Rule0 + def Block: Rule0 + def WL: Rule0 object Literals{ import Basic._ def FloatingPointLiteral = rule { @@ -36,7 +37,6 @@ trait Literals { self: Parser with Basic with Identifiers => (Key.W("null") ~ !(Basic.Letter | Basic.Digit)) } - def EscapedChars = rule { '\\' ~ anyOf("btnfr'\\\"") } // Note that symbols can take on the same values as keywords! @@ -51,7 +51,7 @@ trait Literals { self: Parser with Basic with Identifiers => } def pr(s: String) = rule { run(println(s"LOGGING $cursor: $s")) } def Interpolation = rule{ - "$" ~ Identifiers.Id | "${" ~ Expr ~ "}" | "$$" + "$" ~ Identifiers.Id | "${" ~ Block ~ WL ~ "}" | "$$" } def StringLiteral = rule { (Identifiers.Id ~ "\"\"\"" ~ MultiLineChars ~ ("\"\"\"" ~ zeroOrMore('"'))) | diff --git a/scalaParser/src/test/resources/test.scala b/scalaParser/src/test/resources/test.scala index 62dd0a3..93f8768 100644 --- a/scalaParser/src/test/resources/test.scala +++ b/scalaParser/src/test/resources/test.scala @@ -1,6 +1,6 @@ -object OptimizerCore { - tpe match { - case NothingType | _:RecordType=> 1 - } -} +trait Growable { + xs match { + case xs => xs foreach += + } +}
\ 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 6388d71..f2816b8 100644 --- a/scalaParser/src/test/scala/scalaParser/SyntaxTest.scala +++ b/scalaParser/src/test/scala/scalaParser/SyntaxTest.scala @@ -608,6 +608,81 @@ object SyntaxTest extends TestSuite{ |} """.stripMargin ) + * - check( + """object OptimizerCore { + | tpe match { + | case NothingType | _:RecordType=> 1 + | } + |} + """.stripMargin + ) + * - check( + """class A{ + | 1 + | () => 1 + |} + """.stripMargin + ) + * - check( + """trait ReactorCanReply { + | _: InternalReplyReactor => + |} + """.stripMargin + ) + + * - check( + """object G{ + | def isBefore(pd: SubComponent) = settings.stopBefore + | phaseDescriptors sliding 2 collectFirst () + |} + """.stripMargin + ) + * - check( + """class SymbolLoaders { + | type T = ClassPath[AbstractFile]#ClassRep + |} + """.stripMargin + ) + * - check( + """trait ContextErrors { + | def isUnaffiliatedExpr = expanded.isInstanceOf[scala.reflect.api.Exprs#Expr[_]] + |} + """.stripMargin + ) + * - check( + """trait Typers{ + | s"nested ${ if (1) "trait" else "class" }" + |} + """.stripMargin + ) + * - check( + """trait ReflectSetup { this: Global => + | phase = 1 + |} + """.stripMargin + ) + * - check( + """trait Predef { + | @x + | // a + | type T + |} + """.stripMargin + ) + * - check( + """ + object StringContext { + + s"${ + require(index >= 0 && index < str.length) + val ok = "[\b, \t, \n, \f, \r, \\, \", \']" + if (index == str.length - 1) "at terminal" else s"'\\${str(index + 1)}' not one of $ok at" + }" + + } + """.stripMargin + ) + } 'neg{ * - checkNeg( @@ -679,12 +754,21 @@ object SyntaxTest extends TestSuite{ } 'omg{ - val root = new java.io.File("book/target/clones/scala-js/") +// val root = new java.io.File("book/target/clones/scala-js/") + val root = new java.io.File("../scala") def listFiles(s: java.io.File): Iterator[String] = { val (dirs, files) = s.listFiles().toIterator.partition(_.isDirectory) files.map(_.getPath) ++ dirs.flatMap(listFiles) } - for(f <- listFiles(root).filter(_.endsWith(".scala"))){ + val blacklist = Seq( + "dbuild-meta-json-gen.scala", + "genprod.scala" + ) + for{ + f <- listFiles(root) + if f.endsWith(".scala") + if !blacklist.exists(f.endsWith) + }{ println("CHECKING " + f) checkFile(f) } |