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
4 changes: 4 additions & 0 deletions src/main/java/com/dashjoin/jsonata/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,10 @@ Symbol objectParser(Symbol left) {

public Symbol parse(String jsonata) {
source = jsonata;
ancestry = new ArrayList<>();
ancestorIndex = 0;
ancestorLabel = 0;
errors = new ArrayList<>();

// now invoke the tokenizer and the parser and return the syntax tree
lexer = new Tokenizer(source);
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/com/dashjoin/jsonata/ParserTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.dashjoin.jsonata;

import static com.dashjoin.jsonata.Jsonata.jsonata;

import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand All @@ -15,4 +17,14 @@ public void testUnsupportedEscapeSequence() {
Assertions.assertThrows(JException.class, ()->jsonata("$substring('\\u"));
Assertions.assertEquals("", jsonata("$substring('\\uDDDD', 1)").evaluate(null));
}

@Test
public void testParserStateClear() {
Jsonata jsonata = jsonata("items.[name, % .currency]");
List<Parser.Symbol> ancestry1 = jsonata.parser.ancestry;
Assertions.assertEquals(1, ancestry1.size());
Jsonata jsonata2 = jsonata("items.[name, % .currency]");
List<Parser.Symbol> ancestry2 = jsonata2.parser.ancestry;
Assertions.assertEquals(1, ancestry2.size());
}
}
Loading