-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathParser.php
More file actions
87 lines (79 loc) · 1.97 KB
/
Parser.php
File metadata and controls
87 lines (79 loc) · 1.97 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* @package axy\ml
* @author Oleg Grigoriev <go.vasac@gmail.com>
*/
namespace axy\ml;
use axy\ml\helpers\Tokenizer;
use axy\ml\helpers\Normalizer;
/**
* The parser of axyml document
*/
class Parser
{
/**
* The constructor
*
* @param array $options [optional]
* the custom options list
* @param array $tags [optional]
* the custom tags list
* @param mixed $custom [optional]
* the custom context
*/
public function __construct(array $options = null, array $tags = null, $custom = null)
{
$this->options = new Options($options);
$this->tags = new TagsList($tags);
$this->custom = $custom;
}
/**
* Parses an axyml document
*
* @param string $content
* the document content
* @param string $cut [optional]
* the anchor for document cutting
* @return \axy\ml\Result
* the parsing result
*/
public function parse($content, $cut = null)
{
$content = Normalizer::toParse($content, $this->options);
$tokenizer = new Tokenizer($content, $this->options);
$tokenizer->tokenize($cut);
return new Result($tokenizer, $this->options, $this->tags, $this->custom);
}
/**
* Parses of an axyml document from a file
*
* @param string $filename
* the file name of the document (must exist)
* @param string $cut [optional]
* the anchor for document cutting
* @return \axy\ml\Result
* the result of parsing
*/
public function parseFile($filename, $cut = null)
{
return $this->parse(file_get_contents($filename), $cut);
}
/**
* The parsing options
*
* @var \axy\ml\Options
*/
private $options;
/**
* The current tags list
*
* @var \axy\ml\TagsList
*/
private $tags;
/**
* The custom context
*
* @var mixed
*/
private $custom;
}