From 2610a2920dcff87cb58b67902fd21bfaaf659e64 Mon Sep 17 00:00:00 2001 From: Joel Leitch Date: Wed, 19 May 2010 20:44:27 +0000 Subject: [PATCH] Update Parser to add members to an JsonObject within a loop rather than a recursive call. --- .../com/google/gson/JsonParserJavacc.java | 80 +++++++++---------- .../gson/JsonParserJavaccConstants.java | 2 +- .../gson/JsonParserJavaccTokenManager.java | 34 +------- gson/src/main/javacc/JsonParser.jj | 8 +- 4 files changed, 46 insertions(+), 78 deletions(-) diff --git a/gson/src/main/java/com/google/gson/JsonParserJavacc.java b/gson/src/main/java/com/google/gson/JsonParserJavacc.java index fe0f3175..4d2a5e3c 100644 --- a/gson/src/main/java/com/google/gson/JsonParserJavacc.java +++ b/gson/src/main/java/com/google/gson/JsonParserJavacc.java @@ -73,13 +73,26 @@ final class JsonParserJavacc implements JsonParserJavaccConstants { case IDENTIFIER_STARTS_WITH_EXPONENT: case SINGLE_QUOTE_LITERAL: case DOUBLE_QUOTE_LITERAL: - Members(o); + Pair(o); + label_1: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 28: + ; + break; + default: + jj_la1[3] = jj_gen; + break label_1; + } + jj_consume_token(28); + Pair(o); + } break; default: - jj_la1[3] = jj_gen; + jj_la1[4] = jj_gen; ; } - jj_consume_token(28); + jj_consume_token(29); {if (true) return o;} throw new Error("Missing return statement in function"); } @@ -91,19 +104,6 @@ final class JsonParserJavacc implements JsonParserJavaccConstants { throw new Error("Missing return statement in function"); } - final private void Members(JsonObject o) throws ParseException { - Pair(o); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 29: - jj_consume_token(29); - Members(o); - break; - default: - jj_la1[4] = jj_gen; - ; - } - } - final private void Pair(JsonObject o) throws ParseException { JsonPrimitive property; JsonElement value; @@ -153,15 +153,15 @@ final class JsonParserJavacc implements JsonParserJavaccConstants { case 31: case 33: JsonArrayElement(array); - label_1: + label_2: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 29: + case 28: ; break; default: jj_la1[6] = jj_gen; - break label_1; + break label_2; } JsonArrayNextElement(array); } @@ -192,7 +192,7 @@ final class JsonParserJavacc implements JsonParserJavaccConstants { final private JsonArray JsonArrayNextElement(JsonArray array) throws ParseException { JsonElement element = null; - jj_consume_token(29); + jj_consume_token(28); element = JsonValue(); array.add(element); {if (true) return array;} @@ -430,36 +430,36 @@ final class JsonParserJavacc implements JsonParserJavaccConstants { finally { jj_save(0, xla); } } - private boolean jj_3R_3() { - if (jj_scan_token(NAN)) return true; - return false; - } - - private boolean jj_3R_2() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_3()) { - jj_scanpos = xsp; - if (jj_3R_4()) return true; - } - return false; - } - - private boolean jj_3R_5() { + private boolean jj_3R_6() { if (jj_scan_token(33)) return true; return false; } - private boolean jj_3R_4() { + private boolean jj_3R_5() { Token xsp; xsp = jj_scanpos; - if (jj_3R_5()) jj_scanpos = xsp; + if (jj_3R_6()) jj_scanpos = xsp; if (jj_scan_token(INFINITY)) return true; return false; } private boolean jj_3_1() { - if (jj_3R_2()) return true; + if (jj_3R_3()) return true; + return false; + } + + private boolean jj_3R_4() { + if (jj_scan_token(NAN)) return true; + return false; + } + + private boolean jj_3R_3() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_4()) { + jj_scanpos = xsp; + if (jj_3R_5()) return true; + } return false; } @@ -482,7 +482,7 @@ final class JsonParserJavacc implements JsonParserJavaccConstants { jj_la1_init_1(); } private static void jj_la1_init_0() { - jj_la1_0 = new int[] {0x4000000,0x880307c0,0x8c0307c1,0x31800,0x20000000,0x31800,0x20000000,0x880307c0,0x880307c0,0x30740,0x0,0x20,0x40,0x0,0x300,0x0,0x1800,0x30000,}; + jj_la1_0 = new int[] {0x4000000,0x880307c0,0x8c0307c1,0x10000000,0x31800,0x31800,0x10000000,0x880307c0,0x880307c0,0x30740,0x0,0x20,0x40,0x0,0x300,0x0,0x1800,0x30000,}; } private static void jj_la1_init_1() { jj_la1_1 = new int[] {0x0,0x2,0x2,0x0,0x0,0x0,0x0,0x3,0x2,0x2,0x4,0x0,0x2,0x2,0x2,0x2,0x0,0x0,}; diff --git a/gson/src/main/java/com/google/gson/JsonParserJavaccConstants.java b/gson/src/main/java/com/google/gson/JsonParserJavaccConstants.java index aea3334f..d81c5e65 100644 --- a/gson/src/main/java/com/google/gson/JsonParserJavaccConstants.java +++ b/gson/src/main/java/com/google/gson/JsonParserJavaccConstants.java @@ -88,8 +88,8 @@ interface JsonParserJavaccConstants { "", "\")]}\\\'\\n\"", "\"{\"", - "\"}\"", "\",\"", + "\"}\"", "\":\"", "\"[\"", "\"]\"", diff --git a/gson/src/main/java/com/google/gson/JsonParserJavaccTokenManager.java b/gson/src/main/java/com/google/gson/JsonParserJavaccTokenManager.java index 5f5be626..57098660 100644 --- a/gson/src/main/java/com/google/gson/JsonParserJavaccTokenManager.java +++ b/gson/src/main/java/com/google/gson/JsonParserJavaccTokenManager.java @@ -1,10 +1,8 @@ /* Generated By:JavaCC: Do not edit this line. JsonParserJavaccTokenManager.java */ package com.google.gson; -import java.io.EOFException; /** Token Manager. */ -@SuppressWarnings("all") -final class JsonParserJavaccTokenManager implements JsonParserJavaccConstants +class JsonParserJavaccTokenManager implements JsonParserJavaccConstants { /** Debug output. */ @@ -196,7 +194,7 @@ private int jjMoveStringLiteralDfa0_0() case 41: return jjMoveStringLiteralDfa1_0(0x4000000L); case 44: - return jjStopAtPos(0, 29); + return jjStopAtPos(0, 28); case 45: return jjStopAtPos(0, 33); case 46: @@ -216,7 +214,7 @@ private int jjMoveStringLiteralDfa0_0() case 123: return jjStopAtPos(0, 27); case 125: - return jjStopAtPos(0, 28); + return jjStopAtPos(0, 29); default : return jjMoveNfa_0(4, 0); } @@ -771,18 +769,6 @@ private int jjMoveNfa_0(int startState, int curPos) catch(java.io.IOException e) { return curPos; } } } -private final int jjStopStringLiteralDfa_2(int pos, long active0) -{ - switch (pos) - { - default : - return -1; - } -} -private final int jjStartNfa_2(int pos, long active0) -{ - return jjMoveNfa_2(jjStopStringLiteralDfa_2(pos, active0), pos + 1); -} private int jjMoveStringLiteralDfa0_2() { switch(curChar) @@ -862,18 +848,6 @@ private int jjMoveNfa_2(int startState, int curPos) catch(java.io.IOException e) { return curPos; } } } -private final int jjStopStringLiteralDfa_1(int pos, long active0) -{ - switch (pos) - { - default : - return -1; - } -} -private final int jjStartNfa_1(int pos, long active0) -{ - return jjMoveNfa_1(jjStopStringLiteralDfa_1(pos, active0), pos + 1); -} private int jjMoveStringLiteralDfa0_1() { switch(curChar) @@ -989,7 +963,7 @@ private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, lo public static final String[] jjstrLiteralImages = { "", null, null, null, null, null, null, "\156\165\154\154", "\116\141\116", "\111\156\146\151\156\151\164\171", null, null, null, null, null, null, null, null, "\42", null, null, null, null, -null, null, null, "\51\135\175\47\12", "\173", "\175", "\54", "\72", "\133", "\135", +null, null, null, "\51\135\175\47\12", "\173", "\54", "\175", "\72", "\133", "\135", "\55", "\56", }; /** Lexer state names. */ diff --git a/gson/src/main/javacc/JsonParser.jj b/gson/src/main/javacc/JsonParser.jj index 875dd5e2..48b9b294 100755 --- a/gson/src/main/javacc/JsonParser.jj +++ b/gson/src/main/javacc/JsonParser.jj @@ -76,7 +76,7 @@ private JsonObject JsonObject() : JsonObject o = new JsonObject(); } { - "{" [ Members(o) ] "}" + "{" [ Pair(o) ("," Pair(o))* ] "}" { return o; } } @@ -88,12 +88,6 @@ private JsonNull JsonNull() : t = { return JsonNull.createJsonNull(); } } -private void Members(JsonObject o) : -{ } -{ - Pair(o) [ "," Members(o) ] -} - private void Pair(JsonObject o) : { JsonPrimitive property;