diff options
author | Li Haoyi <haoyi@dropbox.com> | 2014-11-05 21:55:18 -0800 |
---|---|---|
committer | Li Haoyi <haoyi@dropbox.com> | 2014-11-05 21:55:18 -0800 |
commit | ca21a608b3a23d42e5c188679a962c9e56918408 (patch) | |
tree | 756bdf78ce823090722086d3c17af0c805d08721 | |
parent | 850863eeb7a44e3fa367d4088330fdcb556929bd (diff) | |
download | hands-on-scala-js-ca21a608b3a23d42e5c188679a962c9e56918408.tar.gz hands-on-scala-js-ca21a608b3a23d42e5c188679a962c9e56918408.tar.bz2 hands-on-scala-js-ca21a608b3a23d42e5c188679a962c9e56918408.zip |
Fixed bug in SimpleExpr grammar
3 files changed, 31 insertions, 21 deletions
diff --git a/scalatexApi/src/main/scala/scalatex/stages/Parser.scala b/scalatexApi/src/main/scala/scalatex/stages/Parser.scala index 8432f96..4d35fd1 100644 --- a/scalatexApi/src/main/scala/scalatex/stages/Parser.scala +++ b/scalatexApi/src/main/scala/scalatex/stages/Parser.scala @@ -104,7 +104,9 @@ class Parser(input: ParserInput, indent: Int = 0, offset: Int = 0) extends Scala // clones of the version in ScalaSyntax, but without tailing whitespace or newlines def TypeArgs2 = rule { '[' ~ Ws ~ Types ~ ']' } def ArgumentExprs2 = rule { - '(' ~ Ws ~ (optional(Exprs ~ ',' ~ Ws) ~ PostfixExpr ~ ':' ~ Ws ~ '_' ~ Ws ~ '*' ~ Ws | optional(Exprs)) ~ ')' + '(' ~ Ws ~ + (optional(Exprs ~ ',' ~ Ws) ~ PostfixExpr ~ ':' ~ Ws ~ '_' ~ Ws ~ '*' ~ Ws | run(println("ArgumentExprs2 B")) ~ optional(Exprs) ~ run(println("ArgumentExprs2 C"))) ~ + ')' } def BlockExpr2: Rule0 = rule { '{' ~ Ws ~ (CaseClauses | Block) ~ '}' } def BraceBlock: Rule1[Ast.Block] = rule{ '{' ~ Body ~ '}' } diff --git a/scalatexApi/src/main/scala/torimatomeru/ScalaSyntax.scala b/scalatexApi/src/main/scala/torimatomeru/ScalaSyntax.scala index bf0e0e2..3e0c408 100644 --- a/scalatexApi/src/main/scala/torimatomeru/ScalaSyntax.scala +++ b/scalatexApi/src/main/scala/torimatomeru/ScalaSyntax.scala @@ -92,15 +92,15 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif def Expr: Rule0 = rule { (Bindings | optional("implicit") ~ IdS | "_") ~ "=>" ~ Expr | Expr1 } def Expr1: Rule0 = rule { IfCFlow | - WhileCFlow | - TryCFlow | - DoWhileCFlow | - ForCFlow | - "throw" ~ Expr | - "return" ~ optional(Expr) | - SimpleExpr1 ~ ArgumentExprs ~ '=' ~ Expr | - optional(SimpleExpr ~ '.') ~ IdS ~ '=' ~ Expr | - PostfixExpr ~ optional("match" ~ '{' ~ CaseClauses ~ '}' | Ascription) + WhileCFlow | + TryCFlow | + DoWhileCFlow | + ForCFlow | + "throw" ~ Expr | + "return" ~ optional(Expr) | + SimpleExpr1 ~ ArgumentExprs ~ '=' ~ Expr | + optional(SimpleExpr ~ '.') ~ IdS ~ '=' ~ Expr | + PostfixExpr ~ optional("match" ~ '{' ~ CaseClauses ~ '}' | Ascription) } def IfCFlow = rule { "if" ~ '(' ~ Expr ~ ')' ~ zeroOrMore(NewlineS) ~ Expr ~ optional(optional(SemiS) ~ "else" ~ Expr) } @@ -111,19 +111,20 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif def PostfixExpr: Rule0 = rule { InfixExpr ~ optional(IdS ~ optional(NewlineS)) } def InfixExpr: Rule0 = rule { PrefixExpr ~ zeroOrMore(IdS ~ optional(NewlineS) ~ PrefixExpr) } def PrefixExpr = rule { optional(anyOf("-+~!")) ~ SimpleExpr } - def SimpleExpr: Rule0 = rule { SimpleExprNoLiteral | SimpleExpr1 ~ optional(ArgumentExprs) ~ optional('_') } - def SimpleExprNoLiteral: Rule0 = rule { "new" ~ (ClassTemplate | TemplateBody) | BlockExpr } + def SimpleExpr: Rule0 = rule { SimpleExpr1 ~ optional(ArgumentExprs) ~ optional('_') | SimpleExprNoLiteral} + def SimpleExprNoLiteral: Rule0 = rule { + "new" ~ (ClassTemplate | TemplateBody) | BlockExpr | '(' ~ optional(Exprs) ~ ')' + } def SimpleExpr1: Rule0 = rule { // run(println("SimpleExpr1 matching on " + pos)) ~ LiteralS ~ drop[String] | //literal currently captures, so it can be used outside. but since all our rules lack AST, we drop its value in order to be able to compose them - Path | - '_' | - '(' ~ optional(Exprs) ~ ')' | - SimpleExprNoLiteral ~ '.' ~ IdS | - SimpleExprNoLiteral ~ TypeArgs /*| + Path | + '_' | + SimpleExprNoLiteral ~ '.' ~ IdS | + SimpleExprNoLiteral ~ TypeArgs /*| XmlExpr*/ } - def Exprs: Rule0 = rule { oneOrMore(Expr) separatedBy ',' } + def Exprs: Rule0 = rule { oneOrMore(Expr).separatedBy(',') } def ArgumentExprs: Rule0 = rule { '(' ~ (optional(Exprs ~ ',') ~ PostfixExpr ~ ':' ~ '_' ~ '*' | optional(Exprs)) ~ ')' | optional(NewlineS) ~ BlockExpr @@ -132,9 +133,9 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif def Block: Rule0 = rule { zeroOrMore(BlockStat ~ SemiS) ~ optional(ResultExpr) } def BlockStat: Rule0 = rule { &(SemiS) ~ MATCH | //shortcircuit when Semi is found - Import | - zeroOrMore(Annotation) ~ (optional("implicit" | "lazy") ~ Def | zeroOrMore(LocalModifier) ~ TmplDef) | - Expr1 + Import | + zeroOrMore(Annotation) ~ (optional("implicit" | "lazy") ~ Def | zeroOrMore(LocalModifier) ~ TmplDef) | + Expr1 } def ResultExpr: Rule0 = rule { (Bindings | optional("implicit") ~ IdS | "_") ~ "=>" ~ Block | Expr1 } def Enumerators: Rule0 = rule { Generator ~ zeroOrMore(SemiS ~ Enumerator) } diff --git a/scalatexApi/src/test/scala/scalatex/ParserTests.scala b/scalatexApi/src/test/scala/scalatex/ParserTests.scala index 7de01ed..d462d8a 100644 --- a/scalatexApi/src/test/scala/scalatex/ParserTests.scala +++ b/scalatexApi/src/test/scala/scalatex/ParserTests.scala @@ -387,6 +387,13 @@ object ParserTests extends utest.TestSuite{ )) ) } + 'Test{ +// check( +// "@scala.math.abs((1, 2).wtf)", +// _.Body.run(), +// "" +// ) + } } } |