Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
uwetews committed Dec 15, 2014
1 parent f13da8c commit b495ad1
Show file tree
Hide file tree
Showing 8 changed files with 8,388 additions and 0 deletions.
622 changes: 622 additions & 0 deletions smarty_internal_configfilelexer.php

Large diffs are not rendered by default.

221 changes: 221 additions & 0 deletions smarty_internal_configfilelexer.plex
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
<?php
/**
* Smarty Internal Plugin Configfilelexer
*
* This is the lexer to break the config file source into tokens
* @package Smarty
* @subpackage Config
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Configfilelexer
*/
class Smarty_Internal_Configfilelexer
{

public $data;
public $counter;
public $token;
public $value;
public $node;
public $line;
private $state = 1;
public $smarty_token_names = array ( // Text for parser error messages
);


function __construct($data, $smarty)
{
// set instance object
self::instance($this);
$this->data = $data . "\n"; //now all lines are \n-terminated
$this->counter = 0;
$this->line = 1;
$this->smarty = $smarty;
$this->mbstring_overload = ini_get('mbstring.func_overload') & 2;
}
public static function &instance($new_instance = null)
{
static $instance = null;
if (isset($new_instance) && is_object($new_instance))
$instance = $new_instance;
return $instance;
}


/*!lex2php
%input $this->data
%counter $this->counter
%token $this->token
%value $this->value
%line $this->line
commentstart = /#|;/
openB = /\[/
closeB = /\]/
section = /.*?(?=[\.=\[\]\r\n])/
equal = /=/
whitespace = /[ \t\r]+/
dot = /\./
id = /[0-9]*[a-zA-Z_]\w*/
newline = /\n/
single_quoted_string = /'[^'\\]*(?:\\.[^'\\]*)*'(?=[ \t\r]*[\n#;])/
double_quoted_string = /"[^"\\]*(?:\\.[^"\\]*)*"(?=[ \t\r]*[\n#;])/
tripple_quotes = /"""/
tripple_quotes_end = /"""(?=[ \t\r]*[\n#;])/
text = /[\S\s]/
float = /\d+\.\d+(?=[ \t\r]*[\n#;])/
int = /\d+(?=[ \t\r]*[\n#;])/
maybe_bool = /[a-zA-Z]+(?=[ \t\r]*[\n#;])/
naked_string = /[^\n]+?(?=[ \t\r]*\n)/
*/

/*!lex2php
%statename START

commentstart {
$this->token = Smarty_Internal_Configfileparser::TPC_COMMENTSTART;
$this->yypushstate(self::COMMENT);
}
openB {
$this->token = Smarty_Internal_Configfileparser::TPC_OPENB;
$this->yypushstate(self::SECTION);
}
closeB {
$this->token = Smarty_Internal_Configfileparser::TPC_CLOSEB;
}
equal {
$this->token = Smarty_Internal_Configfileparser::TPC_EQUAL;
$this->yypushstate(self::VALUE);
}
whitespace {
return false;
}
newline {
$this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE;
}
id {
$this->token = Smarty_Internal_Configfileparser::TPC_ID;
}
text {
$this->token = Smarty_Internal_Configfileparser::TPC_OTHER;
}

*/

/*!lex2php
%statename VALUE

whitespace {
return false;
}
float {
$this->token = Smarty_Internal_Configfileparser::TPC_FLOAT;
$this->yypopstate();
}
int {
$this->token = Smarty_Internal_Configfileparser::TPC_INT;
$this->yypopstate();
}
tripple_quotes {
$this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_QUOTES;
$this->yypushstate(self::TRIPPLE);
}
single_quoted_string {
$this->token = Smarty_Internal_Configfileparser::TPC_SINGLE_QUOTED_STRING;
$this->yypopstate();
}
double_quoted_string {
$this->token = Smarty_Internal_Configfileparser::TPC_DOUBLE_QUOTED_STRING;
$this->yypopstate();
}
maybe_bool {
if (!$this->smarty->config_booleanize || !in_array(strtolower($this->value), Array("true", "false", "on", "off", "yes", "no")) ) {
$this->yypopstate();
$this->yypushstate(self::NAKED_STRING_VALUE);
return true; //reprocess in new state
} else {
$this->token = Smarty_Internal_Configfileparser::TPC_BOOL;
$this->yypopstate();
}
}
naked_string {
$this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
$this->yypopstate();
}
newline {
$this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
$this->value = "";
$this->yypopstate();
}

*/

/*!lex2php
%statename NAKED_STRING_VALUE

naked_string {
$this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
$this->yypopstate();
}

*/

/*!lex2php
%statename COMMENT

whitespace {
return false;
}
naked_string {
$this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
}
newline {
$this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE;
$this->yypopstate();
}

*/

/*!lex2php
%statename SECTION

dot {
$this->token = Smarty_Internal_Configfileparser::TPC_DOT;
}
section {
$this->token = Smarty_Internal_Configfileparser::TPC_SECTION;
$this->yypopstate();
}

*/
/*!lex2php
%statename TRIPPLE

tripple_quotes_end {
$this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_QUOTES_END;
$this->yypopstate();
$this->yypushstate(self::START);
}
text {
if ($this->mbstring_overload) {
$to = mb_strlen($this->data,'latin1');
} else {
$to = strlen($this->data);
}
preg_match("/\"\"\"[ \t\r]*[\n#;]/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
if (isset($match[0][1])) {
$to = $match[0][1];
} else {
$this->compiler->trigger_template_error ("missing or misspelled literal closing tag");
}
if ($this->mbstring_overload) {
$this->value = mb_substr($this->data,$this->counter,$to-$this->counter,'latin1');
} else {
$this->value = substr($this->data,$this->counter,$to-$this->counter);
}
$this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_TEXT;
}
*/

}
?>
Loading

0 comments on commit b495ad1

Please sign in to comment.