Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationLatte
      • ApplicationTracy
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsLatte
      • Framework
      • HttpTracy
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Drivers
      • Reflection
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Templating
    • Utils
  • NetteModule
  • none
  • Tracy

Classes

  • Compiler
  • Engine
  • HtmlNode
  • MacroNode
  • MacroTokens
  • Object
  • Parser
  • PhpWriter
  • Token

Interfaces

  • ILoader
  • IMacro

Exceptions

  • CompileException
  • RegexpException
  • RuntimeException
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Other releases
  • Nette homepage
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Latte (https://latte.nette.org)
  5:  * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
  6:  */
  7: 
  8: namespace Latte;
  9: 
 10: 
 11: /**
 12:  * Macro tag tokenizer.
 13:  *
 14:  * @author     David Grudl
 15:  */
 16: class MacroTokens extends TokenIterator
 17: {
 18:     const T_WHITESPACE = 1,
 19:         T_COMMENT = 2,
 20:         T_SYMBOL = 3,
 21:         T_NUMBER = 4,
 22:         T_VARIABLE = 5,
 23:         T_STRING = 6,
 24:         T_CAST = 7,
 25:         T_KEYWORD = 8,
 26:         T_CHAR = 9;
 27: 
 28:     /** @var Tokenizer */
 29:     private static $tokenizer;
 30: 
 31:     /** @var int */
 32:     public $depth = 0;
 33: 
 34: 
 35:     public function __construct($input = NULL)
 36:     {
 37:         parent::__construct(is_array($input) ? $input : $this->parse($input));
 38:         $this->ignored = array(self::T_COMMENT, self::T_WHITESPACE);
 39:     }
 40: 
 41: 
 42:     public function parse($s)
 43:     {
 44:         self::$tokenizer = self::$tokenizer ?: new Tokenizer(array(
 45:             self::T_WHITESPACE => '\s+',
 46:             self::T_COMMENT => '(?s)/\*.*?\*/',
 47:             self::T_STRING => Parser::RE_STRING,
 48:             self::T_KEYWORD => '(?:true|false|null|and|or|xor|clone|new|instanceof|return|continue|break|[A-Z_][A-Z0-9_]{2,})(?![\w\pL_])', // keyword or const
 49:             self::T_CAST => '\((?:expand|string|array|int|integer|float|bool|boolean|object)\)', // type casting
 50:             self::T_VARIABLE => '\$[\w\pL_]+',
 51:             self::T_NUMBER => '[+-]?[0-9]+(?:\.[0-9]+)?(?:e[0-9]+)?',
 52:             self::T_SYMBOL => '[\w\pL_]+(?:-[\w\pL_]+)*',
 53:             self::T_CHAR => '::|=>|->|\+\+|--|<<|>>|<=|>=|===|!==|==|!=|<>|&&|\|\||[^"\']', // =>, any char except quotes
 54:         ), 'u');
 55:         return self::$tokenizer->tokenize($s);
 56:     }
 57: 
 58: 
 59:     /**
 60:      * Appends simple token or string (will be parsed).
 61:      * @return self
 62:      */
 63:     public function append($val, $position = NULL)
 64:     {
 65:         if ($val != NULL) { // intentionally @
 66:             array_splice(
 67:                 $this->tokens,
 68:                 $position === NULL ? count($this->tokens) : $position, 0,
 69:                 is_array($val) ? array($val) : $this->parse($val)
 70:             );
 71:         }
 72:         return $this;
 73:     }
 74: 
 75: 
 76:     /**
 77:      * Prepends simple token or string (will be parsed).
 78:      * @return self
 79:      */
 80:     public function prepend($val)
 81:     {
 82:         if ($val != NULL) { // intentionally @
 83:             array_splice($this->tokens, 0, 0, is_array($val) ? array($val) : $this->parse($val));
 84:         }
 85:         return $this;
 86:     }
 87: 
 88: 
 89:     /**
 90:      * Reads single token (optionally delimited by comma) from string.
 91:      * @param  string
 92:      * @return string
 93:      */
 94:     public function fetchWord()
 95:     {
 96:         $words = $this->fetchWords();
 97:         return $words ? implode(':', $words) : FALSE;
 98:     }
 99: 
100: 
101:     /**
102:      * Reads single tokens delimited by colon from string.
103:      * @param  string
104:      * @return array
105:      */
106:     public function fetchWords()
107:     {
108:         do {
109:             $words[] = $this->joinUntil(self::T_WHITESPACE, ',', ':');
110:         } while ($this->nextToken(':'));
111:         $this->nextToken(',');
112:         $this->nextAll(self::T_WHITESPACE, self::T_COMMENT);
113:         return $words === array('') ? array() : $words;
114:     }
115: 
116: 
117:     public function reset()
118:     {
119:         $this->depth = 0;
120:         return parent::reset();
121:     }
122: 
123: 
124:     protected function next()
125:     {
126:         parent::next();
127:         if ($this->isCurrent('[', '(', '{')) {
128:             $this->depth++;
129:         } elseif ($this->isCurrent(']', ')', '}')) {
130:             $this->depth--;
131:         }
132:     }
133: 
134: }
135: 
Nette 2.2 API documentation generated by ApiGen 2.8.0