Skip to content

Commit 176b442

Browse files
authored
Merge pull request #530 from phpDocumentor/feature-inline-rules-document-parser
[FEATURE] Make DocumentParserContext Availible in InlineRules
2 parents 72613f3 + 6c21552 commit 176b442

25 files changed

+65
-68
lines changed

packages/guides-restructured-text/src/RestructuredText/Parser/InlineParser.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Exception;
88
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
99
use phpDocumentor\Guides\Nodes\InlineCompoundNode;
10-
use phpDocumentor\Guides\ParserContext;
1110
use phpDocumentor\Guides\RestructuredText\Parser\Productions\InlineRules\InlineRule;
1211

1312
use function usort;
@@ -26,7 +25,7 @@ public function __construct(iterable $inlineRules)
2625
});
2726
}
2827

29-
public function parse(string $content, ParserContext $parserContext): InlineCompoundNode
28+
public function parse(string $content, DocumentParserContext $documentParserContext): InlineCompoundNode
3029
{
3130
$lexer = new InlineLexer();
3231
$lexer->setInput($content);
@@ -38,7 +37,7 @@ public function parse(string $content, ParserContext $parserContext): InlineComp
3837
foreach ($this->rules as $inlineRule) {
3938
$node = null;
4039
if ($inlineRule->applies($lexer)) {
41-
$node = $inlineRule->apply($parserContext, $lexer);
40+
$node = $inlineRule->apply($documentParserContext, $lexer);
4241
}
4342

4443
if ($node === null) {

packages/guides-restructured-text/src/RestructuredText/Parser/Productions/InlineMarkupRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function apply(DocumentParserContext $documentParserContext, CompoundNode
6363
$documentIterator = $documentParserContext->getDocumentIterator();
6464
$buffer = $this->collectContent($documentIterator);
6565

66-
$node = $this->inlineTokenParser->parse($buffer->getLinesString(), $documentParserContext->getContext());
66+
$node = $this->inlineTokenParser->parse($buffer->getLinesString(), $documentParserContext);
6767

6868
if ($on !== null) {
6969
$on->setValue([$node]);

packages/guides-restructured-text/src/RestructuredText/Parser/Productions/InlineRules/AnnotationRoleRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use phpDocumentor\Guides\Nodes\Inline\CitationInlineNode;
88
use phpDocumentor\Guides\Nodes\Inline\FootnoteInlineNode;
99
use phpDocumentor\Guides\Nodes\Inline\InlineNode;
10-
use phpDocumentor\Guides\ParserContext;
1110
use phpDocumentor\Guides\RestructuredText\Parser\AnnotationUtility;
11+
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
1212
use phpDocumentor\Guides\RestructuredText\Parser\InlineLexer;
1313

1414
/**
@@ -21,7 +21,7 @@ public function applies(InlineLexer $lexer): bool
2121
return $lexer->token?->type === InlineLexer::ANNOTATION_START;
2222
}
2323

24-
public function apply(ParserContext $parserContext, InlineLexer $lexer): InlineNode|null
24+
public function apply(DocumentParserContext $documentParserContext, InlineLexer $lexer): InlineNode|null
2525
{
2626
$startPosition = $lexer->token?->position;
2727
$annotationName = '';

packages/guides-restructured-text/src/RestructuredText/Parser/Productions/InlineRules/AnonymousPhraseRule.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace phpDocumentor\Guides\RestructuredText\Parser\Productions\InlineRules;
66

77
use phpDocumentor\Guides\Nodes\Inline\HyperLinkNode;
8-
use phpDocumentor\Guides\ParserContext;
8+
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
99
use phpDocumentor\Guides\RestructuredText\Parser\InlineLexer;
1010

1111
/**
@@ -25,7 +25,7 @@ public function applies(InlineLexer $lexer): bool
2525
return $lexer->token?->type === InlineLexer::BACKTICK;
2626
}
2727

28-
public function apply(ParserContext $parserContext, InlineLexer $lexer): HyperLinkNode|null
28+
public function apply(DocumentParserContext $documentParserContext, InlineLexer $lexer): HyperLinkNode|null
2929
{
3030
$text = '';
3131
$embeddedUrl = null;
@@ -36,7 +36,7 @@ public function apply(ParserContext $parserContext, InlineLexer $lexer): HyperLi
3636
case InlineLexer::PHRASE_ANONYMOUS_END:
3737
$lexer->moveNext();
3838

39-
return $this->createAnonymousReference($parserContext, $text, $embeddedUrl);
39+
return $this->createAnonymousReference($documentParserContext, $text, $embeddedUrl);
4040

4141
case InlineLexer::EMBEDED_URL_START:
4242
$embeddedUrl = $this->parseEmbeddedUrl($lexer);
@@ -57,11 +57,11 @@ public function apply(ParserContext $parserContext, InlineLexer $lexer): HyperLi
5757
return null;
5858
}
5959

60-
private function createAnonymousReference(ParserContext $parserContext, string $link, string|null $embeddedUrl): HyperLinkNode
60+
private function createAnonymousReference(DocumentParserContext $documentParserContext, string $link, string|null $embeddedUrl): HyperLinkNode
6161
{
62-
$parserContext->resetAnonymousStack();
63-
$node = $this->createReference($parserContext, $link, $embeddedUrl, false);
64-
$parserContext->pushAnonymous($link);
62+
$documentParserContext->getContext()->resetAnonymousStack();
63+
$node = $this->createReference($documentParserContext, $link, $embeddedUrl, false);
64+
$documentParserContext->getContext()->pushAnonymous($link);
6565

6666
return $node;
6767
}

packages/guides-restructured-text/src/RestructuredText/Parser/Productions/InlineRules/AnonymousReferenceRule.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace phpDocumentor\Guides\RestructuredText\Parser\Productions\InlineRules;
66

77
use phpDocumentor\Guides\Nodes\Inline\HyperLinkNode;
8-
use phpDocumentor\Guides\ParserContext;
8+
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
99
use phpDocumentor\Guides\RestructuredText\Parser\InlineLexer;
1010

1111
use function trim;
@@ -26,22 +26,22 @@ public function applies(InlineLexer $lexer): bool
2626
return $lexer->token?->type === InlineLexer::ANONYMOUSE_REFERENCE;
2727
}
2828

29-
public function apply(ParserContext $parserContext, InlineLexer $lexer): HyperLinkNode|null
29+
public function apply(DocumentParserContext $documentParserContext, InlineLexer $lexer): HyperLinkNode|null
3030
{
3131
$node = $this->createAnonymousReference(
32-
$parserContext,
32+
$documentParserContext,
3333
trim((string) $lexer->token?->value, '_'),
3434
);
3535
$lexer->moveNext();
3636

3737
return $node;
3838
}
3939

40-
private function createAnonymousReference(ParserContext $parserContext, string $link): HyperLinkNode
40+
private function createAnonymousReference(DocumentParserContext $documentParserContext, string $link): HyperLinkNode
4141
{
42-
$parserContext->resetAnonymousStack();
43-
$node = $this->createReference($parserContext, $link, null, false);
44-
$parserContext->pushAnonymous($link);
42+
$documentParserContext->getContext()->resetAnonymousStack();
43+
$node = $this->createReference($documentParserContext, $link, null, false);
44+
$documentParserContext->getContext()->pushAnonymous($link);
4545

4646
return $node;
4747
}

packages/guides-restructured-text/src/RestructuredText/Parser/Productions/InlineRules/DefaultTextRoleRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use phpDocumentor\Guides\Nodes\Inline\InlineNode;
88
use phpDocumentor\Guides\Nodes\Inline\LiteralInlineNode;
9-
use phpDocumentor\Guides\ParserContext;
9+
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
1010
use phpDocumentor\Guides\RestructuredText\Parser\InlineLexer;
1111

1212
/**
@@ -19,7 +19,7 @@ public function applies(InlineLexer $lexer): bool
1919
return $lexer->token?->type === InlineLexer::BACKTICK;
2020
}
2121

22-
public function apply(ParserContext $parserContext, InlineLexer $lexer): InlineNode|null
22+
public function apply(DocumentParserContext $documentParserContext, InlineLexer $lexer): InlineNode|null
2323
{
2424
$text = '';
2525

packages/guides-restructured-text/src/RestructuredText/Parser/Productions/InlineRules/EmphasisRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use phpDocumentor\Guides\Nodes\Inline\EmphasisInlineNode;
88
use phpDocumentor\Guides\Nodes\Inline\InlineNode;
9-
use phpDocumentor\Guides\ParserContext;
9+
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
1010
use phpDocumentor\Guides\RestructuredText\Parser\InlineLexer;
1111

1212
/**
@@ -19,7 +19,7 @@ public function applies(InlineLexer $lexer): bool
1919
return $lexer->token?->type === InlineLexer::EMPHASIS_DELIMITER;
2020
}
2121

22-
public function apply(ParserContext $parserContext, InlineLexer $lexer): InlineNode|null
22+
public function apply(DocumentParserContext $documentParserContext, InlineLexer $lexer): InlineNode|null
2323
{
2424
$text = '';
2525

packages/guides-restructured-text/src/RestructuredText/Parser/Productions/InlineRules/EscapeRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace phpDocumentor\Guides\RestructuredText\Parser\Productions\InlineRules;
66

77
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
8-
use phpDocumentor\Guides\ParserContext;
8+
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
99
use phpDocumentor\Guides\RestructuredText\Parser\InlineLexer;
1010

1111
use function preg_match;
@@ -21,7 +21,7 @@ public function applies(InlineLexer $lexer): bool
2121
return $lexer->token?->type === InlineLexer::ESCAPED_SIGN;
2222
}
2323

24-
public function apply(ParserContext $parserContext, InlineLexer $lexer): PlainTextInlineNode|null
24+
public function apply(DocumentParserContext $documentParserContext, InlineLexer $lexer): PlainTextInlineNode|null
2525
{
2626
$char = $lexer->token?->value ?? '';
2727
$char = substr($char, 1);

packages/guides-restructured-text/src/RestructuredText/Parser/Productions/InlineRules/InlineRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
namespace phpDocumentor\Guides\RestructuredText\Parser\Productions\InlineRules;
1515

1616
use phpDocumentor\Guides\Nodes\Inline\InlineNode;
17-
use phpDocumentor\Guides\ParserContext;
17+
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
1818
use phpDocumentor\Guides\RestructuredText\Parser\InlineLexer;
1919

2020
interface InlineRule
2121
{
2222
public function applies(InlineLexer $lexer): bool;
2323

24-
public function apply(ParserContext $parserContext, InlineLexer $lexer): InlineNode|null;
24+
public function apply(DocumentParserContext $documentParserContext, InlineLexer $lexer): InlineNode|null;
2525

2626
public function getPriority(): int;
2727
}

packages/guides-restructured-text/src/RestructuredText/Parser/Productions/InlineRules/InternalReferenceRule.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace phpDocumentor\Guides\RestructuredText\Parser\Productions\InlineRules;
66

77
use phpDocumentor\Guides\Nodes\Inline\InlineNode;
8-
use phpDocumentor\Guides\ParserContext;
8+
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
99
use phpDocumentor\Guides\RestructuredText\Parser\InlineLexer;
1010

1111
class InternalReferenceRule extends ReferenceRule
@@ -15,7 +15,7 @@ public function applies(InlineLexer $lexer): bool
1515
return $lexer->token?->type === InlineLexer::INTERNAL_REFERENCE_START;
1616
}
1717

18-
public function apply(ParserContext $parserContext, InlineLexer $lexer): InlineNode|null
18+
public function apply(DocumentParserContext $documentParserContext, InlineLexer $lexer): InlineNode|null
1919
{
2020
$text = '';
2121
$initialPosition = $lexer->token?->position;
@@ -25,7 +25,7 @@ public function apply(ParserContext $parserContext, InlineLexer $lexer): InlineN
2525
case InlineLexer::BACKTICK:
2626
$lexer->moveNext();
2727

28-
return $this->createReference($parserContext, $text);
28+
return $this->createReference($documentParserContext, $text);
2929

3030
default:
3131
$text .= $lexer->token->value;

0 commit comments

Comments
 (0)