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 <zend_language_parser.h> 62 63char *get_token_type_name(int token_type) 64{ 65\tswitch (token_type) { 66 67 68CODE; 69 70foreach ($matches['token_name'] as $tokenName) { 71 if ($tokenName === 'T_NOELSE' || $tokenName === 'T_ERROR') { 72 continue; 73 } 74 if ($tokenName === 'T_PAAMAYIM_NEKUDOTAYIM') { 75 $result .= "\t\tcase T_PAAMAYIM_NEKUDOTAYIM: return \"T_DOUBLE_COLON\";\n"; 76 } else { 77 $result .= "\t\tcase $tokenName: return \"$tokenName\";\n"; 78 } 79} 80 81$result .= <<<CODE 82 83\t} 84\treturn NULL; 85} 86 87 88CODE; 89 90file_put_contents($outfile_c, $result); 91 92echo "Wrote $outfile_c\n"; 93