mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-15 22:13:13 +00:00
initial import
This commit is contained in:
22
lib/classes/Twig/Grammar/Arguments.php
Executable file
22
lib/classes/Twig/Grammar/Arguments.php
Executable file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Grammar_Arguments extends Twig_Grammar
|
||||
{
|
||||
public function __toString()
|
||||
{
|
||||
return sprintf('<%s:arguments>', $this->name);
|
||||
}
|
||||
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
return $this->parser->getExpressionParser()->parseArguments();
|
||||
}
|
||||
}
|
22
lib/classes/Twig/Grammar/Array.php
Executable file
22
lib/classes/Twig/Grammar/Array.php
Executable file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Grammar_Array extends Twig_Grammar
|
||||
{
|
||||
public function __toString()
|
||||
{
|
||||
return sprintf('<%s:array>', $this->name);
|
||||
}
|
||||
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
return $this->parser->getExpressionParser()->parseArrayExpression();
|
||||
}
|
||||
}
|
39
lib/classes/Twig/Grammar/Body.php
Executable file
39
lib/classes/Twig/Grammar/Body.php
Executable file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Grammar_Body extends Twig_Grammar
|
||||
{
|
||||
protected $end;
|
||||
|
||||
public function __construct($name, $end = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->end = null === $end ? 'end'.$name : $end;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return sprintf('<%s:body>', $this->name);
|
||||
}
|
||||
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$stream = $this->parser->getStream();
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
return $this->parser->subparse(array($this, 'decideBlockEnd'), true);
|
||||
}
|
||||
|
||||
public function decideBlockEnd($token)
|
||||
{
|
||||
return $token->test($this->end);
|
||||
}
|
||||
}
|
24
lib/classes/Twig/Grammar/Boolean.php
Executable file
24
lib/classes/Twig/Grammar/Boolean.php
Executable file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Grammar_Boolean extends Twig_Grammar
|
||||
{
|
||||
public function __toString()
|
||||
{
|
||||
return sprintf('<%s:boolean>', $this->name);
|
||||
}
|
||||
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$this->parser->getStream()->expect(Twig_Token::NAME_TYPE, array('true', 'false'));
|
||||
|
||||
return new Twig_Node_Expression_Constant('true' === $token->getValue() ? true : false, $token->getLine());
|
||||
}
|
||||
}
|
24
lib/classes/Twig/Grammar/Constant.php
Executable file
24
lib/classes/Twig/Grammar/Constant.php
Executable file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Grammar_Constant extends Twig_Grammar
|
||||
{
|
||||
public function __toString()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$this->parser->getStream()->expect($this->name);
|
||||
|
||||
return $this->name;
|
||||
}
|
||||
}
|
22
lib/classes/Twig/Grammar/Expression.php
Executable file
22
lib/classes/Twig/Grammar/Expression.php
Executable file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Grammar_Expression extends Twig_Grammar
|
||||
{
|
||||
public function __toString()
|
||||
{
|
||||
return sprintf('<%s>', $this->name);
|
||||
}
|
||||
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
return $this->parser->getExpressionParser()->parseExpression();
|
||||
}
|
||||
}
|
24
lib/classes/Twig/Grammar/Number.php
Executable file
24
lib/classes/Twig/Grammar/Number.php
Executable file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Grammar_Number extends Twig_Grammar
|
||||
{
|
||||
public function __toString()
|
||||
{
|
||||
return sprintf('<%s:number>', $this->name);
|
||||
}
|
||||
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$this->parser->getStream()->expect(Twig_Token::NUMBER_TYPE);
|
||||
|
||||
return new Twig_Node_Expression_Constant($token->getValue(), $token->getLine());
|
||||
}
|
||||
}
|
64
lib/classes/Twig/Grammar/Optional.php
Executable file
64
lib/classes/Twig/Grammar/Optional.php
Executable file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Grammar_Optional extends Twig_Grammar
|
||||
{
|
||||
protected $grammar;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->grammar = array();
|
||||
foreach (func_get_args() as $grammar) {
|
||||
$this->addGrammar($grammar);
|
||||
}
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$repr = array();
|
||||
foreach ($this->grammar as $grammar) {
|
||||
$repr[] = (string) $grammar;
|
||||
}
|
||||
|
||||
return sprintf('[%s]', implode(' ', $repr));
|
||||
}
|
||||
|
||||
public function addGrammar(Twig_GrammarInterface $grammar)
|
||||
{
|
||||
$this->grammar[] = $grammar;
|
||||
}
|
||||
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
// test if we have the optional element before consuming it
|
||||
if ($this->grammar[0] instanceof Twig_Grammar_Constant) {
|
||||
if (!$this->parser->getStream()->test($this->grammar[0]->getName())) {
|
||||
return array();
|
||||
}
|
||||
} elseif ($this->grammar[0] instanceof Twig_Grammar_Name) {
|
||||
if (!$this->parser->getStream()->test(Twig_Token::NAME_TYPE)) {
|
||||
return array();
|
||||
}
|
||||
} elseif ($this->parser->getStream()->test(Twig_Token::BLOCK_END_TYPE)) {
|
||||
// if this is not a Constant or a Name, it must be the last element of the tag
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
$elements = array();
|
||||
foreach ($this->grammar as $grammar) {
|
||||
$grammar->setParser($this->parser);
|
||||
|
||||
$elements[$grammar->getName()] = $grammar->parse($token);
|
||||
}
|
||||
|
||||
return $elements;
|
||||
}
|
||||
}
|
24
lib/classes/Twig/Grammar/Switch.php
Normal file
24
lib/classes/Twig/Grammar/Switch.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Grammar_Switch extends Twig_Grammar
|
||||
{
|
||||
public function __toString()
|
||||
{
|
||||
return sprintf('<%s:switch>', $this->name);
|
||||
}
|
||||
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$this->parser->getStream()->expect(Twig_Token::NAME_TYPE, $this->name);
|
||||
|
||||
return new Twig_Node_Expression_Constant(true, $token->getLine());
|
||||
}
|
||||
}
|
56
lib/classes/Twig/Grammar/Tag.php
Executable file
56
lib/classes/Twig/Grammar/Tag.php
Executable file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Grammar_Tag extends Twig_Grammar
|
||||
{
|
||||
protected $grammar;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->grammar = array();
|
||||
foreach (func_get_args() as $grammar) {
|
||||
$this->addGrammar($grammar);
|
||||
}
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$repr = array();
|
||||
foreach ($this->grammar as $grammar) {
|
||||
$repr[] = (string) $grammar;
|
||||
}
|
||||
|
||||
return implode(' ', $repr);
|
||||
}
|
||||
|
||||
public function addGrammar(Twig_GrammarInterface $grammar)
|
||||
{
|
||||
$this->grammar[] = $grammar;
|
||||
}
|
||||
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$elements = array();
|
||||
foreach ($this->grammar as $grammar) {
|
||||
$grammar->setParser($this->parser);
|
||||
|
||||
$element = $grammar->parse($token);
|
||||
if (is_array($element)) {
|
||||
$elements = array_merge($elements, $element);
|
||||
} else {
|
||||
$elements[$grammar->getName()] = $element;
|
||||
}
|
||||
}
|
||||
|
||||
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
return $elements;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user