@@ -25,6 +25,8 @@ of this software and associated documentation files (the "Software"), to deal
2525*/
2626
2727import org .json .JSONException ;
28+ import org .json .JSONParseException ;
29+ import org .json .ParsePosition ;
2830import org .json .Scanner ;
2931
3032import java .io .IOException ;
@@ -114,7 +116,7 @@ private char nextClean() throws JSONException {
114116 if (scanner .end ()) {
115117 return c ;
116118 } else {
117- throw scanner . syntaxError ("Illegal control code" );
119+ throw new JSONParseException ("Illegal control code" , scanner . parsePosition () );
118120 }
119121 case (char )1 :
120122 case (char )2 :
@@ -144,7 +146,7 @@ private char nextClean() throws JSONException {
144146 case (char )29 :
145147 case (char )30 :
146148 case (char )31 :
147- throw scanner . syntaxError ("Illegal control code" );
149+ throw new JSONParseException ("Illegal control code" , scanner . parsePosition () );
148150 case (char )9 : // \t
149151 case (char )10 : // \n
150152 case (char )13 : // \r
@@ -216,7 +218,7 @@ public Token nextTokenType() throws JSONException {
216218 scanner .back ();
217219 return Token .NUMBER_VALUE ;
218220 default :
219- throw scanner . syntaxError ("Unexpected value" );
221+ throw new JSONParseException ("Unexpected value" , scanner . parsePosition () );
220222 }
221223 }
222224
@@ -244,7 +246,7 @@ public <T extends Appendable> T nextString(T sb) throws JSONException {
244246 case (char )0 :
245247 case (char )10 : // \n
246248 case (char )13 : // \r
247- throw scanner . syntaxError ("Unterminated string" );
249+ throw new JSONParseException ("Unterminated string" , scanner . parsePosition () );
248250 case (char )1 :
249251 case (char )2 :
250252 case (char )3 :
@@ -274,7 +276,7 @@ public <T extends Appendable> T nextString(T sb) throws JSONException {
274276 case (char )29 :
275277 case (char )30 :
276278 case (char )31 :
277- throw scanner . syntaxError ("Unescaped control code" );
279+ throw new JSONParseException ("Unescaped control code" , scanner . parsePosition () );
278280 case '\\' :
279281 c = scanner .next ();
280282 switch (c ) {
@@ -306,7 +308,7 @@ public <T extends Appendable> T nextString(T sb) throws JSONException {
306308 sb .append (c );
307309 break ;
308310 default :
309- throw scanner . syntaxError ("Illegal escape" );
311+ throw new JSONParseException ("Illegal escape" , scanner . parsePosition () );
310312 }
311313 break ;
312314 case '"' :
@@ -352,7 +354,7 @@ public boolean nextNumber(Appendable sb) throws JSONException {
352354 c = scanner .next ();
353355 }
354356 } else {
355- throw scanner . syntaxError ("Expected number" );
357+ throw new JSONParseException ("Expected number" , scanner . parsePosition () );
356358 }
357359
358360 if (c == '.' ) {
@@ -380,7 +382,7 @@ public boolean nextNumber(Appendable sb) throws JSONException {
380382 sb .append (c );
381383 c = scanner .next ();
382384 } else {
383- throw scanner . syntaxError ("Expected exponent value" );
385+ throw new JSONParseException ("Expected exponent value" , scanner . parsePosition () );
384386 }
385387 while ((c >= '0' ) && (c <= '9' )) {
386388 sb .append (c );
@@ -446,7 +448,7 @@ public Number nextNumber() throws JSONException {
446448 // fall through
447449 }
448450 }
449- throw scanner . syntaxError ("Could not parse number" );
451+ throw new JSONParseException ("Could not parse number" , scanner . parsePosition () );
450452 }
451453
452454 /**
@@ -464,7 +466,7 @@ public BigDecimal nextBigDecimal() throws JSONException {
464466 } catch (Exception exception ) {
465467 // fall through
466468 }
467- throw scanner . syntaxError ("Could not parse big decimal" );
469+ throw new JSONParseException ("Could not parse big decimal" , scanner . parsePosition () );
468470 }
469471
470472 /**
@@ -484,7 +486,7 @@ public BigInteger nextBigInteger() throws JSONException {
484486 // fall through
485487 }
486488 }
487- throw scanner . syntaxError ("Could not parse big integer" );
489+ throw new JSONParseException ("Could not parse big integer" , scanner . parsePosition () );
488490 }
489491
490492 /**
@@ -509,7 +511,7 @@ public double nextDouble() throws JSONException {
509511 } catch (Exception ignore ) {
510512 // fall through
511513 }
512- throw scanner . syntaxError ("Could not parse double" );
514+ throw new JSONParseException ("Could not parse double" , scanner . parsePosition () );
513515 }
514516
515517 /**
@@ -530,7 +532,7 @@ public int nextInt() throws JSONException {
530532 } catch (Exception ignore ) {
531533 // fall through
532534 }
533- throw scanner . syntaxError ("Could not parse int" );
535+ throw new JSONParseException ("Could not parse int" , scanner . parsePosition () );
534536 }
535537
536538 /**
@@ -551,47 +553,17 @@ public long nextLong() throws JSONException {
551553 } catch (Exception ignore ) {
552554 // fall through
553555 }
554- throw scanner . syntaxError ("Could not parse int" );
556+ throw new JSONParseException ("Could not parse int" , scanner . parsePosition () );
555557 }
556558
557559 /**
558- * Make a {@code JSONException} to signal a syntax error .
560+ * Indicates the current position of the scanner .
559561 *
560- * @param message The error message.
561- * @return A JSONException object, suitable for throwing
562+ * @return a {@code ParsePosition} representing the current location of
563+ * the scanner
562564 */
563- public JSONException syntaxError (String message ) {
564- return scanner .syntaxError (message );
565- }
566-
567- /**
568- * Make a {@code JSONException} to signal a syntax error.
569- *
570- * @param message The error message.
571- * @param cause The underlying cause.
572- * @return A JSONException object, suitable for throwing
573- */
574- public JSONException syntaxError (String message , Throwable cause ) {
575- return scanner .syntaxError (message , cause );
576- }
577-
578- /**
579- * Make a {@code JSONException} to signal a syntax error.
580- *
581- * @param cause The underlying cause.
582- * @return A JSONException object, suitable for throwing
583- */
584- public JSONException syntaxError (Throwable cause ) {
585- return scanner .syntaxError (cause );
586- }
587-
588- /**
589- * Indicates the current position of the lexer.
590- *
591- * @return a String of the current position
592- */
593- public String position () {
594- return scanner .toString ();
565+ public ParsePosition parsePosition () {
566+ return scanner .parsePosition ();
595567 }
596568
597569 /**
@@ -601,6 +573,6 @@ public String position() {
601573 */
602574 @ Override
603575 public String toString () {
604- return "JSONLexer" + scanner .toString ();
576+ return "JSONLexer " + scanner .parsePosition (). getPositionDetails ();
605577 }
606578}
0 commit comments