Skip to content

Commit

Permalink
yaml: Update snakeyaml revision
Browse files Browse the repository at this point in the history
  • Loading branch information
zml2008 committed Dec 18, 2021
1 parent 97c7773 commit 8d3cad3
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,18 @@ final class YamlParserComposer extends ParserImpl {
// "api" //

public void singleDocumentStream(final ConfigurationNode node) throws ParsingException {
requireEvent(Event.ID.StreamStart);
document(node);
requireEvent(Event.ID.StreamEnd);
this.requireEvent(Event.ID.StreamStart);
this.document(node);
this.requireEvent(Event.ID.StreamEnd);
}

public void document(final ConfigurationNode node) throws ParsingException {
if (this.processComments && node instanceof CommentedConfigurationNodeIntermediary<@NonNull ?>) {
// Only collect comments if we can handle them in the first place
this.scanner().setEmitComments(true);
this.scanner().setParseComments(true);
}

if (peekEvent().is(Event.ID.StreamEnd)) {
if (this.peekEvent().is(Event.ID.StreamEnd)) {
return;
}

Expand Down Expand Up @@ -125,7 +125,7 @@ public void document(final ConfigurationNode node) throws ParsingException {
ex.initPath(active.node::path);
throw ex;
} finally {
this.scanner().setEmitComments(false);
this.scanner().setParseComments(false);
this.aliases.clear();
this.declaredTags.clear();
}
Expand All @@ -138,7 +138,7 @@ ScannerImpl scanner() {
// events //

void requireEvent(final Event.ID type) throws ParsingException {
final Event next = peekEvent();
final Event next = this.peekEvent();
if (!next.is(type)) {
throw makeError(next.getStartMark(), "Expected next event of type" + type + " but was " + next.getEventId(), null);
}
Expand All @@ -147,7 +147,7 @@ void requireEvent(final Event.ID type) throws ParsingException {

@SuppressWarnings("unchecked")
<T extends Event> T requireEvent(final Event.ID type, final Class<T> clazz) throws ParsingException {
final Event next = peekEvent();
final Event next = this.peekEvent();
if (!next.is(type)) {
throw makeError(next.getStartMark(), "Expected next event of type " + type + " but was " + next.getEventId(), null);
}
Expand Down Expand Up @@ -210,7 +210,7 @@ void popFrame() {
}

Frame peekFrame() {
return peekFrame(0);
return this.peekFrame(0);
}

Frame peekFrame(final int depth) {
Expand Down Expand Up @@ -328,12 +328,12 @@ void applyComment(final @Nullable String comment, final ConfigurationNode node)
}

void collectComments() {
if (!this.processComments || !this.scanner().isEmitComments()) {
if (!this.processComments || !this.scanner().isParseComments()) {
return;
}

while (peekEvent().is(Event.ID.Comment)) {
final CommentEvent event = (CommentEvent) getEvent();
while (this.peekEvent().is(Event.ID.Comment)) {
final CommentEvent event = (CommentEvent) this.getEvent();
if (event.getCommentType() != CommentType.BLANK_LINE) {
@Nullable StringBuilder commentCollector = this.commentCollector;
if (commentCollector == null) {
Expand All @@ -352,23 +352,23 @@ void collectComments() {
}

public <N extends ConfigurationNode> Stream<N> stream(final ConfigurationNodeFactory<N> factory) throws ParsingException {
requireEvent(Event.ID.StreamStart);
this.requireEvent(Event.ID.StreamStart);
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(new Iterator<N>() {
@Override
public boolean hasNext() {
return !checkEvent(Event.ID.StreamEnd);
return !YamlParserComposer.this.checkEvent(Event.ID.StreamEnd);
}

@Override
public N next() {
if (!hasNext()) {
if (!this.hasNext()) {
throw new IndexOutOfBoundsException();
}
try {
final N node = factory.createNode();
document(node);
if (!hasNext()) {
requireEvent(Event.ID.StreamEnd);
YamlParserComposer.this.document(node);
if (!this.hasNext()) {
YamlParserComposer.this.requireEvent(Event.ID.StreamEnd);
}
return node;
} catch (final ConfigurateException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] parser: More tests for comment reading


diff --git a/src/main/java/org/yaml/snakeyaml/parser/ParserImpl.java b/src/main/java/org/yaml/snakeyaml/parser/ParserImpl.java
index d5b16d1edf6e0afa85f50b308cf31000c1bd2c12..a3798b4faf3bf6746654d724d437633624f11bbb 100644
index 6afb9a684ab841ba19a8eec6ed02b6479a822ab2..de0b3717079638a7418f2dd6f8e549cb52acff2f 100644
--- a/src/main/java/org/yaml/snakeyaml/parser/ParserImpl.java
+++ b/src/main/java/org/yaml/snakeyaml/parser/ParserImpl.java
@@ -735,20 +735,24 @@ public class ParserImpl implements Parser {
@@ -729,24 +729,28 @@ public class ParserImpl implements Parser {
public Event produce() {
Token token = scanner.getToken();
marks.push(token.getStartMark());
Expand All @@ -21,7 +21,7 @@ index d5b16d1edf6e0afa85f50b308cf31000c1bd2c12..a3798b4faf3bf6746654d724d4376336
}

private class ParseFlowSequenceEntry implements Production {
- private boolean first = false;
- private final boolean first;
+ private boolean entryTokenSeen = false;

- public ParseFlowSequenceEntry(boolean first) {
Expand All @@ -31,13 +31,18 @@ index d5b16d1edf6e0afa85f50b308cf31000c1bd2c12..a3798b4faf3bf6746654d724d4376336
}

public Event produce() {
if (scanner.checkToken(Token.ID.Comment)) {
- state = new ParseFlowSequenceEntry(first);
+ state = new ParseFlowSequenceEntry(entryTokenSeen);
return produceCommentEvent((CommentToken) scanner.getToken());
}
if (!scanner.checkToken(Token.ID.FlowSequenceEnd)) {
- if (!first) {
+ if (!entryTokenSeen) {
if (scanner.checkToken(Token.ID.FlowEntry)) {
scanner.getToken();
} else {
@@ -764,6 +768,9 @@ public class ParserImpl implements Parser {
if (scanner.checkToken(Token.ID.Comment)) {
@@ -766,6 +770,9 @@ public class ParserImpl implements Parser {
token.getEndMark(), DumperOptions.FlowStyle.FLOW);
state = new ParseFlowSequenceEntryMappingKey();
return event;
Expand All @@ -47,7 +52,7 @@ index d5b16d1edf6e0afa85f50b308cf31000c1bd2c12..a3798b4faf3bf6746654d724d4376336
} else if (!scanner.checkToken(Token.ID.FlowSequenceEnd)) {
states.push(new ParseFlowSequenceEntry(false));
return parseFlowNode();
@@ -805,7 +812,9 @@ public class ParserImpl implements Parser {
@@ -808,7 +815,9 @@ public class ParserImpl implements Parser {

private class ParseFlowSequenceEntryMappingValue implements Production {
public Event produce() {
Expand All @@ -58,7 +63,7 @@ index d5b16d1edf6e0afa85f50b308cf31000c1bd2c12..a3798b4faf3bf6746654d724d4376336
Token token = scanner.getToken();
if (!scanner.checkToken(Token.ID.FlowEntry, Token.ID.FlowSequenceEnd)) {
states.push(new ParseFlowSequenceEntryMappingEnd());
@@ -841,6 +850,9 @@ public class ParserImpl implements Parser {
@@ -844,6 +853,9 @@ public class ParserImpl implements Parser {
*/
private class ParseFlowMappingFirstKey implements Production {
public Event produce() {
Expand All @@ -68,7 +73,7 @@ index d5b16d1edf6e0afa85f50b308cf31000c1bd2c12..a3798b4faf3bf6746654d724d4376336
Token token = scanner.getToken();
marks.push(token.getStartMark());
return new ParseFlowMappingKey(true).produce();
@@ -848,15 +860,15 @@ public class ParserImpl implements Parser {
@@ -851,15 +863,15 @@ public class ParserImpl implements Parser {
}

private class ParseFlowMappingKey implements Production {
Expand All @@ -88,7 +93,7 @@ index d5b16d1edf6e0afa85f50b308cf31000c1bd2c12..a3798b4faf3bf6746654d724d4376336
if (scanner.checkToken(Token.ID.FlowEntry)) {
scanner.getToken();
} else {
@@ -876,6 +888,9 @@ public class ParserImpl implements Parser {
@@ -879,6 +891,9 @@ public class ParserImpl implements Parser {
state = new ParseFlowMappingValue();
return processEmptyScalar(token.getEndMark());
}
Expand All @@ -98,7 +103,7 @@ index d5b16d1edf6e0afa85f50b308cf31000c1bd2c12..a3798b4faf3bf6746654d724d4376336
} else if (!scanner.checkToken(Token.ID.FlowMappingEnd)) {
states.push(new ParseFlowMappingEmptyValue());
return parseFlowNode();
@@ -895,7 +910,9 @@ public class ParserImpl implements Parser {
@@ -898,7 +913,9 @@ public class ParserImpl implements Parser {

private class ParseFlowMappingValue implements Production {
public Event produce() {
Expand All @@ -110,7 +115,7 @@ index d5b16d1edf6e0afa85f50b308cf31000c1bd2c12..a3798b4faf3bf6746654d724d4376336
if (!scanner.checkToken(Token.ID.FlowEntry, Token.ID.FlowMappingEnd)) {
states.push(new ParseFlowMappingKey(false));
diff --git a/src/test/java/org/yaml/snakeyaml/comment/ParserWithCommentEnabledTest.java b/src/test/java/org/yaml/snakeyaml/comment/ParserWithCommentEnabledTest.java
index eccc9bbce38ffa5ea9d791da90dded8dcce8c562..b0b91977a769b68e0f28f203852c5a9705cebc33 100644
index 9ba830d223b41e4d17b62ed258c81257268d3839..de7227375613d4524fefbb72430401fed0f7264b 100644
--- a/src/test/java/org/yaml/snakeyaml/comment/ParserWithCommentEnabledTest.java
+++ b/src/test/java/org/yaml/snakeyaml/comment/ParserWithCommentEnabledTest.java
@@ -21,6 +21,9 @@ import org.yaml.snakeyaml.events.Event.ID;
Expand All @@ -132,7 +137,7 @@ index eccc9bbce38ffa5ea9d791da90dded8dcce8c562..b0b91977a769b68e0f28f203852c5a97

private void println(String s) {
if (DEBUG) System.out.println(s);
@@ -380,7 +383,7 @@ public class ParserWithCommentEnabledTest {
@@ -352,7 +355,7 @@ public class ParserWithCommentEnabledTest {
// printEventList(sut);
assertEventListEquals(expectedEventIdList, sut);
}
Expand All @@ -141,10 +146,11 @@ index eccc9bbce38ffa5ea9d791da90dded8dcce8c562..b0b91977a769b68e0f28f203852c5a97
@Test
public void testKeepingNewLineInsideSequence() throws Exception {
String data = "" +
@@ -431,4 +434,103 @@ public class ParserWithCommentEnabledTest {

@@ -397,4 +400,104 @@ public class ParserWithCommentEnabledTest {
//printEventList(sut);
assertEventListEquals(expectedEventIdList, sut);
}
+
+ @Test
+ public void testInlineCommentsInBlockSequence() throws Exception {
+ String data = "" +
Expand Down Expand Up @@ -236,7 +242,7 @@ index eccc9bbce38ffa5ea9d791da90dded8dcce8c562..b0b91977a769b68e0f28f203852c5a97
+ ID.StreamEnd
+ );
+
+ final Scanner scanner = new ScannerImpl(new StreamReader(data)).setEmitComments(true);
+ final Scanner scanner = new ScannerImpl(new StreamReader(data)).setParseComments(true);
+ do {
+ System.out.println(scanner.getToken().getTokenId().name());
+ } while (!scanner.checkToken(Token.ID.StreamEnd));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ Subject: [PATCH] scanner: Initial implementation of tab acceptance


diff --git a/src/main/java/org/yaml/snakeyaml/scanner/ScannerImpl.java b/src/main/java/org/yaml/snakeyaml/scanner/ScannerImpl.java
index f3c3f65b023a8ee2c9359baa219f36f81e39cf53..abfdce3eb9403f22e9c6941566f6106c687c9226 100644
index 31a51e5249a842f847082374387637f1ca251b74..640f85755bd1a479998b4244edc91318298eca55 100644
--- a/src/main/java/org/yaml/snakeyaml/scanner/ScannerImpl.java
+++ b/src/main/java/org/yaml/snakeyaml/scanner/ScannerImpl.java
@@ -184,6 +184,8 @@ public final class ScannerImpl implements Scanner {
// A flag that indicates if comments should be emitted
private boolean emitComments;
// A flag that indicates if comments should be parsed
private boolean parseComments;

+ private boolean acceptTabs;
+
// Variables related to simple keys treatment. See PyYAML.

/**
@@ -243,6 +245,27 @@ public final class ScannerImpl implements Scanner {
return emitComments;
return parseComments;
}

+ /**
Expand All @@ -45,7 +45,7 @@ index f3c3f65b023a8ee2c9359baa219f36f81e39cf53..abfdce3eb9403f22e9c6941566f6106c
/**
* Check whether the next token is one of the given types.
*/
@@ -1225,7 +1248,7 @@ public final class ScannerImpl implements Scanner {
@@ -1227,7 +1250,7 @@ public final class ScannerImpl implements Scanner {
int ff = 0;
// Peek ahead until we find the first non-space character, then
// move forward directly to that character.
Expand All @@ -55,7 +55,7 @@ index f3c3f65b023a8ee2c9359baa219f36f81e39cf53..abfdce3eb9403f22e9c6941566f6106c
}
if (ff > 0) {
diff --git a/src/test/java/org/yaml/snakeyaml/scanner/ScannerImplTest.java b/src/test/java/org/yaml/snakeyaml/scanner/ScannerImplTest.java
index eca1fa06187ae55bba64597a607bcc7fa0c8b8ae..34c32a88a279534d4f12df4ae2a3ac512a9f5fcc 100644
index 85aa62fe61b496ac6d059fea78ca56afd857bfae..aee5c0158f2103eb7501d9a8e8c2b9294701b5f4 100644
--- a/src/test/java/org/yaml/snakeyaml/scanner/ScannerImplTest.java
+++ b/src/test/java/org/yaml/snakeyaml/scanner/ScannerImplTest.java
@@ -16,6 +16,7 @@
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ sequences. It might be nice to capture the prettiness status of input
data, but that seems extremely error-prone and probably not worth doing.

diff --git a/src/main/java/org/yaml/snakeyaml/emitter/Emitter.java b/src/main/java/org/yaml/snakeyaml/emitter/Emitter.java
index cad49156be009cd37eeb0bb0bd70248908ef1630..5df8a3be0034233cf9330fa752bae82591d66c30 100644
index 021cb0e706657dc86f67e5a30f9947e7a891f5df..886348cc41ad9cd359f4a37852a5a715f31e0e6a 100644
--- a/src/main/java/org/yaml/snakeyaml/emitter/Emitter.java
+++ b/src/main/java/org/yaml/snakeyaml/emitter/Emitter.java
@@ -151,7 +151,14 @@ public final class Emitter implements Emitable {
Expand Down Expand Up @@ -36,7 +36,7 @@ index cad49156be009cd37eeb0bb0bd70248908ef1630..5df8a3be0034233cf9330fa752bae825
this.allowUnicode = opts.isAllowUnicode();
this.bestIndent = 2;
if ((opts.getIndent() > MIN_INDENT) && (opts.getIndent() < MAX_INDENT)) {
@@ -499,6 +506,9 @@ public final class Emitter implements Emitable {
@@ -494,6 +501,9 @@ public final class Emitter implements Emitable {
private void expectFlowSequence() throws IOException {
writeIndicator("[", true, true, false);
flowLevel++;
Expand All @@ -46,7 +46,7 @@ index cad49156be009cd37eeb0bb0bd70248908ef1630..5df8a3be0034233cf9330fa752bae825
increaseIndent(true, false);
if (prettyFlow) {
writeIndent();
@@ -512,6 +522,11 @@ public final class Emitter implements Emitable {
@@ -507,6 +517,11 @@ public final class Emitter implements Emitable {
indent = indents.pop();
flowLevel--;
writeIndicator("]", false, false, false);
Expand All @@ -58,7 +58,7 @@ index cad49156be009cd37eeb0bb0bd70248908ef1630..5df8a3be0034233cf9330fa752bae825
inlineCommentsCollector.collectEvents();
writeInlineComments();
state = states.pop();
@@ -542,6 +557,11 @@ public final class Emitter implements Emitable {
@@ -537,6 +552,11 @@ public final class Emitter implements Emitable {
writeIndent();
}
writeIndicator("]", false, false, false);
Expand All @@ -70,7 +70,7 @@ index cad49156be009cd37eeb0bb0bd70248908ef1630..5df8a3be0034233cf9330fa752bae825
inlineCommentsCollector.collectEvents();
writeInlineComments();
if (prettyFlow) {
@@ -569,6 +589,9 @@ public final class Emitter implements Emitable {
@@ -564,6 +584,9 @@ public final class Emitter implements Emitable {
private void expectFlowMapping() throws IOException {
writeIndicator("{", true, true, false);
flowLevel++;
Expand All @@ -80,7 +80,7 @@ index cad49156be009cd37eeb0bb0bd70248908ef1630..5df8a3be0034233cf9330fa752bae825
increaseIndent(true, false);
if (prettyFlow) {
writeIndent();
@@ -584,6 +607,11 @@ public final class Emitter implements Emitable {
@@ -579,6 +602,11 @@ public final class Emitter implements Emitable {
indent = indents.pop();
flowLevel--;
writeIndicator("}", false, false, false);
Expand All @@ -92,7 +92,7 @@ index cad49156be009cd37eeb0bb0bd70248908ef1630..5df8a3be0034233cf9330fa752bae825
inlineCommentsCollector.collectEvents();
writeInlineComments();
state = states.pop();
@@ -616,6 +644,11 @@ public final class Emitter implements Emitable {
@@ -611,6 +639,11 @@ public final class Emitter implements Emitable {
writeIndent();
}
writeIndicator("}", false, false, false);
Expand All @@ -104,7 +104,7 @@ index cad49156be009cd37eeb0bb0bd70248908ef1630..5df8a3be0034233cf9330fa752bae825
inlineCommentsCollector.collectEvents();
writeInlineComments();
state = states.pop();
@@ -1480,6 +1513,11 @@ public final class Emitter implements Emitable {
@@ -1475,6 +1508,11 @@ public final class Emitter implements Emitable {
if(!blockCommentsCollector.isEmpty()) {
writeIndent();
writeCommentLines(blockCommentsCollector.consume());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ first element of the sequence. I don't think there's anything we can
do about that though.... needs more thought i suppose

diff --git a/src/main/java/org/yaml/snakeyaml/emitter/Emitter.java b/src/main/java/org/yaml/snakeyaml/emitter/Emitter.java
index 5df8a3be0034233cf9330fa752bae82591d66c30..457dfa07ec29a1d1fc0c781b99d9f8d192dfa130 100644
index 886348cc41ad9cd359f4a37852a5a715f31e0e6a..a560345e276fbdc6215faaf3640b6bc49652cf6e 100644
--- a/src/main/java/org/yaml/snakeyaml/emitter/Emitter.java
+++ b/src/main/java/org/yaml/snakeyaml/emitter/Emitter.java
@@ -723,9 +723,12 @@ public final class Emitter implements Emitable {
@@ -718,9 +718,12 @@ public final class Emitter implements Emitable {
if (!this.first && event instanceof SequenceEndEvent) {
indent = indents.pop();
state = states.pop();
Expand All @@ -25,7 +25,7 @@ index 5df8a3be0034233cf9330fa752bae82591d66c30..457dfa07ec29a1d1fc0c781b99d9f8d1
writeIndent();
if (!indentWithIndicator || this.first) {
writeWhitespace(indicatorIndent);
@@ -734,17 +737,6 @@ public final class Emitter implements Emitable {
@@ -729,17 +732,6 @@ public final class Emitter implements Emitable {
if (indentWithIndicator && this.first) {
indent += indicatorIndent;
}
Expand All @@ -44,7 +44,7 @@ index 5df8a3be0034233cf9330fa752bae82591d66c30..457dfa07ec29a1d1fc0c781b99d9f8d1
expectNode(false, false, false);
inlineCommentsCollector.collectEvents();
diff --git a/src/test/java/org/yaml/snakeyaml/comment/EmitterWithCommentEnabledTest.java b/src/test/java/org/yaml/snakeyaml/comment/EmitterWithCommentEnabledTest.java
index e1f56aae0fa9b325ebe1d796e661bbca195e1607..ae57e230c10d811d6917b2501f447732cbcb5a2c 100644
index 46ac29e2648b7f05c5988d99e3332ae664355b72..d1c2b0a14a964f7d4c18b5e5aeee657eb83acf49 100644
--- a/src/test/java/org/yaml/snakeyaml/comment/EmitterWithCommentEnabledTest.java
+++ b/src/test/java/org/yaml/snakeyaml/comment/EmitterWithCommentEnabledTest.java
@@ -15,6 +15,8 @@
Expand Down
2 changes: 1 addition & 1 deletion vendor/snakeyaml-upstream
Submodule snakeyaml-upstream updated from e68e3e to 94bd8e

0 comments on commit 8d3cad3

Please sign in to comment.