@@ -109,6 +109,9 @@ final class DocumentParser
109109 /** @var string|null */
110110 private $ listMarker = null ;
111111
112+ /** @var array{name: string,body: string,offset: int}|null */
113+ private $ fieldOption = null ;
114+
112115 /**
113116 * @param Directive[] $directives
114117 */
@@ -454,20 +457,37 @@ private function parseLine(string $line): bool
454457 break ;
455458
456459 case State::DIRECTIVE :
457- if (! $ this ->isDirectiveOption ($ line )) {
458- if (! $ this ->lineChecker ->isDirective ($ line )) {
459- $ directive = $ this ->getCurrentDirective ();
460- $ this ->isCode = $ directive !== null ? $ directive ->wantCode () : false ;
461- $ this ->setState (State::BEGIN );
460+ if ($ this ->lineChecker ->isDirective ($ line ) && $ this ->directive === null ) {
461+ $ this ->flush ();
462+ $ this ->initDirective ($ line );
462463
463- return false ;
464+ break ;
465+ }
466+
467+ if ($ this ->fieldOption !== null && $ this ->lineChecker ->isBlockLine ($ line , $ this ->fieldOption ['offset ' ])) {
468+ $ line = ltrim ($ line );
469+ $ this ->fieldOption ['body ' ] .= strlen ($ line ) > 0 ? ' ' .$ line : '' ;
470+
471+ break ;
472+ }
473+
474+ if ($ this ->lineChecker ->isFieldList ($ line )) {
475+ if ($ this ->fieldOption !== null ) {
476+ $ this ->directive ->setOption ($ this ->fieldOption ['name ' ], $ this ->fieldOption ['body ' ]);
464477 }
465478
466- $ this ->flush ();
467- $ this ->initDirective ($ line );
479+ $ fieldData = $ this ->lineDataParser ->parseFieldList ($ line );
480+ $ fieldData ['offset ' ] = strlen ($ fieldData ['offset ' ]) + 1 ;
481+ $ this ->fieldOption = $ fieldData ;
482+
483+ break ;
468484 }
469485
470- break ;
486+ $ directive = $ this ->getCurrentDirective ();
487+ $ this ->isCode = $ directive !== null ? $ directive ->wantCode () : false ;
488+ $ this ->setState (State::BEGIN );
489+
490+ return false ;
471491
472492 default :
473493 $ this ->environment ->getErrorManager ()->error ('Parser ended in an unexcepted state ' );
@@ -599,6 +619,11 @@ private function flush(): void
599619 if ($ this ->directive !== null ) {
600620 $ currentDirective = $ this ->getCurrentDirective ();
601621
622+ if ($ this ->fieldOption !== null ) {
623+ $ this ->directive ->setOption ($ this ->fieldOption ['name ' ], $ this ->fieldOption ['body ' ]);
624+ $ this ->fieldOption = null ;
625+ }
626+
602627 if ($ currentDirective !== null ) {
603628 try {
604629 $ currentDirective ->process (
@@ -646,23 +671,6 @@ private function getCurrentDirective(): ?Directive
646671 return $ this ->directives [$ name ];
647672 }
648673
649- private function isDirectiveOption (string $ line ): bool
650- {
651- if ($ this ->directive === null ) {
652- return false ;
653- }
654-
655- $ directiveOption = $ this ->lineDataParser ->parseDirectiveOption ($ line );
656-
657- if ($ directiveOption === null ) {
658- return false ;
659- }
660-
661- $ this ->directive ->setOption ($ directiveOption ->getName (), $ directiveOption ->getValue ());
662-
663- return true ;
664- }
665-
666674 private function initDirective (string $ line ): bool
667675 {
668676 $ parserDirective = $ this ->lineDataParser ->parseDirective ($ line );
0 commit comments