@@ -109,6 +109,9 @@ final class DocumentParser
109109 /** @var string|null */
110110 private $ listMarker = null ;
111111
112+ /** @var FieldOption|null */
113+ private $ fieldOption = null ;
114+
112115 /**
113116 * @param Directive[] $directives
114117 */
@@ -454,20 +457,34 @@ 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 ->getOffset ())) {
468+ $ this ->fieldOption ->appendLine ($ line );
469+
470+ break ;
471+ }
472+
473+ if ($ this ->lineChecker ->isFieldOption ($ line )) {
474+ if ($ this ->fieldOption !== null ) {
475+ $ this ->directive ->setOption ($ this ->fieldOption ->getName (), $ this ->fieldOption ->getBody ());
464476 }
465477
466- $ this ->flush ();
467- $ this ->initDirective ($ line );
478+ $ this ->fieldOption = $ this ->lineDataParser ->parseFieldOption ($ line );
479+
480+ break ;
468481 }
469482
470- break ;
483+ $ directive = $ this ->getCurrentDirective ();
484+ $ this ->isCode = $ directive !== null ? $ directive ->wantCode () : false ;
485+ $ this ->setState (State::BEGIN );
486+
487+ return false ;
471488
472489 default :
473490 $ this ->environment ->getErrorManager ()->error ('Parser ended in an unexcepted state ' );
@@ -599,6 +616,11 @@ private function flush(): void
599616 if ($ this ->directive !== null ) {
600617 $ currentDirective = $ this ->getCurrentDirective ();
601618
619+ if ($ this ->fieldOption !== null ) {
620+ $ this ->directive ->setOption ($ this ->fieldOption ->getName (), $ this ->fieldOption ->getBody ());
621+ $ this ->fieldOption = null ;
622+ }
623+
602624 if ($ currentDirective !== null ) {
603625 try {
604626 $ currentDirective ->process (
@@ -646,23 +668,6 @@ private function getCurrentDirective(): ?Directive
646668 return $ this ->directives [$ name ];
647669 }
648670
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-
666671 private function initDirective (string $ line ): bool
667672 {
668673 $ parserDirective = $ this ->lineDataParser ->parseDirective ($ line );
0 commit comments