@@ -6,35 +6,35 @@ |
||
6 | 6 | * @version 1.0 */ |
7 | 7 | namespace Transphporm\Parser; |
8 | 8 | class TokenFilterIterator implements \Iterator { |
9 | - private $ignore; |
|
10 | - private $tokens; |
|
9 | + private $ignore; |
|
10 | + private $tokens; |
|
11 | 11 | |
12 | - public function __construct(Tokens $tokens, array $ignore) { |
|
13 | - $this->ignore = $ignore; |
|
14 | - $this->tokens = $tokens; |
|
15 | - } |
|
12 | + public function __construct(Tokens $tokens, array $ignore) { |
|
13 | + $this->ignore = $ignore; |
|
14 | + $this->tokens = $tokens; |
|
15 | + } |
|
16 | 16 | |
17 | - public function current() { |
|
18 | - return $this->tokens->current(); |
|
19 | - } |
|
17 | + public function current() { |
|
18 | + return $this->tokens->current(); |
|
19 | + } |
|
20 | 20 | |
21 | - public function key() { |
|
22 | - return $this->tokens->key(); |
|
23 | - } |
|
21 | + public function key() { |
|
22 | + return $this->tokens->key(); |
|
23 | + } |
|
24 | 24 | |
25 | - public function valid() { |
|
26 | - return $this->tokens->valid(); |
|
27 | - } |
|
25 | + public function valid() { |
|
26 | + return $this->tokens->valid(); |
|
27 | + } |
|
28 | 28 | |
29 | - public function next() { |
|
30 | - do { |
|
31 | - $this->tokens->next(); |
|
32 | - } |
|
33 | - while ($this->tokens->valid() && in_array($this->tokens->current()['type'], $this->ignore)); |
|
34 | - } |
|
29 | + public function next() { |
|
30 | + do { |
|
31 | + $this->tokens->next(); |
|
32 | + } |
|
33 | + while ($this->tokens->valid() && in_array($this->tokens->current()['type'], $this->ignore)); |
|
34 | + } |
|
35 | 35 | |
36 | - public function rewind() { |
|
37 | - $this->tokens->rewind(); |
|
38 | - while ($this->tokens->valid() && in_array($this->tokens->current()['type'], $this->ignore)) $this->tokens->next(); |
|
39 | - } |
|
36 | + public function rewind() { |
|
37 | + $this->tokens->rewind(); |
|
38 | + while ($this->tokens->valid() && in_array($this->tokens->current()['type'], $this->ignore)) $this->tokens->next(); |
|
39 | + } |
|
40 | 40 | } |
41 | 41 | \ No newline at end of file |
@@ -102,14 +102,14 @@ |
||
102 | 102 | } |
103 | 103 | |
104 | 104 | private function getProperties($tokens) { |
105 | - $rules = $tokens->splitOnToken(Tokenizer::SEMI_COLON); |
|
105 | + $rules = $tokens->splitOnToken(Tokenizer::SEMI_COLON); |
|
106 | 106 | |
107 | - $return = []; |
|
108 | - foreach ($rules as $rule) { |
|
109 | - $name = $rule->from(Tokenizer::NAME, true)->to(Tokenizer::COLON)->read(); |
|
110 | - $return[$name] = $rule->from(Tokenizer::COLON)->trim(); |
|
111 | - } |
|
107 | + $return = []; |
|
108 | + foreach ($rules as $rule) { |
|
109 | + $name = $rule->from(Tokenizer::NAME, true)->to(Tokenizer::COLON)->read(); |
|
110 | + $return[$name] = $rule->from(Tokenizer::COLON)->trim(); |
|
111 | + } |
|
112 | 112 | |
113 | - return $return; |
|
114 | - } |
|
113 | + return $return; |
|
114 | + } |
|
115 | 115 | } |
@@ -6,28 +6,28 @@ discard block |
||
6 | 6 | * @version 1.0 */ |
7 | 7 | namespace Transphporm\Parser; |
8 | 8 | class Tokens implements \Iterator, \Countable { |
9 | - private $tokens; |
|
10 | - private $iterator = 0; |
|
9 | + private $tokens; |
|
10 | + private $iterator = 0; |
|
11 | 11 | |
12 | - public function __construct(array $tokens) { |
|
13 | - $this->tokens = $tokens; |
|
14 | - } |
|
12 | + public function __construct(array $tokens) { |
|
13 | + $this->tokens = $tokens; |
|
14 | + } |
|
15 | 15 | |
16 | - public function count() { |
|
17 | - return count($this->tokens); |
|
18 | - } |
|
16 | + public function count() { |
|
17 | + return count($this->tokens); |
|
18 | + } |
|
19 | 19 | |
20 | - // Iterator Functions |
|
21 | - public function current() { |
|
22 | - return $this->tokens[$this->iterator]; |
|
23 | - } |
|
20 | + // Iterator Functions |
|
21 | + public function current() { |
|
22 | + return $this->tokens[$this->iterator]; |
|
23 | + } |
|
24 | 24 | |
25 | - public function key() { |
|
26 | - return $this->iterator; |
|
27 | - } |
|
25 | + public function key() { |
|
26 | + return $this->iterator; |
|
27 | + } |
|
28 | 28 | |
29 | - public function next() { |
|
30 | - ++$this->iterator; |
|
29 | + public function next() { |
|
30 | + ++$this->iterator; |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | public function valid() { |
@@ -38,63 +38,63 @@ discard block |
||
38 | 38 | $this->iterator = 0; |
39 | 39 | } |
40 | 40 | |
41 | - private function getKeysOfTokenType($tokenType) { |
|
42 | - return array_keys(array_column($this->tokens, 'type'), $tokenType); |
|
43 | - } |
|
41 | + private function getKeysOfTokenType($tokenType) { |
|
42 | + return array_keys(array_column($this->tokens, 'type'), $tokenType); |
|
43 | + } |
|
44 | 44 | |
45 | - public function from($tokenType, $inclusive = false) { |
|
46 | - $keys = $this->getKeysOfTokenType($tokenType); |
|
47 | - if (count($keys) === 0) return new Tokens([]); |
|
48 | - $key = $keys[0]; |
|
49 | - for ($i = 0; $key < $this->iterator; $i++) $key = $keys[$i]; |
|
50 | - if (!$inclusive) $key++; |
|
51 | - return new Tokens(array_slice($this->tokens, $key)); |
|
52 | - } |
|
45 | + public function from($tokenType, $inclusive = false) { |
|
46 | + $keys = $this->getKeysOfTokenType($tokenType); |
|
47 | + if (count($keys) === 0) return new Tokens([]); |
|
48 | + $key = $keys[0]; |
|
49 | + for ($i = 0; $key < $this->iterator; $i++) $key = $keys[$i]; |
|
50 | + if (!$inclusive) $key++; |
|
51 | + return new Tokens(array_slice($this->tokens, $key)); |
|
52 | + } |
|
53 | 53 | |
54 | - public function to($tokenType, $inclusive = false) { |
|
55 | - $keys = $this->getKeysOfTokenType($tokenType); |
|
56 | - if (empty($keys)) return new Tokens([]); |
|
57 | - $key = $keys[0]; |
|
58 | - for ($i = 0; $key < $this->iterator; $i++) $key = $keys[$i]; |
|
59 | - if ($inclusive) $key++; |
|
60 | - return new Tokens(array_slice($this->tokens, 0, $key)); |
|
61 | - } |
|
54 | + public function to($tokenType, $inclusive = false) { |
|
55 | + $keys = $this->getKeysOfTokenType($tokenType); |
|
56 | + if (empty($keys)) return new Tokens([]); |
|
57 | + $key = $keys[0]; |
|
58 | + for ($i = 0; $key < $this->iterator; $i++) $key = $keys[$i]; |
|
59 | + if ($inclusive) $key++; |
|
60 | + return new Tokens(array_slice($this->tokens, 0, $key)); |
|
61 | + } |
|
62 | 62 | |
63 | - public function skip($count) { |
|
64 | - $this->iterator += $count; |
|
65 | - } |
|
63 | + public function skip($count) { |
|
64 | + $this->iterator += $count; |
|
65 | + } |
|
66 | 66 | |
67 | - public function splitOnToken($tokenType) { |
|
68 | - $splitTokens = []; |
|
67 | + public function splitOnToken($tokenType) { |
|
68 | + $splitTokens = []; |
|
69 | 69 | $i = 0; |
70 | 70 | foreach ($this->tokens as $token) { |
71 | 71 | if ($token['type'] === $tokenType) $i++; |
72 | 72 | else $splitTokens[$i][] = $token; |
73 | 73 | } |
74 | - return array_map(function ($tokens) { |
|
75 | - return new Tokens($tokens); |
|
76 | - }, $splitTokens); |
|
74 | + return array_map(function ($tokens) { |
|
75 | + return new Tokens($tokens); |
|
76 | + }, $splitTokens); |
|
77 | 77 | //return $splitTokens; |
78 | - } |
|
78 | + } |
|
79 | 79 | |
80 | - public function trim() { |
|
81 | - $tokens = $this->tokens; |
|
82 | - // Remove end whitespace |
|
83 | - while (end($tokens)['type'] === Tokenizer::WHITESPACE) { |
|
84 | - array_pop($tokens); |
|
85 | - } |
|
86 | - // Remove begining whitespace |
|
87 | - while (isset($tokens[0]) && $tokens[0]['type'] === Tokenizer::WHITESPACE) { |
|
88 | - array_shift($tokens); |
|
89 | - } |
|
90 | - return new Tokens($tokens); |
|
91 | - } |
|
80 | + public function trim() { |
|
81 | + $tokens = $this->tokens; |
|
82 | + // Remove end whitespace |
|
83 | + while (end($tokens)['type'] === Tokenizer::WHITESPACE) { |
|
84 | + array_pop($tokens); |
|
85 | + } |
|
86 | + // Remove begining whitespace |
|
87 | + while (isset($tokens[0]) && $tokens[0]['type'] === Tokenizer::WHITESPACE) { |
|
88 | + array_shift($tokens); |
|
89 | + } |
|
90 | + return new Tokens($tokens); |
|
91 | + } |
|
92 | 92 | |
93 | - public function read($offset = 0) { |
|
94 | - return isset($this->tokens[$offset]) ? $this->tokens[$offset]['value'] : false; |
|
95 | - } |
|
93 | + public function read($offset = 0) { |
|
94 | + return isset($this->tokens[$offset]) ? $this->tokens[$offset]['value'] : false; |
|
95 | + } |
|
96 | 96 | |
97 | - public function type($offset = 0) { |
|
98 | - return isset($this->tokens[$offset]) ? $this->tokens[$offset]['type'] : false; |
|
99 | - } |
|
97 | + public function type($offset = 0) { |
|
98 | + return isset($this->tokens[$offset]) ? $this->tokens[$offset]['type'] : false; |
|
99 | + } |
|
100 | 100 | } |