PageRenderTime 13ms CodeModel.GetById 6ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/scalate-jsp-converter/src/main/scala/org/fusesource/scalate/converter/MarkupScanner.scala

http://github.com/scalate/scalate
Scala | 60 lines | 20 code | 14 blank | 26 comment | 0 complexity | c918b5f556452299cf4f74bbae4e79f4 MD5 | raw file
 1/**
 2 * Copyright (C) 2009-2011 the original author or authors.
 3 * See the notice.md file distributed with this work for additional
 4 * information regarding copyright ownership.
 5 *
 6 * Licensed under the Apache License, Version 2.0 (the "License");
 7 * you may not use this file except in compliance with the License.
 8 * You may obtain a copy of the License at
 9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18package org.fusesource.scalate.converter
19
20import org.fusesource.scalate.support.ScalaParseSupport
21
22class MarkupScanner extends ScalaParseSupport {
23
24  override def skipWhitespace = false
25
26  //   ident     {nmstart}{nmchar}*
27  def IDENT = (nmstart ~ rep(nmchar)) ^^ { case n ~ l => n + l.mkString("") }
28
29  // nmstart   [_a-z]|{nonascii}|{escape}
30  private def nmstart = """[_a-zA-Z]""".r | nonascii | escape
31
32  // nonascii  [^\0-\177]
33  private def nonascii = """[^\x00-\xB1]""".r
34
35  // unicode   \\[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])?
36  private def unicode = """\\[0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?""".r
37
38  // escape    {unicode}|\\[^\n\r\f0-9a-f]
39  private def escape = unicode | """\\[^\n\r\f0-9a-fA-F]""".r
40
41  // nmchar    [_a-z0-9-]|{nonascii}|{escape}
42  private def nmchar = """[_a-zA-Z0-9-]""".r | nonascii | escape
43
44  // string    {string1}|{string2}
45  def STRING = string1 | string2
46
47  // string1   \"([^\n\r\f\\"]|\\{nl}|{nonascii}|{escape})*\"
48  private[this] val string1 = ("\"" ~> rep("""[^\n\r\f\\"]""".r | ("\\" + nl).r | nonascii | escape) <~ "\"") ^^ { case l => l.mkString("") }
49
50  // string2   \'([^\n\r\f\\']|\\{nl}|{nonascii}|{escape})*\'
51  private[this] val string2 = ("'" ~> rep("""[^\n\r\f\']""".r | ("\\" + nl).r | nonascii | escape) <~ "'") ^^ { case l => l.mkString("") }
52
53  // nl        \n|\r\n|\r|\f
54  private[this] val nl = """\n|\r\n|\r|\f"""
55
56  val S = """\s+""".r
57  val repS = """[\s]*""".r
58  val rep1S = """[\s]+""".r
59
60}