@@ -9,46 +9,46 @@ |
||
9 | 9 | */ |
10 | 10 | abstract class Filters extends Extensions |
11 | 11 | { |
12 | - /** |
|
13 | - * Register / override new filter. |
|
14 | - * |
|
15 | - * @param string name |
|
16 | - * @param callable filter |
|
17 | - * |
|
18 | - * @return $this |
|
19 | - */ |
|
20 | - public function filter($name, $filter) |
|
21 | - { |
|
22 | - $this->filters[$name] = $filter; |
|
23 | - |
|
24 | - return $this; |
|
25 | - } |
|
26 | - |
|
27 | - /** |
|
28 | - * Check if a filter is registered. |
|
29 | - * |
|
30 | - * @param string name |
|
31 | - * |
|
32 | - * @return bool |
|
33 | - */ |
|
34 | - public function hasFilter($name) |
|
35 | - { |
|
36 | - $helper = new FilterHelper($this->filters, $this->options['filterAutoLoad']); |
|
37 | - |
|
38 | - return $helper->hasFilter($name); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Get a registered filter by name. |
|
43 | - * |
|
44 | - * @param string name |
|
45 | - * |
|
46 | - * @return callable |
|
47 | - */ |
|
48 | - public function getFilter($name) |
|
49 | - { |
|
50 | - $helper = new FilterHelper($this->filters, $this->options['filterAutoLoad']); |
|
51 | - |
|
52 | - return $helper->getFilter($name); |
|
53 | - } |
|
12 | + /** |
|
13 | + * Register / override new filter. |
|
14 | + * |
|
15 | + * @param string name |
|
16 | + * @param callable filter |
|
17 | + * |
|
18 | + * @return $this |
|
19 | + */ |
|
20 | + public function filter($name, $filter) |
|
21 | + { |
|
22 | + $this->filters[$name] = $filter; |
|
23 | + |
|
24 | + return $this; |
|
25 | + } |
|
26 | + |
|
27 | + /** |
|
28 | + * Check if a filter is registered. |
|
29 | + * |
|
30 | + * @param string name |
|
31 | + * |
|
32 | + * @return bool |
|
33 | + */ |
|
34 | + public function hasFilter($name) |
|
35 | + { |
|
36 | + $helper = new FilterHelper($this->filters, $this->options['filterAutoLoad']); |
|
37 | + |
|
38 | + return $helper->hasFilter($name); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Get a registered filter by name. |
|
43 | + * |
|
44 | + * @param string name |
|
45 | + * |
|
46 | + * @return callable |
|
47 | + */ |
|
48 | + public function getFilter($name) |
|
49 | + { |
|
50 | + $helper = new FilterHelper($this->filters, $this->options['filterAutoLoad']); |
|
51 | + |
|
52 | + return $helper->getFilter($name); |
|
53 | + } |
|
54 | 54 | } |
@@ -7,36 +7,36 @@ |
||
7 | 7 | */ |
8 | 8 | abstract class MixinScanner extends CaseScanner |
9 | 9 | { |
10 | - /** |
|
11 | - * @return object |
|
12 | - */ |
|
13 | - protected function scanCall() |
|
14 | - { |
|
15 | - if (preg_match('/^\+(\w[-\w]*)/', $this->input, $matches)) { |
|
16 | - $this->consume($matches[0]); |
|
17 | - $token = $this->token('call', $matches[1]); |
|
10 | + /** |
|
11 | + * @return object |
|
12 | + */ |
|
13 | + protected function scanCall() |
|
14 | + { |
|
15 | + if (preg_match('/^\+(\w[-\w]*)/', $this->input, $matches)) { |
|
16 | + $this->consume($matches[0]); |
|
17 | + $token = $this->token('call', $matches[1]); |
|
18 | 18 | |
19 | - // check for arguments |
|
20 | - if (preg_match('/^ *\((.*?)\)/', $this->input, $matchesArguments)) { |
|
21 | - $this->consume($matchesArguments[0]); |
|
22 | - $token->arguments = $matchesArguments[1]; |
|
23 | - } |
|
19 | + // check for arguments |
|
20 | + if (preg_match('/^ *\((.*?)\)/', $this->input, $matchesArguments)) { |
|
21 | + $this->consume($matchesArguments[0]); |
|
22 | + $token->arguments = $matchesArguments[1]; |
|
23 | + } |
|
24 | 24 | |
25 | - return $token; |
|
26 | - } |
|
27 | - } |
|
25 | + return $token; |
|
26 | + } |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * @return object |
|
31 | - */ |
|
32 | - protected function scanMixin() |
|
33 | - { |
|
34 | - if (preg_match('/^mixin +(\w[-\w]*)(?: *\((.*)\))?/', $this->input, $matches)) { |
|
35 | - $this->consume($matches[0]); |
|
36 | - $token = $this->token('mixin', $matches[1]); |
|
37 | - $token->arguments = isset($matches[2]) ? $matches[2] : null; |
|
29 | + /** |
|
30 | + * @return object |
|
31 | + */ |
|
32 | + protected function scanMixin() |
|
33 | + { |
|
34 | + if (preg_match('/^mixin +(\w[-\w]*)(?: *\((.*)\))?/', $this->input, $matches)) { |
|
35 | + $this->consume($matches[0]); |
|
36 | + $token = $this->token('mixin', $matches[1]); |
|
37 | + $token->arguments = isset($matches[2]) ? $matches[2] : null; |
|
38 | 38 | |
39 | - return $token; |
|
40 | - } |
|
41 | - } |
|
39 | + return $token; |
|
40 | + } |
|
41 | + } |
|
42 | 42 | } |
@@ -7,62 +7,62 @@ |
||
7 | 7 | */ |
8 | 8 | abstract class IndentScanner extends InputHandler |
9 | 9 | { |
10 | - /** |
|
11 | - * Scan EOS from input & return it if found. |
|
12 | - * |
|
13 | - * @return object|null |
|
14 | - */ |
|
15 | - protected function scanEOS() |
|
16 | - { |
|
17 | - if (!$this->length()) { |
|
18 | - if (count($this->indentStack)) { |
|
19 | - array_shift($this->indentStack); |
|
10 | + /** |
|
11 | + * Scan EOS from input & return it if found. |
|
12 | + * |
|
13 | + * @return object|null |
|
14 | + */ |
|
15 | + protected function scanEOS() |
|
16 | + { |
|
17 | + if (!$this->length()) { |
|
18 | + if (count($this->indentStack)) { |
|
19 | + array_shift($this->indentStack); |
|
20 | 20 | |
21 | - return $this->token('outdent'); |
|
22 | - } |
|
21 | + return $this->token('outdent'); |
|
22 | + } |
|
23 | 23 | |
24 | - return $this->token('eos'); |
|
25 | - } |
|
26 | - } |
|
24 | + return $this->token('eos'); |
|
25 | + } |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * @return object |
|
30 | - */ |
|
31 | - protected function scanBlank() |
|
32 | - { |
|
33 | - if (preg_match('/^\n *\n/', $this->input, $matches)) { |
|
34 | - $this->consume(substr($matches[0], 0, -1)); // do not cosume the last \r |
|
35 | - $this->lineno++; |
|
28 | + /** |
|
29 | + * @return object |
|
30 | + */ |
|
31 | + protected function scanBlank() |
|
32 | + { |
|
33 | + if (preg_match('/^\n *\n/', $this->input, $matches)) { |
|
34 | + $this->consume(substr($matches[0], 0, -1)); // do not cosume the last \r |
|
35 | + $this->lineno++; |
|
36 | 36 | |
37 | - if ($this->pipeless) { |
|
38 | - return $this->token('text', ''); |
|
39 | - } |
|
37 | + if ($this->pipeless) { |
|
38 | + return $this->token('text', ''); |
|
39 | + } |
|
40 | 40 | |
41 | - return $this->next(); |
|
42 | - } |
|
43 | - } |
|
41 | + return $this->next(); |
|
42 | + } |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @throws \ErrorException |
|
47 | - * |
|
48 | - * @return mixed|object |
|
49 | - */ |
|
50 | - protected function scanIndent() |
|
51 | - { |
|
52 | - $matches = $this->getNextIndent(); |
|
45 | + /** |
|
46 | + * @throws \ErrorException |
|
47 | + * |
|
48 | + * @return mixed|object |
|
49 | + */ |
|
50 | + protected function scanIndent() |
|
51 | + { |
|
52 | + $matches = $this->getNextIndent(); |
|
53 | 53 | |
54 | - if ($matches !== null) { |
|
55 | - $indents = strlen($matches[1]); |
|
54 | + if ($matches !== null) { |
|
55 | + $indents = strlen($matches[1]); |
|
56 | 56 | |
57 | - $this->lineno++; |
|
58 | - $this->consume($matches[0]); |
|
59 | - $firstChar = substr($this->input, 0, 1); |
|
57 | + $this->lineno++; |
|
58 | + $this->consume($matches[0]); |
|
59 | + $firstChar = substr($this->input, 0, 1); |
|
60 | 60 | |
61 | - if ($this->length() && (' ' === $firstChar || "\t" === $firstChar)) { |
|
62 | - throw new \ErrorException('Invalid indentation, you can use tabs or spaces but not both', 20); |
|
63 | - } |
|
61 | + if ($this->length() && (' ' === $firstChar || "\t" === $firstChar)) { |
|
62 | + throw new \ErrorException('Invalid indentation, you can use tabs or spaces but not both', 20); |
|
63 | + } |
|
64 | 64 | |
65 | - return $this->getTokenFromIndent($firstChar, $indents); |
|
66 | - } |
|
67 | - } |
|
65 | + return $this->getTokenFromIndent($firstChar, $indents); |
|
66 | + } |
|
67 | + } |
|
68 | 68 | } |
@@ -7,27 +7,27 @@ |
||
7 | 7 | */ |
8 | 8 | abstract class CaseScanner extends BlockScanner |
9 | 9 | { |
10 | - /** |
|
11 | - * @return object |
|
12 | - */ |
|
13 | - protected function scanCase() |
|
14 | - { |
|
15 | - return $this->scan('/^case +([^\n]+)/', 'case'); |
|
16 | - } |
|
10 | + /** |
|
11 | + * @return object |
|
12 | + */ |
|
13 | + protected function scanCase() |
|
14 | + { |
|
15 | + return $this->scan('/^case +([^\n]+)/', 'case'); |
|
16 | + } |
|
17 | 17 | |
18 | - /** |
|
19 | - * @return object |
|
20 | - */ |
|
21 | - protected function scanWhen() |
|
22 | - { |
|
23 | - return $this->scan('/^when +((::|[^\n:]+)+)/', 'when'); |
|
24 | - } |
|
18 | + /** |
|
19 | + * @return object |
|
20 | + */ |
|
21 | + protected function scanWhen() |
|
22 | + { |
|
23 | + return $this->scan('/^when +((::|[^\n:]+)+)/', 'when'); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * @return object |
|
28 | - */ |
|
29 | - protected function scanDefault() |
|
30 | - { |
|
31 | - return $this->scan('/^default */', 'default'); |
|
32 | - } |
|
26 | + /** |
|
27 | + * @return object |
|
28 | + */ |
|
29 | + protected function scanDefault() |
|
30 | + { |
|
31 | + return $this->scan('/^default */', 'default'); |
|
32 | + } |
|
33 | 33 | } |
@@ -7,36 +7,36 @@ |
||
7 | 7 | */ |
8 | 8 | class StringAttribute |
9 | 9 | { |
10 | - protected $char; |
|
10 | + protected $char; |
|
11 | 11 | |
12 | - public function __construct($char) |
|
13 | - { |
|
14 | - $this->char = $char; |
|
15 | - } |
|
12 | + public function __construct($char) |
|
13 | + { |
|
14 | + $this->char = $char; |
|
15 | + } |
|
16 | 16 | |
17 | - public function parse(AttributesState $states, &$val, &$quote) |
|
18 | - { |
|
19 | - switch ($states->current()) { |
|
20 | - case 'key': |
|
21 | - $states->push('key char'); |
|
22 | - break; |
|
17 | + public function parse(AttributesState $states, &$val, &$quote) |
|
18 | + { |
|
19 | + switch ($states->current()) { |
|
20 | + case 'key': |
|
21 | + $states->push('key char'); |
|
22 | + break; |
|
23 | 23 | |
24 | - case 'key char': |
|
25 | - $states->pop(); |
|
26 | - break; |
|
24 | + case 'key char': |
|
25 | + $states->pop(); |
|
26 | + break; |
|
27 | 27 | |
28 | - case 'string': |
|
29 | - if ($this->char === $quote) { |
|
30 | - $states->pop(); |
|
31 | - } |
|
32 | - $val .= $this->char; |
|
33 | - break; |
|
28 | + case 'string': |
|
29 | + if ($this->char === $quote) { |
|
30 | + $states->pop(); |
|
31 | + } |
|
32 | + $val .= $this->char; |
|
33 | + break; |
|
34 | 34 | |
35 | - default: |
|
36 | - $states->push('string'); |
|
37 | - $val .= $this->char; |
|
38 | - $quote = $this->char; |
|
39 | - break; |
|
40 | - } |
|
41 | - } |
|
35 | + default: |
|
36 | + $states->push('string'); |
|
37 | + $val .= $this->char; |
|
38 | + $quote = $this->char; |
|
39 | + break; |
|
40 | + } |
|
41 | + } |
|
42 | 42 | } |
@@ -7,69 +7,69 @@ |
||
7 | 7 | */ |
8 | 8 | abstract class BlockScanner extends IndentScanner |
9 | 9 | { |
10 | - /** |
|
11 | - * @return object |
|
12 | - */ |
|
13 | - protected function scanExtends() |
|
14 | - { |
|
15 | - return $this->scan('/^extends? +([^\n]+)/', 'extends'); |
|
16 | - } |
|
10 | + /** |
|
11 | + * @return object |
|
12 | + */ |
|
13 | + protected function scanExtends() |
|
14 | + { |
|
15 | + return $this->scan('/^extends? +([^\n]+)/', 'extends'); |
|
16 | + } |
|
17 | 17 | |
18 | - /** |
|
19 | - * @return object |
|
20 | - */ |
|
21 | - protected function scanPrepend() |
|
22 | - { |
|
23 | - if (preg_match('/^prepend +([^\n]+)/', $this->input, $matches)) { |
|
24 | - $this->consume($matches[0]); |
|
25 | - $token = $this->token('block', $matches[1]); |
|
26 | - $token->mode = 'prepend'; |
|
18 | + /** |
|
19 | + * @return object |
|
20 | + */ |
|
21 | + protected function scanPrepend() |
|
22 | + { |
|
23 | + if (preg_match('/^prepend +([^\n]+)/', $this->input, $matches)) { |
|
24 | + $this->consume($matches[0]); |
|
25 | + $token = $this->token('block', $matches[1]); |
|
26 | + $token->mode = 'prepend'; |
|
27 | 27 | |
28 | - return $token; |
|
29 | - } |
|
30 | - } |
|
28 | + return $token; |
|
29 | + } |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * @return object |
|
34 | - */ |
|
35 | - protected function scanAppend() |
|
36 | - { |
|
37 | - if (preg_match('/^append +([^\n]+)/', $this->input, $matches)) { |
|
38 | - $this->consume($matches[0]); |
|
39 | - $token = $this->token('block', $matches[1]); |
|
40 | - $token->mode = 'append'; |
|
32 | + /** |
|
33 | + * @return object |
|
34 | + */ |
|
35 | + protected function scanAppend() |
|
36 | + { |
|
37 | + if (preg_match('/^append +([^\n]+)/', $this->input, $matches)) { |
|
38 | + $this->consume($matches[0]); |
|
39 | + $token = $this->token('block', $matches[1]); |
|
40 | + $token->mode = 'append'; |
|
41 | 41 | |
42 | - return $token; |
|
43 | - } |
|
44 | - } |
|
42 | + return $token; |
|
43 | + } |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @return object |
|
48 | - */ |
|
49 | - protected function scanBlock() |
|
50 | - { |
|
51 | - if (preg_match("/^block\b *(?:(prepend|append) +)?([^\n]*)/", $this->input, $matches)) { |
|
52 | - $this->consume($matches[0]); |
|
53 | - $token = $this->token('block', $matches[2]); |
|
54 | - $token->mode = strlen($matches[1]) === 0 ? 'replace' : $matches[1]; |
|
46 | + /** |
|
47 | + * @return object |
|
48 | + */ |
|
49 | + protected function scanBlock() |
|
50 | + { |
|
51 | + if (preg_match("/^block\b *(?:(prepend|append) +)?([^\n]*)/", $this->input, $matches)) { |
|
52 | + $this->consume($matches[0]); |
|
53 | + $token = $this->token('block', $matches[2]); |
|
54 | + $token->mode = strlen($matches[1]) === 0 ? 'replace' : $matches[1]; |
|
55 | 55 | |
56 | - return $token; |
|
57 | - } |
|
58 | - } |
|
56 | + return $token; |
|
57 | + } |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @return object |
|
62 | - */ |
|
63 | - protected function scanYield() |
|
64 | - { |
|
65 | - return $this->scan('/^yield */', 'yield'); |
|
66 | - } |
|
60 | + /** |
|
61 | + * @return object |
|
62 | + */ |
|
63 | + protected function scanYield() |
|
64 | + { |
|
65 | + return $this->scan('/^yield */', 'yield'); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return object |
|
70 | - */ |
|
71 | - protected function scanInclude() |
|
72 | - { |
|
73 | - return $this->scan('/^include +([^\n]+)/', 'include'); |
|
74 | - } |
|
68 | + /** |
|
69 | + * @return object |
|
70 | + */ |
|
71 | + protected function scanInclude() |
|
72 | + { |
|
73 | + return $this->scan('/^include +([^\n]+)/', 'include'); |
|
74 | + } |
|
75 | 75 | } |
@@ -9,191 +9,191 @@ |
||
9 | 9 | */ |
10 | 10 | class Attributes |
11 | 11 | { |
12 | - protected $token; |
|
13 | - |
|
14 | - public function __construct($token = null) |
|
15 | - { |
|
16 | - $this->token = $token; |
|
17 | - } |
|
18 | - |
|
19 | - protected function parseSpace($states, $escapedAttribute, &$key, &$val, $char, $previousNonBlankChar, $nextChar) |
|
20 | - { |
|
21 | - if ( |
|
22 | - in_array($states->current(), array('expr', 'array', 'string', 'object')) || |
|
23 | - ( |
|
24 | - ($char === ' ' || $char === "\t") && |
|
25 | - ( |
|
26 | - !preg_match('/^[a-zA-Z0-9_\\x7f-\\xff"\'\\]\\)\\}]$/', $previousNonBlankChar) || |
|
27 | - !preg_match('/^[a-zA-Z0-9_]$/', $nextChar) |
|
28 | - ) |
|
29 | - ) |
|
30 | - ) { |
|
31 | - $val .= $char; |
|
32 | - |
|
33 | - return; |
|
34 | - } |
|
35 | - |
|
36 | - $states->push('key'); |
|
37 | - $val = trim($val); |
|
38 | - $key = trim($key); |
|
39 | - |
|
40 | - if (empty($key)) { |
|
41 | - return; |
|
42 | - } |
|
43 | - |
|
44 | - $key = preg_replace( |
|
45 | - array('/^[\'\"]|[\'\"]$/', '/\!/'), '', $key |
|
46 | - ); |
|
47 | - $this->token->escaped[$key] = $escapedAttribute; |
|
48 | - |
|
49 | - $this->token->attributes[$key] = ('' === $val) ? true : $this->interpolate($val); |
|
50 | - |
|
51 | - $key = ''; |
|
52 | - $val = ''; |
|
53 | - } |
|
54 | - |
|
55 | - protected function replaceInterpolationsInStrings($match) |
|
56 | - { |
|
57 | - $quote = $match[1]; |
|
58 | - |
|
59 | - return str_replace('\\#{', '#{', preg_replace_callback('/(?<!\\\\)#{([^}]+)}/', function ($match) use ($quote) { |
|
60 | - return $quote . ' . ' . CommonUtils::addDollarIfNeeded(preg_replace_callback( |
|
61 | - '/(?<![a-zA-Z0-9_\$])(\$?[a-zA-Z_][a-zA-Z0-9_]*)\.([a-zA-Z_][a-zA-Z0-9_]*)(?![a-zA-Z0-9_])/', |
|
62 | - function ($match) { |
|
63 | - return CommonUtils::getGetter($match[1], $match[2]); |
|
64 | - }, |
|
65 | - $match[1] |
|
66 | - )) . ' . ' . $quote; |
|
67 | - }, $match[0])); |
|
68 | - } |
|
69 | - |
|
70 | - protected function interpolate($attr) |
|
71 | - { |
|
72 | - return preg_replace_callback('/([\'"]).*?(?<!\\\\)(?:\\\\\\\\)*\1/', array($this, 'replaceInterpolationsInStrings'), $attr); |
|
73 | - } |
|
74 | - |
|
75 | - protected function parseEqual($states, &$escapedAttribute, &$key, &$val, $char, $previousChar) |
|
76 | - { |
|
77 | - switch ($states->current()) { |
|
78 | - case 'key char': |
|
79 | - $key .= $char; |
|
80 | - break; |
|
81 | - |
|
82 | - case 'val': |
|
83 | - case 'expr': |
|
84 | - case 'array': |
|
85 | - case 'string': |
|
86 | - case 'object': |
|
87 | - $val .= $char; |
|
88 | - break; |
|
89 | - |
|
90 | - default: |
|
91 | - $escapedAttribute = '!' !== $previousChar; |
|
92 | - $states->push('val'); |
|
93 | - } |
|
94 | - } |
|
95 | - |
|
96 | - protected function parsePairs($states, $char, &$val) |
|
97 | - { |
|
98 | - switch ($char) { |
|
99 | - case '(': |
|
100 | - $states->pushFor('expr', 'val', 'expr'); |
|
101 | - break; |
|
102 | - |
|
103 | - case ')': |
|
104 | - $states->popFor('val', 'expr'); |
|
105 | - break; |
|
106 | - |
|
107 | - case '{': |
|
108 | - $states->pushFor('object', 'val'); |
|
109 | - break; |
|
110 | - |
|
111 | - case '}': |
|
112 | - $states->popFor('object'); |
|
113 | - break; |
|
114 | - |
|
115 | - case '[': |
|
116 | - $states->pushFor('array', 'val'); |
|
117 | - break; |
|
118 | - |
|
119 | - case ']': |
|
120 | - $states->popFor('array'); |
|
121 | - break; |
|
122 | - |
|
123 | - default: |
|
124 | - return false; |
|
125 | - } |
|
126 | - $val .= $char; |
|
127 | - |
|
128 | - return true; |
|
129 | - } |
|
130 | - |
|
131 | - protected function parseString(&$states, &$key, &$val, &$quote, $char) |
|
132 | - { |
|
133 | - if (($char === '"' || $char === "'") && !CommonUtils::escapedEnd($val)) { |
|
134 | - $stringParser = new StringAttribute($char); |
|
135 | - $stringParser->parse($states, $val, $quote); |
|
136 | - |
|
137 | - return; |
|
138 | - } |
|
139 | - ${in_array($states->current(), array('key', 'key char')) ? 'key' : 'val'} .= $char; |
|
140 | - } |
|
141 | - |
|
142 | - public function parseChar($char, &$nextChar, &$key, &$val, &$quote, $states, &$escapedAttribute, &$previousChar, &$previousNonBlankChar) |
|
143 | - { |
|
144 | - if ($this->parsePairs($states, $char, $val)) { |
|
145 | - return; |
|
146 | - } |
|
147 | - |
|
148 | - switch ($char) { |
|
149 | - case ',': |
|
150 | - case "\n": |
|
151 | - case "\t": |
|
152 | - case ' ': |
|
153 | - $this->parseSpace($states, $escapedAttribute, $key, $val, $char, $previousNonBlankChar, $nextChar); |
|
154 | - break; |
|
155 | - |
|
156 | - case '=': |
|
157 | - $this->parseEqual($states, $escapedAttribute, $key, $val, $char, $previousChar); |
|
158 | - break; |
|
159 | - |
|
160 | - default: |
|
161 | - $this->parseString($states, $key, $val, $quote, $char); |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - protected function getParseFunction(&$key, &$val, &$quote, $states, &$escapedAttribute, &$previousChar, &$previousNonBlankChar, $parser) |
|
166 | - { |
|
167 | - return function ($char, $nextChar = '') use (&$key, &$val, &$quote, $states, &$escapedAttribute, &$previousChar, &$previousNonBlankChar, $parser) { |
|
168 | - $parser->parseChar($char, $nextChar, $key, $val, $quote, $states, $escapedAttribute, $previousChar, $previousNonBlankChar); |
|
169 | - $previousChar = $char; |
|
170 | - if (trim($char) !== '') { |
|
171 | - $previousNonBlankChar = $char; |
|
172 | - } |
|
173 | - }; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * @return object |
|
178 | - */ |
|
179 | - public function parseWith($str) |
|
180 | - { |
|
181 | - $parser = $this; |
|
182 | - |
|
183 | - $key = ''; |
|
184 | - $val = ''; |
|
185 | - $quote = ''; |
|
186 | - $states = new AttributesState(); |
|
187 | - $escapedAttribute = ''; |
|
188 | - $previousChar = ''; |
|
189 | - $previousNonBlankChar = ''; |
|
190 | - |
|
191 | - $parse = $this->getParseFunction($key, $val, $quote, $states, $escapedAttribute, $previousChar, $previousNonBlankChar, $parser); |
|
192 | - |
|
193 | - for ($i = 0; $i < strlen($str); $i++) { |
|
194 | - $parse(substr($str, $i, 1), substr($str, $i + 1, 1)); |
|
195 | - } |
|
196 | - |
|
197 | - $parse(','); |
|
198 | - } |
|
12 | + protected $token; |
|
13 | + |
|
14 | + public function __construct($token = null) |
|
15 | + { |
|
16 | + $this->token = $token; |
|
17 | + } |
|
18 | + |
|
19 | + protected function parseSpace($states, $escapedAttribute, &$key, &$val, $char, $previousNonBlankChar, $nextChar) |
|
20 | + { |
|
21 | + if ( |
|
22 | + in_array($states->current(), array('expr', 'array', 'string', 'object')) || |
|
23 | + ( |
|
24 | + ($char === ' ' || $char === "\t") && |
|
25 | + ( |
|
26 | + !preg_match('/^[a-zA-Z0-9_\\x7f-\\xff"\'\\]\\)\\}]$/', $previousNonBlankChar) || |
|
27 | + !preg_match('/^[a-zA-Z0-9_]$/', $nextChar) |
|
28 | + ) |
|
29 | + ) |
|
30 | + ) { |
|
31 | + $val .= $char; |
|
32 | + |
|
33 | + return; |
|
34 | + } |
|
35 | + |
|
36 | + $states->push('key'); |
|
37 | + $val = trim($val); |
|
38 | + $key = trim($key); |
|
39 | + |
|
40 | + if (empty($key)) { |
|
41 | + return; |
|
42 | + } |
|
43 | + |
|
44 | + $key = preg_replace( |
|
45 | + array('/^[\'\"]|[\'\"]$/', '/\!/'), '', $key |
|
46 | + ); |
|
47 | + $this->token->escaped[$key] = $escapedAttribute; |
|
48 | + |
|
49 | + $this->token->attributes[$key] = ('' === $val) ? true : $this->interpolate($val); |
|
50 | + |
|
51 | + $key = ''; |
|
52 | + $val = ''; |
|
53 | + } |
|
54 | + |
|
55 | + protected function replaceInterpolationsInStrings($match) |
|
56 | + { |
|
57 | + $quote = $match[1]; |
|
58 | + |
|
59 | + return str_replace('\\#{', '#{', preg_replace_callback('/(?<!\\\\)#{([^}]+)}/', function ($match) use ($quote) { |
|
60 | + return $quote . ' . ' . CommonUtils::addDollarIfNeeded(preg_replace_callback( |
|
61 | + '/(?<![a-zA-Z0-9_\$])(\$?[a-zA-Z_][a-zA-Z0-9_]*)\.([a-zA-Z_][a-zA-Z0-9_]*)(?![a-zA-Z0-9_])/', |
|
62 | + function ($match) { |
|
63 | + return CommonUtils::getGetter($match[1], $match[2]); |
|
64 | + }, |
|
65 | + $match[1] |
|
66 | + )) . ' . ' . $quote; |
|
67 | + }, $match[0])); |
|
68 | + } |
|
69 | + |
|
70 | + protected function interpolate($attr) |
|
71 | + { |
|
72 | + return preg_replace_callback('/([\'"]).*?(?<!\\\\)(?:\\\\\\\\)*\1/', array($this, 'replaceInterpolationsInStrings'), $attr); |
|
73 | + } |
|
74 | + |
|
75 | + protected function parseEqual($states, &$escapedAttribute, &$key, &$val, $char, $previousChar) |
|
76 | + { |
|
77 | + switch ($states->current()) { |
|
78 | + case 'key char': |
|
79 | + $key .= $char; |
|
80 | + break; |
|
81 | + |
|
82 | + case 'val': |
|
83 | + case 'expr': |
|
84 | + case 'array': |
|
85 | + case 'string': |
|
86 | + case 'object': |
|
87 | + $val .= $char; |
|
88 | + break; |
|
89 | + |
|
90 | + default: |
|
91 | + $escapedAttribute = '!' !== $previousChar; |
|
92 | + $states->push('val'); |
|
93 | + } |
|
94 | + } |
|
95 | + |
|
96 | + protected function parsePairs($states, $char, &$val) |
|
97 | + { |
|
98 | + switch ($char) { |
|
99 | + case '(': |
|
100 | + $states->pushFor('expr', 'val', 'expr'); |
|
101 | + break; |
|
102 | + |
|
103 | + case ')': |
|
104 | + $states->popFor('val', 'expr'); |
|
105 | + break; |
|
106 | + |
|
107 | + case '{': |
|
108 | + $states->pushFor('object', 'val'); |
|
109 | + break; |
|
110 | + |
|
111 | + case '}': |
|
112 | + $states->popFor('object'); |
|
113 | + break; |
|
114 | + |
|
115 | + case '[': |
|
116 | + $states->pushFor('array', 'val'); |
|
117 | + break; |
|
118 | + |
|
119 | + case ']': |
|
120 | + $states->popFor('array'); |
|
121 | + break; |
|
122 | + |
|
123 | + default: |
|
124 | + return false; |
|
125 | + } |
|
126 | + $val .= $char; |
|
127 | + |
|
128 | + return true; |
|
129 | + } |
|
130 | + |
|
131 | + protected function parseString(&$states, &$key, &$val, &$quote, $char) |
|
132 | + { |
|
133 | + if (($char === '"' || $char === "'") && !CommonUtils::escapedEnd($val)) { |
|
134 | + $stringParser = new StringAttribute($char); |
|
135 | + $stringParser->parse($states, $val, $quote); |
|
136 | + |
|
137 | + return; |
|
138 | + } |
|
139 | + ${in_array($states->current(), array('key', 'key char')) ? 'key' : 'val'} .= $char; |
|
140 | + } |
|
141 | + |
|
142 | + public function parseChar($char, &$nextChar, &$key, &$val, &$quote, $states, &$escapedAttribute, &$previousChar, &$previousNonBlankChar) |
|
143 | + { |
|
144 | + if ($this->parsePairs($states, $char, $val)) { |
|
145 | + return; |
|
146 | + } |
|
147 | + |
|
148 | + switch ($char) { |
|
149 | + case ',': |
|
150 | + case "\n": |
|
151 | + case "\t": |
|
152 | + case ' ': |
|
153 | + $this->parseSpace($states, $escapedAttribute, $key, $val, $char, $previousNonBlankChar, $nextChar); |
|
154 | + break; |
|
155 | + |
|
156 | + case '=': |
|
157 | + $this->parseEqual($states, $escapedAttribute, $key, $val, $char, $previousChar); |
|
158 | + break; |
|
159 | + |
|
160 | + default: |
|
161 | + $this->parseString($states, $key, $val, $quote, $char); |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + protected function getParseFunction(&$key, &$val, &$quote, $states, &$escapedAttribute, &$previousChar, &$previousNonBlankChar, $parser) |
|
166 | + { |
|
167 | + return function ($char, $nextChar = '') use (&$key, &$val, &$quote, $states, &$escapedAttribute, &$previousChar, &$previousNonBlankChar, $parser) { |
|
168 | + $parser->parseChar($char, $nextChar, $key, $val, $quote, $states, $escapedAttribute, $previousChar, $previousNonBlankChar); |
|
169 | + $previousChar = $char; |
|
170 | + if (trim($char) !== '') { |
|
171 | + $previousNonBlankChar = $char; |
|
172 | + } |
|
173 | + }; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * @return object |
|
178 | + */ |
|
179 | + public function parseWith($str) |
|
180 | + { |
|
181 | + $parser = $this; |
|
182 | + |
|
183 | + $key = ''; |
|
184 | + $val = ''; |
|
185 | + $quote = ''; |
|
186 | + $states = new AttributesState(); |
|
187 | + $escapedAttribute = ''; |
|
188 | + $previousChar = ''; |
|
189 | + $previousNonBlankChar = ''; |
|
190 | + |
|
191 | + $parse = $this->getParseFunction($key, $val, $quote, $states, $escapedAttribute, $previousChar, $previousNonBlankChar, $parser); |
|
192 | + |
|
193 | + for ($i = 0; $i < strlen($str); $i++) { |
|
194 | + $parse(substr($str, $i, 1), substr($str, $i + 1, 1)); |
|
195 | + } |
|
196 | + |
|
197 | + $parse(','); |
|
198 | + } |
|
199 | 199 | } |
@@ -56,14 +56,14 @@ discard block |
||
56 | 56 | { |
57 | 57 | $quote = $match[1]; |
58 | 58 | |
59 | - return str_replace('\\#{', '#{', preg_replace_callback('/(?<!\\\\)#{([^}]+)}/', function ($match) use ($quote) { |
|
60 | - return $quote . ' . ' . CommonUtils::addDollarIfNeeded(preg_replace_callback( |
|
59 | + return str_replace('\\#{', '#{', preg_replace_callback('/(?<!\\\\)#{([^}]+)}/', function($match) use ($quote) { |
|
60 | + return $quote.' . '.CommonUtils::addDollarIfNeeded(preg_replace_callback( |
|
61 | 61 | '/(?<![a-zA-Z0-9_\$])(\$?[a-zA-Z_][a-zA-Z0-9_]*)\.([a-zA-Z_][a-zA-Z0-9_]*)(?![a-zA-Z0-9_])/', |
62 | - function ($match) { |
|
62 | + function($match) { |
|
63 | 63 | return CommonUtils::getGetter($match[1], $match[2]); |
64 | 64 | }, |
65 | 65 | $match[1] |
66 | - )) . ' . ' . $quote; |
|
66 | + )).' . '.$quote; |
|
67 | 67 | }, $match[0])); |
68 | 68 | } |
69 | 69 | |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | |
165 | 165 | protected function getParseFunction(&$key, &$val, &$quote, $states, &$escapedAttribute, &$previousChar, &$previousNonBlankChar, $parser) |
166 | 166 | { |
167 | - return function ($char, $nextChar = '') use (&$key, &$val, &$quote, $states, &$escapedAttribute, &$previousChar, &$previousNonBlankChar, $parser) { |
|
167 | + return function($char, $nextChar = '') use (&$key, &$val, &$quote, $states, &$escapedAttribute, &$previousChar, &$previousNonBlankChar, $parser) { |
|
168 | 168 | $parser->parseChar($char, $nextChar, $key, $val, $quote, $states, $escapedAttribute, $previousChar, $previousNonBlankChar); |
169 | 169 | $previousChar = $char; |
170 | 170 | if (trim($char) !== '') { |
@@ -7,39 +7,39 @@ |
||
7 | 7 | */ |
8 | 8 | class AttributesState |
9 | 9 | { |
10 | - protected $states = array('key'); |
|
11 | - |
|
12 | - public function current() |
|
13 | - { |
|
14 | - return $this->states[count($this->states) - 1]; |
|
15 | - } |
|
16 | - |
|
17 | - protected function isIn() |
|
18 | - { |
|
19 | - return in_array($this->current(), func_get_args()); |
|
20 | - } |
|
21 | - |
|
22 | - public function pop() |
|
23 | - { |
|
24 | - array_pop($this->states); |
|
25 | - } |
|
26 | - |
|
27 | - public function push($value) |
|
28 | - { |
|
29 | - array_push($this->states, $value); |
|
30 | - } |
|
31 | - |
|
32 | - public function popFor() |
|
33 | - { |
|
34 | - if (call_user_func_array(array($this, 'isIn'), func_get_args())) { |
|
35 | - $this->pop(); |
|
36 | - } |
|
37 | - } |
|
38 | - |
|
39 | - public function pushFor($value) |
|
40 | - { |
|
41 | - if (call_user_func_array(array($this, 'isIn'), array_slice(func_get_args(), 1))) { |
|
42 | - $this->push($value); |
|
43 | - } |
|
44 | - } |
|
10 | + protected $states = array('key'); |
|
11 | + |
|
12 | + public function current() |
|
13 | + { |
|
14 | + return $this->states[count($this->states) - 1]; |
|
15 | + } |
|
16 | + |
|
17 | + protected function isIn() |
|
18 | + { |
|
19 | + return in_array($this->current(), func_get_args()); |
|
20 | + } |
|
21 | + |
|
22 | + public function pop() |
|
23 | + { |
|
24 | + array_pop($this->states); |
|
25 | + } |
|
26 | + |
|
27 | + public function push($value) |
|
28 | + { |
|
29 | + array_push($this->states, $value); |
|
30 | + } |
|
31 | + |
|
32 | + public function popFor() |
|
33 | + { |
|
34 | + if (call_user_func_array(array($this, 'isIn'), func_get_args())) { |
|
35 | + $this->pop(); |
|
36 | + } |
|
37 | + } |
|
38 | + |
|
39 | + public function pushFor($value) |
|
40 | + { |
|
41 | + if (call_user_func_array(array($this, 'isIn'), array_slice(func_get_args(), 1))) { |
|
42 | + $this->push($value); |
|
43 | + } |
|
44 | + } |
|
45 | 45 | } |
@@ -8,77 +8,77 @@ |
||
8 | 8 | */ |
9 | 9 | abstract class CompilerConfig |
10 | 10 | { |
11 | - /** |
|
12 | - * @const string |
|
13 | - */ |
|
14 | - const VARNAME = '[a-zA-Z\\\\\\x7f-\\xff][a-zA-Z0-9\\\\_\\x7f-\\xff]*'; |
|
11 | + /** |
|
12 | + * @const string |
|
13 | + */ |
|
14 | + const VARNAME = '[a-zA-Z\\\\\\x7f-\\xff][a-zA-Z0-9\\\\_\\x7f-\\xff]*'; |
|
15 | 15 | |
16 | - // This pattern matches against string constants, some php keywords, number constants and a empty string |
|
17 | - // |
|
18 | - // the pattern without php escaping: |
|
19 | - // |
|
20 | - // [ \t]*((['"])(?:\\.|[^'"\\])*\g{-1}|true|false|null|[0-9]+|\b\b)[ \t]* |
|
21 | - // |
|
22 | - // pattern explained: |
|
23 | - // |
|
24 | - // [ \t]* - we ignore spaces at the beginning and at the end: useful for the recursive pattern bellow |
|
25 | - // |
|
26 | - // the first part of the unamed subpattern matches strings: |
|
27 | - // "(?:\\.|[^"\\])*" - quoted string with " |
|
28 | - // '(?:\\.|[^'\\])*' - quoted string with ' |
|
29 | - // |
|
30 | - // the rest of the pattern: |
|
31 | - // true|false|null - language constants |
|
32 | - // 0-9 - number constants |
|
33 | - // \b\b - matches a empty string: useful for a empty array |
|
34 | - /** |
|
35 | - * @const string |
|
36 | - */ |
|
37 | - const CONSTANT_VALUE = '[ \t]*("(?:\\\\.|[^"\\\\])*"|\'(?:\\\\.|[^\'\\\\])*\'|true|false|null|undefined|[0-9]+|\b\b)[ \t]*'; |
|
16 | + // This pattern matches against string constants, some php keywords, number constants and a empty string |
|
17 | + // |
|
18 | + // the pattern without php escaping: |
|
19 | + // |
|
20 | + // [ \t]*((['"])(?:\\.|[^'"\\])*\g{-1}|true|false|null|[0-9]+|\b\b)[ \t]* |
|
21 | + // |
|
22 | + // pattern explained: |
|
23 | + // |
|
24 | + // [ \t]* - we ignore spaces at the beginning and at the end: useful for the recursive pattern bellow |
|
25 | + // |
|
26 | + // the first part of the unamed subpattern matches strings: |
|
27 | + // "(?:\\.|[^"\\])*" - quoted string with " |
|
28 | + // '(?:\\.|[^'\\])*' - quoted string with ' |
|
29 | + // |
|
30 | + // the rest of the pattern: |
|
31 | + // true|false|null - language constants |
|
32 | + // 0-9 - number constants |
|
33 | + // \b\b - matches a empty string: useful for a empty array |
|
34 | + /** |
|
35 | + * @const string |
|
36 | + */ |
|
37 | + const CONSTANT_VALUE = '[ \t]*("(?:\\\\.|[^"\\\\])*"|\'(?:\\\\.|[^\'\\\\])*\'|true|false|null|undefined|[0-9]+|\b\b)[ \t]*'; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @const string |
|
41 | - */ |
|
42 | - const ESCAPED = 'echo \\Jade\\Compiler::getEscapedValue(%s, %s)'; |
|
39 | + /** |
|
40 | + * @const string |
|
41 | + */ |
|
42 | + const ESCAPED = 'echo \\Jade\\Compiler::getEscapedValue(%s, %s)'; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @const string |
|
46 | - */ |
|
47 | - const UNESCAPED = 'echo \\Jade\\Compiler::getUnescapedValue(%s)'; |
|
44 | + /** |
|
45 | + * @const string |
|
46 | + */ |
|
47 | + const UNESCAPED = 'echo \\Jade\\Compiler::getUnescapedValue(%s)'; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @var array |
|
51 | - */ |
|
52 | - protected $doctypes = array( |
|
53 | - '5' => '<!DOCTYPE html>', |
|
54 | - 'html' => '<!DOCTYPE html>', |
|
55 | - 'default' => '<!DOCTYPE html>', |
|
56 | - 'transitional' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', |
|
57 | - 'strict' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">', |
|
58 | - 'frameset' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">', |
|
59 | - '1.1' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">', |
|
60 | - 'basic' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">', |
|
61 | - 'mobile' => '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">', |
|
62 | - 'xml' => '<<?php echo \'?xml version="1.0" encoding="utf-8" ?\'; ?>>', |
|
63 | - ); |
|
49 | + /** |
|
50 | + * @var array |
|
51 | + */ |
|
52 | + protected $doctypes = array( |
|
53 | + '5' => '<!DOCTYPE html>', |
|
54 | + 'html' => '<!DOCTYPE html>', |
|
55 | + 'default' => '<!DOCTYPE html>', |
|
56 | + 'transitional' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', |
|
57 | + 'strict' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">', |
|
58 | + 'frameset' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">', |
|
59 | + '1.1' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">', |
|
60 | + 'basic' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">', |
|
61 | + 'mobile' => '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">', |
|
62 | + 'xml' => '<<?php echo \'?xml version="1.0" encoding="utf-8" ?\'; ?>>', |
|
63 | + ); |
|
64 | 64 | |
65 | - /** |
|
66 | - * @var array |
|
67 | - */ |
|
68 | - protected $selfClosing = array('meta', 'img', 'link', 'input', 'source', 'area', 'base', 'col', 'br', 'hr'); |
|
65 | + /** |
|
66 | + * @var array |
|
67 | + */ |
|
68 | + protected $selfClosing = array('meta', 'img', 'link', 'input', 'source', 'area', 'base', 'col', 'br', 'hr'); |
|
69 | 69 | |
70 | - /** |
|
71 | - * @var array |
|
72 | - */ |
|
73 | - protected $phpKeywords = array('true', 'false', 'null', 'switch', 'case', 'default', 'endswitch', 'if', 'elseif', 'else', 'endif', 'while', 'endwhile', 'do', 'for', 'endfor', 'foreach', 'endforeach', 'as', 'unless'); |
|
70 | + /** |
|
71 | + * @var array |
|
72 | + */ |
|
73 | + protected $phpKeywords = array('true', 'false', 'null', 'switch', 'case', 'default', 'endswitch', 'if', 'elseif', 'else', 'endif', 'while', 'endwhile', 'do', 'for', 'endfor', 'foreach', 'endforeach', 'as', 'unless'); |
|
74 | 74 | |
75 | - /** |
|
76 | - * @var array |
|
77 | - */ |
|
78 | - protected $phpOpenBlock = array('switch', 'if', 'else if', 'elseif', 'else', 'while', 'do', 'foreach', 'for', 'unless'); |
|
75 | + /** |
|
76 | + * @var array |
|
77 | + */ |
|
78 | + protected $phpOpenBlock = array('switch', 'if', 'else if', 'elseif', 'else', 'while', 'do', 'foreach', 'for', 'unless'); |
|
79 | 79 | |
80 | - /** |
|
81 | - * @var array |
|
82 | - */ |
|
83 | - protected $phpCloseBlock = array('endswitch', 'endif', 'endwhile', 'endfor', 'endforeach'); |
|
80 | + /** |
|
81 | + * @var array |
|
82 | + */ |
|
83 | + protected $phpCloseBlock = array('endswitch', 'endif', 'endwhile', 'endfor', 'endforeach'); |
|
84 | 84 | } |