1#!/bin/sh
2
3INFILE="../../Zend/zend_language_parser.h"
4OUTFILE="tokenizer_data.c"
5AWK=awk
6
7####################################################################
8
9if test ! -f "./tokenizer.c"; then
10    echo "Please run this script from within php-src/ext/tokenizer"
11    exit 0
12fi
13
14
15echo '/*
16   +----------------------------------------------------------------------+
17   | PHP Version 7                                                        |
18   +----------------------------------------------------------------------+
19   | Copyright (c) 1997-2018 The PHP Group                                |
20   +----------------------------------------------------------------------+
21   | This source file is subject to version 3.01 of the PHP license,      |
22   | that is bundled with this package in the file LICENSE, and is        |
23   | available through the world-wide-web at the following url:           |
24   | http://www.php.net/license/3_01.txt                                  |
25   | If you did not receive a copy of the PHP license and are unable to   |
26   | obtain it through the world-wide-web, please send a note to          |
27   | license@php.net so we can mail you a copy immediately.               |
28   +----------------------------------------------------------------------+
29   | Author: Johannes Schlueter <johannes@php.net>                        |
30   +----------------------------------------------------------------------+
31*/
32
33/*
34   DO NOT EDIT THIS FILE!
35   This file is generated using tokenizer_data_gen.sh
36*/
37
38#include "php.h"
39#include "zend.h"
40#include <zend_language_parser.h>
41
42' > $OUTFILE
43
44
45echo 'void tokenizer_register_constants(INIT_FUNC_ARGS) {' >> $OUTFILE
46$AWK '
47	/^#define T_(NOELSE|ERROR)/ { next }
48	/^#define T_/  { print "	REGISTER_LONG_CONSTANT(\"" $2 "\", " $2 ", CONST_CS | CONST_PERSISTENT);" }
49' < $INFILE >> $OUTFILE
50echo '	REGISTER_LONG_CONSTANT("T_DOUBLE_COLON", T_PAAMAYIM_NEKUDOTAYIM, CONST_CS | CONST_PERSISTENT);' >> $OUTFILE
51echo '}' >> $OUTFILE
52
53
54echo '
55char *get_token_type_name(int token_type)
56{
57	switch (token_type) {
58' >> $OUTFILE
59
60$AWK '
61	/^#define T_PAAMAYIM_NEKUDOTAYIM/ {
62		print "		case T_PAAMAYIM_NEKUDOTAYIM: return \"T_DOUBLE_COLON\";"
63		next
64	}
65	/^#define T_(NOELSE|ERROR)/ { next }
66	/^#define T_/ {
67		print "		case " $2 ": return \"" $2 "\";"
68	}
69' < $INFILE >> $OUTFILE
70
71echo '
72	}
73	return "UNKNOWN";
74}
75' >> $OUTFILE
76
77echo "Wrote $OUTFILE"
78