diff options
author | Haoyi Li <haoyi@haoyi-mbp.corp.dropbox.com> | 2014-11-26 00:44:40 -0800 |
---|---|---|
committer | Haoyi Li <haoyi@haoyi-mbp.corp.dropbox.com> | 2014-11-26 00:44:40 -0800 |
commit | c50f0d417b34d7a8be432c34bac92088734a14ca (patch) | |
tree | 1fee0dc07793e900b6c1b848fac2b7d6fd86b04b | |
parent | 8e76b69d7576877ce5d706651b57d8e1d6ecd717 (diff) | |
download | hands-on-scala-js-c50f0d417b34d7a8be432c34bac92088734a14ca.tar.gz hands-on-scala-js-c50f0d417b34d7a8be432c34bac92088734a14ca.tar.bz2 hands-on-scala-js-c50f0d417b34d7a8be432c34bac92088734a14ca.zip |
tweaks
4 files changed, 50 insertions, 30 deletions
diff --git a/scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala b/scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala index b164ec4..de9f039 100644 --- a/scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala +++ b/scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala @@ -189,7 +189,7 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif def SimpleExpr1 = rule{ K.W("new") ~ (ClassTemplate | TemplateBody) | BlockExpr | - Literal ~ drop[String] | + Literal | Path | K.W("_") | '(' ~ optional(Exprs) ~ ")" @@ -208,9 +208,8 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif def Block: R0 = rule { optional(Semis) ~ ( + BlockStats ~ optional(Semis ~ ResultExpr) ~ BlockEnd | ResultExpr ~ BlockEnd | - BlockStats ~ Semis ~ ResultExpr ~ BlockEnd | - BlockStats ~ BlockEnd | MATCH ~ BlockEnd ) } @@ -245,17 +244,17 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif } def SimplePattern: R0 = rule { K.W("_") | - Literal ~ drop[String] | - '(' ~ optional(Patterns) ~ ')' | - ( - StableId ~ - optional( - '(' ~ - (optional(Patterns ~ ',') ~ optional(VarId ~ '@') ~ K.W("_") ~ '*' | optional(Patterns)) ~ - ')' - ) - ) | - VarId + Literal | + '(' ~ optional(Patterns) ~ ')' | + ( + StableId ~ + optional( + '(' ~ + (optional(Patterns ~ ',') ~ optional(VarId ~ '@') ~ K.W("_") ~ '*' | optional(Patterns)) ~ + ')' + ) + ) | + VarId } def Patterns: R0 = rule { K.W("_") ~ '*' | oneOrMore(Pattern).separatedBy(',') } @@ -408,8 +407,10 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif pr("CompulationUnit 0") ~ optional(Semis) ~ pr("CompulationUnit 1") ~ - (TopPackageSeq ~ Semis ~ TopStatSeq | TopPackageSeq | TopStatSeq) ~ + (TopPackageSeq ~ optional(Semis ~ TopStatSeq) | TopStatSeq) ~ + optional(Semis) ~ WL + ) } } diff --git a/scalaParser/src/main/scala/scalaParser/syntax/Literals.scala b/scalaParser/src/main/scala/scalaParser/syntax/Literals.scala index b8342e2..9fd9d5b 100644 --- a/scalaParser/src/main/scala/scalaParser/syntax/Literals.scala +++ b/scalaParser/src/main/scala/scalaParser/syntax/Literals.scala @@ -7,17 +7,18 @@ trait Literals { self: Parser with Basic with Identifiers => object Literals{ import Basic._ def FloatingPointLiteral = rule { - capture( + + "." ~ oneOrMore(Digit) ~ optional(ExponentPart) ~ optional(FloatType) | + oneOrMore(Digit) ~ ( "." ~ oneOrMore(Digit) ~ optional(ExponentPart) ~ optional(FloatType) | - oneOrMore(Digit) ~ ( - "." ~ oneOrMore(Digit) ~ optional(ExponentPart) ~ optional(FloatType) | - ExponentPart ~ optional(FloatType) | - optional(ExponentPart) ~ FloatType)) + ExponentPart ~ optional(FloatType) | + optional(ExponentPart) ~ FloatType + ) } - def IntegerLiteral = rule { capture((DecimalNumeral | HexNumeral) ~ optional(anyOf("Ll"))) } + def IntegerLiteral = rule { (DecimalNumeral | HexNumeral) ~ optional(anyOf("Ll")) } - def BooleanLiteral = rule { capture(Key.W("true") | Key.W("false")) } + def BooleanLiteral = rule { Key.W("true") | Key.W("false") } def MultilineComment: Rule0 = rule { "/*" ~ zeroOrMore(MultilineComment | !"*/" ~ ANY) ~ "*/" } def Comment: Rule0 = rule { @@ -26,26 +27,26 @@ trait Literals { self: Parser with Basic with Identifiers => } def Literal = rule { - (capture(optional("-")) ~ (FloatingPointLiteral | IntegerLiteral) ~> ((sign: String, number) => sign + number)) | + (optional("-") ~ (FloatingPointLiteral | IntegerLiteral)) | BooleanLiteral | CharacterLiteral | StringLiteral | SymbolLiteral | - capture(Key.W("null") ~ !(Basic.Letter | Basic.Digit)) + (Key.W("null") ~ !(Basic.Letter | Basic.Digit)) } def EscapedChars = rule { '\\' ~ anyOf("rnt\\\"") } // Note that symbols can take on the same values as keywords! - def SymbolLiteral = rule { ''' ~ capture(Identifiers.PlainId | Identifiers.Keywords) } + def SymbolLiteral = rule { ''' ~ (Identifiers.PlainId | Identifiers.Keywords) } - def CharacterLiteral = rule { ''' ~ capture(UnicodeExcape | EscapedChars | !'\\' ~ CharPredicate.from(isPrintableChar)) ~ ''' } + def CharacterLiteral = rule { ''' ~ (UnicodeExcape | EscapedChars | !'\\' ~ CharPredicate.from(isPrintableChar)) ~ ''' } def MultiLineChars = rule { zeroOrMore(optional('"') ~ optional('"') ~ noneOf("\"")) } def StringLiteral = rule { - (optional(Identifiers.Id) ~ "\"\"\"" ~ capture(MultiLineChars) ~ capture("\"\"\"" ~ zeroOrMore('"')) ~> ((multilineChars: String, quotes) => multilineChars + quotes.dropRight(3))) | - (optional(Identifiers.Id) ~ '"' ~ capture(zeroOrMore("\\\"" | noneOf("\n\""))) ~ '"') + (optional(Identifiers.Id) ~ "\"\"\"" ~ MultiLineChars ~ ("\"\"\"" ~ zeroOrMore('"'))) | + (optional(Identifiers.Id) ~ '"' ~ zeroOrMore("\\\"" | noneOf("\n\"")) ~ '"') } def isPrintableChar(c: Char): Boolean = { diff --git a/scalaParser/src/test/scala/scalaParser/SyntaxTest.scala b/scalaParser/src/test/scala/scalaParser/SyntaxTest.scala index d33ead0..fe5fc2c 100644 --- a/scalaParser/src/test/scala/scalaParser/SyntaxTest.scala +++ b/scalaParser/src/test/scala/scalaParser/SyntaxTest.scala @@ -388,6 +388,25 @@ object SyntaxTest extends TestSuite{ | """.stripMargin ) + * - check( + """ + | + | + | + |package omg + |; + | + |; + | + |; + |class Parser + |; + | + |; + | + |; + """.stripMargin + ) } def checkFile(path: String) = check(io.Source.fromFile(path).mkString) 'file{ @@ -426,4 +445,4 @@ object SyntaxTest extends TestSuite{ // } // } } -} +}
\ No newline at end of file diff --git a/scalatexApi/src/main/scala/scalatex/stages/Compiler.scala b/scalatexApi/src/main/scala/scalatex/stages/Compiler.scala index 4f11b04..3df8da7 100644 --- a/scalatexApi/src/main/scala/scalatex/stages/Compiler.scala +++ b/scalatexApi/src/main/scala/scalatex/stages/Compiler.scala @@ -48,7 +48,6 @@ object Compiler{ incPos(q"$curr(..${compileBlock(parts, offset1)})", offset1) case (curr, Ast.Header(header, block, offset1)) => incPos(q"$curr(${compileHeader(header, block, offset1)})", offset1) - } out |