File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed
tests/Fixtures/templates/tags Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change 21
21
* @internal
22
22
*
23
23
* thanks to @giorgiopogliani for the inspiration on this lexer <3
24
+ *
24
25
* @see https://github.com/giorgiopogliani/twig-components
25
26
*/
26
27
class ComponentLexer extends Lexer
27
28
{
29
+ public const ATTRIBUTES_REGEX = '(?<attributes>(?:\s+[\w\-:.@]+(=(?:"[^"]*"| \'[^ \']* \'|[^ \'\\\"=<>]+))?)*\s*) ' ;
30
+ public const OPEN_TAGS_REGEX = '/<\s*t:(?<name>([[\w\-\:\.]+))\s* ' .self ::ATTRIBUTES_REGEX .'(\s?)+>/ ' ;
31
+ public const CLOSE_TAGS_REGEX = '/<\/\s*t:([\w\-\:\.]+)\s*>/ ' ;
32
+ public const SELF_CLOSE_TAGS_REGEX = '/<\s*t:(?<name>([\w\-\:\.]+))\s* ' .self ::ATTRIBUTES_REGEX .'(\s?)+\/>/ ' ;
33
+ public const BLOCK_TAGS_OPEN = '/<\s*t:block\s+name=("| \')(?<name>([\w\-\:\.]+))("| \')\s*>/ ' ;
34
+ public const BLOCK_TAGS_CLOSE = '/<\s*\/\s*t:block\s*>/ ' ;
35
+ public const ATTRIBUTE_BAG_REGEX = '/(?:^|\s+)\{\{\s*(attributes(?:.+?(?<!\s))?)\s*\}\}/x ' ;
36
+ public const ATTRIBUTE_KEY_VALUE_REGEX = '/(?<attribute>[\w\-:.@]+)(=(?<value>(\"[^\"]+\"| \\\'[^ \\\']+ \\\'|[^\s>]+)))?/x ' ;
37
+
28
38
public function tokenize (Source $ source ): TokenStream
29
39
{
30
40
$ preLexer = new TwigPreLexer ();
Original file line number Diff line number Diff line change 1
- <t:component _a propA propB =' hello' >
1
+ <t:component _a propA propB =" hello" >
2
2
</t:component _a>
You can’t perform that action at this time.
0 commit comments