-
-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
YAML comments support #410
Open
Tim203
wants to merge
18
commits into
SpongePowered:master
Choose a base branch
from
Tim203:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,701
−16
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
57d820f
Added support for YAML comments
Tim203 a0901bf
Changed the example and changed the sequence node tag
Tim203 8b06a98
Added support for reading comments
Tim203 4b79298
Improved getting mapping key comments
Tim203 90ee1ed
Correctly remove all line breaks from comments when reading comments
Tim203 1d885c3
Minor change
Tim203 fb49dd9
Added an option to disable handling comments
Tim203 ee483ea
Merge remote-tracking branch 'origin/master' into Tim203/master
zml2008 cc14b5c
fix(format/yaml): Test and fix for complex keys
zml2008 618f113
chore(format/yaml): Add failing tests to demonstrate roundtripping flaws
zml2008 3cdcc04
fix(format/yaml): Re-serialize complex keys properly
zml2008 8105881
Empty comments should be empty line
Tim203 3de5368
Represent null as empty string instead of literal null
Tim203 c33572d
Made the line length configurable
Tim203 ffcbfcb
Fix checkstyle
Tim203 f8acad9
chore(yaml): Clear up some stream usage
zml2008 e5986b4
chore(yaml): Tweak formatting, preserve scalar + node styles
zml2008 ce36736
Update test files to match latest changes
Tim203 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
format/yaml/src/main/java/org/spongepowered/configurate/yaml/ScalarStyle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* Configurate | ||
* Copyright (C) zml and Configurate contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.spongepowered.configurate.yaml; | ||
|
||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
import org.yaml.snakeyaml.DumperOptions; | ||
|
||
import java.util.EnumMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Style that can be used to represent a scalar. | ||
* | ||
* @since 4.2.0 | ||
*/ | ||
public enum ScalarStyle { | ||
|
||
/** | ||
* A double-quoted string. | ||
* | ||
* <pre>"hello world"</pre> | ||
* | ||
* @since 4.2.0 | ||
*/ | ||
DOUBLE_QUOTED(DumperOptions.ScalarStyle.DOUBLE_QUOTED), | ||
|
||
/** | ||
* A single-quoted string. | ||
* | ||
* <pre>'hello world'</pre> | ||
* | ||
* @since 4.2.0 | ||
*/ | ||
SINGLE_QUOTED(DumperOptions.ScalarStyle.SINGLE_QUOTED), | ||
|
||
/** | ||
* String without any quotation. | ||
* | ||
* <p>This may be ambiguous with non-string types.</p> | ||
* | ||
* @since 4.2.0 | ||
*/ | ||
UNQUOTED(DumperOptions.ScalarStyle.PLAIN), | ||
|
||
/** | ||
* Folded scalar. | ||
* | ||
* <pre>{@code | ||
* key: > | ||
* folded scalar | ||
* line breaks collapsed | ||
* }</pre> | ||
* | ||
* @since 4.2.0 | ||
*/ | ||
FOLDED(DumperOptions.ScalarStyle.FOLDED), | ||
|
||
/** | ||
* Literal scalar. | ||
* | ||
* <pre>{@code | ||
* key: | | ||
* literal scalar | ||
* line breaks preserved | ||
* }</pre> | ||
* | ||
* @since 4.2.0 | ||
*/ | ||
LITERAL(DumperOptions.ScalarStyle.LITERAL) | ||
; | ||
|
||
private static final Map<DumperOptions.ScalarStyle, ScalarStyle> BY_SNAKE = new EnumMap<>(DumperOptions.ScalarStyle.class); | ||
private final DumperOptions.ScalarStyle snake; | ||
|
||
ScalarStyle(final DumperOptions.ScalarStyle snake) { | ||
this.snake = snake; | ||
} | ||
|
||
static DumperOptions.ScalarStyle asSnakeYaml( | ||
final @Nullable ScalarStyle style, | ||
final DumperOptions.@Nullable ScalarStyle fallback | ||
) { | ||
if (style != null) { | ||
return style.snake; | ||
} else if (fallback != null) { | ||
return fallback; | ||
} else { | ||
return DumperOptions.ScalarStyle.PLAIN; | ||
} | ||
} | ||
|
||
static ScalarStyle fromSnakeYaml(final DumperOptions.ScalarStyle style) { | ||
return BY_SNAKE.getOrDefault(style, UNQUOTED); | ||
} | ||
|
||
static { | ||
for (final ScalarStyle style : values()) { | ||
BY_SNAKE.put(style.snake, style); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a regression here:
load
returns null when the file is empty, whichConfigurationNode#from
can't receive.