@@ -537,7 +537,27 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
537
537
}
538
538
539
539
if (null === $ indentation ) {
540
- $ newIndent = $ this ->getCurrentLineIndentation ();
540
+ $ newIndent = null ;
541
+ $ movements = 0 ;
542
+
543
+ do {
544
+ $ EOF = false ;
545
+
546
+ // comment-like lines do not influence the indentation depth
547
+ if ($ this ->isCurrentLineComment ()) {
548
+ $ EOF = !$ this ->moveToNextLine ();
549
+
550
+ if (!$ EOF ) {
551
+ ++$ movements ;
552
+ }
553
+ } else {
554
+ $ newIndent = $ this ->getCurrentLineIndentation ();
555
+ }
556
+ } while (!$ EOF && null === $ newIndent );
557
+
558
+ for ($ i = 0 ; $ i < $ movements ; ++$ i ) {
559
+ $ this ->moveToPreviousLine ();
560
+ }
541
561
542
562
$ unindentedEmbedBlock = $ this ->isStringUnIndentedCollectionItem ();
543
563
@@ -551,6 +571,8 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
551
571
$ data = array ();
552
572
if ($ this ->getCurrentLineIndentation () >= $ newIndent ) {
553
573
$ data [] = substr ($ this ->currentLine , $ newIndent );
574
+ } elseif ($ this ->isCurrentLineComment ()) {
575
+ $ data [] = $ this ->currentLine ;
554
576
} else {
555
577
$ this ->moveToPreviousLine ();
556
578
@@ -866,19 +888,25 @@ private function parseBlockScalar($style, $chomping = '', $indentation = 0)
866
888
private function isNextLineIndented ()
867
889
{
868
890
$ currentIndentation = $ this ->getCurrentLineIndentation ();
869
- $ EOF = ! $ this -> moveToNextLine () ;
891
+ $ movements = 0 ;
870
892
871
- while (! $ EOF && $ this -> isCurrentLineEmpty ()) {
893
+ do {
872
894
$ EOF = !$ this ->moveToNextLine ();
873
- }
895
+
896
+ if (!$ EOF ) {
897
+ ++$ movements ;
898
+ }
899
+ } while (!$ EOF && ($ this ->isCurrentLineEmpty () || $ this ->isCurrentLineComment ()));
874
900
875
901
if ($ EOF ) {
876
902
return false ;
877
903
}
878
904
879
905
$ ret = $ this ->getCurrentLineIndentation () > $ currentIndentation ;
880
906
881
- $ this ->moveToPreviousLine ();
907
+ for ($ i = 0 ; $ i < $ movements ; ++$ i ) {
908
+ $ this ->moveToPreviousLine ();
909
+ }
882
910
883
911
return $ ret ;
884
912
}
@@ -967,19 +995,25 @@ private function cleanup($value)
967
995
private function isNextLineUnIndentedCollection ()
968
996
{
969
997
$ currentIndentation = $ this ->getCurrentLineIndentation ();
970
- $ notEOF = $ this -> moveToNextLine () ;
998
+ $ movements = 0 ;
971
999
972
- while ($ notEOF && $ this ->isCurrentLineEmpty ()) {
973
- $ notEOF = $ this ->moveToNextLine ();
974
- }
1000
+ do {
1001
+ $ EOF = !$ this ->moveToNextLine ();
1002
+
1003
+ if (!$ EOF ) {
1004
+ ++$ movements ;
1005
+ }
1006
+ } while (!$ EOF && ($ this ->isCurrentLineEmpty () || $ this ->isCurrentLineComment ()));
975
1007
976
- if (false === $ notEOF ) {
1008
+ if ($ EOF ) {
977
1009
return false ;
978
1010
}
979
1011
980
1012
$ ret = $ this ->getCurrentLineIndentation () === $ currentIndentation && $ this ->isStringUnIndentedCollectionItem ();
981
1013
982
- $ this ->moveToPreviousLine ();
1014
+ for ($ i = 0 ; $ i < $ movements ; ++$ i ) {
1015
+ $ this ->moveToPreviousLine ();
1016
+ }
983
1017
984
1018
return $ ret ;
985
1019
}
0 commit comments