diff options
author | Li Haoyi <haoyi@dropbox.com> | 2014-11-05 22:25:58 -0800 |
---|---|---|
committer | Li Haoyi <haoyi@dropbox.com> | 2014-11-05 22:25:58 -0800 |
commit | 784f3da4192a0e30ddd94cfb10f91d0bc8dc4f7f (patch) | |
tree | 83bc659db8b89e904b6b3377d91ef3016be98d18 /scalatexApi/src/main/scala/torimatomeru/ScalaSyntax.scala | |
parent | 62871430033658a36e04772a4417526ac399b0dc (diff) | |
download | hands-on-scala-js-784f3da4192a0e30ddd94cfb10f91d0bc8dc4f7f.tar.gz hands-on-scala-js-784f3da4192a0e30ddd94cfb10f91d0bc8dc4f7f.tar.bz2 hands-on-scala-js-784f3da4192a0e30ddd94cfb10f91d0bc8dc4f7f.zip |
Fixed the Scala grammar, property/call/type-param chaining now works and more tests pass
Diffstat (limited to 'scalatexApi/src/main/scala/torimatomeru/ScalaSyntax.scala')
-rw-r--r-- | scalatexApi/src/main/scala/torimatomeru/ScalaSyntax.scala | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/scalatexApi/src/main/scala/torimatomeru/ScalaSyntax.scala b/scalatexApi/src/main/scala/torimatomeru/ScalaSyntax.scala index 3e0c408..caaac87 100644 --- a/scalatexApi/src/main/scala/torimatomeru/ScalaSyntax.scala +++ b/scalatexApi/src/main/scala/torimatomeru/ScalaSyntax.scala @@ -98,7 +98,7 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif ForCFlow | "throw" ~ Expr | "return" ~ optional(Expr) | - SimpleExpr1 ~ ArgumentExprs ~ '=' ~ Expr | + SimpleExpr ~ ArgumentExprs ~ '=' ~ Expr | optional(SimpleExpr ~ '.') ~ IdS ~ '=' ~ Expr | PostfixExpr ~ optional("match" ~ '{' ~ CaseClauses ~ '}' | Ascription) } @@ -111,19 +111,32 @@ 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 { SimpleExpr1 ~ optional(ArgumentExprs) ~ optional('_') | SimpleExprNoLiteral} - def SimpleExprNoLiteral: Rule0 = rule { - "new" ~ (ClassTemplate | TemplateBody) | BlockExpr | '(' ~ optional(Exprs) ~ ')' +""" + SimpleExpr ::= ‘new’ (ClassTemplate | TemplateBody) + | BlockExpr + | SimpleExpr1 [‘_’] + SimpleExpr1 ::= Literal + | Path + | ‘_’ + | ‘(’ [Exprs] ‘)’ + | SimpleExpr ‘.’ id s + | SimpleExpr TypeArgs + | SimpleExpr1 ArgmentExprs +""" + def SimpleExpr: Rule0 = rule { + SimpleExpr1 ~ zeroOrMore('.' ~ IdS | TypeArgs | ArgumentExprs) ~ optional('_') } - 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 + + def SimpleExpr1 = rule{ + "new" ~ (ClassTemplate | TemplateBody) | + BlockExpr | + LiteralS ~ drop[String] | Path | '_' | - SimpleExprNoLiteral ~ '.' ~ IdS | - SimpleExprNoLiteral ~ TypeArgs /*| - XmlExpr*/ + '(' ~ optional(Exprs) ~ ')' } + + def Exprs: Rule0 = rule { oneOrMore(Expr).separatedBy(',') } def ArgumentExprs: Rule0 = rule { '(' ~ (optional(Exprs ~ ',') ~ PostfixExpr ~ ':' ~ '_' ~ '*' | optional(Exprs)) ~ ')' | |