summaryrefslogtreecommitdiff
path: root/scalatexApi/src/test/scala/scalatex/Main.scala
diff options
context:
space:
mode:
Diffstat (limited to 'scalatexApi/src/test/scala/scalatex/Main.scala')
-rw-r--r--scalatexApi/src/test/scala/scalatex/Main.scala44
1 files changed, 7 insertions, 37 deletions
diff --git a/scalatexApi/src/test/scala/scalatex/Main.scala b/scalatexApi/src/test/scala/scalatex/Main.scala
index 968e34c..fa0d213 100644
--- a/scalatexApi/src/test/scala/scalatex/Main.scala
+++ b/scalatexApi/src/test/scala/scalatex/Main.scala
@@ -30,7 +30,12 @@ object Main extends utest.TestSuite{
'Block{
* - check("{i am a cow}", _.TBlock.run(), Block(Seq(Block.Text("i am a cow"))))
* - check("{i @am a @cow}", _.TBlock.run(),
- Block(Seq(Block.Text("i "), Chain(Code("am"),Seq()), Block.Text(" a "), Chain(Code("cow"),Seq())))
+ Block(Seq(
+ Block.Text("i "),
+ Chain(Code("am"),Seq()),
+ Block.Text(" a "),
+ Chain(Code("cow"),Seq())
+ ))
)
}
'Chain{
@@ -46,43 +51,8 @@ object Main extends utest.TestSuite{
))
)
}
-
- }
- def p(input: String) = {
- new ScalatexParser(input)
- }
-}
-trait Ast{
- def offset: Int
-}
-object Ast{
- case class Code(code: String, offset: Int = 0) extends Ast
- case class Block(parts: Seq[Block.Sub], offset: Int = 0) extends Chain.Sub
- object Block{
- trait Sub
- case class Text(txt: String, offset: Int = 0) extends Block.Sub
}
- case class Chain(lhs: Code, parts: Seq[Chain.Sub], offset: Int = 0) extends Block.Sub
- object Chain{
- trait Sub extends Ast
- case class Prop(str: String, offset: Int = 0) extends Sub
- case class Args(str: String, offset: Int = 0) extends Sub
- }
-}
-class ScalatexParser(input: ParserInput) extends ScalaSyntax(input) {
- def TextNot(chars: String) = rule { capture(oneOrMore(noneOf(chars) | "@@")) ~> (x => Ast.Block.Text(x.replace("@@", "@"))) }
- def Text = TextNot("@")
- def Code = rule {
- "@" ~ capture(Id | BlockExpr | ('(' ~ optional(Exprs) ~ ')')) ~> (Ast.Code(_))
- }
- def ScalaChain = rule { Code ~ zeroOrMore(Extension) ~> (Ast.Chain(_, _)) }
- def Extension: Rule1[Ast.Chain.Sub] = rule {
- (capture(('.' ~ Id) ~ optional(TypeArgs)) ~> (Ast.Chain.Prop(_))) |
- (capture(!BlockExpr ~ ArgumentExprs) ~> (Ast.Chain.Args(_))) |
- TBlock
- }
- def TBlock = rule{ '{' ~ Body ~ '}' }
- def Body = rule{ zeroOrMore(TextNot("@}") | ScalaChain) ~> (x => Ast.Block(x)) }
+
}