More formatting

By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
Bukkit/Spigot 2011-01-03 15:35:30 +00:00
parent 346e41a6e5
commit 05b2a299c0
12 changed files with 2190 additions and 2184 deletions

View file

@ -18,9 +18,8 @@ public class ItemList {
private String sp = ","; private String sp = ",";
List items = new ArrayList(); List items = new ArrayList();
public ItemList() {
public ItemList(){} }
public ItemList(String s) { public ItemList(String s) {
this.split(s, sp, items); this.split(s, sp, items);
@ -44,29 +43,31 @@ public class ItemList {
} }
public void split(String s, String sp, List append, boolean isMultiToken) { public void split(String s, String sp, List append, boolean isMultiToken) {
if(s==null || sp==null) if (s == null || sp == null) {
return; return;
}
if (isMultiToken) { if (isMultiToken) {
StringTokenizer tokens = new StringTokenizer(s, sp); StringTokenizer tokens = new StringTokenizer(s, sp);
while (tokens.hasMoreTokens()) { while (tokens.hasMoreTokens()) {
append.add(tokens.nextToken().trim()); append.add(tokens.nextToken().trim());
} }
} } else {
else{
this.split(s, sp, append); this.split(s, sp, append);
} }
} }
public void split(String s, String sp, List append) { public void split(String s, String sp, List append) {
if(s==null || sp==null) if (s == null || sp == null) {
return; return;
}
int pos = 0; int pos = 0;
int prevPos = 0; int prevPos = 0;
do { do {
prevPos = pos; prevPos = pos;
pos = s.indexOf(sp, pos); pos = s.indexOf(sp, pos);
if(pos==-1) if (pos == -1) {
break; break;
}
append.add(s.substring(prevPos, pos).trim()); append.add(s.substring(prevPos, pos).trim());
pos += sp.length(); pos += sp.length();
} while (pos != -1); } while (pos != -1);
@ -78,14 +79,16 @@ public class ItemList {
} }
public void add(int i, String item) { public void add(int i, String item) {
if(item==null) if (item == null) {
return; return;
}
items.add(i, item.trim()); items.add(i, item.trim());
} }
public void add(String item) { public void add(String item) {
if(item==null) if (item == null) {
return; return;
}
items.add(item.trim()); items.add(item.trim());
} }
@ -125,9 +128,9 @@ public class ItemList {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
for (int i = 0; i < items.size(); i++) { for (int i = 0; i < items.size(); i++) {
if(i==0) if (i == 0) {
sb.append(items.get(i)); sb.append(items.get(i));
else{ } else {
sb.append(sp); sb.append(sp);
sb.append(items.get(i)); sb.append(items.get(i));
} }

View file

@ -10,7 +10,6 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
/** /**
* A JSON array. JSONObject supports java.util.List interface. * A JSON array. JSONObject supports java.util.List interface.
* *
@ -39,10 +38,11 @@ public class JSONArray extends ArrayList implements List, JSONAware, JSONStreamA
out.write('['); out.write('[');
while (iter.hasNext()) { while (iter.hasNext()) {
if(first) if (first) {
first = false; first = false;
else } else {
out.write(','); out.write(',');
}
Object value = iter.next(); Object value = iter.next();
if (value == null) { if (value == null) {
@ -69,8 +69,9 @@ public class JSONArray extends ArrayList implements List, JSONAware, JSONStreamA
* @return JSON text, or "null" if list is null. * @return JSON text, or "null" if list is null.
*/ */
public static String toJSONString(List list) { public static String toJSONString(List list) {
if(list == null) if (list == null) {
return "null"; return "null";
}
boolean first = true; boolean first = true;
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
@ -78,10 +79,11 @@ public class JSONArray extends ArrayList implements List, JSONAware, JSONStreamA
sb.append('['); sb.append('[');
while (iter.hasNext()) { while (iter.hasNext()) {
if(first) if (first) {
first = false; first = false;
else } else {
sb.append(','); sb.append(',');
}
Object value = iter.next(); Object value = iter.next();
if (value == null) { if (value == null) {
@ -101,7 +103,4 @@ public class JSONArray extends ArrayList implements List, JSONAware, JSONStreamA
public String toString() { public String toString() {
return toJSONString(); return toJSONString();
} }
} }

View file

@ -38,10 +38,11 @@ public class JSONObject extends HashMap implements Map, JSONAware, JSONStreamAwa
out.write('{'); out.write('{');
while (iter.hasNext()) { while (iter.hasNext()) {
if(first) if (first) {
first = false; first = false;
else } else {
out.write(','); out.write(',');
}
Map.Entry entry = (Map.Entry) iter.next(); Map.Entry entry = (Map.Entry) iter.next();
out.write('\"'); out.write('\"');
out.write(escape(String.valueOf(entry.getKey()))); out.write(escape(String.valueOf(entry.getKey())));
@ -66,8 +67,9 @@ public class JSONObject extends HashMap implements Map, JSONAware, JSONStreamAwa
* @return JSON text, or "null" if map is null. * @return JSON text, or "null" if map is null.
*/ */
public static String toJSONString(Map map) { public static String toJSONString(Map map) {
if(map == null) if (map == null) {
return "null"; return "null";
}
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
boolean first = true; boolean first = true;
@ -75,10 +77,11 @@ public class JSONObject extends HashMap implements Map, JSONAware, JSONStreamAwa
sb.append('{'); sb.append('{');
while (iter.hasNext()) { while (iter.hasNext()) {
if(first) if (first) {
first = false; first = false;
else } else {
sb.append(','); sb.append(',');
}
Map.Entry entry = (Map.Entry) iter.next(); Map.Entry entry = (Map.Entry) iter.next();
toJSONString(String.valueOf(entry.getKey()), entry.getValue(), sb); toJSONString(String.valueOf(entry.getKey()), entry.getValue(), sb);
@ -93,10 +96,11 @@ public class JSONObject extends HashMap implements Map, JSONAware, JSONStreamAwa
private static String toJSONString(String key, Object value, StringBuffer sb) { private static String toJSONString(String key, Object value, StringBuffer sb) {
sb.append('\"'); sb.append('\"');
if(key == null) if (key == null) {
sb.append("null"); sb.append("null");
else } else {
JSONValue.escape(key, sb); JSONValue.escape(key, sb);
}
sb.append('\"').append(':'); sb.append('\"').append(':');
sb.append(JSONValue.toJSONString(value)); sb.append(JSONValue.toJSONString(value));

View file

@ -14,7 +14,6 @@ import java.util.Map;
import org.json.simple.parser.JSONParser; import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
/** /**
* @author FangYidong<fangyidong@yahoo.com.cn> * @author FangYidong<fangyidong@yahoo.com.cn>
*/ */
@ -40,8 +39,7 @@ public class JSONValue {
try { try {
JSONParser parser = new JSONParser(); JSONParser parser = new JSONParser();
return parser.parse(in); return parser.parse(in);
} } catch (Exception e) {
catch(Exception e){
return null; return null;
} }
} }
@ -106,18 +104,20 @@ public class JSONValue {
} }
if (value instanceof Double) { if (value instanceof Double) {
if(((Double)value).isInfinite() || ((Double)value).isNaN()) if (((Double) value).isInfinite() || ((Double) value).isNaN()) {
out.write("null"); out.write("null");
else } else {
out.write(value.toString()); out.write(value.toString());
}
return; return;
} }
if (value instanceof Float) { if (value instanceof Float) {
if(((Float)value).isInfinite() || ((Float)value).isNaN()) if (((Float) value).isInfinite() || ((Float) value).isNaN()) {
out.write("null"); out.write("null");
else } else {
out.write(value.toString()); out.write(value.toString());
}
return; return;
} }
@ -169,40 +169,49 @@ public class JSONValue {
* @return JSON text, or "null" if value is null or it's an NaN or an INF number. * @return JSON text, or "null" if value is null or it's an NaN or an INF number.
*/ */
public static String toJSONString(Object value) { public static String toJSONString(Object value) {
if(value == null) if (value == null) {
return "null"; return "null";
}
if(value instanceof String) if (value instanceof String) {
return "\"" + escape((String) value) + "\""; return "\"" + escape((String) value) + "\"";
}
if (value instanceof Double) { if (value instanceof Double) {
if(((Double)value).isInfinite() || ((Double)value).isNaN()) if (((Double) value).isInfinite() || ((Double) value).isNaN()) {
return "null"; return "null";
else } else {
return value.toString(); return value.toString();
} }
}
if (value instanceof Float) { if (value instanceof Float) {
if(((Float)value).isInfinite() || ((Float)value).isNaN()) if (((Float) value).isInfinite() || ((Float) value).isNaN()) {
return "null"; return "null";
else } else {
return value.toString();
}
}
if (value instanceof Number) {
return value.toString(); return value.toString();
} }
if(value instanceof Number) if (value instanceof Boolean) {
return value.toString(); return value.toString();
}
if(value instanceof Boolean) if ((value instanceof JSONAware)) {
return value.toString();
if((value instanceof JSONAware))
return ((JSONAware) value).toJSONString(); return ((JSONAware) value).toJSONString();
}
if(value instanceof Map) if (value instanceof Map) {
return JSONObject.toJSONString((Map) value); return JSONObject.toJSONString((Map) value);
}
if(value instanceof List) if (value instanceof List) {
return JSONArray.toJSONString((List) value); return JSONArray.toJSONString((List) value);
}
return value.toString(); return value.toString();
} }
@ -213,8 +222,9 @@ public class JSONValue {
* @return * @return
*/ */
public static String escape(String s) { public static String escape(String s) {
if(s==null) if (s == null) {
return null; return null;
}
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
escape(s, sb); escape(s, sb);
return sb.toString(); return sb.toString();
@ -261,12 +271,10 @@ public class JSONValue {
sb.append('0'); sb.append('0');
} }
sb.append(ss.toUpperCase()); sb.append(ss.toUpperCase());
} } else {
else{
sb.append(ch); sb.append(ch);
} }
} }
}//for }//for
} }
} }

View file

@ -106,5 +106,4 @@ public interface ContentHandler {
* @throws ParseException * @throws ParseException
*/ */
boolean primitive(Object value) throws ParseException, IOException; boolean primitive(Object value) throws ParseException, IOException;
} }

View file

@ -14,7 +14,6 @@ import java.util.Map;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
/** /**
* Parser for JSON text. Please note that JSONParser is NOT thread-safe. * Parser for JSON text. Please note that JSONParser is NOT thread-safe.
* *
@ -29,15 +28,15 @@ public class JSONParser {
public static final int S_IN_PAIR_VALUE = 5; public static final int S_IN_PAIR_VALUE = 5;
public static final int S_END = 6; public static final int S_END = 6;
public static final int S_IN_ERROR = -1; public static final int S_IN_ERROR = -1;
private LinkedList handlerStatusStack; private LinkedList handlerStatusStack;
private Yylex lexer = new Yylex((Reader) null); private Yylex lexer = new Yylex((Reader) null);
private Yytoken token = null; private Yytoken token = null;
private int status = S_INIT; private int status = S_INIT;
private int peekStatus(LinkedList statusStack) { private int peekStatus(LinkedList statusStack) {
if(statusStack.size()==0) if (statusStack.size() == 0) {
return -1; return -1;
}
Integer status = (Integer) statusStack.getFirst(); Integer status = (Integer) statusStack.getFirst();
return status.intValue(); return status.intValue();
} }
@ -79,8 +78,7 @@ public class JSONParser {
StringReader in = new StringReader(s); StringReader in = new StringReader(s);
try { try {
return parse(in, containerFactory); return parse(in, containerFactory);
} } catch (IOException ie) {
catch(IOException ie){
/* /*
* Actually it will never happen. * Actually it will never happen.
*/ */
@ -140,10 +138,11 @@ public class JSONParser {
break; break;
case S_IN_FINISHED_VALUE: case S_IN_FINISHED_VALUE:
if(token.type==Yytoken.TYPE_EOF) if (token.type == Yytoken.TYPE_EOF) {
return valueStack.removeFirst(); return valueStack.removeFirst();
else } else {
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token); throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
}
case S_IN_OBJECT: case S_IN_OBJECT:
switch (token.type) { switch (token.type) {
@ -155,8 +154,7 @@ public class JSONParser {
valueStack.addFirst(key); valueStack.addFirst(key);
status = S_PASSED_PAIR_KEY; status = S_PASSED_PAIR_KEY;
statusStack.addFirst(new Integer(status)); statusStack.addFirst(new Integer(status));
} } else {
else{
status = S_IN_ERROR; status = S_IN_ERROR;
} }
break; break;
@ -165,8 +163,7 @@ public class JSONParser {
statusStack.removeFirst(); statusStack.removeFirst();
valueStack.removeFirst(); valueStack.removeFirst();
status = peekStatus(statusStack); status = peekStatus(statusStack);
} } else {
else{
status = S_IN_FINISHED_VALUE; status = S_IN_FINISHED_VALUE;
} }
break; break;
@ -225,8 +222,7 @@ public class JSONParser {
statusStack.removeFirst(); statusStack.removeFirst();
valueStack.removeFirst(); valueStack.removeFirst();
status = peekStatus(statusStack); status = peekStatus(statusStack);
} } else {
else{
status = S_IN_FINISHED_VALUE; status = S_IN_FINISHED_VALUE;
} }
break; break;
@ -257,8 +253,7 @@ public class JSONParser {
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token); throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
} }
} while (token.type != Yytoken.TYPE_EOF); } while (token.type != Yytoken.TYPE_EOF);
} } catch (IOException ie) {
catch(IOException ie){
throw ie; throw ie;
} }
@ -267,27 +262,32 @@ public class JSONParser {
private void nextToken() throws ParseException, IOException { private void nextToken() throws ParseException, IOException {
token = lexer.yylex(); token = lexer.yylex();
if(token == null) if (token == null) {
token = new Yytoken(Yytoken.TYPE_EOF, null); token = new Yytoken(Yytoken.TYPE_EOF, null);
} }
}
private Map createObjectContainer(ContainerFactory containerFactory) { private Map createObjectContainer(ContainerFactory containerFactory) {
if(containerFactory == null) if (containerFactory == null) {
return new JSONObject(); return new JSONObject();
}
Map m = containerFactory.createObjectContainer(); Map m = containerFactory.createObjectContainer();
if(m == null) if (m == null) {
return new JSONObject(); return new JSONObject();
}
return m; return m;
} }
private List createArrayContainer(ContainerFactory containerFactory) { private List createArrayContainer(ContainerFactory containerFactory) {
if(containerFactory == null) if (containerFactory == null) {
return new JSONArray(); return new JSONArray();
}
List l = containerFactory.creatArrayContainer(); List l = containerFactory.creatArrayContainer();
if(l == null) if (l == null) {
return new JSONArray(); return new JSONArray();
}
return l; return l;
} }
@ -299,8 +299,7 @@ public class JSONParser {
StringReader in = new StringReader(s); StringReader in = new StringReader(s);
try { try {
parse(in, contentHandler, isResume); parse(in, contentHandler, isResume);
} } catch (IOException ie) {
catch(IOException ie){
/* /*
* Actually it will never happen. * Actually it will never happen.
*/ */
@ -330,8 +329,7 @@ public class JSONParser {
if (!isResume) { if (!isResume) {
reset(in); reset(in);
handlerStatusStack = new LinkedList(); handlerStatusStack = new LinkedList();
} } else {
else{
if (handlerStatusStack == null) { if (handlerStatusStack == null) {
isResume = false; isResume = false;
reset(in); reset(in);
@ -351,20 +349,23 @@ public class JSONParser {
case Yytoken.TYPE_VALUE: case Yytoken.TYPE_VALUE:
status = S_IN_FINISHED_VALUE; status = S_IN_FINISHED_VALUE;
statusStack.addFirst(new Integer(status)); statusStack.addFirst(new Integer(status));
if(!contentHandler.primitive(token.value)) if (!contentHandler.primitive(token.value)) {
return; return;
}
break; break;
case Yytoken.TYPE_LEFT_BRACE: case Yytoken.TYPE_LEFT_BRACE:
status = S_IN_OBJECT; status = S_IN_OBJECT;
statusStack.addFirst(new Integer(status)); statusStack.addFirst(new Integer(status));
if(!contentHandler.startObject()) if (!contentHandler.startObject()) {
return; return;
}
break; break;
case Yytoken.TYPE_LEFT_SQUARE: case Yytoken.TYPE_LEFT_SQUARE:
status = S_IN_ARRAY; status = S_IN_ARRAY;
statusStack.addFirst(new Integer(status)); statusStack.addFirst(new Integer(status));
if(!contentHandler.startArray()) if (!contentHandler.startArray()) {
return; return;
}
break; break;
default: default:
status = S_IN_ERROR; status = S_IN_ERROR;
@ -377,8 +378,7 @@ public class JSONParser {
contentHandler.endJSON(); contentHandler.endJSON();
status = S_END; status = S_END;
return; return;
} } else {
else{
status = S_IN_ERROR; status = S_IN_ERROR;
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token); throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
} }
@ -393,10 +393,10 @@ public class JSONParser {
String key = (String) token.value; String key = (String) token.value;
status = S_PASSED_PAIR_KEY; status = S_PASSED_PAIR_KEY;
statusStack.addFirst(new Integer(status)); statusStack.addFirst(new Integer(status));
if(!contentHandler.startObjectEntry(key)) if (!contentHandler.startObjectEntry(key)) {
return; return;
} }
else{ } else {
status = S_IN_ERROR; status = S_IN_ERROR;
} }
break; break;
@ -404,12 +404,12 @@ public class JSONParser {
if (statusStack.size() > 1) { if (statusStack.size() > 1) {
statusStack.removeFirst(); statusStack.removeFirst();
status = peekStatus(statusStack); status = peekStatus(statusStack);
} } else {
else{
status = S_IN_FINISHED_VALUE; status = S_IN_FINISHED_VALUE;
} }
if(!contentHandler.endObject()) if (!contentHandler.endObject()) {
return; return;
}
break; break;
default: default:
status = S_IN_ERROR; status = S_IN_ERROR;
@ -425,26 +425,30 @@ public class JSONParser {
case Yytoken.TYPE_VALUE: case Yytoken.TYPE_VALUE:
statusStack.removeFirst(); statusStack.removeFirst();
status = peekStatus(statusStack); status = peekStatus(statusStack);
if(!contentHandler.primitive(token.value)) if (!contentHandler.primitive(token.value)) {
return; return;
if(!contentHandler.endObjectEntry()) }
if (!contentHandler.endObjectEntry()) {
return; return;
}
break; break;
case Yytoken.TYPE_LEFT_SQUARE: case Yytoken.TYPE_LEFT_SQUARE:
statusStack.removeFirst(); statusStack.removeFirst();
statusStack.addFirst(new Integer(S_IN_PAIR_VALUE)); statusStack.addFirst(new Integer(S_IN_PAIR_VALUE));
status = S_IN_ARRAY; status = S_IN_ARRAY;
statusStack.addFirst(new Integer(status)); statusStack.addFirst(new Integer(status));
if(!contentHandler.startArray()) if (!contentHandler.startArray()) {
return; return;
}
break; break;
case Yytoken.TYPE_LEFT_BRACE: case Yytoken.TYPE_LEFT_BRACE:
statusStack.removeFirst(); statusStack.removeFirst();
statusStack.addFirst(new Integer(S_IN_PAIR_VALUE)); statusStack.addFirst(new Integer(S_IN_PAIR_VALUE));
status = S_IN_OBJECT; status = S_IN_OBJECT;
statusStack.addFirst(new Integer(status)); statusStack.addFirst(new Integer(status));
if(!contentHandler.startObject()) if (!contentHandler.startObject()) {
return; return;
}
break; break;
default: default:
status = S_IN_ERROR; status = S_IN_ERROR;
@ -458,8 +462,9 @@ public class JSONParser {
*/ */
statusStack.removeFirst(); statusStack.removeFirst();
status = peekStatus(statusStack); status = peekStatus(statusStack);
if(!contentHandler.endObjectEntry()) if (!contentHandler.endObjectEntry()) {
return; return;
}
break; break;
case S_IN_ARRAY: case S_IN_ARRAY:
@ -468,31 +473,34 @@ public class JSONParser {
case Yytoken.TYPE_COMMA: case Yytoken.TYPE_COMMA:
break; break;
case Yytoken.TYPE_VALUE: case Yytoken.TYPE_VALUE:
if(!contentHandler.primitive(token.value)) if (!contentHandler.primitive(token.value)) {
return; return;
}
break; break;
case Yytoken.TYPE_RIGHT_SQUARE: case Yytoken.TYPE_RIGHT_SQUARE:
if (statusStack.size() > 1) { if (statusStack.size() > 1) {
statusStack.removeFirst(); statusStack.removeFirst();
status = peekStatus(statusStack); status = peekStatus(statusStack);
} } else {
else{
status = S_IN_FINISHED_VALUE; status = S_IN_FINISHED_VALUE;
} }
if(!contentHandler.endArray()) if (!contentHandler.endArray()) {
return; return;
}
break; break;
case Yytoken.TYPE_LEFT_BRACE: case Yytoken.TYPE_LEFT_BRACE:
status = S_IN_OBJECT; status = S_IN_OBJECT;
statusStack.addFirst(new Integer(status)); statusStack.addFirst(new Integer(status));
if(!contentHandler.startObject()) if (!contentHandler.startObject()) {
return; return;
}
break; break;
case Yytoken.TYPE_LEFT_SQUARE: case Yytoken.TYPE_LEFT_SQUARE:
status = S_IN_ARRAY; status = S_IN_ARRAY;
statusStack.addFirst(new Integer(status)); statusStack.addFirst(new Integer(status));
if(!contentHandler.startArray()) if (!contentHandler.startArray()) {
return; return;
}
break; break;
default: default:
status = S_IN_ERROR; status = S_IN_ERROR;
@ -509,20 +517,16 @@ public class JSONParser {
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token); throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
} }
} while (token.type != Yytoken.TYPE_EOF); } while (token.type != Yytoken.TYPE_EOF);
} } catch (IOException ie) {
catch(IOException ie){
status = S_IN_ERROR; status = S_IN_ERROR;
throw ie; throw ie;
} } catch (ParseException pe) {
catch(ParseException pe){
status = S_IN_ERROR; status = S_IN_ERROR;
throw pe; throw pe;
} } catch (RuntimeException re) {
catch(RuntimeException re){
status = S_IN_ERROR; status = S_IN_ERROR;
throw re; throw re;
} } catch (Error e) {
catch(Error e){
status = S_IN_ERROR; status = S_IN_ERROR;
throw e; throw e;
} }

View file

@ -8,11 +8,9 @@ package org.json.simple.parser;
*/ */
public class ParseException extends Exception { public class ParseException extends Exception {
private static final long serialVersionUID = -7880698968187728548L; private static final long serialVersionUID = -7880698968187728548L;
public static final int ERROR_UNEXPECTED_CHAR = 0; public static final int ERROR_UNEXPECTED_CHAR = 0;
public static final int ERROR_UNEXPECTED_TOKEN = 1; public static final int ERROR_UNEXPECTED_TOKEN = 1;
public static final int ERROR_UNEXPECTED_EXCEPTION = 2; public static final int ERROR_UNEXPECTED_EXCEPTION = 2;
private int errorType; private int errorType;
private Object unexpectedObject; private Object unexpectedObject;
private int position; private int position;

View file

@ -1,19 +1,14 @@
/* The following code was generated by JFlex 1.4.2 */ /* The following code was generated by JFlex 1.4.2 */
package org.json.simple.parser; package org.json.simple.parser;
class Yylex { class Yylex {
/** This character denotes the end of file */ /** This character denotes the end of file */
public static final int YYEOF = -1; public static final int YYEOF = -1;
/** initial size of the lookahead buffer */ /** initial size of the lookahead buffer */
private static final int ZZ_BUFFERSIZE = 16384; private static final int ZZ_BUFFERSIZE = 16384;
/** lexical states */ /** lexical states */
public static final int YYINITIAL = 0; public static final int YYINITIAL = 0;
public static final int STRING_BEGIN = 2; public static final int STRING_BEGIN = 2;
/** /**
* ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l * ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l
* ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l * ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l
@ -23,33 +18,29 @@ class Yylex {
private static final int ZZ_LEXSTATE[] = { private static final int ZZ_LEXSTATE[] = {
0, 0, 1, 1 0, 0, 1, 1
}; };
/** /**
* Translates characters to character classes * Translates characters to character classes
*/ */
private static final String ZZ_CMAP_PACKED = private static final String ZZ_CMAP_PACKED =
"\11\0\1\7\1\7\2\0\1\7\22\0\1\7\1\0\1\11\10\0"+ "\11\0\1\7\1\7\2\0\1\7\22\0\1\7\1\0\1\11\10\0"
"\1\6\1\31\1\2\1\4\1\12\12\3\1\32\6\0\4\1\1\5"+ + "\1\6\1\31\1\2\1\4\1\12\12\3\1\32\6\0\4\1\1\5"
"\1\1\24\0\1\27\1\10\1\30\3\0\1\22\1\13\2\1\1\21"+ + "\1\1\24\0\1\27\1\10\1\30\3\0\1\22\1\13\2\1\1\21"
"\1\14\5\0\1\23\1\0\1\15\3\0\1\16\1\24\1\17\1\20"+ + "\1\14\5\0\1\23\1\0\1\15\3\0\1\16\1\24\1\17\1\20"
"\5\0\1\25\1\0\1\26\uff82\0"; + "\5\0\1\25\1\0\1\26\uff82\0";
/** /**
* Translates characters to character classes * Translates characters to character classes
*/ */
private static final char[] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED); private static final char[] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED);
/** /**
* Translates DFA states to action switch labels. * Translates DFA states to action switch labels.
*/ */
private static final int[] ZZ_ACTION = zzUnpackAction(); private static final int[] ZZ_ACTION = zzUnpackAction();
private static final String ZZ_ACTION_PACKED_0 = private static final String ZZ_ACTION_PACKED_0 =
"\2\0\2\1\1\2\1\3\1\4\3\1\1\5\1\6"+ "\2\0\2\1\1\2\1\3\1\4\3\1\1\5\1\6"
"\1\7\1\10\1\11\1\12\1\13\1\14\1\15\5\0"+ + "\1\7\1\10\1\11\1\12\1\13\1\14\1\15\5\0"
"\1\14\1\16\1\17\1\20\1\21\1\22\1\23\1\24"+ + "\1\14\1\16\1\17\1\20\1\21\1\22\1\23\1\24"
"\1\0\1\25\1\0\1\25\4\0\1\26\1\27\2\0"+ + "\1\0\1\25\1\0\1\25\4\0\1\26\1\27\2\0"
"\1\30"; + "\1\30";
private static int[] zzUnpackAction() { private static int[] zzUnpackAction() {
int[] result = new int[45]; int[] result = new int[45];
@ -65,24 +56,23 @@ class Yylex {
while (i < l) { while (i < l) {
int count = packed.charAt(i++); int count = packed.charAt(i++);
int value = packed.charAt(i++); int value = packed.charAt(i++);
do result[j++] = value; while (--count > 0); do {
result[j++] = value;
} while (--count > 0);
} }
return j; return j;
} }
/** /**
* Translates a state to a row index in the transition table * Translates a state to a row index in the transition table
*/ */
private static final int[] ZZ_ROWMAP = zzUnpackRowMap(); private static final int[] ZZ_ROWMAP = zzUnpackRowMap();
private static final String ZZ_ROWMAP_PACKED_0 = private static final String ZZ_ROWMAP_PACKED_0 =
"\0\0\0\33\0\66\0\121\0\154\0\207\0\66\0\242"+ "\0\0\0\33\0\66\0\121\0\154\0\207\0\66\0\242"
"\0\275\0\330\0\66\0\66\0\66\0\66\0\66\0\66"+ + "\0\275\0\330\0\66\0\66\0\66\0\66\0\66\0\66"
"\0\363\0\u010e\0\66\0\u0129\0\u0144\0\u015f\0\u017a\0\u0195"+ + "\0\363\0\u010e\0\66\0\u0129\0\u0144\0\u015f\0\u017a\0\u0195"
"\0\66\0\66\0\66\0\66\0\66\0\66\0\66\0\66"+ + "\0\66\0\66\0\66\0\66\0\66\0\66\0\66\0\66"
"\0\u01b0\0\u01cb\0\u01e6\0\u01e6\0\u0201\0\u021c\0\u0237\0\u0252"+ + "\0\u01b0\0\u01cb\0\u01e6\0\u01e6\0\u0201\0\u021c\0\u0237\0\u0252"
"\0\66\0\66\0\u026d\0\u0288\0\66"; + "\0\66\0\66\0\u026d\0\u0288\0\66";
private static int[] zzUnpackRowMap() { private static int[] zzUnpackRowMap() {
int[] result = new int[45]; int[] result = new int[45];
@ -101,7 +91,6 @@ class Yylex {
} }
return j; return j;
} }
/** /**
* The transition table of the DFA * The transition table of the DFA
*/ */
@ -173,8 +162,7 @@ class Yylex {
-1, -1, -1, -1, -1, -1, -1, -1, -1, 44, -1, -1, -1, -1, -1, -1, -1, -1, -1, 44,
-1, 44, -1, 44, -1, -1, -1, -1, -1, 44, -1, 44, -1, 44, -1, -1, -1, -1, -1, 44,
44, -1, -1, -1, -1, 44, 44, -1, -1, -1, 44, -1, -1, -1, -1, 44, 44, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,};
};
/* error codes */ /* error codes */
private static final int ZZ_UNKNOWN_ERROR = 0; private static final int ZZ_UNKNOWN_ERROR = 0;
@ -187,16 +175,14 @@ class Yylex {
"Error: could not match input", "Error: could not match input",
"Error: pushback value was too large" "Error: pushback value was too large"
}; };
/** /**
* ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code> * ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
*/ */
private static final int[] ZZ_ATTRIBUTE = zzUnpackAttribute(); private static final int[] ZZ_ATTRIBUTE = zzUnpackAttribute();
private static final String ZZ_ATTRIBUTE_PACKED_0 = private static final String ZZ_ATTRIBUTE_PACKED_0 =
"\2\0\1\11\3\1\1\11\3\1\6\11\2\1\1\11"+ "\2\0\1\11\3\1\1\11\3\1\6\11\2\1\1\11"
"\5\0\10\11\1\0\1\1\1\0\1\1\4\0\2\11"+ + "\5\0\10\11\1\0\1\1\1\0\1\1\4\0\2\11"
"\2\0\1\11"; + "\2\0\1\11";
private static int[] zzUnpackAttribute() { private static int[] zzUnpackAttribute() {
int[] result = new int[45]; int[] result = new int[45];
@ -212,54 +198,43 @@ class Yylex {
while (i < l) { while (i < l) {
int count = packed.charAt(i++); int count = packed.charAt(i++);
int value = packed.charAt(i++); int value = packed.charAt(i++);
do result[j++] = value; while (--count > 0); do {
result[j++] = value;
} while (--count > 0);
} }
return j; return j;
} }
/** the input device */ /** the input device */
private java.io.Reader zzReader; private java.io.Reader zzReader;
/** the current state of the DFA */ /** the current state of the DFA */
private int zzState; private int zzState;
/** the current lexical state */ /** the current lexical state */
private int zzLexicalState = YYINITIAL; private int zzLexicalState = YYINITIAL;
/** this buffer contains the current text to be matched and is /** this buffer contains the current text to be matched and is
the source of the yytext() string */ the source of the yytext() string */
private char zzBuffer[] = new char[ZZ_BUFFERSIZE]; private char zzBuffer[] = new char[ZZ_BUFFERSIZE];
/** the textposition at the last accepting state */ /** the textposition at the last accepting state */
private int zzMarkedPos; private int zzMarkedPos;
/** the current text position in the buffer */ /** the current text position in the buffer */
private int zzCurrentPos; private int zzCurrentPos;
/** startRead marks the beginning of the yytext() string in the buffer */ /** startRead marks the beginning of the yytext() string in the buffer */
private int zzStartRead; private int zzStartRead;
/** endRead marks the last character in the buffer, that has been read /** endRead marks the last character in the buffer, that has been read
from input */ from input */
private int zzEndRead; private int zzEndRead;
/** number of newlines encountered up to the start of the matched text */ /** number of newlines encountered up to the start of the matched text */
private int yyline; private int yyline;
/** the number of characters up to the start of the matched text */ /** the number of characters up to the start of the matched text */
private int yychar; private int yychar;
/** /**
* the number of characters from the last newline up to the start of the * the number of characters from the last newline up to the start of the
* matched text * matched text
*/ */
private int yycolumn; private int yycolumn;
/** /**
* zzAtBOL == true <=> the scanner is currently at the beginning of a line * zzAtBOL == true <=> the scanner is currently at the beginning of a line
*/ */
private boolean zzAtBOL = true; private boolean zzAtBOL = true;
/** zzAtEOF == true <=> the scanner is at the EOF */ /** zzAtEOF == true <=> the scanner is at the EOF */
private boolean zzAtEOF; private boolean zzAtEOF;
@ -270,8 +245,6 @@ int getPosition(){
return yychar; return yychar;
} }
/** /**
* Creates a new scanner * Creates a new scanner
* There is also a java.io.InputStream version of this constructor. * There is also a java.io.InputStream version of this constructor.
@ -305,12 +278,13 @@ int getPosition(){
while (i < 90) { while (i < 90) {
int count = packed.charAt(i++); int count = packed.charAt(i++);
char value = packed.charAt(i++); char value = packed.charAt(i++);
do map[j++] = value; while (--count > 0); do {
map[j++] = value;
} while (--count > 0);
} }
return map; return map;
} }
/** /**
* Refills the input buffer. * Refills the input buffer.
* *
@ -364,7 +338,6 @@ int getPosition(){
return true; return true;
} }
/** /**
* Closes the input stream. * Closes the input stream.
*/ */
@ -372,10 +345,10 @@ int getPosition(){
zzAtEOF = true; /* indicate end of file */ zzAtEOF = true; /* indicate end of file */
zzEndRead = zzStartRead; /* invalidate buffer */ zzEndRead = zzStartRead; /* invalidate buffer */
if (zzReader != null) if (zzReader != null) {
zzReader.close(); zzReader.close();
} }
}
/** /**
* Resets the scanner to read from a new input stream. * Resets the scanner to read from a new input stream.
@ -397,7 +370,6 @@ int getPosition(){
zzLexicalState = YYINITIAL; zzLexicalState = YYINITIAL;
} }
/** /**
* Returns the current lexical state. * Returns the current lexical state.
*/ */
@ -405,7 +377,6 @@ int getPosition(){
return zzLexicalState; return zzLexicalState;
} }
/** /**
* Enters a new lexical state * Enters a new lexical state
* *
@ -415,7 +386,6 @@ int getPosition(){
zzLexicalState = newState; zzLexicalState = newState;
} }
/** /**
* Returns the text matched by the current regular expression. * Returns the text matched by the current regular expression.
*/ */
@ -423,7 +393,6 @@ int getPosition(){
return new String(zzBuffer, zzStartRead, zzMarkedPos - zzStartRead); return new String(zzBuffer, zzStartRead, zzMarkedPos - zzStartRead);
} }
/** /**
* Returns the character at position <tt>pos</tt> from the * Returns the character at position <tt>pos</tt> from the
* matched text. * matched text.
@ -439,7 +408,6 @@ int getPosition(){
return zzBuffer[zzStartRead + pos]; return zzBuffer[zzStartRead + pos];
} }
/** /**
* Returns the length of the matched text region. * Returns the length of the matched text region.
*/ */
@ -447,7 +415,6 @@ int getPosition(){
return zzMarkedPos - zzStartRead; return zzMarkedPos - zzStartRead;
} }
/** /**
* Reports an error that occured while scanning. * Reports an error that occured while scanning.
* *
@ -466,15 +433,13 @@ int getPosition(){
String message; String message;
try { try {
message = ZZ_ERROR_MSG[errorCode]; message = ZZ_ERROR_MSG[errorCode];
} } catch (ArrayIndexOutOfBoundsException e) {
catch (ArrayIndexOutOfBoundsException e) {
message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR]; message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
} }
throw new Error(message); throw new Error(message);
} }
/** /**
* Pushes the specified amount of characters back into the input stream. * Pushes the specified amount of characters back into the input stream.
* *
@ -484,13 +449,13 @@ int getPosition(){
* This number must not be greater than yylength()! * This number must not be greater than yylength()!
*/ */
public void yypushback(int number) { public void yypushback(int number) {
if ( number > yylength() ) if (number > yylength()) {
zzScanError(ZZ_PUSHBACK_2BIG); zzScanError(ZZ_PUSHBACK_2BIG);
}
zzMarkedPos -= number; zzMarkedPos -= number;
} }
/** /**
* Resumes scanning until the next regular expression is matched, * Resumes scanning until the next regular expression is matched,
* the end of input is encountered or an I/O-Error occurs. * the end of input is encountered or an I/O-Error occurs.
@ -525,16 +490,16 @@ int getPosition(){
zzState = ZZ_LEXSTATE[zzLexicalState]; zzState = ZZ_LEXSTATE[zzLexicalState];
zzForAction: { zzForAction:
{
while (true) { while (true) {
if (zzCurrentPosL < zzEndReadL) if (zzCurrentPosL < zzEndReadL) {
zzInput = zzBufferL[zzCurrentPosL++]; zzInput = zzBufferL[zzCurrentPosL++];
else if (zzAtEOF) { } else if (zzAtEOF) {
zzInput = YYEOF; zzInput = YYEOF;
break zzForAction; break zzForAction;
} } else {
else {
// store back cached positions // store back cached positions
zzCurrentPos = zzCurrentPosL; zzCurrentPos = zzCurrentPosL;
zzMarkedPos = zzMarkedPosL; zzMarkedPos = zzMarkedPosL;
@ -547,20 +512,23 @@ int getPosition(){
if (eof) { if (eof) {
zzInput = YYEOF; zzInput = YYEOF;
break zzForAction; break zzForAction;
} } else {
else {
zzInput = zzBufferL[zzCurrentPosL++]; zzInput = zzBufferL[zzCurrentPosL++];
} }
} }
int zzNext = zzTransL[zzRowMapL[zzState] + zzCMapL[zzInput]]; int zzNext = zzTransL[zzRowMapL[zzState] + zzCMapL[zzInput]];
if (zzNext == -1) break zzForAction; if (zzNext == -1) {
break zzForAction;
}
zzState = zzNext; zzState = zzNext;
int zzAttributes = zzAttrL[zzState]; int zzAttributes = zzAttrL[zzState];
if ((zzAttributes & 1) == 1) { if ((zzAttributes & 1) == 1) {
zzAction = zzState; zzAction = zzState;
zzMarkedPosL = zzCurrentPosL; zzMarkedPosL = zzCurrentPosL;
if ( (zzAttributes & 8) == 8 ) break zzForAction; if ((zzAttributes & 8) == 8) {
break zzForAction;
}
} }
} }
@ -570,119 +538,143 @@ int getPosition(){
zzMarkedPos = zzMarkedPosL; zzMarkedPos = zzMarkedPosL;
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) { switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
case 11: case 11: {
{ sb.append(yytext()); sb.append(yytext());
} }
case 25: break; case 25:
case 4: break;
{ sb.delete(0, sb.length());yybegin(STRING_BEGIN); case 4: {
sb.delete(0, sb.length());
yybegin(STRING_BEGIN);
} }
case 26: break; case 26:
case 16: break;
{ sb.append('\b'); case 16: {
sb.append('\b');
} }
case 27: break; case 27:
case 6: break;
{ return new Yytoken(Yytoken.TYPE_RIGHT_BRACE,null); case 6: {
return new Yytoken(Yytoken.TYPE_RIGHT_BRACE, null);
} }
case 28: break; case 28:
case 23: break;
{ Boolean val=Boolean.valueOf(yytext()); return new Yytoken(Yytoken.TYPE_VALUE, val); case 23: {
Boolean val = Boolean.valueOf(yytext());
return new Yytoken(Yytoken.TYPE_VALUE, val);
} }
case 29: break; case 29:
case 22: break;
{ return new Yytoken(Yytoken.TYPE_VALUE, null); case 22: {
return new Yytoken(Yytoken.TYPE_VALUE, null);
} }
case 30: break; case 30:
case 13: break;
{ yybegin(YYINITIAL);return new Yytoken(Yytoken.TYPE_VALUE, sb.toString()); case 13: {
yybegin(YYINITIAL);
return new Yytoken(Yytoken.TYPE_VALUE, sb.toString());
} }
case 31: break; case 31:
case 12: break;
{ sb.append('\\'); case 12: {
sb.append('\\');
} }
case 32: break; case 32:
case 21: break;
{ Double val=Double.valueOf(yytext()); return new Yytoken(Yytoken.TYPE_VALUE, val); case 21: {
Double val = Double.valueOf(yytext());
return new Yytoken(Yytoken.TYPE_VALUE, val);
} }
case 33: break; case 33:
case 1: break;
{ throw new ParseException(yychar, ParseException.ERROR_UNEXPECTED_CHAR, new Character(yycharat(0))); case 1: {
throw new ParseException(yychar, ParseException.ERROR_UNEXPECTED_CHAR, new Character(yycharat(0)));
} }
case 34: break; case 34:
case 8: break;
{ return new Yytoken(Yytoken.TYPE_RIGHT_SQUARE,null); case 8: {
return new Yytoken(Yytoken.TYPE_RIGHT_SQUARE, null);
} }
case 35: break; case 35:
case 19: break;
{ sb.append('\r'); case 19: {
sb.append('\r');
} }
case 36: break; case 36:
case 15: break;
{ sb.append('/'); case 15: {
sb.append('/');
} }
case 37: break; case 37:
case 10: break;
{ return new Yytoken(Yytoken.TYPE_COLON,null); case 10: {
return new Yytoken(Yytoken.TYPE_COLON, null);
} }
case 38: break; case 38:
case 14: break;
{ sb.append('"'); case 14: {
sb.append('"');
} }
case 39: break; case 39:
case 5: break;
{ return new Yytoken(Yytoken.TYPE_LEFT_BRACE,null); case 5: {
return new Yytoken(Yytoken.TYPE_LEFT_BRACE, null);
} }
case 40: break; case 40:
case 17: break;
{ sb.append('\f'); case 17: {
sb.append('\f');
} }
case 41: break; case 41:
case 24: break;
{ try{ case 24: {
try {
int ch = Integer.parseInt(yytext().substring(2), 16); int ch = Integer.parseInt(yytext().substring(2), 16);
sb.append((char) ch); sb.append((char) ch);
} } catch (Exception e) {
catch(Exception e){
throw new ParseException(yychar, ParseException.ERROR_UNEXPECTED_EXCEPTION, e); throw new ParseException(yychar, ParseException.ERROR_UNEXPECTED_EXCEPTION, e);
} }
} }
case 42: break; case 42:
case 20: break;
{ sb.append('\t'); case 20: {
sb.append('\t');
} }
case 43: break; case 43:
case 7: break;
{ return new Yytoken(Yytoken.TYPE_LEFT_SQUARE,null); case 7: {
return new Yytoken(Yytoken.TYPE_LEFT_SQUARE, null);
} }
case 44: break; case 44:
case 2: break;
{ Long val=Long.valueOf(yytext()); return new Yytoken(Yytoken.TYPE_VALUE, val); case 2: {
Long val = Long.valueOf(yytext());
return new Yytoken(Yytoken.TYPE_VALUE, val);
} }
case 45: break; case 45:
case 18: break;
{ sb.append('\n'); case 18: {
sb.append('\n');
} }
case 46: break; case 46:
case 9: break;
{ return new Yytoken(Yytoken.TYPE_COMMA,null); case 9: {
return new Yytoken(Yytoken.TYPE_COMMA, null);
} }
case 47: break; case 47:
case 3: break;
{ case 3: {
} }
case 48: break; case 48:
break;
default: default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true; zzAtEOF = true;
return null; return null;
} } else {
else {
zzScanError(ZZ_NO_MATCH); zzScanError(ZZ_NO_MATCH);
} }
} }
} }
} }
} }

View file

@ -16,7 +16,6 @@ public class Yytoken {
public static final int TYPE_COMMA = 5; public static final int TYPE_COMMA = 5;
public static final int TYPE_COLON = 6; public static final int TYPE_COLON = 6;
public static final int TYPE_EOF = -1;//end of file public static final int TYPE_EOF = -1;//end of file
public int type = 0; public int type = 0;
public Object value = null; public Object value = null;