Skip to content

Commit

Permalink
Add support for empty closing tags
Browse files Browse the repository at this point in the history
Summary:
<foo>bar</> is now valid syntax. "</>" will just close whatever tag happens to
be open at the time. This mimics the behavior of a subset of SGML's SHORTTAG
directive.

Reviewed By: dcorson

Test Plan: xhpize + various clients of XHP

Revert: OK
  • Loading branch information
Marcel Laverdet committed Oct 26, 2009
1 parent 12255a0 commit 1d0bdef
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ext.hpp
Expand Up @@ -4,7 +4,7 @@
#endif
#include "php.h"

#define PHP_XHP_VERSION "1.3.3"
#define PHP_XHP_VERSION "1.3.5"
#define PHP_XHP_EXTNAME "xhp"

extern zend_module_entry xhp_module_entry;
Expand Down
14 changes: 12 additions & 2 deletions xhp/parser.y
Expand Up @@ -158,7 +158,8 @@ static void replacestr(string &source, const string &find, const string &rep) {

%token T_XHP_WHITESPACE
%token T_XHP_TEXT
%token T_XHP_LESS_THAN_DIV
%token T_XHP_LT_DIV
%token T_XHP_LT_DIV_GT
%token T_XHP_ATTRIBUTE
%token T_XHP_CATEGORY
%token T_XHP_CHILDREN
Expand Down Expand Up @@ -1468,7 +1469,7 @@ xhp_tag_open:
;

xhp_tag_close:
T_XHP_LESS_THAN_DIV xhp_label_no_space '>' {
T_XHP_LT_DIV xhp_label_no_space '>' {
pop_state(); // XHP_CHILD_START
if (yyextra->peekTag() != $2.c_str()) {
string e1 = $2.c_str();
Expand All @@ -1487,6 +1488,15 @@ xhp_tag_close:
}
$$ = "))";
}
| T_XHP_LT_DIV_GT {
// empty end tag -- SGML SHORTTAG
pop_state(); // XHP_CHILD_START
yyextra->popTag();
if (yyextra->haveTag()) {
set_state(XHP_CHILD_START);
}
$$ = "))";
}
;

xhp_tag_start:
Expand Down
6 changes: 5 additions & 1 deletion xhp/scanner.l
Expand Up @@ -607,7 +607,11 @@ NEWLINE ("\r\n"|"\n"|"\r")
}
{WHITESPACE}*"</" {
yy_scan_newlines(yytext, yyg);
tok(T_XHP_LESS_THAN_DIV);
tok(T_XHP_LT_DIV);
}
{WHITESPACE}*"</>" {
yy_scan_newlines(yytext, yyg);
tok(T_XHP_LT_DIV_GT);
}
}

Expand Down

0 comments on commit 1d0bdef

Please sign in to comment.