-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEndOfInputParser.php
More file actions
66 lines (56 loc) · 1.34 KB
/
Copy pathEndOfInputParser.php
File metadata and controls
66 lines (56 loc) · 1.34 KB
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
<?php
namespace petitparser;
/**
* A parser that succeeds only at the end of the input.
*/
class EndOfInputParser extends DelegateParser
{
/**
* @var string
*/
protected $_message;
/**
* @param Parser $parser
* @param string $message
*/
public function __construct(Parser $parser, $message)
{
parent::__construct($parser);
$this->_message = $message;
}
/**
* @param Context $context
*
* @return Result
*/
public function parseOn(Context $context)
{
$result = $this->_delegate->parseOn($context);
if ($result->isFailure() || $result->getPosition() == $result->getBuffer()->getLength()) {
return $result;
}
return $result->failure($this->_message, $result->getPosition());
}
public function __toString()
{
return parent::__toString() . '[' . $this->_message . ']';
}
/**
* @return Parser
*/
public function copy()
{
return new EndOfInputParser($this->_delegate, $this->_message);
}
/**
* @param Parser $other
*
* @return bool
*/
public function hasEqualProperties(Parser $other)
{
return parent::hasEqualProperties($other)
&& $other instanceof self
&& $this->_message === $other->_message;
}
}