yylex example


                $this->value = current($yymatches); // token value                 $r = $this->{'yy_r1_' . $this->token}($yysubmatches);
                if ($r === null) {
                    $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1')strlen($this->value));
                    $this->line += substr_count($this->value, "\n");
                    // accept this token                     return true;
                } elseif ($r === true) {
                    // we have changed state                     // process this token in the new state                     return $this->yylex();
                } elseif ($r === false) {
                    $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1')strlen($this->value));
                    $this->line += substr_count($this->value, "\n");
                    if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1')strlen($this->data))) {
                        return false; // end of input                     }
                    // skip this token                     continue;
                }            } else {
                throw new Exception('Unexpected input at line' . $this->line .
                    ': ' . $this->data[$this->counter]);
            }
protected function doCompile($_content)
    {
        /* here is where the compiling takes place. Smarty tags in the templates are replaces with PHP code, then written to compiled files. */
        // init the lexer/parser to compile the template         $this->lex = new $this->lexer_class($_content$this);
        $this->parser = new $this->parser_class($this->lex, $this);
        if ($this->smarty->_parserdebug)
            $this->parser->PrintTrace();
        // get tokens from lexer and parse them         while ($this->lex->yylex() && !$this->abort_and_recompile) {
            if ($this->smarty->_parserdebug) {
                echo "<pre>Line {$this->lex->line} Parsing {$this->parser->yyTokenName[$this->lex->token]} Token " .
                    htmlentities($this->lex->value) . "</pre>";
            }
            $this->parser->doParse($this->lex->token, $this->lex->value);
        }

        if ($this->abort_and_recompile) {
            // exit here on abort             return false;
        }
        

                $this->value = current($yymatches); // token value                 $r = $this->{'yy_r1_' . $this->token}($yysubmatches);
                if ($r === null) {
                    $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1')strlen($this->value));
                    $this->line += substr_count($this->value, "\n");
                    // accept this token                     return true;
                } elseif ($r === true) {
                    // we have changed state                     // process this token in the new state                     return $this->yylex();
                } elseif ($r === false) {
                    $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1')strlen($this->value));
                    $this->line += substr_count($this->value, "\n");
                    if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1')strlen($this->data))) {
                        return false; // end of input                     }
                    // skip this token                     continue;
                }            } else {
                throw new Exception('Unexpected input at line' . $this->line .
                    ': ' . $this->data[$this->counter]);
            }
// get config file source         $_content = $config->source->content . "\n";
        // on empty template just return         if ($_content == '') {
            return true;
        }
        // init the lexer/parser to compile the config file         $lex = new Smarty_Internal_Configfilelexer($_content$this->smarty);
        $parser = new Smarty_Internal_Configfileparser($lex$this);
        if ($this->smarty->_parserdebug) $parser->PrintTrace();
        // get tokens from lexer and parse them         while ($lex->yylex()) {
            if ($this->smarty->_parserdebug) echo "<br>Parsing {$parser->yyTokenName[$lex->token]} Token {$lex->value} Line {$lex->line} \n";
            $parser->doParse($lex->token, $lex->value);
        }
        // finish parsing process         $parser->doParse(0, 0);
        $config->compiled_config = '<?php $_config_vars = ' . var_export($this->config_data, true) . '; ?>';
    }

    /** * display compiler error messages without dying * * If parameter $args is empty it is a parser detected syntax error. * In this case the parser is called to obtain information about exspected tokens. * * If parameter $args contains a string this is used as error message * * @param string $args individual error message or null */
Home | Imprint | This part of the site doesn't use cookies.