summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Haoyi <haoyi@dropbox.com>2014-11-27 23:37:49 -0800
committerLi Haoyi <haoyi@dropbox.com>2014-11-27 23:37:49 -0800
commitb723dc6e2eead395df692fbb2459c93b60808974 (patch)
treec03479346053129999ddfb2e82564b4e03ab55b1
parent011f7aafd6f075615ea0a7af9ec3cfb453239109 (diff)
downloadhands-on-scala-js-b723dc6e2eead395df692fbb2459c93b60808974.tar.gz
hands-on-scala-js-b723dc6e2eead395df692fbb2459c93b60808974.tar.bz2
hands-on-scala-js-b723dc6e2eead395df692fbb2459c93b60808974.zip
some reshuffling...
-rw-r--r--examples/demos/src/main/scala/scrollmenu/ScrollMenu.scala2
-rw-r--r--scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala49
-rw-r--r--scalaParser/src/main/scala/scalaParser/syntax/Identifiers.scala8
-rw-r--r--scalaParser/src/test/resources/test.scala16
-rw-r--r--scalaParser/src/test/scala/scalaParser/SyntaxTest.scala54
-rw-r--r--test.txt3
6 files changed, 92 insertions, 40 deletions
diff --git a/examples/demos/src/main/scala/scrollmenu/ScrollMenu.scala b/examples/demos/src/main/scala/scrollmenu/ScrollMenu.scala
index 691122a..6378451 100644
--- a/examples/demos/src/main/scala/scrollmenu/ScrollMenu.scala
+++ b/examples/demos/src/main/scala/scrollmenu/ScrollMenu.scala
@@ -88,7 +88,7 @@ class ScrollSpy(structure: Tree[String],
if (!scrolling) {
println("Scroll...")
scrolling = true
- dom.setTimeout(() => start(), 200)
+ dom.requestAnimationFrame((d: Double) => start())
}
}
private[this] var previousWin: MenuNode = null
diff --git a/scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala b/scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala
index de9f039..9000395 100644
--- a/scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala
+++ b/scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala
@@ -111,17 +111,17 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif
oneOrMore(AnnotType).separatedBy(WL ~ K.W("with")) ~ optional(Refinement)
}
def AnnotType = rule {
- SimpleType ~ zeroOrMore(WL ~ Annotation)
+ SimpleType ~ zeroOrMore(WL ~ Annotation)
}
def SimpleType: R0 = rule {
BasicType ~
- optional(WL ~ '#' ~ Id) ~
- optional(WL ~ TypeArgs)
+ optional(WL ~ '#' ~ Id) ~
+ optional(WL ~ TypeArgs)
}
def BasicType: R0 = rule {
- '(' ~ Types ~ ')' |
- Path ~ '.' ~ K.W("type") |
- StableId
+ '(' ~ Types ~ ')' |
+ Path ~ '.' ~ K.W("type") |
+ StableId
}
def TypeArgs = rule { '[' ~ Types ~ "]" }
def Types = rule { oneOrMore(Type).separatedBy(',') }
@@ -131,14 +131,21 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif
def RefineStat = rule { "type" ~ TypeDef | Dcl | MATCH }
def TypePat = rule { CompoundType }
def Ascription = rule {
- ":" ~ ("_" ~ "*" | InfixType | oneOrMore(Annotation))
+ ":" ~ ("_" ~ "*" | InfixType | oneOrMore(Annotation))
}
def ParamType = rule { K.O("=>") ~ Type | Type ~ "*" | Type }
+ def LambdaHead: R0 = rule{
+ (
+ Bindings |
+ optional(K.W("implicit")) ~ Id ~ optional(Ascription) |
+ "_" ~ optional(Ascription)
+ ) ~
+ K.O("=>")
+ }
def Expr: R0 = rule {
- (Bindings | optional(K.W("implicit")) ~ Id | "_") ~ K.O("=>") ~ Expr |
- Expr1
+ zeroOrMore(LambdaHead) ~ Expr1
}
def Expr1: R0 = rule {
IfCFlow |
@@ -206,12 +213,13 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif
def BlockExpr: R0 = rule { '{' ~ (CaseClauses | Block) ~ "}" }
def BlockEnd: R0 = rule{ optional(Semis) ~ &("}" | "case") }
def Block: R0 = rule {
- optional(Semis) ~
- (
- BlockStats ~ optional(Semis ~ ResultExpr) ~ BlockEnd |
- ResultExpr ~ BlockEnd |
- MATCH ~ BlockEnd
- )
+ zeroOrMore(LambdaHead) ~
+ optional(Semis) ~
+ (
+ ResultExpr ~ BlockEnd |
+ BlockStats ~ optional(Semis ~ ResultExpr) ~ BlockEnd |
+ MATCH ~ BlockEnd
+ )
}
def BlockStats: R0 = rule{
oneOrMore(BlockStat).separatedBy(Semis)
@@ -221,9 +229,8 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif
zeroOrMore(Annotation) ~ (optional(K.W("implicit") | K.W("lazy")) ~ Def | zeroOrMore(LocalModifier) ~ TmplDef) |
Expr1
}
- def ResultExpr: R0 = rule {
- (Bindings | optional(K.W("implicit")) ~ Id | "_") ~ K.W("=>") ~ Block | Expr1
- }
+
+ def ResultExpr: R0 = Expr
def Enumerators: R0 = rule { Generator ~ zeroOrMore(Semi ~ Enumerator) ~ WL }
def Enumerator: R0 = rule { Generator | Guard | Pattern1 ~ K.O("=") ~ Expr }
def Generator: R0 = rule { Pattern1 ~ K.O("<-") ~ Expr ~ optional(WL ~ Guard) }
@@ -286,7 +293,7 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif
def AccessModifier: R0 = rule { (K.W("private") | K.W("protected")) ~ optional(AccessQualifier) }
def AccessQualifier: R0 = rule { '[' ~ (K.W("this") | Id) ~ ']' }
- def Annotation: R0 = rule { '@' ~ SimpleType ~ zeroOrMore(WL ~ ArgumentExprs) }
+ def Annotation: R0 = rule { '@' ~ SimpleType ~ zeroOrMore(WL ~ ArgumentExprs) }
def ConstrAnnotation: R0 = rule { '@' ~ SimpleType ~ ArgumentExprs }
def TemplateBody: R0 = rule {
@@ -404,9 +411,9 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif
}
def CompilationUnit: Rule1[String] = rule {
capture(
- pr("CompulationUnit 0") ~
+
optional(Semis) ~
- pr("CompulationUnit 1") ~
+
(TopPackageSeq ~ optional(Semis ~ TopStatSeq) | TopStatSeq) ~
optional(Semis) ~
WL
diff --git a/scalaParser/src/main/scala/scalaParser/syntax/Identifiers.scala b/scalaParser/src/main/scala/scalaParser/syntax/Identifiers.scala
index 4bc972f..78fdba4 100644
--- a/scalaParser/src/main/scala/scalaParser/syntax/Identifiers.scala
+++ b/scalaParser/src/main/scala/scalaParser/syntax/Identifiers.scala
@@ -9,9 +9,13 @@ trait Identifiers { self: Parser with Basic =>
def Operator = rule(oneOrMore(OperatorChar))
def VarId = rule {
- !(Keywords ~ (WhitespaceChar | Newline | "//" | "/*")) ~ Lower ~ IdRest
+ !(Keywords | WhitespaceChar | Newline | "//" | "/*") ~ Lower ~ IdRest
+ }
+ def PlainId = rule {
+ Upper ~ IdRest |
+ VarId |
+ !(Keywords | WhitespaceChar | Newline | "//" | "/*") ~ !Keywords ~ Operator
}
- def PlainId = rule { Upper ~ IdRest | VarId | !(Keywords ~ (WhitespaceChar | Newline | "//" | "/*")) ~ Operator }
def Id = rule { PlainId | ("`" ~ oneOrMore(noneOf("`")) ~ "`") }
def IdRest = rule {
zeroOrMore(zeroOrMore("_") ~ oneOrMore(!"_" ~ Letter | Digit)) ~
diff --git a/scalaParser/src/test/resources/test.scala b/scalaParser/src/test/resources/test.scala
new file mode 100644
index 0000000..44c60ed
--- /dev/null
+++ b/scalaParser/src/test/resources/test.scala
@@ -0,0 +1,16 @@
+package scalatex
+package stages
+import acyclic.file
+import org.parboiled2._
+import scalaParser.ScalaSyntax
+
+object O{
+ {
+ val index = 0
+ i: Int => 10
+ 0
+ }
+
+
+}
+
diff --git a/scalaParser/src/test/scala/scalaParser/SyntaxTest.scala b/scalaParser/src/test/scala/scalaParser/SyntaxTest.scala
index fe5fc2c..b6c855a 100644
--- a/scalaParser/src/test/scala/scalaParser/SyntaxTest.scala
+++ b/scalaParser/src/test/scala/scalaParser/SyntaxTest.scala
@@ -17,7 +17,11 @@ object SyntaxTest extends TestSuite{
println(f.formatTraces)
throw new Exception(f.position + "\t" + f.formatTraces)
case Success(parsed) =>
- assert(parsed == input)
+ if(parsed != input)
+
+ throw new Exception(
+ "Parsing Failed at " + parsed.length + "\n" + input.drop(parsed.length).take(50)
+ )
}
}
println("running")
@@ -407,11 +411,35 @@ object SyntaxTest extends TestSuite{
|;
""".stripMargin
)
+ * - check(
+ """
+ |
+ |object GenJSCode {
+ | code: @switch
+ |}
+ """.stripMargin
+ )
+ * - check(
+ """object B {
+ | { a: L => }
+ |}
+ """.stripMargin
+ )
+ * - check(
+ """object O{
+ | {
+ | val index = 0
+ | i: Int => 10
+ | 0
+ | }
+ |}
+ """.stripMargin
+ )
}
def checkFile(path: String) = check(io.Source.fromFile(path).mkString)
'file{
- * - checkFile("test.txt")
+ * - checkFile("scalaParser/src/test/resources/test.scala")
* - checkFile("scalaParser/src/main/scala/scalaParser/syntax/Basic.scala")
* - checkFile("scalaParser/src/main/scala/scalaParser/syntax/Identifiers.scala")
* - checkFile("scalaParser/src/main/scala/scalaParser/syntax/Literals.scala")
@@ -433,16 +461,16 @@ object SyntaxTest extends TestSuite{
* - checkFile("scalatexPlugin/src/main/scala/scalatex/ScalaTexPlugin.scala")
}
-// 'omg{
-// val root = new java.io.File("../scala-js/")
-// 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"))){
-// println("CHECKING " + f)
-// checkFile(f)
-// }
-// }
+ 'omg{
+ val root = new java.io.File("book/target/clones/scala-js/")
+ 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"))){
+ println("CHECKING " + f)
+ checkFile(f)
+ }
+ }
}
} \ No newline at end of file
diff --git a/test.txt b/test.txt
deleted file mode 100644
index a36a573..0000000
--- a/test.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-class Parser {
- {() => }
-}