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/* $Id$ */
34
35/*
36   DO NOT EDIT THIS FILE!
37   This file is generated using tokenizer_data_gen.sh
38*/
39
40#include "php.h"
41#include "zend.h"
42#include <zend_language_parser.h>
43
44' > $OUTFILE
45
46
47echo 'void tokenizer_register_constants(INIT_FUNC_ARGS) {' >> $OUTFILE
48$AWK '
49	/^#define T_(NOELSE|ERROR)/ { next }
50	/^#define T_/  { print "	REGISTER_LONG_CONSTANT(\"" $2 "\", " $2 ", CONST_CS | CONST_PERSISTENT);" }
51' < $INFILE >> $OUTFILE
52echo '	REGISTER_LONG_CONSTANT("T_DOUBLE_COLON", T_PAAMAYIM_NEKUDOTAYIM, CONST_CS | CONST_PERSISTENT);' >> $OUTFILE
53echo '}' >> $OUTFILE
54
55
56echo '
57char *get_token_type_name(int token_type)
58{
59	switch (token_type) {
60' >> $OUTFILE
61
62$AWK '
63	/^#define T_PAAMAYIM_NEKUDOTAYIM/ {
64		print "		case T_PAAMAYIM_NEKUDOTAYIM: return \"T_DOUBLE_COLON\";"
65		next
66	}
67	/^#define T_(NOELSE|ERROR)/ { next }
68	/^#define T_/ {
69		print "		case " $2 ": return \"" $2 "\";"
70	}
71' < $INFILE >> $OUTFILE
72
73echo '
74	}
75	return "UNKNOWN";
76}
77' >> $OUTFILE
78
79echo "Wrote $OUTFILE"
80