Skip to content

Commit

Permalink
Add START_ESCAPED_OBJECT as internal token
Browse files Browse the repository at this point in the history
  • Loading branch information
pchitolina-fauna committed Jan 31, 2024
1 parent fc51a22 commit 275ac11
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public enum FaunaTokenType {
NONE,

START_OBJECT,
START_ESCAPED_OBJECT,
END_OBJECT,

START_ARRAY,
Expand Down
52 changes: 24 additions & 28 deletions faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,15 @@ public class FaunaParser {
private static final String SET_TAG = "@set";
private static final String OBJECT_TAG = "@object";//TODO Understand Module
private final JsonParser jsonParser;
private final Stack<FaunaTokenType> tokenStack = new Stack<>();
private final Stack<Object> tokenStack = new Stack<>();
private FaunaTokenType currentFaunaTokenType;
private FaunaTokenType bufferedFaunaTokenType;
private String taggedTokenValue;

private enum InternalTokenType {
START_ESCAPED_OBJECT
}

public FaunaParser(InputStream body) throws IOException {
JsonFactory factory = new JsonFactory();
this.jsonParser = factory.createParser(body);
Expand Down Expand Up @@ -91,8 +95,6 @@ public boolean read() throws IOException {
JsonToken currentToken = jsonParser.currentToken();
if (currentToken != null) {
switch (currentToken) {
case NOT_AVAILABLE:
break;
case VALUE_STRING:
currentFaunaTokenType = FaunaTokenType.STRING;
break;
Expand Down Expand Up @@ -157,7 +159,7 @@ private void handleStartObject() throws IOException {
case OBJECT_TAG:
advanceTrue();
currentFaunaTokenType = FaunaTokenType.START_OBJECT;
tokenStack.push(FaunaTokenType.START_ESCAPED_OBJECT);
tokenStack.push(InternalTokenType.START_ESCAPED_OBJECT);
break;
case DOC_TAG:
case REF_TAG:
Expand All @@ -183,30 +185,24 @@ private void handleStartObject() throws IOException {
}

private void handleEndObject() {
FaunaTokenType startToken = tokenStack.pop();
switch (startToken) {
case START_DOCUMENT:
currentFaunaTokenType = END_DOCUMENT;
advanceTrue();
break;
case START_PAGE:
currentFaunaTokenType = END_PAGE;
advanceTrue();
break;
case START_REF:
currentFaunaTokenType = END_REF;
advanceTrue();
break;
case START_ESCAPED_OBJECT:
currentFaunaTokenType = END_OBJECT;
advanceTrue();
break;
case START_OBJECT:
currentFaunaTokenType = END_OBJECT;
break;
default:
throw new SerializationException(
"Unexpected token " + startToken + ". This might be a bug.");
Object startToken = tokenStack.pop();
if (startToken.equals(FaunaTokenType.START_DOCUMENT)) {
currentFaunaTokenType = END_DOCUMENT;
advanceTrue();
} else if (startToken.equals(FaunaTokenType.START_PAGE)) {
currentFaunaTokenType = END_PAGE;
advanceTrue();
} else if (startToken.equals(FaunaTokenType.START_REF)) {
currentFaunaTokenType = END_REF;
advanceTrue();
} else if (startToken.equals(InternalTokenType.START_ESCAPED_OBJECT)) {
currentFaunaTokenType = END_OBJECT;
advanceTrue();
} else if (startToken.equals(FaunaTokenType.START_OBJECT)) {
currentFaunaTokenType = END_OBJECT;
} else {
throw new SerializationException(
"Unexpected token " + startToken + ". This might be a bug.");
}
}

Expand Down

0 comments on commit 275ac11

Please sign in to comment.