| [ Index ] |
PHP Cross Reference of Akelos Framework |
[Summary view] [Print] [Text view]
1 <?php 2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 3 4 // +----------------------------------------------------------------------+ 5 // | Akelos Framework - http://www.akelos.org | 6 // +----------------------------------------------------------------------+ 7 // | Copyright (c) 2002-2007, Akelos Media, S.L. & Bermi Ferrer Martinez | 8 // | Released under the GNU Lesser General Public License, see LICENSE.txt| 9 // +----------------------------------------------------------------------+ 10 11 /** 12 * @package ActionView 13 * @subpackage Sintags 14 * @author Bermi Ferrer <bermi a.t akelos c.om> 15 * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org 16 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html> 17 */ 18 19 class AkSintagsLexer extends AkLexer 20 { 21 var $_SINTAGS_REMOVE_PHP_SILENTLY = AK_SINTAGS_REMOVE_PHP_SILENTLY; 22 var $_SINTAGS_HIDDEN_COMMENTS_TAG = AK_SINTAGS_HIDDEN_COMMENTS_TAG; 23 24 var $_SINTAGS_OPEN_HELPER_TAG = AK_SINTAGS_OPEN_HELPER_TAG; 25 var $_SINTAGS_CLOSE_HELPER_TAG = AK_SINTAGS_CLOSE_HELPER_TAG; 26 27 var $_modes = array( 28 'Xml', 29 'Php', 30 'Comment', 31 'Block', 32 'Helper', 33 'EscapedText', 34 'Translation', 35 'VariableTranslation', 36 'EndTag', 37 'ElseTag', 38 'ConditionStart', 39 'ConditionalVariable', 40 'Variable', 41 'Loop', 42 'LoopAs', 43 'Helper', 44 'InlineHelper', 45 ); 46 47 function AkSintagsLexer(&$parser) 48 { 49 $this->AkLexer($parser, 'Text'); 50 $this->mapHandler('Text', 'Text'); 51 foreach ($this->_modes as $mode){ 52 $this->{'_add'.$mode.'Tokens'}(); 53 } 54 } 55 56 function _addXmlTokens() 57 { 58 $this->addSpecialPattern('<\?xml','Text','XmlOpening'); 59 } 60 61 function _addPhpTokens() 62 { 63 if(!$this->_SINTAGS_REMOVE_PHP_SILENTLY){ 64 $this->addEntryPattern('<\?','Text','PhpCode'); 65 $this->addExitPattern('\?>','PhpCode'); 66 }else{ 67 $this->mapHandler('php', 'ignore'); 68 $this->addEntryPattern('<\?', 'Text', 'php'); 69 $this->addExitPattern('\?>', 'php'); 70 } 71 } 72 73 function _addCommentTokens() 74 { 75 if(!empty($this->_SINTAGS_HIDDEN_COMMENTS_TAG)){ 76 $this->mapHandler('comment', 'ignore'); 77 $this->addEntryPattern("<$this->_SINTAGS_HIDDEN_COMMENTS_TAG>", 'Text', 'comment'); 78 $this->addExitPattern("</$this->_SINTAGS_HIDDEN_COMMENTS_TAG>", 'comment'); 79 } 80 } 81 82 function _addEscapedTextTokens() 83 { 84 $this->addSpecialPattern('\x5C_(?={)','Text','EscapedText'); 85 } 86 87 function _addTranslationTokens() 88 { 89 $this->addEntryPattern('_{','Text','Translation'); 90 $this->addExitPattern('}','Translation'); 91 92 $this->addSpecialPattern('\x5C?\x25[A-Za-z][\.A-Za-z0-9_-]*','Translation','TranslationToken'); 93 } 94 95 function _addVariableTranslationTokens() 96 { 97 $this->addSpecialPattern('{_[A-Za-z][\.A-Za-z0-9_-]*}','Text','VariableTranslation'); 98 } 99 100 function _addVariableTokens() 101 { 102 $this->addSpecialPattern('{[A-Za-z][\.A-Za-z0-9_-]*}','Text','Variable'); 103 } 104 105 function _addConditionalVariableTokens() 106 { 107 $this->addSpecialPattern('{[A-Za-z][\.A-Za-z0-9_-]*\?}','Text','ConditionalVariable'); 108 } 109 110 function _addConditionStartTokens() 111 { 112 $this->addSpecialPattern('{[\?!][A-Za-z][\.A-Za-z0-9_-]*}','Text','ConditionStart'); 113 } 114 115 function _addEndTagTokens() 116 { 117 $this->addSpecialPattern('{end}','Text','EndTag'); 118 } 119 120 function _addElseTagTokens() 121 { 122 $this->addSpecialPattern('{else}','Text','ElseTag'); 123 } 124 125 function _addLoopTokens() 126 { 127 $this->addSpecialPattern('{loop[ \n\t]+[A-Za-z][\.A-Za-z0-9_-]*\??}','Text','Loop'); 128 } 129 130 function _addLoopAsTokens() 131 { 132 $this->addSpecialPattern('{loop[ \n\t]+[A-Za-z][\.A-Za-z0-9_-]+[ \n\t]+as[ \n\t]+[A-Za-z][\.A-Za-z0-9_-]*\??}','Text','Loop'); 133 } 134 135 function _addBlockTokens() 136 { 137 if(!$this->_SINTAGS_REMOVE_PHP_SILENTLY){ 138 $this->addEntryPattern($this->_SINTAGS_OPEN_HELPER_TAG.'[ \n\t]*[A-Za-z][\.A-Za-z0-9_ ,=-]*[ \n\t]*\x7B[ \n\t]*\x7c','Text', 'Block'); 139 $this->addPattern('[A-Za-z0-9_, \n\t\x7c]+[ \n\t]*\x7c','Block'); 140 $this->addExitPattern('\x7D[ \n\t]*'.$this->_SINTAGS_CLOSE_HELPER_TAG, 'Block'); 141 }else{ 142 $this->mapHandler('php', 'ignore'); 143 $this->addEntryPattern($this->_SINTAGS_OPEN_HELPER_TAG.'[ \n\t]*[A-Za-z][\.A-Za-z0-9_ ,=-]*[ \n\t]*\x7B[ \n\t]*\x7c','Text', 'ignore'); 144 $this->addPattern('[A-Za-z0-9_, \n\t\x7c]+[ \n\t]*\x7c','ignore'); 145 $this->addExitPattern('\x7D[ \n\t]*'.$this->_SINTAGS_CLOSE_HELPER_TAG, 'ignore'); 146 } 147 148 149 150 151 } 152 153 function _addHelperTokens() 154 { 155 $this->addEntryPattern($this->_SINTAGS_OPEN_HELPER_TAG.'\x3D?[ \n\t]*[A-Za-z0-9_]+[ \n\t\x3D]*\x28?[ \n\t]*'. 156 '(?=.*'.$this->_SINTAGS_CLOSE_HELPER_TAG.')','Text','Helper'); 157 $this->addExitPattern('\x29?[ \n\t]*'.$this->_SINTAGS_CLOSE_HELPER_TAG, 'Helper'); 158 159 $this->addSpecialPattern('#{[A-Za-z][\.A-Za-z0-9_-]*}','DoubleQuote','InlineVariable'); 160 161 $this->addEntryPattern('#{[ \n\t]*[A-Za-z0-9_]+[ \n\t]*\x28?[ \n\t]*(?=.*})','DoubleQuote','InlineHelper'); 162 $this->addExitPattern('[ \n\t]*}', 'InlineHelper'); 163 $this->_addSintagsHelperParametersForScope('InlineHelper'); 164 165 $this->_addSintagsHelperParametersForScope('Helper'); 166 $this->_addSintagsHelperParametersForScope('Hash'); 167 $this->_addSintagsHelperParametersForScope('HelperFunction'); 168 $this->_addSintagsHelperParametersForScope('Struct'); 169 } 170 171 172 function _addInlineHelperTokens() 173 { 174 $this->addSpecialPattern('#{[A-Za-z][\.A-Za-z0-9_-]*}','DoubleQuote','InlineVariable'); 175 176 $this->addEntryPattern('#{[ \n\t]*[A-Za-z0-9_]+[ \n\t]*\x28?[ \n\t]*(?=.*})','DoubleQuote','InlineHelper'); 177 $this->addExitPattern('[ \n\t]*}', 'InlineHelper'); 178 $this->_addSintagsHelperParametersForScope('InlineHelper'); 179 } 180 181 function _addSintagsHelperParametersForScope($scope = 'Helper') 182 { 183 $this->addEntryPattern('[A-Za-z][A-Za-z0-9_]*[ \n\t]*\x28(?=.*\x29)',$scope,'HelperFunction'); 184 $this->addExitPattern('\x29', 'HelperFunction'); 185 186 $this->addEntryPattern('_[ \n\t]*\x28(?=.*\x29)',$scope,'HelperFunction'); 187 $this->addExitPattern('\x29', 'HelperFunction'); 188 189 $this->addEntryPattern("\x7B", $scope, 'Hash'); 190 $this->addExitPattern("\x7D", 'Hash'); 191 192 $this->addEntryPattern('"', $scope, 'DoubleQuote'); 193 $this->addPattern("\\\\\"", 'DoubleQuote'); 194 $this->addExitPattern('"', 'DoubleQuote'); 195 196 197 $this->addEntryPattern("'", $scope, 'SingleQuote'); 198 $this->addPattern("\\\\'", 'SingleQuote'); 199 $this->addExitPattern("'", 'SingleQuote'); 200 201 $this->addSpecialPattern('[0-9]+[\.0-9]*', $scope, 'Numbers'); 202 203 $this->addSpecialPattern('true|false|null', $scope, 'Text'); 204 205 $this->addSpecialPattern('\x3A[A-Za-z0-9_]+',$scope,'Symbol'); 206 207 $this->addSpecialPattern('@?[A-Za-z][\.A-Za-z0-9_-]*',$scope,'HelperVariable'); 208 209 210 $this->addSpecialPattern('\x5B',$scope,'Struct'); 211 $this->addSpecialPattern('\x5D',$scope,'Struct'); 212 } 213 } 214 215 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Oct 27 12:43:49 2008 | Cross-referenced by PHPXref 0.6 |