@@ -62,13 +62,11 @@ public Optional<ErrorContext> parseNode(final @NotNull Line line, final @NotNull
6262 String lineText = line .getText ().trim ();
6363 String inlineComment = null ;
6464 if (lineText .contains ("#" )) {
65- // Check if # is inside a string or not. Simple check for now.
66- // Assuming # as comment start if it's preceded by space or is at start (handled above)
6765 int commentIndex = lineText .indexOf (" #" );
6866 if (commentIndex != -1 ) {
6967 inlineComment = lineText .substring (commentIndex + 2 ).trim ();
7068 lineText = lineText .substring (0 , commentIndex ).trim ();
71- line .setText (lineText ); // Update line text for further processing without comment
69+ line .setText (lineText );
7270 }
7371 }
7472
@@ -83,7 +81,7 @@ public Optional<ErrorContext> parseNode(final @NotNull Line line, final @NotNull
8381 if (parts .length > 1 ) {
8482 String value = parts [1 ].trim ();
8583
86- if (value .isBlank () && ! reader . read ( line .getPosition () + 1 ). trim (). startsWith ( "-" )) {
84+ if (value .isBlank () && isNextLineIndented ( reader , line .getPosition () + 1 , actualIndent . length () )) {
8785 final SectionNode section = new SectionNode () {
8886 private final Set <ConfigNode > nodes = new LinkedHashSet <>();
8987
@@ -201,7 +199,6 @@ public String getKey() {
201199 }
202200
203201 if (value .equalsIgnoreCase ("Null" )) return Optional .empty ();
204- if (value .isBlank () || reader .read (line .getPosition () + 1 ).trim ().startsWith ("-" )) return Optional .empty ();
205202
206203 InlineValue <?> inlineMatched = ValueRegistry .REGISTRY .getInline (String .class ).orElseThrow ();
207204
@@ -215,6 +212,7 @@ public String getKey() {
215212 }
216213
217214 final Object o = inlineMatched .deserialize (value );
215+
218216 if (o == null ) return Optional .empty ();
219217
220218 final ScalarNode <?> node = new ScalarNode <>() {
@@ -318,7 +316,7 @@ private void writeNode(final @NotNull InscriptStringWriter writer, final @NotNul
318316 if (!section .getInlineComments ().isEmpty ()) {
319317 writer .write (" # " + String .join (" " , section .getInlineComments ()));
320318 }
321- writer .write ("\n " + InscriptConstants . INDENT . getValue (). apply ( 1 ) + " \n " );
319+ writer .write ("\n " );
322320 return ;
323321 }
324322
@@ -383,6 +381,18 @@ private void writeNode(final @NotNull InscriptStringWriter writer, final @NotNul
383381 }
384382 }
385383
384+ private boolean isNextLineIndented (final @ NotNull InscriptReader reader , int nextLinePosition , int currentIndentLength ) {
385+ if (nextLinePosition >= reader .getLines ().size ()) {
386+ return false ;
387+ }
388+ final String nextLine = reader .read (nextLinePosition );
389+ if (nextLine .isBlank ()) {
390+ return false ;
391+ }
392+ final String nextLineIndent = nextLine .substring (0 , nextLine .length () - nextLine .trim ().length ());
393+ return nextLineIndent .length () > currentIndentLength ;
394+ }
395+
386396 @ NotNull
387397 @ Override
388398 @ Unmodifiable
0 commit comments