Skip to content

Commit

Permalink
move .plex and .y definiton files into Smarty distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
uwetews committed Dec 15, 2014
1 parent 7afc813 commit 7c6caba
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 10,355 deletions.
43 changes: 21 additions & 22 deletions Create_Config_Parser.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
<?php
$smartyPath = '../smarty/libs/sysplugins/';
$lexerPath = '../smarty/lexer/';
if (!is_dir($lexerPath)) {
echo '<br><br>Fatal error: Missing lexer / parser definition folder \'lexer\' in distribution <br>';
exit(1);
}
copy("{$smartyPath}smarty_internal_configfilelexer.php", "{$lexerPath}smarty_internal_configfilelexer.php.bak");
copy("{$smartyPath}smarty_internal_configfileparser.php", "{$lexerPath}smarty_internal_configfileparser.php.bak");

// Create Lexer
require_once './LexerGenerator.php';
$lex = new PHP_LexerGenerator('smarty_internal_configfilelexer.plex');
$contents = file_get_contents('smarty_internal_configfilelexer.php');
file_put_contents('smarty_internal_configfilelexer.php', $contents."\n");

$lex = new PHP_LexerGenerator("{$lexerPath}smarty_internal_configfilelexer.plex");
unset($lex);

// Create Parser
passthru("php ./ParserGenerator/cli.php smarty_internal_configfileparser.y");
require_once './ParserGenerator.php';
$parser = new PHP_ParserGenerator();
$parser->main("{$lexerPath}smarty_internal_configfileparser.y");
unset($parser);

$contents = file_get_contents('smarty_internal_configfileparser.php');
$contents = '<?php
/**
* Smarty Internal Plugin Configfileparser
*
* This is the config file parser.
* It is generated from the internal.configfileparser.y file
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
*/
'.substr($contents,6);
file_put_contents('smarty_internal_configfileparser.php', $contents."\n");
$content = file_get_contents("{$lexerPath}smarty_internal_configfileparser.php");
$content = preg_replace(array('#/\*\s*\d+\s*\*/#', "#'lhs'#", "#'rhs'#"), array('', 0, 1), $content);
file_put_contents("{$lexerPath}smarty_internal_configfileparser.php", $content);

copy("{$lexerPath}smarty_internal_configfilelexer.php", "{$smartyPath}smarty_internal_configfilelexer.php");
copy("{$lexerPath}smarty_internal_configfileparser.php", "{$smartyPath}smarty_internal_configfileparser.php");

if (is_dir('../smarty/libs/sysplugins')) {
copy('smarty_internal_configfilelexer.php', '../smarty/libs/sysplugins/smarty_internal_configfilelexer.php');
copy('smarty_internal_configfileparser.php', '../smarty/libs/sysplugins/smarty_internal_configfileparser.php');
}
46 changes: 24 additions & 22 deletions Create_Template_Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,33 @@
ini_set('max_execution_time',300);
ini_set('xdebug.max_nesting_level',300);

$smartyPath = '../smarty/libs/sysplugins/';
$lexerPath = '../smarty/lexer/';
if (!is_dir($lexerPath)) {
echo '<br><br>Fatal error: Missing lexer / parser definition folder \'lexer\' in distribution <br>';
exit(1);
}

copy("{$smartyPath}smarty_internal_templatelexer.php", "{$lexerPath}smarty_internal_templatelexer.php.bak");
copy("{$smartyPath}smarty_internal_templateparser.php", "{$lexerPath}smarty_internal_templateparser.php.bak");
// Create Lexer
require_once './LexerGenerator.php';
$lex = new PHP_LexerGenerator('smarty_internal_templatelexer.plex');
$contents = file_get_contents('smarty_internal_templatelexer.php');
$contents = str_replace(array('SMARTYldel','SMARTYrdel'),array('".$this->ldel."','".$this->rdel."'),$contents);
file_put_contents('smarty_internal_templatelexer.php', $contents);
$lex = new PHP_LexerGenerator("{$lexerPath}smarty_internal_templatelexer.plex");
unset($lex);

$content = file_get_contents("{$lexerPath}smarty_internal_templatelexer.php");
$content = str_replace(array('SMARTYldel','SMARTYrdel'),array('".$this->ldel."','".$this->rdel."'),$content);
file_put_contents("{$lexerPath}smarty_internal_templatelexer.php", $content);

// Create Parser
passthru("php ./ParserGenerator/cli.php smarty_internal_templateparser.y");
require_once './ParserGenerator.php';
$parser = new PHP_ParserGenerator();
$parser->main("{$lexerPath}smarty_internal_templateparser.y");
unset($parser);

$contents = file_get_contents('smarty_internal_templateparser.php');
$contents = '<?php
/**
* Smarty Internal Plugin Templateparser
*
* This is the template parser.
* It is generated from the internal.templateparser.y file
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
*/
'.substr($contents,6);
file_put_contents('smarty_internal_templateparser.php', $contents."?>");
$content = file_get_contents("{$lexerPath}smarty_internal_templateparser.php");
$content = preg_replace(array('#/\*\s*\d+\s*\*/#', "#'lhs'#", "#'rhs'#"), array('', 0, 1), $content);
file_put_contents("{$lexerPath}smarty_internal_templateparser.php", $content);

if (is_dir('../smarty/libs/sysplugins')) {
copy('smarty_internal_templatelexer.php', '../smarty/libs/sysplugins/smarty_internal_templatelexer.php');
copy('smarty_internal_templateparser.php', '../smarty/libs/sysplugins/smarty_internal_templateparser.php');
}
copy("{$lexerPath}smarty_internal_templatelexer.php", "{$smartyPath}smarty_internal_templatelexer.php");
copy("{$lexerPath}smarty_internal_templateparser.php", "{$smartyPath}smarty_internal_templateparser.php");
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
The "smarty/smarty-lexer" package is used to generate the lexer and parser class files.


**NOTE: The "smarty/smarty-lexer" version must be identical with the target "smarty/smarty" version**
**For Smarty versions >= 3.1.22 require "smarty/smarty-lexer": "~3.1" to get the latest version of the package**


**For Smarty versions <= 3.1.21 The "smarty/smarty-lexer" version must be identical with the target Smarty version**

Use for example

Expand All @@ -13,7 +16,9 @@ Use for example
}

in your composer.json file to get the generator for Smarty 3.1.8.




To generate the template lexer and parser run Create_Template_Parser.php.
It will create
smarty_internal_templatelexer.php from smarty_internal_templatelexer.plex
Expand Down
Loading

0 comments on commit 7c6caba

Please sign in to comment.