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   | Copyright (c) The PHP Group                                          |
22   +----------------------------------------------------------------------+
23   | This source file is subject to version 3.01 of the PHP license,      |
24   | that is bundled with this package in the file LICENSE, and is        |
25   | available through the world-wide-web at the following url:           |
26   | http://www.php.net/license/3_01.txt                                  |
27   | If you did not receive a copy of the PHP license and are unable to   |
28   | obtain it through the world-wide-web, please send a note to          |
29   | license@php.net so we can mail you a copy immediately.               |
30   +----------------------------------------------------------------------+
31   | Author: Johannes Schlueter <johannes@php.net>                        |
32   +----------------------------------------------------------------------+
33*/
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
46echo 'void tokenizer_register_constants(INIT_FUNC_ARGS) {' >> $outfile
47awk '
48	/^    T_(NOELSE|ERROR)/ { next }
49	/^    T_/  { print "	REGISTER_LONG_CONSTANT(\"" $1 "\", " $1 ", CONST_CS | CONST_PERSISTENT);" }
50' < $infile >> $outfile
51echo '	REGISTER_LONG_CONSTANT("T_DOUBLE_COLON", T_PAAMAYIM_NEKUDOTAYIM, CONST_CS | CONST_PERSISTENT);' >> $outfile
52echo '}' >> $outfile
53
54
55echo '
56char *get_token_type_name(int token_type)
57{
58	switch (token_type) {
59' >> $outfile
60
61awk '
62	/^    T_PAAMAYIM_NEKUDOTAYIM/ {
63		print "		case T_PAAMAYIM_NEKUDOTAYIM: return \"T_DOUBLE_COLON\";"
64		next
65	}
66	/^    T_(NOELSE|ERROR)/ { next }
67	/^    T_/ {
68		print "		case " $1 ": return \"" $1 "\";"
69	}
70' < $infile >> $outfile
71
72echo '
73	}
74	return NULL;
75}
76' >> $outfile
77
78echo "Wrote $outfile"
79