diff --git a/ext/tokenizer/Makefile.frag b/ext/tokenizer/Makefile.frag index f971394741d73..79655a8c8d7ae 100644 --- a/ext/tokenizer/Makefile.frag +++ b/ext/tokenizer/Makefile.frag @@ -1,4 +1,7 @@ $(top_srcdir)/Zend/zend_language_parser.c: $(top_srcdir)/Zend/zend_language_scanner.c: -$(top_srcdir)/ext/tokenizer/tokenizer_data.c: $(top_srcdir)/Zend/zend_language_parser.h +$(top_srcdir)/ext/tokenizer/tokenizer_data.c: $(top_srcdir)/Zend/zend_language_parser.y $(top_srcdir)/Zend/zend_language_parser.h + if test ! -z "$(PHP_EXECUTABLE)" && test -x "$(PHP_EXECUTABLE)"; then \ + $(PHP_EXECUTABLE) $(srcdir)/tokenizer_data_gen.php; \ + fi; $(builddir)/tokenizer.lo: $(top_srcdir)/Zend/zend_language_parser.c $(top_srcdir)/Zend/zend_language_scanner.c diff --git a/ext/tokenizer/tokenizer_data.c b/ext/tokenizer/tokenizer_data.c index 5699c57566b7d..10663442c4c13 100644 --- a/ext/tokenizer/tokenizer_data.c +++ b/ext/tokenizer/tokenizer_data.c @@ -16,7 +16,7 @@ /* DO NOT EDIT THIS FILE! - This file is generated using tokenizer_data_gen.sh + This file is generated using tokenizer_data_gen.php */ #include "php.h" diff --git a/ext/tokenizer/tokenizer_data_gen.php b/ext/tokenizer/tokenizer_data_gen.php new file mode 100644 index 0000000000000..13e6aaa31dc80 --- /dev/null +++ b/ext/tokenizer/tokenizer_data_gen.php @@ -0,0 +1,92 @@ + | + +----------------------------------------------------------------------+ +*/ + +/* + DO NOT EDIT THIS FILE! + This file is generated using tokenizer_data_gen.php +*/ + +#include "php.h" +#include "zend.h" +#include + + +void tokenizer_register_constants(INIT_FUNC_ARGS) { + +CODE; + +$incontent = file_get_contents($infile); +preg_match_all('(^ (?T_.*?)\b)m', $incontent, $matches); + +foreach ($matches['token_name'] as $tokenName) { + if ($tokenName === 'T_NOELSE' || $tokenName === 'T_ERROR') { + continue; + } + $result .= "\tREGISTER_LONG_CONSTANT(\"$tokenName\", $tokenName, CONST_CS | CONST_PERSISTENT);\n"; +} +$result .= "\tREGISTER_LONG_CONSTANT(\"T_DOUBLE_COLON\", T_PAAMAYIM_NEKUDOTAYIM, CONST_CS | CONST_PERSISTENT);\n"; + +$result .= <<&2 - echo "" >&2 - echo "Please, generate the PHP parser files by scripts/dev/genfiles" >&2 - echo "or by running the ./configure build step." >&2 - exit 1 -fi - -echo '/* - +----------------------------------------------------------------------+ - | Copyright (c) The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Johannes Schlueter | - +----------------------------------------------------------------------+ -*/ - -/* - DO NOT EDIT THIS FILE! - This file is generated using tokenizer_data_gen.sh -*/ - -#include "php.h" -#include "zend.h" -#include - -' > $outfile - -echo 'void tokenizer_register_constants(INIT_FUNC_ARGS) {' >> $outfile -awk ' - /^ T_(NOELSE|ERROR)/ { next } - /^ T_/ { print " REGISTER_LONG_CONSTANT(\"" $1 "\", " $1 ", CONST_CS | CONST_PERSISTENT);" } -' < $infile >> $outfile -echo ' REGISTER_LONG_CONSTANT("T_DOUBLE_COLON", T_PAAMAYIM_NEKUDOTAYIM, CONST_CS | CONST_PERSISTENT);' >> $outfile -echo '}' >> $outfile - - -echo ' -char *get_token_type_name(int token_type) -{ - switch (token_type) { -' >> $outfile - -awk ' - /^ T_PAAMAYIM_NEKUDOTAYIM/ { - print " case T_PAAMAYIM_NEKUDOTAYIM: return \"T_DOUBLE_COLON\";" - next - } - /^ T_(NOELSE|ERROR)/ { next } - /^ T_/ { - print " case " $1 ": return \"" $1 "\";" - } -' < $infile >> $outfile - -echo ' - } - return NULL; -} -' >> $outfile - -echo "Wrote $outfile"