Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to set default syntax from Latte\Engine #359

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion src/Latte/Compiler/TagLexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private function tokenizeCode(): void
(?<Php_NameFullyQualified> \\ (?&label) ( \\ (?&label) )* )|
(?<Php_NameQualified> (?&label) ( \\ (?&label) )+ )|
(?<Php_IdentifierFollowed> (?&label) (?= [ \t\r\n]* [(&=] ) )|
(?<Php_Identifier> (?&label)((--?|\.)[a-zA-Z0-9_\x80-\xff]+)* )|
(?<Php_Identifier> (?&label)((--?|\.|\+)[a-zA-Z0-9_\x80-\xff]+)* )|
(
(
(?<Php_ObjectOperator> -> )|
Expand Down
10 changes: 10 additions & 0 deletions src/Latte/Compiler/TemplateParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/Latte/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Engine
private ?string $phpBinary = null;
private ?string $cacheKey;
private ?string $locale = null;
private ?string $defaultSyntax = null;


public function __construct()
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions tests/phpPrint/unquotedStrings.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ $test = <<<'XX'
a-b-c,
a--b--c,

/* dots */
a.b,
/* special chars */
a.b+c,
a . b,

/* usage */
Expand All @@ -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(),
Expand Down