1
|
|
|
<?php |
2
|
|
|
/* @description Transformation Style Sheets - Revolutionising PHP templating * |
3
|
|
|
* @author Tom Butler [email protected] * |
4
|
|
|
* @copyright 2015 Tom Butler <[email protected]> | https://r.je/ * |
5
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License * |
6
|
|
|
* @version 1.0 */ |
7
|
|
|
namespace Transphporm\Parser; |
8
|
|
|
class Tokenizer { |
9
|
|
|
private $str; |
10
|
|
|
private $tokenizeRules = []; |
11
|
|
|
|
12
|
|
|
const NAME = 'LITERAL'; |
13
|
|
|
const STRING = 'STRING'; |
14
|
|
|
const OPEN_BRACKET = 'OPEN_BRACKET'; |
15
|
|
|
const CLOSE_BRACKET = 'CLOSE_BRACKET'; |
16
|
|
|
const OPEN_SQUARE_BRACKET = 'SQUARE_BRACKET'; |
17
|
|
|
const CLOSE_SQUARE_BRACKET = 'CLOSE_SQUARE_BRACKET'; |
18
|
|
|
const CONCAT = 'CONCAT'; |
19
|
|
|
const ARG = 'ARG'; |
20
|
|
|
const WHITESPACE = 'WHITESPACE'; |
21
|
|
|
const NEW_LINE = 'NEW_LINE'; |
22
|
|
|
const DOT = 'DOT'; |
23
|
|
|
const NUMERIC = 'NUMERIC'; |
24
|
|
|
const EQUALS = 'EQUALS'; |
25
|
|
|
const NOT = 'NOT'; |
26
|
|
|
const OPEN_BRACE = 'OPEN_BRACE'; |
27
|
|
|
const CLOSE_BRACE = 'CLOSE_BRACE'; |
28
|
|
|
const BOOL = 'BOOL'; |
29
|
|
|
const COLON = 'COLON'; |
30
|
|
|
const SEMI_COLON = 'SEMI_COLON'; |
31
|
|
|
const NUM_SIGN = 'NUM_SIGN'; |
32
|
|
|
const GREATER_THAN = 'GREATER_THAN'; |
33
|
|
|
const LOWER_THAN = 'LOWER_THAN'; |
34
|
|
|
const AT_SIGN = 'AT_SIGN'; |
35
|
|
|
const SUBTRACT = 'SUBTRACT'; |
36
|
|
|
const MULTIPLY = 'MULTIPLY'; |
37
|
|
|
const DIVIDE = 'DIVIDE'; |
38
|
|
|
|
39
|
|
|
public function __construct($str) { |
40
|
|
|
$this->str = new Tokenizer\TokenizedString($str); |
41
|
|
|
|
42
|
|
|
$this->tokenizeRules = [ |
43
|
|
|
new Tokenizer\Comments, |
44
|
|
|
new Tokenizer\BasicChars, |
45
|
|
|
new Tokenizer\Literals, |
46
|
|
|
new Tokenizer\Strings, |
47
|
|
|
new Tokenizer\Brackets |
48
|
|
|
]; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function getTokens() { |
52
|
|
|
$tokens = new Tokens; |
53
|
|
|
$this->str->reset(); |
54
|
|
|
|
55
|
|
|
while ($this->str->next()) { |
56
|
|
|
foreach ($this->tokenizeRules as $tokenizer) { |
57
|
|
|
$tokenizer->tokenize($this->str, $tokens); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $tokens; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
} |
65
|
|
|
|