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