Skip to content

Commit 5994818

Browse files
committed
show better messages for parsing errors on a root object without braces
1 parent 30fec55 commit 5994818

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/main/org/hjson/HjsonParser.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ void reset() {
6666
}
6767

6868
JsonValue parse() throws IOException {
69-
JsonValue v;
7069
// Braces for the root object are optional
7170

7271
read();
@@ -75,24 +74,24 @@ JsonValue parse() throws IOException {
7574
switch (current) {
7675
case '[':
7776
case '{':
78-
v=readValue();
79-
break;
77+
return checkTrailing(readValue());
8078
default:
8179
try {
8280
// assume we have a root object without braces
83-
v=readObject(true);
81+
return checkTrailing(readObject(true));
8482
} catch (Exception exception) {
8583
// test if we are dealing with a single JSON value instead (true/false/null/num/"")
8684
reset();
8785
read();
8886
skipWhiteSpace();
89-
try { v=readValue(); break; }
87+
try { return checkTrailing(readValue()); }
9088
catch (Exception exception2) { }
9189
throw exception; // throw original error
9290
}
93-
break;
9491
}
92+
}
9593

94+
JsonValue checkTrailing(JsonValue v) throws ParseException, IOException {
9695
skipWhiteSpace();
9796
if (!isEndOfText()) throw error("Extra characters in input: "+current);
9897
return v;
@@ -113,7 +112,7 @@ private JsonValue readTfnns() throws IOException {
113112
StringBuilder value=new StringBuilder();
114113
int first=current;
115114
if (JsonValue.isPunctuatorChar(first))
116-
throw error("Found a punctuator character '" + (char)first + "' when excpecting a quoteless string (check your syntax)");
115+
throw error("Found a punctuator character '" + (char)first + "' when expecting a quoteless string (check your syntax)");
117116
value.append((char)current);
118117
for (;;) {
119118
read();

0 commit comments

Comments
 (0)