Skip to content

Commit b4dec0e

Browse files
committed
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
1 parent a07d422 commit b4dec0e

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

ext/tokenizer/tokenizer_data_gen.sh

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
#!/bin/sh
2+
#
3+
# Generate the tokenizer extension data file from the parser header file.
24

3-
INFILE="../../Zend/zend_language_parser.h"
4-
OUTFILE="tokenizer_data.c"
5-
AWK=awk
5+
# Go to project root directory.
6+
cd $(CDPATH= cd -- "$(dirname -- "$0")/../../" && pwd -P)
67

7-
####################################################################
8+
infile="Zend/zend_language_parser.h"
9+
outfile="ext/tokenizer/tokenizer_data.c"
810

9-
if test ! -f "./tokenizer.c"; then
10-
echo "Please run this script from within php-src/ext/tokenizer"
11-
exit 0
11+
if test ! -f "$infile"; then
12+
echo "$infile is missing." >&2
13+
echo "" >&2
14+
echo "Please, generate the PHP parser files by scripts/dev/genfiles" >&2
15+
echo "or by running the ./configure build step." >&2
16+
exit 1
1217
fi
1318

14-
1519
echo '/*
1620
+----------------------------------------------------------------------+
1721
| PHP Version 7 |
@@ -39,25 +43,24 @@ echo '/*
3943
#include "zend.h"
4044
#include <zend_language_parser.h>
4145
42-
' > $OUTFILE
43-
46+
' > $outfile
4447

45-
echo 'void tokenizer_register_constants(INIT_FUNC_ARGS) {' >> $OUTFILE
46-
$AWK '
48+
echo 'void tokenizer_register_constants(INIT_FUNC_ARGS) {' >> $outfile
49+
awk '
4750
/^ T_(NOELSE|ERROR)/ { next }
4851
/^ T_/ { print " REGISTER_LONG_CONSTANT(\"" $1 "\", " $1 ", CONST_CS | CONST_PERSISTENT);" }
49-
' < $INFILE >> $OUTFILE
50-
echo ' REGISTER_LONG_CONSTANT("T_DOUBLE_COLON", T_PAAMAYIM_NEKUDOTAYIM, CONST_CS | CONST_PERSISTENT);' >> $OUTFILE
51-
echo '}' >> $OUTFILE
52+
' < $infile >> $outfile
53+
echo ' REGISTER_LONG_CONSTANT("T_DOUBLE_COLON", T_PAAMAYIM_NEKUDOTAYIM, CONST_CS | CONST_PERSISTENT);' >> $outfile
54+
echo '}' >> $outfile
5255

5356

5457
echo '
5558
char *get_token_type_name(int token_type)
5659
{
5760
switch (token_type) {
58-
' >> $OUTFILE
61+
' >> $outfile
5962

60-
$AWK '
63+
awk '
6164
/^ T_PAAMAYIM_NEKUDOTAYIM/ {
6265
print " case T_PAAMAYIM_NEKUDOTAYIM: return \"T_DOUBLE_COLON\";"
6366
next
@@ -66,12 +69,12 @@ $AWK '
6669
/^ T_/ {
6770
print " case " $1 ": return \"" $1 "\";"
6871
}
69-
' < $INFILE >> $OUTFILE
72+
' < $infile >> $outfile
7073

7174
echo '
7275
}
7376
return "UNKNOWN";
7477
}
75-
' >> $OUTFILE
78+
' >> $outfile
7679

77-
echo "Wrote $OUTFILE"
80+
echo "Wrote $outfile"

0 commit comments

Comments
 (0)