diff options
author | Mathias <mathias@spray.io> | 2015-02-24 17:04:52 +0100 |
---|---|---|
committer | Mathias <mathias@spray.io> | 2015-02-24 17:04:52 +0100 |
commit | ed9240223d00c9c4967ccdc069c6cea3dda38a4b (patch) | |
tree | a4a6c05e5fbcf0a7cf0b1b48f3433ac8e2b26a01 /src | |
parent | a53a5a895e462a4a83f88be06a5eb36a21f2efb0 (diff) | |
download | spray-json-ed9240223d00c9c4967ccdc069c6cea3dda38a4b.tar.gz spray-json-ed9240223d00c9c4967ccdc069c6cea3dda38a4b.tar.bz2 spray-json-ed9240223d00c9c4967ccdc069c6cea3dda38a4b.zip |
Small improvements to JsonParser
Diffstat (limited to 'src')
-rw-r--r-- | src/main/scala/spray/json/JsonParser.scala | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/main/scala/spray/json/JsonParser.scala b/src/main/scala/spray/json/JsonParser.scala index ea48842..3d61cb4 100644 --- a/src/main/scala/spray/json/JsonParser.scala +++ b/src/main/scala/spray/json/JsonParser.scala @@ -71,17 +71,17 @@ class JsonParser(input: ParserInput) { // http://tools.ietf.org/html/rfc4627#section-2.2 private def `object`(): Unit = { ws() - var map = Map.empty[String, JsValue] - @tailrec def members(): Unit = { + @tailrec def members(map: Map[String, JsValue]): Map[String, JsValue] = { `string`() require(':') ws() val key = sb.toString `value`() - map = map.updated(key, jsValue) - if (ws(',')) members() + val nextMap = map.updated(key, jsValue) + if (ws(',')) members(nextMap) else nextMap } - if (cursorChar != '}') members() + var map = Map.empty[String, JsValue] + if (cursorChar != '}') map = members(map) require('}') ws() jsValue = JsObject(map) @@ -90,7 +90,7 @@ class JsonParser(input: ParserInput) { // http://tools.ietf.org/html/rfc4627#section-2.3 private def `array`(): Unit = { ws() - var list = Vector.newBuilder[JsValue] + val list = Vector.newBuilder[JsValue] @tailrec def values(): Unit = { `value`() list += jsValue @@ -115,7 +115,7 @@ class JsonParser(input: ParserInput) { private def `int`(): Unit = if (!ch('0')) oneOrMoreDigits() private def `frac`(): Unit = if (ch('.')) oneOrMoreDigits() - private def `exp`(): Unit = if ((ch('e') || ch('E')) && (ch('-') || ch('+') || true)) oneOrMoreDigits() + private def `exp`(): Unit = if (ch('e') || ch('E')) { ch('-') || ch('+'); oneOrMoreDigits() } private def oneOrMoreDigits(): Unit = if (DIGIT()) zeroOrMoreDigits() else fail("DIGIT") @tailrec private def zeroOrMoreDigits(): Unit = if (DIGIT()) zeroOrMoreDigits() |