-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathASPIS.php
60 lines (55 loc) · 1.57 KB
/
ASPIS.php
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
<?php
namespace ASPIS;
require_once('vendor/autoload.php');
use ASPIS\lib\ASPISParser;
use ASPIS\lib\ASPISLexer;
use \Exception;
class ASPIS
{
//root gets set in the parser
public $root = null;
public $parser = null;
private function parse($filePointer)
{
if (!isset($this->parser)) {
$this->parser = new ASPISParser($this);
}
$scanner = new ASPISLexer($filePointer);
while ($token = $scanner->nextToken()) {
if ($token->type != -1) {
$this->parser->doParse($token->type, $token);
} else {
$this->root = null;
$err = 'Invalid Input in line ' . $token->line . '. Problem with: ' . $token->value . fgets($filePointer, 15);
throw new Exception($err);
}
}
$this->parser->doParse(0);
if ($this->root == null) {
$err = 'Could not finish Parsing';
throw new Exception($err);
}
}
public function parseString($string)
{
$filePointer = fopen("php://memory", 'r+');
fwrite($filePointer, $string);
rewind($filePointer);
return $this->parse($filePointer);
}
public function parseFile($file)
{
try {
$filePointer = fopen($file, 'r+');
} catch (Exception $e) {
throw new Exception('Unable to open file with path: ' . $file, 0, $e);
}
return $this->parse($filePointer);
}
public function resetParser()
{
//cheap way
unset($parser);
unset($root);
}
}