1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
<?php
namespace SourceSpan;
use League\Uri\Contracts\UriInterface;
/**
* An interface that describes a segment of source text.
*/
interface SourceSpan
{
/**
* The start location of this span.
*/
public function getStart(): SourceLocation;
/**
* The end location of this span, exclusive.
*/
public function getEnd(): SourceLocation;
/**
* The source text for this span.
*/
public function getText(): string;
/**
* The URL of the source (typically a file) of this span.
*
* This may be null, indicating that the source URL is unknown or
* unavailable.
*/
public function getSourceUrl(): ?UriInterface;
/**
* The length of this span, in bytes.
*/
public function getLength(): int;
/**
* Creates a new span that's the union of $this and $other.
*
* The two spans must have the same source URL and may not be disjoint.
* {@see getText} is computed by combining `$this->getText()` and `$other->getText()`.
*/
public function union(SourceSpan $other): SourceSpan;
/**
* Compares two spans.
*
* It returns a negative integer if $this is ordered before $other,
* a positive integer if $this is ordered after $other,
* and zero if $this and $other are ordered together.
*
* $other must have the same source URL as `this`. This orders spans by
* {@see getStart} then {@see getLength}.
*/
public function compareTo(SourceSpan $other): int;
/**
* Formats $message in a human-friendly way associated with this span.
*
* @param string $message
*
* @return string
*/
public function message(string $message): string;
/**
* Like {@see message}, but also highlights $secondarySpans to provide
* the user with additional context.
*
* Each span takes a label ($label for this span, and the keys of the
* $secondarySpans map for the secondary spans) that's used to indicate to
* the user what that particular span represents.
*
* @throws \InvalidArgumentException if any secondary span has a different source URL than this span.
*
* @param array<string, SourceSpan> $secondarySpans
*/
public function messageMultiple(string $message, string $label, array $secondarySpans): string;
/**
* Prints the text associated with this span in a user-friendly way.
*
* This is identical to {@see message}, except that it doesn't print the file
* name, line number, column number, or message.
*/
public function highlight(): string;
/**
* Like {@see highlight}, but also highlights $secondarySpans to provide
* the user with additional context.
*
* Each span takes a label ($label for this span, and the keys of the
* $secondarySpans map for the secondary spans) that's used to indicate to
* the user what that particular span represents.
*
* @throws \InvalidArgumentException if any secondary span has a different source URL than this span.
*
* @param array<string, SourceSpan> $secondarySpans
*/
public function highlightMultiple(string $label, array $secondarySpans): string;
/**
* Return a span from $start bytes (inclusive) to $end bytes
* (exclusive) after the beginning of this span
*/
public function subspan(int $start, ?int $end = null): SourceSpan;
}
|