1
1
#! /bin/sh
2
+ #
3
+ # Generate the tokenizer extension data file from the parser header file.
2
4
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)
6
7
7
- # ###################################################################
8
+ infile=" Zend/zend_language_parser.h"
9
+ outfile=" ext/tokenizer/tokenizer_data.c"
8
10
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
12
17
fi
13
18
14
-
15
19
echo ' /*
16
20
+----------------------------------------------------------------------+
17
21
| PHP Version 7 |
@@ -39,25 +43,24 @@ echo '/*
39
43
#include "zend.h"
40
44
#include <zend_language_parser.h>
41
45
42
- ' > $OUTFILE
43
-
46
+ ' > $outfile
44
47
45
- echo ' void tokenizer_register_constants(INIT_FUNC_ARGS) {' >> $OUTFILE
46
- $AWK '
48
+ echo ' void tokenizer_register_constants(INIT_FUNC_ARGS) {' >> $outfile
49
+ awk '
47
50
/^ T_(NOELSE|ERROR)/ { next }
48
51
/^ 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
52
55
53
56
54
57
echo '
55
58
char *get_token_type_name(int token_type)
56
59
{
57
60
switch (token_type) {
58
- ' >> $OUTFILE
61
+ ' >> $outfile
59
62
60
- $AWK '
63
+ awk '
61
64
/^ T_PAAMAYIM_NEKUDOTAYIM/ {
62
65
print " case T_PAAMAYIM_NEKUDOTAYIM: return \"T_DOUBLE_COLON\";"
63
66
next
@@ -66,12 +69,12 @@ $AWK '
66
69
/^ T_/ {
67
70
print " case " $1 ": return \"" $1 "\";"
68
71
}
69
- ' < $INFILE >> $OUTFILE
72
+ ' < $infile >> $outfile
70
73
71
74
echo '
72
75
}
73
76
return "UNKNOWN";
74
77
}
75
- ' >> $OUTFILE
78
+ ' >> $outfile
76
79
77
- echo " Wrote $OUTFILE "
80
+ echo " Wrote $outfile "
0 commit comments