From 9239e2fd464e72bc6454076b251871a4fdc91fce Mon Sep 17 00:00:00 2001 From: "e.e d3si9n" Date: Sun, 11 Mar 2012 15:02:50 -0400 Subject: [PATCH] fixes NotQuoted --- util/complete/Parsers.scala | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/util/complete/Parsers.scala b/util/complete/Parsers.scala index 9413a728e..7a84a13a1 100644 --- a/util/complete/Parsers.scala +++ b/util/complete/Parsers.scala @@ -48,10 +48,12 @@ trait Parsers lazy val URIClass = URIChar.+.string !!! "Invalid URI" lazy val VerbatimDQuotes = "\"\"\"" lazy val DQuoteChar = '\"' + lazy val BackslashChar = '\\' lazy val DQuoteClass = charClass(_ == DQuoteChar, "double-quote character") - lazy val NotDQuoteClass = charClass(_ != DQuoteChar, "non-double-quote character") - lazy val NotDQuoteBackslashClass = charClass({ c: Char => - c != DQuoteChar && c != '\\' }, "non-double-quote character") + lazy val NotDQuoteSpaceClass = + charClass({ c: Char => (c != DQuoteChar) && !c.isWhitespace }, "non-double-quote-space character") + lazy val NotDQuoteBackslashClass = + charClass({ c: Char => (c != DQuoteChar) && (c != BackslashChar) }, "non-double-quote-backslash character") lazy val URIChar = charClass(alphanum) | chars("_-!.~'()*,;:$&+=?/[]@%#") def alphanum(c: Char) = ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') @@ -69,19 +71,15 @@ trait Parsers lazy val StringVerbatim: Parser[String] = VerbatimDQuotes ~> any.+.string.filter(!_.contains(VerbatimDQuotes), _ => "Invalid verbatim string") <~ VerbatimDQuotes - lazy val StringEscapable: Parser[String] = { - val p = DQuoteChar ~> - (EscapeSequence | NotDQuoteBackslashClass map {_.toString}).* <~ DQuoteChar - p map { _.mkString } - } - lazy val EscapeSequence: Parser[String] = - "\\" ~> ("b" ^^^ "\b" | "t" ^^^ "\t" | "n" ^^^ "\n" | "f" ^^^ "\f" | "r" ^^^ "\r" | - "\"" ^^^ "\"" | "'" ^^^ "\'" | "\\" ^^^ "\\" | UnicodeEscape) - lazy val UnicodeEscape: Parser[String] = - ("u" ~> repeat(HexDigit, 4, 4)) map { seq => - Integer.parseInt(seq.mkString, 16).asInstanceOf[Char].toString - } - lazy val NotQuoted = (NotDQuoteClass ~ NotSpace) map { case (c, s) => c.toString + s } + lazy val StringEscapable: Parser[String] = + (DQuoteChar ~> (NotDQuoteBackslashClass | EscapeSequence).+.string <~ DQuoteChar | + (DQuoteChar ~ DQuoteChar) ^^^ "") + lazy val EscapeSequence: Parser[Char] = + BackslashChar ~> ('b' ^^^ '\b' | 't' ^^^ '\t' | 'n' ^^^ '\n' | 'f' ^^^ '\f' | 'r' ^^^ '\r' | + '\"' ^^^ '\"' | '\'' ^^^ '\'' | '\\' ^^^ '\\' | UnicodeEscape) + lazy val UnicodeEscape: Parser[Char] = + ("u" ~> repeat(HexDigit, 4, 4)) map { seq => Integer.parseInt(seq.mkString, 16).toChar } + lazy val NotQuoted = (NotDQuoteSpaceClass ~ NotSpace) map { case (c, s) => c.toString + s } def repsep[T](rep: Parser[T], sep: Parser[_]): Parser[Seq[T]] = rep1sep(rep, sep) ?? Nil