XHP comment syntax
XML comment syntax for XHP is one of the top wishlist items within the UIE group (+ some other people).
Currently, the only way to have comments inside XHP blocks is to use expressions and block comments, e.g.
<div>{/* comment */}</div>
After this change, you can use the more familiar syntax. This syntax is limited to XHP child contexts:
// Only single-line, doc, block comments work outside XHP
$xhp =
<div>
<!--XML comments only work within XHP children contexts-->
</div>;
Based on http://www.w3.org/TR/REC-xml/#sec-comments - except we ignore the rule about double hyphens ('--') within a comment because we don't care about SGML.
Esse commit está contido em:
@@ -365,7 +365,7 @@ static void xhp_attribute(Parser *_p, Token &out, Token &type, Token &label,
|
||||
Token &def, Token &req) {
|
||||
/**
|
||||
* The basic builtin types "bool", "int", "double", and "string" all map to
|
||||
* T_STRING in the parser, and the parser uses always uses type code 5 for
|
||||
* T_STRING in the parser, and the parser always uses type code 5 for
|
||||
* T_STRING. However, XHP uses different type codes for these basic builtin
|
||||
* types, so we need to fix up the type code here to make XHP happy.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
class :node {
|
||||
private $children;
|
||||
public function __construct($_, $children) {
|
||||
$this->children = $children;
|
||||
}
|
||||
public function __toString() {
|
||||
$o = '';
|
||||
foreach ($this->children as $child) {
|
||||
$o .= (string)$child;
|
||||
}
|
||||
$o .= count($this->children);
|
||||
return $o;
|
||||
}
|
||||
}
|
||||
|
||||
$n1 =
|
||||
<node>
|
||||
<!--hey-->
|
||||
</node>;
|
||||
|
||||
$n2 =
|
||||
<node>
|
||||
{'a'}
|
||||
<!--hey-->
|
||||
<!--
|
||||
multiline comment
|
||||
with multiple lines
|
||||
-->
|
||||
{'b'}
|
||||
<node>
|
||||
{'c'}
|
||||
<!--nested comment-->
|
||||
</node>
|
||||
<!--comment-with -- extra--hyphens----->
|
||||
</node>;
|
||||
|
||||
echo
|
||||
(string)$n1.
|
||||
(string)$n2.
|
||||
"\n";
|
||||
@@ -0,0 +1 @@
|
||||
0abc13
|
||||
@@ -172,6 +172,7 @@ static int getNextTokenType(int t) {
|
||||
%x ST_XHP_END_SINGLETON_TAG
|
||||
%x ST_XHP_END_CLOSE_TAG
|
||||
%x ST_XHP_CHILD
|
||||
%x ST_XHP_COMMENT
|
||||
|
||||
%option stack
|
||||
|
||||
@@ -811,6 +812,20 @@ BACKQUOTE_CHARS ("{"*([^$`\\{]|("\\"{ANY_CHAR}))|{BACKQUOTE_LITERAL_DOLLAR})
|
||||
yymore();
|
||||
}
|
||||
|
||||
<ST_XHP_COMMENT>[^-]+ {
|
||||
yymore();
|
||||
}
|
||||
|
||||
<ST_XHP_COMMENT>"-->" {
|
||||
STEPPOS;
|
||||
yy_pop_state(yyscanner);
|
||||
return T_COMMENT;
|
||||
}
|
||||
|
||||
<ST_XHP_COMMENT>"-" {
|
||||
yymore();
|
||||
}
|
||||
|
||||
<ST_IN_SCRIPTING>"?>"{NEWLINE}? {
|
||||
if (_scanner->isHackMode()) {
|
||||
_scanner->error("Hack mode: ?> not allowed");
|
||||
@@ -955,6 +970,11 @@ BACKQUOTE_CHARS ("{"*([^$`\\{]|("\\"{ANY_CHAR}))|{BACKQUOTE_LITERAL_DOLLAR})
|
||||
return T_XHP_TAG_GT;
|
||||
}
|
||||
|
||||
<ST_XHP_CHILD>"<!--" {
|
||||
yy_push_state(ST_XHP_COMMENT, yyscanner);
|
||||
yymore();
|
||||
}
|
||||
|
||||
<ST_XHP_CHILD>[^{<]+ {
|
||||
SETTOKEN;
|
||||
return T_XHP_TEXT;
|
||||
|
||||
@@ -286,7 +286,7 @@ static void xhp_attribute(Parser *_p, Token &out, Token &type, Token &label,
|
||||
Token &def, Token &req) {
|
||||
/**
|
||||
* The basic builtin types "bool", "int", "double", and "string" all map to
|
||||
* T_STRING in the parser, and the parser uses always uses type code 5 for
|
||||
* T_STRING in the parser, and the parser always uses type code 5 for
|
||||
* T_STRING. However, XHP uses different type codes for these basic builtin
|
||||
* types, so we need to fix up the type code here to make XHP happy.
|
||||
*/
|
||||
|
||||
+22153
-21800
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
Referência em uma Nova Issue
Bloquear um usuário