Passed
Push — master ( 0f10a6...8f1e95 )
by Koen
11:27
created

InputStream::error()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Vlaswinkel\Lua;
4
5
/**
6
 * Class InputStream
7
 *
8
 * @see     http://lisperator.net/pltut/parser/input-stream
9
 *
10
 * @author  Koen Vlaswinkel <[email protected]>
11
 * @package Vlaswinkel\Lua
12
 */
13
class InputStream {
14
    /**
15
     * @var string
16
     */
17
    private $input;
18
19
    /**
20
     * @var int
21
     */
22
    private $position = 0;
23
    /**
24
     * @var int
25
     */
26
    private $line = 1;
27
    /**
28
     * @var int
29
     */
30
    private $column = 0;
31
32
    /**
33
     * InputStream constructor.
34
     *
35
     * @param string $input
36
     */
37 27
    public function __construct($input) {
38 27
        $this->input = $input;
39 27
    }
40
41 26
    public function next() {
42 26
        $char = $this->input[$this->position++];
43 26
        if ($char == "\n") {
44 5
            $this->line++;
45 5
            $this->column = 0;
46 5
        } else {
47 26
            $this->column++;
48
        }
49 26
        return $char;
50
    }
51
52 21
    public function peek() {
53 21
        return $this->input[$this->position];
54
    }
55
56 22
    public function eof() {
57 22
        return $this->position >= strlen($this->input);
58
    }
59
60 6
    public function error($msg) {
61 6
        throw new ParseException($msg . ' (' . $this->line . ':' . $this->column . ')');
62
    }
63
}