Skip to content

Commit f5f14fe

Browse files
authored
Merge branch 'webmamba/new_syntax_for_twig_component' into refactor-twig-component-syntax
2 parents aa3b7cf + 01df60f commit f5f14fe

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/TwigComponent/src/Twig/ComponentLexer.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,20 @@
2121
* @internal
2222
*
2323
* thanks to @giorgiopogliani for the inspiration on this lexer <3
24+
*
2425
* @see https://github.com/giorgiopogliani/twig-components
2526
*/
2627
class ComponentLexer extends Lexer
2728
{
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+
2838
public function tokenize(Source $source): TokenStream
2939
{
3040
$preLexer = new TwigPreLexer();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
<t:component_a propA propB='hello'>
1+
<t:component_a propA propB="hello">
22
</t:component_a>

0 commit comments

Comments
 (0)