1#!/usr/bin/env php
2<?php
3
4$infile = __DIR__ . '/../../Zend/zend_language_parser.y';
5$outfile_stub = __DIR__ . '/tokenizer_data.stub.php';
6$outfile_c = __DIR__ . '/tokenizer_data.c';
7
8if (!file_exists($infile)) {
9    fwrite(STDERR, <<<ERROR
10$infile is missing.
11
12Please, generate the PHP parser files by scripts/dev/genfiles
13or by running the ./configure build step.
14ERROR
15    );
16    exit(1);
17}
18
19$result = "<?php\n\n/** @generate-class-entries */\n\n";
20
21$incontent = file_get_contents($infile);
22preg_match_all('(^%token.*\b(?<token_name>T_.*?)\b)m', $incontent, $matches);
23
24foreach ($matches['token_name'] as $tokenName) {
25    if ($tokenName === 'T_NOELSE' || $tokenName === 'T_ERROR') {
26        continue;
27    }
28    $result .= "/**\n * @var int\n * @cvalue $tokenName\n */\n";
29    $result .= "const $tokenName = UNKNOWN;\n";
30}
31
32$result .= "/**\n * @var int\n * @cvalue T_PAAMAYIM_NEKUDOTAYIM\n */\n";
33$result .= "const T_DOUBLE_COLON = UNKNOWN;\n";
34
35file_put_contents($outfile_stub, $result);
36
37echo "Wrote $outfile_stub\n";
38
39$result = <<<CODE
40/*
41   +----------------------------------------------------------------------+
42   | Copyright (c) The PHP Group                                          |
43   +----------------------------------------------------------------------+
44   | This source file is subject to version 3.01 of the PHP license,      |
45   | that is bundled with this package in the file LICENSE, and is        |
46   | available through the world-wide-web at the following url:           |
47   | https://www.php.net/license/3_01.txt                                 |
48   | If you did not receive a copy of the PHP license and are unable to   |
49   | obtain it through the world-wide-web, please send a note to          |
50   | license@php.net so we can mail you a copy immediately.               |
51   +----------------------------------------------------------------------+
52   | Author: Johannes Schlueter <johannes@php.net>                        |
53   +----------------------------------------------------------------------+
54*/
55
56/*
57   DO NOT EDIT THIS FILE!
58   This file is generated using tokenizer_data_gen.php
59*/
60
61#include "php.h"
62#include "zend.h"
63#include <zend_language_parser.h>
64
65char *get_token_type_name(int token_type)
66{
67\tswitch (token_type) {
68
69
70CODE;
71
72foreach ($matches['token_name'] as $tokenName) {
73    if ($tokenName === 'T_NOELSE' || $tokenName === 'T_ERROR') {
74        continue;
75    }
76    if ($tokenName === 'T_PAAMAYIM_NEKUDOTAYIM') {
77        $result .= "\t\tcase T_PAAMAYIM_NEKUDOTAYIM: return \"T_DOUBLE_COLON\";\n";
78    } else {
79        $result .= "\t\tcase $tokenName: return \"$tokenName\";\n";
80    }
81}
82
83$result .= <<<CODE
84
85\t}
86\treturn NULL;
87}
88
89
90CODE;
91
92file_put_contents($outfile_c, $result);
93
94echo "Wrote $outfile_c\n";
95