• Download Gist
php-master-no-open-tags.20120401.patch.diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
diff --git a/Zend/zend.c b/Zend/zend.c
index dd299f1..d3501eb 100644
--- a/Zend/zend.c
+++ b/Zend/zend.c
@@ -466,20 +466,14 @@ static FILE *zend_fopen_wrapper(const char *filename, char **opened_path TSRMLS_
/* }}} */
#ifdef ZTS
-static zend_bool asp_tags_default = 0;
-static zend_bool short_tags_default = 1;
static zend_uint compiler_options_default = ZEND_COMPILE_DEFAULT;
#else
-# define asp_tags_default 0
-# define short_tags_default 1
# define compiler_options_default ZEND_COMPILE_DEFAULT
#endif
static void zend_set_default_compile_time_values(TSRMLS_D) /* {{{ */
{
/* default compile-time values */
- CG(asp_tags) = asp_tags_default;
- CG(short_tags) = short_tags_default;
CG(compiler_options) = compiler_options_default;
}
/* }}} */
@@ -788,8 +782,6 @@ void zend_post_startup(TSRMLS_D) /* {{{ */
*GLOBAL_CLASS_TABLE = *compiler_globals->class_table;
*GLOBAL_CONSTANTS_TABLE = *executor_globals->zend_constants;
- asp_tags_default = CG(asp_tags);
- short_tags_default = CG(short_tags);
compiler_options_default = CG(compiler_options);
zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index c3c35eb..04c6d01 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -196,6 +196,7 @@ void zend_init_compiler_data_structures(TSRMLS_D) /* {{{ */
zend_llist_init(&CG(dimension_llist), sizeof(int), NULL, 0);
zend_stack_init(&CG(list_stack));
CG(in_compilation) = 0;
+ CG(first_token) = 1;
CG(start_lineno) = 0;
CG(current_namespace) = NULL;
CG(in_namespace) = 0;
@@ -6690,24 +6691,24 @@ again:
Z_TYPE(zendlval->u.constant) = IS_LONG;
retval = lex_scan(&zendlval->u.constant TSRMLS_CC);
switch (retval) {
+ case T_OPEN_TAG:
+ if (CG(first_token)) {
+ goto again;
+ }
+ zend_error(E_COMPILE_ERROR, "Open tag must occur at the top of the script");
+ break;
+
case T_COMMENT:
case T_DOC_COMMENT:
- case T_OPEN_TAG:
case T_WHITESPACE:
goto again;
case T_CLOSE_TAG:
- if (LANG_SCNG(yy_text)[LANG_SCNG(yy_leng)-1] != '>') {
- CG(increment_lineno) = 1;
- }
- if (CG(has_bracketed_namespaces) && !CG(in_namespace)) {
- goto again;
+ if (CG(has_bracketed_namespaces) && CG(in_namespace)) {
+ zend_error(E_COMPILE_ERROR, "Close tag may not occur in the namespace");
}
retval = ';'; /* implicit ; */
break;
- case T_OPEN_TAG_WITH_ECHO:
- retval = T_ECHO;
- break;
case T_END_HEREDOC:
efree(Z_STRVAL(zendlval->u.constant));
break;
@@ -6715,6 +6716,7 @@ again:
INIT_PZVAL(&zendlval->u.constant);
zendlval->op_type = IS_CONST;
+ CG(first_token) = 0;
return retval;
}
/* }}} */
diff --git a/Zend/zend_globals.h b/Zend/zend_globals.h
index dbbcf97..0f9d0d5 100644
--- a/Zend/zend_globals.h
+++ b/Zend/zend_globals.h
@@ -103,8 +103,7 @@ struct _zend_compiler_globals {
zend_bool parse_error;
zend_bool in_compilation;
- zend_bool short_tags;
- zend_bool asp_tags;
+ zend_bool first_token;
zend_declarables declarables;
diff --git a/Zend/zend_language_scanner.l b/Zend/zend_language_scanner.l
index d530b53..52f255d 100644
--- a/Zend/zend_language_scanner.l
+++ b/Zend/zend_language_scanner.l
@@ -519,7 +519,7 @@ ZEND_API int open_file_for_scanning(zend_file_handle *file_handle TSRMLS_DC)
zend_error_noreturn(E_COMPILE_ERROR, "zend_stream_mmap() failed");
}
- BEGIN(INITIAL);
+ BEGIN(ST_IN_SCRIPTING);
if (file_handle->opened_path) {
file_path = file_handle->opened_path;
@@ -812,7 +812,7 @@ int highlight_string(zval *str, zend_syntax_highlighter_ini *syntax_highlighter_
zend_restore_lexical_state(&original_lex_state TSRMLS_CC);
return FAILURE;
}
- BEGIN(INITIAL);
+ BEGIN(ST_IN_SCRIPTING);
zend_highlight(syntax_highlighter_ini TSRMLS_CC);
if (SCNG(script_filtered)) {
efree(SCNG(script_filtered));
@@ -1705,142 +1705,32 @@ NEWLINE ("\r"|"\n"|"\r\n")
return T_NS_C;
}
-<INITIAL>"<script"{WHITESPACE}+"language"{WHITESPACE}*"="{WHITESPACE}*("php"|"\"php\""|"'php'"){WHITESPACE}*">" {
- YYCTYPE *bracket = (YYCTYPE*)zend_memrchr(yytext, '<', yyleng - (sizeof("script language=php>") - 1));
-
- if (bracket != SCNG(yy_text)) {
- /* Handle previously scanned HTML, as possible <script> tags found are assumed to not be PHP's */
- YYCURSOR = bracket;
- goto inline_html;
- }
-
- HANDLE_NEWLINES(yytext, yyleng);
+<ST_IN_SCRIPTING>"<%" {
zendlval->value.str.val = yytext; /* no copying - intentional */
zendlval->value.str.len = yyleng;
zendlval->type = IS_STRING;
- BEGIN(ST_IN_SCRIPTING);
return T_OPEN_TAG;
}
-<INITIAL>"<%=" {
- if (CG(asp_tags)) {
- zendlval->value.str.val = yytext; /* no copying - intentional */
- zendlval->value.str.len = yyleng;
- zendlval->type = IS_STRING;
- BEGIN(ST_IN_SCRIPTING);
- return T_OPEN_TAG_WITH_ECHO;
- } else {
- goto inline_char_handler;
- }
-}
-
-
-<INITIAL>"<?=" {
+<ST_IN_SCRIPTING>"<?php"([ \t]|{NEWLINE}) {
zendlval->value.str.val = yytext; /* no copying - intentional */
zendlval->value.str.len = yyleng;
zendlval->type = IS_STRING;
- BEGIN(ST_IN_SCRIPTING);
- return T_OPEN_TAG_WITH_ECHO;
-}
-
-
-<INITIAL>"<%" {
- if (CG(asp_tags)) {
- zendlval->value.str.val = yytext; /* no copying - intentional */
- zendlval->value.str.len = yyleng;
- zendlval->type = IS_STRING;
- BEGIN(ST_IN_SCRIPTING);
- return T_OPEN_TAG;
- } else {
- goto inline_char_handler;
- }
+ HANDLE_NEWLINE(yytext[yyleng-1]);
+ return T_OPEN_TAG;
}
-<INITIAL>"<?php"([ \t]|{NEWLINE}) {
+<ST_IN_SCRIPTING>"<?" {
zendlval->value.str.val = yytext; /* no copying - intentional */
zendlval->value.str.len = yyleng;
zendlval->type = IS_STRING;
- HANDLE_NEWLINE(yytext[yyleng-1]);
BEGIN(ST_IN_SCRIPTING);
return T_OPEN_TAG;
}
-<INITIAL>"<?" {
- if (CG(short_tags)) {
- zendlval->value.str.val = yytext; /* no copying - intentional */
- zendlval->value.str.len = yyleng;
- zendlval->type = IS_STRING;
- BEGIN(ST_IN_SCRIPTING);
- return T_OPEN_TAG;
- } else {
- goto inline_char_handler;
- }
-}
-
-<INITIAL>{ANY_CHAR} {
- if (YYCURSOR > YYLIMIT) {
- return 0;
- }
-
-inline_char_handler:
-
- while (1) {
- YYCTYPE *ptr = memchr(YYCURSOR, '<', YYLIMIT - YYCURSOR);
-
- YYCURSOR = ptr ? ptr + 1 : YYLIMIT;
-
- if (YYCURSOR < YYLIMIT) {
- switch (*YYCURSOR) {
- case '?':
- if (CG(short_tags) || !strncasecmp((char*)YYCURSOR + 1, "php", 3) || (*(YYCURSOR + 1) == '=')) { /* Assume [ \t\n\r] follows "php" */
- break;
- }
- continue;
- case '%':
- if (CG(asp_tags)) {
- break;
- }
- continue;
- case 's':
- case 'S':
- /* Probably NOT an opening PHP <script> tag, so don't end the HTML chunk yet
- * If it is, the PHP <script> tag rule checks for any HTML scanned before it */
- YYCURSOR--;
- yymore();
- default:
- continue;
- }
-
- YYCURSOR--;
- }
-
- break;
- }
-
-inline_html:
- yyleng = YYCURSOR - SCNG(yy_text);
-
- if (SCNG(output_filter)) {
- int readsize;
- size_t sz = 0;
- readsize = SCNG(output_filter)((unsigned char **)&(zendlval->value.str.val), &sz, (unsigned char *)yytext, (size_t)yyleng TSRMLS_CC);
- zendlval->value.str.len = sz;
- if (readsize < yyleng) {
- yyless(readsize);
- }
- } else {
- zendlval->value.str.val = (char *) estrndup(yytext, yyleng);
- zendlval->value.str.len = yyleng;
- }
- zendlval->type = IS_STRING;
- HANDLE_NEWLINES(yytext, yyleng);
- return T_INLINE_HTML;
-}
-
-
/* Make sure a label character follows "->", otherwise there is no property
* and "->" will be taken literally
*/
@@ -1904,10 +1794,6 @@ inline_html:
CG(zend_lineno)++;
break;
case '%':
- if (!CG(asp_tags)) {
- continue;
- }
- /* fall through */
case '?':
if (*YYCURSOR == '>') {
YYCURSOR--;
@@ -1964,22 +1850,15 @@ inline_html:
zendlval->value.str.val = yytext; /* no copying - intentional */
zendlval->value.str.len = yyleng;
zendlval->type = IS_STRING;
- BEGIN(INITIAL);
return T_CLOSE_TAG; /* implicit ';' at php-end tag */
}
<ST_IN_SCRIPTING>"%>"{NEWLINE}? {
- if (CG(asp_tags)) {
- BEGIN(INITIAL);
- zendlval->value.str.len = yyleng;
- zendlval->type = IS_STRING;
- zendlval->value.str.val = yytext; /* no copying - intentional */
- return T_CLOSE_TAG; /* implicit ';' at php-end tag */
- } else {
- yyless(1);
- return yytext[0];
- }
+ zendlval->value.str.len = yyleng;
+ zendlval->type = IS_STRING;
+ zendlval->value.str.val = yytext; /* no copying - intentional */
+ return T_CLOSE_TAG; /* implicit ';' at php-end tag */
}
diff --git a/Zend/zend_language_scanner_defs.h b/Zend/zend_language_scanner_defs.h
index 015a903..ff8d13a 100644
--- a/Zend/zend_language_scanner_defs.h
+++ b/Zend/zend_language_scanner_defs.h
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.13.5 on Thu Mar 1 21:27:30 2012 */
+/* Generated by re2c 0.13.5 on Sun Apr 1 01:38:20 2012 */
#line 3 "Zend/zend_language_scanner_defs.h"
enum YYCONDTYPE {
@@ -9,7 +9,6 @@ enum YYCONDTYPE {
yycST_HEREDOC,
yycST_LOOKING_FOR_VARNAME,
yycST_VAR_OFFSET,
- yycINITIAL,
yycST_END_HEREDOC,
yycST_NOWDOC,
};
diff --git a/ext/tokenizer/tokenizer.c b/ext/tokenizer/tokenizer.c
index c5cbf6c..effa815 100644
--- a/ext/tokenizer/tokenizer.c
+++ b/ext/tokenizer/tokenizer.c
@@ -121,7 +121,6 @@ static void tokenize(zval *return_value TSRMLS_DC)
CG(zend_lineno)++;
}
case T_OPEN_TAG:
- case T_OPEN_TAG_WITH_ECHO:
case T_WHITESPACE:
case T_COMMENT:
case T_DOC_COMMENT:
@@ -200,7 +199,7 @@ PHP_FUNCTION(token_get_all)
RETURN_FALSE;
}
- LANG_SCNG(yy_state) = yycINITIAL;
+ LANG_SCNG(yy_state) = yycST_IN_SCRIPTING;
tokenize(return_value TSRMLS_CC);
diff --git a/main/main.c b/main/main.c
index 6ec8d79..ba6a49d 100644
--- a/main/main.c
+++ b/main/main.c
@@ -483,7 +483,6 @@ PHP_INI_BEGIN()
PHP_INI_ENTRY_EX("highlight.keyword", HL_KEYWORD_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
PHP_INI_ENTRY_EX("highlight.string", HL_STRING_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
- STD_PHP_INI_BOOLEAN("asp_tags", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, asp_tags, zend_compiler_globals, compiler_globals)
STD_PHP_INI_ENTRY_EX("display_errors", "1", PHP_INI_ALL, OnUpdateDisplayErrors, display_errors, php_core_globals, core_globals, display_errors_mode)
STD_PHP_INI_BOOLEAN("display_startup_errors", "0", PHP_INI_ALL, OnUpdateBool, display_startup_errors, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("enable_dl", "1", PHP_INI_SYSTEM, OnUpdateBool, enable_dl, php_core_globals, core_globals)
@@ -506,7 +505,6 @@ PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("output_handler", NULL, PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateString, output_handler, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("register_argc_argv", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, register_argc_argv, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("auto_globals_jit", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, auto_globals_jit, php_core_globals, core_globals)
- STD_PHP_INI_BOOLEAN("short_open_tag", DEFAULT_SHORT_OPEN_TAG, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, short_tags, zend_compiler_globals, compiler_globals)
STD_PHP_INI_BOOLEAN("sql.safe_mode", "0", PHP_INI_SYSTEM, OnUpdateBool, sql_safe_mode, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("track_errors", "0", PHP_INI_ALL, OnUpdateBool, track_errors, php_core_globals, core_globals)

Nice work. I would like to see option that controls w/ and w/o tag ;)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.