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

http://github.com/scalate/scalate · Scala · 60 lines · 18 code · 15 blank · 27 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. */
  18. package org.fusesource.scalate.converter
  19. import org.fusesource.scalate.support.ScalaParseSupport
  20. class MarkupScanner extends ScalaParseSupport {
  21. override def skipWhitespace = false
  22. // ident {nmstart}{nmchar}*
  23. def IDENT = (nmstart ~ rep(nmchar)) ^^ { case n ~ l => n + l.mkString("") }
  24. // nmstart [_a-z]|{nonascii}|{escape}
  25. private def nmstart = """[_a-zA-Z]""".r | nonascii | escape
  26. // nonascii [^\0-\177]
  27. private def nonascii = """[^\x00-\xB1]""".r
  28. // unicode \\[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])?
  29. private def unicode = """\\[0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?""".r
  30. // escape {unicode}|\\[^\n\r\f0-9a-f]
  31. private def escape = unicode | """\\[^\n\r\f0-9a-fA-F]""".r
  32. // nmchar [_a-z0-9-]|{nonascii}|{escape}
  33. private def nmchar = """[_a-zA-Z0-9-]""".r | nonascii | escape
  34. // string {string1}|{string2}
  35. def STRING = string1 | string2
  36. // string1 \"([^\n\r\f\\"]|\\{nl}|{nonascii}|{escape})*\"
  37. private[this] val string1 = ("\"" ~> rep("""[^\n\r\f\\"]""".r | ("\\" + nl).r | nonascii | escape) <~ "\"") ^^ { case l => l.mkString("") }
  38. // string2 \'([^\n\r\f\\']|\\{nl}|{nonascii}|{escape})*\'
  39. private[this] val string2 = ("'" ~> rep("""[^\n\r\f\']""".r | ("\\" + nl).r | nonascii | escape) <~ "'") ^^ { case l => l.mkString("") }
  40. // nl \n|\r\n|\r|\f
  41. private[this] val nl = """\n|\r\n|\r|\f"""
  42. val S = """\s+""".r
  43. val repS = """[\s]*""".r
  44. val rep1S = """[\s]+""".r
  45. }