library/smarty/lexer/smarty_internal_configfilelexer.plex
changeset 0 4869aea77e21
equal deleted inserted replaced
-1:000000000000 0:4869aea77e21
       
     1 <?php
       
     2 /**
       
     3 * Smarty Internal Plugin Configfilelexer
       
     4 *
       
     5 * This is the lexer to break the config file source into tokens 
       
     6 * @package Smarty
       
     7 * @subpackage Config
       
     8 * @author Uwe Tews 
       
     9 */
       
    10 /**
       
    11 * Smarty_Internal_Configfilelexer
       
    12 *
       
    13 * This is the config file lexer.
       
    14 * It is generated from the smarty_internal_configfilelexer.plex file
       
    15 *
       
    16 * @package Smarty
       
    17 * @subpackage Compiler
       
    18 * @author Uwe Tews
       
    19 */
       
    20 class Smarty_Internal_Configfilelexer
       
    21 {
       
    22     /**
       
    23      * Source
       
    24      *
       
    25      * @var string
       
    26      */
       
    27     public $data;
       
    28     /**
       
    29      * byte counter
       
    30      *
       
    31      * @var int
       
    32      */
       
    33     public $counter;
       
    34     /**
       
    35      * token number
       
    36      *
       
    37      * @var int
       
    38      */
       
    39     public $token;
       
    40     /**
       
    41      * token value
       
    42      *
       
    43      * @var string
       
    44      */
       
    45     public $value;
       
    46     /**
       
    47      * current line
       
    48      *
       
    49      * @var int
       
    50      */
       
    51     public $line;
       
    52     /**
       
    53      * state number
       
    54      *
       
    55      * @var int
       
    56      */
       
    57     public $state = 1;
       
    58     /**
       
    59      * Smarty object
       
    60      *
       
    61      * @var Smarty
       
    62      */
       
    63     public $smarty = null;
       
    64     /**
       
    65      * compiler object
       
    66      *
       
    67      * @var Smarty_Internal_Config_File_Compiler
       
    68      */
       
    69     private $compiler = null;
       
    70     /**
       
    71      * copy of config_booleanize
       
    72      *
       
    73      * @var bool
       
    74      */
       
    75     private $configBooleanize = false;
       
    76     /**
       
    77      * trace file
       
    78      *
       
    79      * @var resource
       
    80      */
       
    81     public $yyTraceFILE;
       
    82     /**
       
    83      * trace prompt
       
    84      *
       
    85      * @var string
       
    86      */
       
    87     public $yyTracePrompt;
       
    88     /**
       
    89      * state names
       
    90      *
       
    91      * @var array
       
    92      */
       
    93     public $state_name = array(1 => 'START', 2 => 'VALUE', 3 => 'NAKED_STRING_VALUE', 4 => 'COMMENT', 5 => 'SECTION', 6 => 'TRIPPLE');
       
    94 
       
    95     /**
       
    96      * storage for assembled token patterns
       
    97      *
       
    98      * @var sring
       
    99      */
       
   100     private $yy_global_pattern1 = null;
       
   101     private $yy_global_pattern2 = null;
       
   102     private $yy_global_pattern3 = null;
       
   103     private $yy_global_pattern4 = null;
       
   104     private $yy_global_pattern5 = null;
       
   105     private $yy_global_pattern6 = null;
       
   106 
       
   107     /**
       
   108      * token names
       
   109      *
       
   110      * @var array
       
   111      */
       
   112     public $smarty_token_names = array(        // Text for parser error messages
       
   113     );
       
   114 
       
   115     /**
       
   116      * constructor
       
   117      *
       
   118      * @param   string                             $data template source
       
   119      * @param Smarty_Internal_Config_File_Compiler $compiler
       
   120      */
       
   121     function __construct($data, Smarty_Internal_Config_File_Compiler $compiler)
       
   122     {
       
   123         // set instance object
       
   124         self::instance($this);
       
   125         $this->data = $data . "\n"; //now all lines are \n-terminated
       
   126         $this->counter = 0;
       
   127         if (preg_match('/^\xEF\xBB\xBF/', $this->data, $match)) {
       
   128             $this->counter += strlen($match[0]);
       
   129         }
       
   130         $this->line = 1;
       
   131         $this->compiler = $compiler;
       
   132         $this->smarty = $compiler->smarty;
       
   133         $this->configBooleanize = $this->smarty->config_booleanize;
       
   134     }
       
   135 
       
   136     public static function &instance($new_instance = null)
       
   137     {
       
   138         static $instance = null;
       
   139         if (isset($new_instance) && is_object($new_instance)) {
       
   140             $instance = $new_instance;
       
   141         }
       
   142         return $instance;
       
   143     }
       
   144 
       
   145     public function PrintTrace()
       
   146     {
       
   147         $this->yyTraceFILE = fopen('php://output', 'w');
       
   148         $this->yyTracePrompt = '<br>';
       
   149     }
       
   150 
       
   151 
       
   152 /*!lex2php
       
   153 %input $this->data
       
   154 %counter $this->counter
       
   155 %token $this->token
       
   156 %value $this->value
       
   157 %line $this->line
       
   158 commentstart = /#|;/
       
   159 openB = /\[/
       
   160 closeB = /\]/
       
   161 section = /.*?(?=[\.=\[\]\r\n])/
       
   162 equal = /=/
       
   163 whitespace = /[ \t\r]+/
       
   164 dot = /\./
       
   165 id = /[0-9]*[a-zA-Z_]\w*/
       
   166 newline = /\n/
       
   167 single_quoted_string = /'[^'\\]*(?:\\.[^'\\]*)*'(?=[ \t\r]*[\n#;])/
       
   168 double_quoted_string = /"[^"\\]*(?:\\.[^"\\]*)*"(?=[ \t\r]*[\n#;])/
       
   169 tripple_quotes = /"""/
       
   170 tripple_quotes_end = /"""(?=[ \t\r]*[\n#;])/
       
   171 text = /[\S\s]/
       
   172 float = /\d+\.\d+(?=[ \t\r]*[\n#;])/
       
   173 int = /\d+(?=[ \t\r]*[\n#;])/
       
   174 maybe_bool = /[a-zA-Z]+(?=[ \t\r]*[\n#;])/
       
   175 naked_string = /[^\n]+?(?=[ \t\r]*\n)/
       
   176 */
       
   177 
       
   178 /*!lex2php
       
   179 %statename START
       
   180 
       
   181 commentstart {
       
   182     $this->token = Smarty_Internal_Configfileparser::TPC_COMMENTSTART;
       
   183     $this->yypushstate(self::COMMENT);
       
   184 }
       
   185 openB {
       
   186     $this->token = Smarty_Internal_Configfileparser::TPC_OPENB;
       
   187     $this->yypushstate(self::SECTION);
       
   188 }
       
   189 closeB {
       
   190     $this->token = Smarty_Internal_Configfileparser::TPC_CLOSEB;
       
   191 }
       
   192 equal {
       
   193     $this->token = Smarty_Internal_Configfileparser::TPC_EQUAL;
       
   194     $this->yypushstate(self::VALUE);
       
   195 }
       
   196 whitespace {
       
   197     return false;
       
   198 }
       
   199 newline {
       
   200     $this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE;
       
   201 }
       
   202 id {
       
   203     $this->token = Smarty_Internal_Configfileparser::TPC_ID;
       
   204 }
       
   205 text {
       
   206     $this->token = Smarty_Internal_Configfileparser::TPC_OTHER;
       
   207 }
       
   208 
       
   209 */
       
   210 
       
   211 /*!lex2php
       
   212 %statename VALUE
       
   213 
       
   214 whitespace {
       
   215     return false;
       
   216 }
       
   217 float {
       
   218     $this->token = Smarty_Internal_Configfileparser::TPC_FLOAT;
       
   219     $this->yypopstate();
       
   220 }
       
   221 int {
       
   222     $this->token = Smarty_Internal_Configfileparser::TPC_INT;
       
   223     $this->yypopstate();
       
   224 }
       
   225 tripple_quotes {
       
   226     $this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_QUOTES;
       
   227     $this->yypushstate(self::TRIPPLE);
       
   228 }
       
   229 single_quoted_string {
       
   230     $this->token = Smarty_Internal_Configfileparser::TPC_SINGLE_QUOTED_STRING;
       
   231     $this->yypopstate();
       
   232 }
       
   233 double_quoted_string {
       
   234     $this->token = Smarty_Internal_Configfileparser::TPC_DOUBLE_QUOTED_STRING;
       
   235     $this->yypopstate();
       
   236 }
       
   237 maybe_bool {
       
   238     if (!$this->configBooleanize || !in_array(strtolower($this->value), Array("true", "false", "on", "off", "yes", "no")) ) {
       
   239         $this->yypopstate();
       
   240         $this->yypushstate(self::NAKED_STRING_VALUE);
       
   241         return true; //reprocess in new state
       
   242     } else {
       
   243         $this->token = Smarty_Internal_Configfileparser::TPC_BOOL;
       
   244         $this->yypopstate();
       
   245     }
       
   246 }
       
   247 naked_string {
       
   248     $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
       
   249     $this->yypopstate();
       
   250 }
       
   251 newline {
       
   252     $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
       
   253     $this->value = "";
       
   254     $this->yypopstate();
       
   255 }
       
   256 
       
   257 */
       
   258 
       
   259 /*!lex2php
       
   260 %statename NAKED_STRING_VALUE
       
   261 
       
   262 naked_string {
       
   263     $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
       
   264     $this->yypopstate();
       
   265 }
       
   266 
       
   267 */
       
   268 
       
   269 /*!lex2php
       
   270 %statename COMMENT
       
   271 
       
   272 whitespace {
       
   273     return false;
       
   274 }
       
   275 naked_string {
       
   276     $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
       
   277 }
       
   278 newline {
       
   279     $this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE;
       
   280     $this->yypopstate();
       
   281 }
       
   282 
       
   283 */
       
   284 
       
   285 /*!lex2php
       
   286 %statename SECTION
       
   287 
       
   288 dot {
       
   289     $this->token = Smarty_Internal_Configfileparser::TPC_DOT;
       
   290 }
       
   291 section {
       
   292     $this->token = Smarty_Internal_Configfileparser::TPC_SECTION;
       
   293     $this->yypopstate();
       
   294 }
       
   295 
       
   296 */
       
   297 /*!lex2php
       
   298 %statename TRIPPLE
       
   299 
       
   300 tripple_quotes_end {
       
   301     $this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_QUOTES_END;
       
   302     $this->yypopstate();
       
   303     $this->yypushstate(self::START);
       
   304 }
       
   305 text {
       
   306   $to = strlen($this->data);
       
   307   preg_match("/\"\"\"[ \t\r]*[\n#;]/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
       
   308   if (isset($match[0][1])) {
       
   309     $to = $match[0][1];
       
   310   } else {
       
   311     $this->compiler->trigger_template_error ("missing or misspelled literal closing tag");
       
   312   }  
       
   313   $this->value = substr($this->data,$this->counter,$to-$this->counter);
       
   314   $this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_TEXT;
       
   315 }
       
   316 */
       
   317 
       
   318 }