Chris@0
|
1 <?php
|
Chris@0
|
2 namespace Masterminds\HTML5\Parser;
|
Chris@0
|
3
|
Chris@0
|
4 /**
|
Chris@0
|
5 * Interface for stream readers.
|
Chris@0
|
6 *
|
Chris@0
|
7 * The parser only reads from streams. Various input sources can write
|
Chris@0
|
8 * an adapater to this InputStream.
|
Chris@0
|
9 *
|
Chris@0
|
10 * Currently provided InputStream implementations include
|
Chris@0
|
11 * FileInputStream and StringInputStream.
|
Chris@0
|
12 */
|
Chris@0
|
13 interface InputStream extends \Iterator
|
Chris@0
|
14 {
|
Chris@0
|
15
|
Chris@0
|
16 /**
|
Chris@0
|
17 * Returns the current line that is being consumed.
|
Chris@0
|
18 *
|
Chris@0
|
19 * TODO: Move this to the scanner.
|
Chris@0
|
20 */
|
Chris@0
|
21 public function currentLine();
|
Chris@0
|
22
|
Chris@0
|
23 /**
|
Chris@0
|
24 * Returns the current column of the current line that the tokenizer is at.
|
Chris@0
|
25 *
|
Chris@0
|
26 * Newlines are column 0. The first char after a newline is column 1.
|
Chris@0
|
27 *
|
Chris@0
|
28 * @TODO Move this to the scanner.
|
Chris@0
|
29 *
|
Chris@0
|
30 * @return int The column number.
|
Chris@0
|
31 */
|
Chris@0
|
32 public function columnOffset();
|
Chris@0
|
33
|
Chris@0
|
34 /**
|
Chris@0
|
35 * Get all characters until EOF.
|
Chris@0
|
36 *
|
Chris@0
|
37 * This consumes characters until the EOF.
|
Chris@0
|
38 */
|
Chris@0
|
39 public function remainingChars();
|
Chris@0
|
40
|
Chris@0
|
41 /**
|
Chris@0
|
42 * Read to a particular match (or until $max bytes are consumed).
|
Chris@0
|
43 *
|
Chris@0
|
44 * This operates on byte sequences, not characters.
|
Chris@0
|
45 *
|
Chris@0
|
46 * Matches as far as possible until we reach a certain set of bytes
|
Chris@0
|
47 * and returns the matched substring.
|
Chris@0
|
48 *
|
Chris@0
|
49 * @see strcspn
|
Chris@0
|
50 * @param string $bytes
|
Chris@0
|
51 * Bytes to match.
|
Chris@0
|
52 * @param int $max
|
Chris@0
|
53 * Maximum number of bytes to scan.
|
Chris@0
|
54 * @return mixed Index or false if no match is found. You should use strong
|
Chris@0
|
55 * equality when checking the result, since index could be 0.
|
Chris@0
|
56 */
|
Chris@0
|
57 public function charsUntil($bytes, $max = null);
|
Chris@0
|
58
|
Chris@0
|
59 /**
|
Chris@0
|
60 * Returns the string so long as $bytes matches.
|
Chris@0
|
61 *
|
Chris@0
|
62 * Matches as far as possible with a certain set of bytes
|
Chris@0
|
63 * and returns the matched substring.
|
Chris@0
|
64 *
|
Chris@0
|
65 * @see strspn
|
Chris@0
|
66 * @param string $bytes
|
Chris@0
|
67 * A mask of bytes to match. If ANY byte in this mask matches the
|
Chris@0
|
68 * current char, the pointer advances and the char is part of the
|
Chris@0
|
69 * substring.
|
Chris@0
|
70 * @param int $max
|
Chris@0
|
71 * The max number of chars to read.
|
Chris@0
|
72 */
|
Chris@0
|
73 public function charsWhile($bytes, $max = null);
|
Chris@0
|
74
|
Chris@0
|
75 /**
|
Chris@0
|
76 * Unconsume one character.
|
Chris@0
|
77 *
|
Chris@0
|
78 * @param int $howMany
|
Chris@0
|
79 * The number of characters to move the pointer back.
|
Chris@0
|
80 */
|
Chris@0
|
81 public function unconsume($howMany = 1);
|
Chris@0
|
82
|
Chris@0
|
83 /**
|
Chris@0
|
84 * Retrieve the next character without advancing the pointer.
|
Chris@0
|
85 */
|
Chris@0
|
86 public function peek();
|
Chris@0
|
87 }
|