aboutsummaryrefslogtreecommitdiff
path: root/src/org/json/simple/parser/JSONParser.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/json/simple/parser/JSONParser.java')
-rw-r--r--src/org/json/simple/parser/JSONParser.java39
1 files changed, 26 insertions, 13 deletions
diff --git a/src/org/json/simple/parser/JSONParser.java b/src/org/json/simple/parser/JSONParser.java
index 4874eea..85472bb 100644
--- a/src/org/json/simple/parser/JSONParser.java
+++ b/src/org/json/simple/parser/JSONParser.java
@@ -78,7 +78,8 @@ public class JSONParser {
78 return this.parse(s, (ContainerFactory) null); 78 return this.parse(s, (ContainerFactory) null);
79 } 79 }
80 80
81 public Object parse(final String s, final ContainerFactory containerFactory) throws ParseException { 81 public Object parse(final String s, final ContainerFactory containerFactory)
82 throws ParseException {
82 final StringReader in = new StringReader(s); 83 final StringReader in = new StringReader(s);
83 try { 84 try {
84 return this.parse(in, containerFactory); 85 return this.parse(in, containerFactory);
@@ -109,7 +110,8 @@ public class JSONParser {
109 * @throws ParseException 110 * @throws ParseException
110 */ 111 */
111 @SuppressWarnings({ "rawtypes", "unchecked" }) 112 @SuppressWarnings({ "rawtypes", "unchecked" })
112 public Object parse(final Reader in, final ContainerFactory containerFactory) throws IOException, ParseException { 113 public Object parse(final Reader in, final ContainerFactory containerFactory)
114 throws IOException, ParseException {
113 this.reset(in); 115 this.reset(in);
114 final LinkedList statusStack = new LinkedList(); 116 final LinkedList statusStack = new LinkedList();
115 final LinkedList valueStack = new LinkedList(); 117 final LinkedList valueStack = new LinkedList();
@@ -144,7 +146,8 @@ public class JSONParser {
144 if (this.token.type == Yytoken.TYPE_EOF) { 146 if (this.token.type == Yytoken.TYPE_EOF) {
145 return valueStack.removeFirst(); 147 return valueStack.removeFirst();
146 } else { 148 } else {
147 throw new ParseException(this.getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, this.token); 149 throw new ParseException(this.getPosition(),
150 ParseException.ERROR_UNEXPECTED_TOKEN, this.token);
148 } 151 }
149 152
150 case S_IN_OBJECT: 153 case S_IN_OBJECT:
@@ -250,17 +253,20 @@ public class JSONParser {
250 }// inner switch 253 }// inner switch
251 break; 254 break;
252 case S_IN_ERROR: 255 case S_IN_ERROR:
253 throw new ParseException(this.getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, this.token); 256 throw new ParseException(this.getPosition(),
257 ParseException.ERROR_UNEXPECTED_TOKEN, this.token);
254 }// switch 258 }// switch
255 if (this.status == JSONParser.S_IN_ERROR) { 259 if (this.status == JSONParser.S_IN_ERROR) {
256 throw new ParseException(this.getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, this.token); 260 throw new ParseException(this.getPosition(),
261 ParseException.ERROR_UNEXPECTED_TOKEN, this.token);
257 } 262 }
258 } while (this.token.type != Yytoken.TYPE_EOF); 263 } while (this.token.type != Yytoken.TYPE_EOF);
259 } catch (final IOException ie) { 264 } catch (final IOException ie) {
260 throw ie; 265 throw ie;
261 } 266 }
262 267
263 throw new ParseException(this.getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, this.token); 268 throw new ParseException(this.getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN,
269 this.token);
264 } 270 }
265 271
266 private void nextToken() throws ParseException, IOException { 272 private void nextToken() throws ParseException, IOException {
@@ -298,7 +304,8 @@ public class JSONParser {
298 this.parse(s, contentHandler, false); 304 this.parse(s, contentHandler, false);
299 } 305 }
300 306
301 public void parse(final String s, final ContentHandler contentHandler, final boolean isResume) throws ParseException { 307 public void parse(final String s, final ContentHandler contentHandler, final boolean isResume)
308 throws ParseException {
302 final StringReader in = new StringReader(s); 309 final StringReader in = new StringReader(s);
303 try { 310 try {
304 this.parse(in, contentHandler, isResume); 311 this.parse(in, contentHandler, isResume);
@@ -310,7 +317,8 @@ public class JSONParser {
310 } 317 }
311 } 318 }
312 319
313 public void parse(final Reader in, final ContentHandler contentHandler) throws IOException, ParseException { 320 public void parse(final Reader in, final ContentHandler contentHandler) throws IOException,
321 ParseException {
314 this.parse(in, contentHandler, false); 322 this.parse(in, contentHandler, false);
315 } 323 }
316 324
@@ -331,7 +339,8 @@ public class JSONParser {
331 * @throws ParseException 339 * @throws ParseException
332 */ 340 */
333 @SuppressWarnings({ "unchecked", "rawtypes" }) 341 @SuppressWarnings({ "unchecked", "rawtypes" })
334 public void parse(final Reader in, final ContentHandler contentHandler, boolean isResume) throws IOException, ParseException { 342 public void parse(final Reader in, final ContentHandler contentHandler, boolean isResume)
343 throws IOException, ParseException {
335 if (!isResume) { 344 if (!isResume) {
336 this.reset(in); 345 this.reset(in);
337 this.handlerStatusStack = new LinkedList<>(); 346 this.handlerStatusStack = new LinkedList<>();
@@ -386,7 +395,8 @@ public class JSONParser {
386 return; 395 return;
387 } else { 396 } else {
388 this.status = JSONParser.S_IN_ERROR; 397 this.status = JSONParser.S_IN_ERROR;
389 throw new ParseException(this.getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, this.token); 398 throw new ParseException(this.getPosition(),
399 ParseException.ERROR_UNEXPECTED_TOKEN, this.token);
390 } 400 }
391 401
392 case S_IN_OBJECT: 402 case S_IN_OBJECT:
@@ -518,10 +528,12 @@ public class JSONParser {
518 return; 528 return;
519 529
520 case S_IN_ERROR: 530 case S_IN_ERROR:
521 throw new ParseException(this.getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, this.token); 531 throw new ParseException(this.getPosition(),
532 ParseException.ERROR_UNEXPECTED_TOKEN, this.token);
522 }// switch 533 }// switch
523 if (this.status == JSONParser.S_IN_ERROR) { 534 if (this.status == JSONParser.S_IN_ERROR) {
524 throw new ParseException(this.getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, this.token); 535 throw new ParseException(this.getPosition(),
536 ParseException.ERROR_UNEXPECTED_TOKEN, this.token);
525 } 537 }
526 } while (this.token.type != Yytoken.TYPE_EOF); 538 } while (this.token.type != Yytoken.TYPE_EOF);
527 } catch (final IOException ie) { 539 } catch (final IOException ie) {
@@ -539,6 +551,7 @@ public class JSONParser {
539 } 551 }
540 552
541 this.status = JSONParser.S_IN_ERROR; 553 this.status = JSONParser.S_IN_ERROR;
542 throw new ParseException(this.getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, this.token); 554 throw new ParseException(this.getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN,
555 this.token);
543 } 556 }
544} 557}