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
1217fi
1318
14-
1519echo ' /*
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
5457echo '
5558char *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
7174echo '
7275 }
7376 return "UNKNOWN";
7477}
75- ' >> $OUTFILE
78+ ' >> $outfile
7679
77- echo " Wrote $OUTFILE "
80+ echo " Wrote $outfile "
0 commit comments