PEEL Shopping
Open source ecommerce : PEEL Shopping
TokenStream.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of Twig.
5  *
6  * (c) 2009 Fabien Potencier
7  * (c) 2009 Armin Ronacher
8  *
9  * For the full copyright and license information, please view the LICENSE
10  * file that was distributed with this source code.
11  */
12 
19 {
20  protected $tokens;
21  protected $current;
22  protected $filename;
23 
30  public function __construct(array $tokens, $filename = null)
31  {
32  $this->tokens = $tokens;
33  $this->current = 0;
34  $this->filename = $filename;
35  }
36 
42  public function __toString()
43  {
44  return implode("\n", $this->tokens);
45  }
46 
47  public function injectTokens(array $tokens)
48  {
49  $this->tokens = array_merge(array_slice($this->tokens, 0, $this->current), $tokens, array_slice($this->tokens, $this->current));
50  }
51 
57  public function next()
58  {
59  if (!isset($this->tokens[++$this->current])) {
60  throw new Twig_Error_Syntax('Unexpected end of template', $this->tokens[$this->current - 1]->getLine(), $this->filename);
61  }
62 
63  return $this->tokens[$this->current - 1];
64  }
65 
71  public function expect($type, $value = null, $message = null)
72  {
73  $token = $this->tokens[$this->current];
74  if (!$token->test($type, $value)) {
75  $line = $token->getLine();
76  throw new Twig_Error_Syntax(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s)',
77  $message ? $message.'. ' : '',
78  Twig_Token::typeToEnglish($token->getType(), $line), $token->getValue(),
79  Twig_Token::typeToEnglish($type, $line), $value ? sprintf(' with value "%s"', $value) : ''),
80  $line,
81  $this->filename
82  );
83  }
84  $this->next();
85 
86  return $token;
87  }
88 
96  public function look($number = 1)
97  {
98  if (!isset($this->tokens[$this->current + $number])) {
99  throw new Twig_Error_Syntax('Unexpected end of template', $this->tokens[$this->current + $number - 1]->getLine(), $this->filename);
100  }
101 
102  return $this->tokens[$this->current + $number];
103  }
104 
110  public function test($primary, $secondary = null)
111  {
112  return $this->tokens[$this->current]->test($primary, $secondary);
113  }
114 
120  public function isEOF()
121  {
122  return $this->tokens[$this->current]->getType() === Twig_Token::EOF_TYPE;
123  }
124 
130  public function getCurrent()
131  {
132  return $this->tokens[$this->current];
133  }
134 
140  public function getFilename()
141  {
142  return $this->filename;
143  }
144 }
next()
Sets the pointer to the next token and returns the old one.
Definition: TokenStream.php:57
isEOF()
Checks if end of stream was reached.
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:18
look($number=1)
Looks at the next token.
Definition: TokenStream.php:96
static typeToEnglish($type, $line=-1)
Returns the english representation of a given type.
Definition: Token.php:185
injectTokens(array $tokens)
Definition: TokenStream.php:47
Represents a token stream.
Definition: TokenStream.php:18
expect($type, $value=null, $message=null)
Tests a token and returns it or throws a syntax error.
Definition: TokenStream.php:71
getFilename()
Gets the filename associated with this stream.
test($primary, $secondary=null)
Tests the current token.
__construct(array $tokens, $filename=null)
Constructor.
Definition: TokenStream.php:30
getCurrent()
Gets the current token.
__toString()
Returns a string representation of the token stream.
Definition: TokenStream.php:42
const EOF_TYPE
Definition: Token.php:24

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:41:19 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.