summaryrefslogtreecommitdiff
path: root/src/HTML5/Parser/Scanner.php
blob: 1ce8428065af72200808f0708ad245372af28986 (plain)
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
<?php
namespace HTML5\Parser;

/**
 * The scanner.
 *
 * This scans over an input stream.
 */
class Scanner {
  const CHARS_HEX = 'abcdefABCDEF01234567890';
  const CHARS_ALNUM = 'abcdefAghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890';
  const CHARS_ALPHA = 'abcdefAghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXYZ';


  protected $char;
  protected $is;

  public function __construct($input) {
    $this->is = $input;
  }

  public function position() {
    return $this->is->position();
  }

  public function peek() {
    return $this->is->peek();
  }

  public function next() {
    $this->char = $this->is->char();
    return $this->char;
  }

  public function current() {
    return $this->char;
  }

  public function unconsume($howMany = 1) {
    for ($i = 0; $i < $howMany; ++$i) {
      $this->is->unconsume();
    }
  }

  public function getHex() {
    $this->charsWhile(self::CHARS_HEX);
  }
  public function getAsciiAlpha() {
    $this->charsWhile(self::CHARS_ALPHA);
  }
  public function getAsciiAlphaNum() {
    $this->charsWhile(self::CHARS_ALNUM);
  }
  public function getNumeric() {
    $this->charsWhile('0123456789');
  }


}
class ParseError extends Exception {
}