Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/main/java/com/dashjoin/jsonata/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -40,7 +41,7 @@

//var parseSignature = require('./signature');
@SuppressWarnings({"unchecked"})
public class Parser {
public class Parser implements Serializable {

boolean dbg = false;

Expand Down Expand Up @@ -92,7 +93,7 @@ public static<T> T clone(T object) {
}
}

public class Symbol implements Cloneable {
public class Symbol implements Cloneable, Serializable {

//Symbol s;
String id;
Expand Down Expand Up @@ -505,7 +506,7 @@ public Parser() {
c.value = "(";
Symbol p = new Symbol();
c.procedure = p; p.type = "variable"; p.value = "exists";
c.arguments = List.of(left);
c.arguments = List.of(Parser.clone(left));
}
this.then = left;
this._else = expression(0);
Expand Down Expand Up @@ -812,7 +813,12 @@ Symbol led(Symbol left) {

@Override Symbol led(Symbol left) {
this.type = "condition";
this.condition = left;
// Deep-clone `left` so the condition and then branches have
// independent AST nodes. Sharing the same reference causes
// post-parse processing (e.g. predicate stages, unary minus
// folding on number literals) to mutate the same node twice,
// producing wrong results (see #773 for the equivalent ?? fix).
this.condition = Parser.clone(left);
this.then = left;
this._else = expression(0);
return this;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/dashjoin/jsonata/Tokenizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Tokenizer { // = function (path) {
public class Tokenizer implements java.io.Serializable { // = function (path) {

static HashMap<String, Integer> operators = new HashMap<String, Integer>() {{
put(".", 75);
Expand Down
Loading