diff --git a/src/Latte/Compiler/TagLexer.php b/src/Latte/Compiler/TagLexer.php index 710b603e2..5749f602c 100644 --- a/src/Latte/Compiler/TagLexer.php +++ b/src/Latte/Compiler/TagLexer.php @@ -120,7 +120,7 @@ private function tokenizeCode(): void (? \\ (?&label) ( \\ (?&label) )* )| (? (?&label) ( \\ (?&label) )+ )| (? (?&label) (?= [ \t\r\n]* [(&=] ) )| - (? (?&label)((--?|\.)[a-zA-Z0-9_\x80-\xff]+)* )| + (? (?&label)((--?|\.|\+)[a-zA-Z0-9_\x80-\xff]+)* )| ( ( (? -> )| diff --git a/src/Latte/Compiler/TemplateParser.php b/src/Latte/Compiler/TemplateParser.php index 279ee6406..d35f58901 100644 --- a/src/Latte/Compiler/TemplateParser.php +++ b/src/Latte/Compiler/TemplateParser.php @@ -408,6 +408,16 @@ public function getContentType(): string return $this->contentType; } + + /** + * Sets tag syntax for lexer + */ + public function setSyntax(?string $syntax): static + { + $this->lexer->setSyntax($syntax); + return $this; + } + /** @internal */ public function getStream(): TokenStream diff --git a/src/Latte/Engine.php b/src/Latte/Engine.php index eb2688a3b..8b4e617d6 100644 --- a/src/Latte/Engine.php +++ b/src/Latte/Engine.php @@ -51,6 +51,7 @@ class Engine private ?string $phpBinary = null; private ?string $cacheKey; private ?string $locale = null; + private ?string $defaultSyntax = null; public function __construct() @@ -148,6 +149,9 @@ public function compile(string $name): string public function parse(string $template): TemplateNode { $parser = new Compiler\TemplateParser; + if ($this->defaultSyntax) { + $parser->setSyntax($this->defaultSyntax); + } $parser->strict = $this->strictParsing; foreach ($this->extensions as $extension) { @@ -565,6 +569,16 @@ public function isStrictParsing(): bool return $this->strictParsing; } + + /** + * Sets default tag syntax + */ + public function setDefaultSyntax(?string $defaultSyntax): static + { + $this->defaultSyntax = $defaultSyntax; + return $this; + } + /** * Sets the locale. It uses the same identifiers as the PHP intl extension. diff --git a/tests/phpPrint/unquotedStrings.phpt b/tests/phpPrint/unquotedStrings.phpt index 9f36af4d8..dd06168b2 100644 --- a/tests/phpPrint/unquotedStrings.phpt +++ b/tests/phpPrint/unquotedStrings.phpt @@ -18,8 +18,8 @@ $test = <<<'XX' a-b-c, a--b--c, - /* dots */ - a.b, + /* special chars */ + a.b+c, a . b, /* usage */ @@ -43,7 +43,7 @@ __halt_compiler(); MD5, 'a-b-c', 'a--b--c', -'a.b', +'a.b+c', 'a' . 'b', 'a-b.c-d', a.b(),