Cope with extraneous whitespace in sexp reader
This commit is contained in:
parent
4df94ffe40
commit
074fd181c9
|
@ -81,31 +81,37 @@ public class SexpReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object _read(int c) throws IOException {
|
public Object _read(int c) throws IOException {
|
||||||
switch (c) {
|
while (true) {
|
||||||
case -1:
|
switch (c) {
|
||||||
return null;
|
case -1:
|
||||||
case '(':
|
return null;
|
||||||
return _readList();
|
case '(':
|
||||||
case ')':
|
return _readList();
|
||||||
throw new SexpSyntaxError("Unexpected close-paren");
|
case ')':
|
||||||
case '[':
|
throw new SexpSyntaxError("Unexpected close-paren");
|
||||||
byte[] hint = readSimpleString();
|
case '[':
|
||||||
switch (_input.read()) {
|
byte[] hint = readSimpleString();
|
||||||
case -1:
|
switch (_input.read()) {
|
||||||
throw new SexpSyntaxError("End-of-stream between display hint and body");
|
case -1:
|
||||||
case ']':
|
throw new SexpSyntaxError("End-of-stream between display hint and body");
|
||||||
break;
|
case ']':
|
||||||
default:
|
break;
|
||||||
throw new SexpSyntaxError("Unexpected character after display hint");
|
default:
|
||||||
}
|
throw new SexpSyntaxError("Unexpected character after display hint");
|
||||||
byte[] body = readSimpleString();
|
}
|
||||||
return new SexpDisplayHint(hint, body);
|
byte[] body = readSimpleString();
|
||||||
default:
|
return new SexpDisplayHint(hint, body);
|
||||||
if (Character.isDigit(c)) {
|
default:
|
||||||
return new SexpBytes(_readSimpleString(c - '0'));
|
if (Character.isDigit(c)) {
|
||||||
} else {
|
return new SexpBytes(_readSimpleString(c - '0'));
|
||||||
throw new SexpSyntaxError("Unexpected character");
|
} else if (Character.isWhitespace(c)) {
|
||||||
}
|
// Skip harmless (?) whitespace
|
||||||
|
c = _input.read();
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
throw new SexpSyntaxError("Unexpected character: " + c);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue