|
| 1 | +# This is CMake-based alternative of ext/tokenizer/tokenizer_data_gen.php |
| 2 | +# |
| 3 | +# Run as: |
| 4 | +# cmake -D PHP_SOURCE_DIR=<php-src> -P GenerateTokenizerData.cmake |
| 5 | + |
| 6 | +cmake_minimum_required(VERSION 3.25...3.31) |
| 7 | + |
| 8 | +if(NOT CMAKE_SCRIPT_MODE_FILE) |
| 9 | + message(FATAL_ERROR "This is a command-line script.") |
| 10 | +endif() |
| 11 | + |
| 12 | +if(NOT PHP_SOURCE_DIR) |
| 13 | + message(FATAL_ERROR "PHP_SOURCE_DIR variable is required.") |
| 14 | +endif() |
| 15 | + |
| 16 | +set(regex "^%token [^T]*(T_[^ \n]+)") |
| 17 | + |
| 18 | +file( |
| 19 | + STRINGS |
| 20 | + "${PHP_SOURCE_DIR}/Zend/zend_language_parser.y" |
| 21 | + lines |
| 22 | + REGEX "${regex}" |
| 23 | +) |
| 24 | + |
| 25 | +# Bypass the [ and ] characters issue in lists: |
| 26 | +# https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#cmake-language-lists |
| 27 | +string(REPLACE "[" "LEFT_BRACKET" lines "${lines}") |
| 28 | +string(REPLACE "]" "RIGHT_BRACKET" lines "${lines}") |
| 29 | + |
| 30 | +# Get a list of tokens. |
| 31 | +set(tokens "") |
| 32 | +foreach(line IN LISTS lines) |
| 33 | + if(line MATCHES "${regex}") |
| 34 | + set(token "${CMAKE_MATCH_1}") |
| 35 | + |
| 36 | + if(token MATCHES "^T_(NOELSE|ERROR)$") |
| 37 | + continue() |
| 38 | + endif() |
| 39 | + |
| 40 | + list(APPEND tokens "${token}") |
| 41 | + endif() |
| 42 | +endforeach() |
| 43 | + |
| 44 | +set(content "") |
| 45 | +foreach(token IN LISTS tokens) |
| 46 | + string( |
| 47 | + APPEND |
| 48 | + content |
| 49 | + "/**\n * @var int\n * @cvalue ${token}\n */\n" |
| 50 | + "const ${token} = UNKNOWN;\n" |
| 51 | + ) |
| 52 | +endforeach() |
| 53 | +string(STRIP "${content}" content) |
| 54 | + |
| 55 | +file( |
| 56 | + CONFIGURE |
| 57 | + OUTPUT "${PHP_SOURCE_DIR}/ext/tokenizer/tokenizer_data.stub.php" |
| 58 | + CONTENT [[ |
| 59 | +<?php |
| 60 | +
|
| 61 | +/** @generate-class-entries */ |
| 62 | +
|
| 63 | +@content@ |
| 64 | +/** |
| 65 | + * @var int |
| 66 | + * @cvalue T_PAAMAYIM_NEKUDOTAYIM |
| 67 | + */ |
| 68 | +const T_DOUBLE_COLON = UNKNOWN; |
| 69 | +]] @ONLY) |
| 70 | + |
| 71 | +set(content "") |
| 72 | +foreach(token IN LISTS tokens) |
| 73 | + if(token STREQUAL "T_PAAMAYIM_NEKUDOTAYIM") |
| 74 | + string( |
| 75 | + APPEND |
| 76 | + content |
| 77 | + "\t\tcase T_PAAMAYIM_NEKUDOTAYIM: return \"T_DOUBLE_COLON\";\n" |
| 78 | + ) |
| 79 | + else() |
| 80 | + string(APPEND content "\t\tcase ${token}: return \"${token}\";\n") |
| 81 | + endif() |
| 82 | +endforeach() |
| 83 | + |
| 84 | +set(tab "\t") |
| 85 | + |
| 86 | +file( |
| 87 | + CONFIGURE |
| 88 | + OUTPUT "${PHP_SOURCE_DIR}/ext/tokenizer/tokenizer_data.c" |
| 89 | + CONTENT [[ |
| 90 | +/* |
| 91 | + +----------------------------------------------------------------------+ |
| 92 | + | Copyright (c) The PHP Group | |
| 93 | + +----------------------------------------------------------------------+ |
| 94 | + | This source file is subject to version 3.01 of the PHP license, | |
| 95 | + | that is bundled with this package in the file LICENSE, and is | |
| 96 | + | available through the world-wide-web at the following url: | |
| 97 | + | https://www.php.net/license/3_01.txt | |
| 98 | + | If you did not receive a copy of the PHP license and are unable to | |
| 99 | + | obtain it through the world-wide-web, please send a note to | |
| 100 | + | [email protected] so we can mail you a copy immediately. | |
| 101 | + +----------------------------------------------------------------------+ |
| 102 | + | Author: Johannes Schlueter <[email protected]> | |
| 103 | + +----------------------------------------------------------------------+ |
| 104 | +*/ |
| 105 | +
|
| 106 | +/* |
| 107 | + DO NOT EDIT THIS FILE! |
| 108 | + This file is generated using tokenizer_data_gen.php |
| 109 | +*/ |
| 110 | +
|
| 111 | +#include <zend_language_parser.h> |
| 112 | +
|
| 113 | +char *get_token_type_name(int token_type) |
| 114 | +{ |
| 115 | +@tab@switch (token_type) { |
| 116 | +
|
| 117 | +@content@ |
| 118 | +@tab@} |
| 119 | +@tab@return NULL; |
| 120 | +} |
| 121 | +
|
| 122 | +]] @ONLY) |
0 commit comments