com php-src: Enhance the tokenizer data generator script: ext/tokenizer/tokenizer_data_gen.sh
| From: | Peter Kokot | Date: | Tue, 14 May 2019 19:50:29 +0000 |
| Subject: | com php-src: Enhance the tokenizer data generator script: ext/tokenizer/tokenizer_data_gen.sh | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-106191@lists.php.net to get a copy of this message | ||
Commit: b4dec0e11dbfd20cd6ad3d0f812fa0879cb5e3ee
Author: Peter Kokot <peterkokot@gmail.com> Tue, 14 May 2019 21:50:29 +0200
Parents: a07d422ade48e875740a6733543179e7f67a573e
Branches: PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=b4dec0e11dbfd20cd6ad3d0f812fa0879cb5e3ee
Log:
Enhance the tokenizer data generator script
Changes:
- executable from any location (for example, project root)
- some minor common shell scripts CS fixes
- error reporting done based on the presence of the parser file
Changed paths:
M ext/tokenizer/tokenizer_data_gen.sh
Diff:
diff --git a/ext/tokenizer/tokenizer_data_gen.sh b/ext/tokenizer/tokenizer_data_gen.sh
index d545f04..979ecb9 100755
--- a/ext/tokenizer/tokenizer_data_gen.sh
+++ b/ext/tokenizer/tokenizer_data_gen.sh
@@ -1,17 +1,21 @@
#!/bin/sh
+#
+# Generate the tokenizer extension data file from the parser header file.
-INFILE="../../Zend/zend_language_parser.h"
-OUTFILE="tokenizer_data.c"
-AWK=awk
+# Go to project root directory.
+cd $(CDPATH= cd -- "$(dirname -- "$0")/../../" && pwd -P)
-####################################################################
+infile="Zend/zend_language_parser.h"
+outfile="ext/tokenizer/tokenizer_data.c"
-if test ! -f "./tokenizer.c"; then
- echo "Please run this script from within php-src/ext/tokenizer"
- exit 0
+if test ! -f "$infile"; then
+ echo "$infile is missing." >&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 '/*
+----------------------------------------------------------------------+
| PHP Version 7 |
@@ -39,25 +43,24 @@ echo '/*
#include "zend.h"
#include <zend_language_parser.h>
-' > $OUTFILE
-
+' > $outfile
-echo 'void tokenizer_register_constants(INIT_FUNC_ARGS) {' >> $OUTFILE
-$AWK '
+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
+' < $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
+' >> $outfile
-$AWK '
+awk '
/^ T_PAAMAYIM_NEKUDOTAYIM/ {
print " case T_PAAMAYIM_NEKUDOTAYIM: return \"T_DOUBLE_COLON\";"
next
@@ -66,12 +69,12 @@ $AWK '
/^ T_/ {
print " case " $1 ": return \"" $1 "\";"
}
-' < $INFILE >> $OUTFILE
+' < $infile >> $outfile
echo '
}
return "UNKNOWN";
}
-' >> $OUTFILE
+' >> $outfile
-echo "Wrote $OUTFILE"
+echo "Wrote $outfile"