зеркало из https://github.com/mozilla/gecko-dev.git
bug 590774, r=cdleary: implement function::identifier E4X extension
This commit is contained in:
Родитель
86ec86aeb6
Коммит
8e10f31b0b
|
@ -102,6 +102,7 @@ ASTDEF(AST_XMLESCAPE, "XMLEscape")
|
|||
ASTDEF(AST_XMLFILTER, "XMLFilterExpression")
|
||||
ASTDEF(AST_XMLDEFAULT, "XMLDefaultDeclaration")
|
||||
ASTDEF(AST_XMLQUAL, "XMLQualifiedIdentifier")
|
||||
ASTDEF(AST_XMLFUNCQUAL, "XMLFunctionQualifiedIdentifier")
|
||||
ASTDEF(AST_XMLELEM, "XMLElement")
|
||||
ASTDEF(AST_XMLTEXT, "XMLText")
|
||||
ASTDEF(AST_XMLLIST, "XMLList")
|
||||
|
|
|
@ -457,6 +457,8 @@ class NodeBuilder
|
|||
|
||||
bool xmlQualifiedIdentifier(Value left, Value right, bool computed, TokenPos *pos, Value *dst);
|
||||
|
||||
bool xmlFunctionQualifiedIdentifier(Value right, bool computed, TokenPos *pos, Value *dst);
|
||||
|
||||
bool xmlElement(NodeVector &elts, TokenPos *pos, Value *dst);
|
||||
|
||||
bool xmlText(Value text, TokenPos *pos, Value *dst);
|
||||
|
@ -1087,6 +1089,15 @@ NodeBuilder::xmlAttributeSelector(Value expr, TokenPos *pos, Value *dst)
|
|||
return newNode(AST_XMLATTR_SEL, pos, "attribute", expr, dst);
|
||||
}
|
||||
|
||||
bool
|
||||
NodeBuilder::xmlFunctionQualifiedIdentifier(Value right, bool computed, TokenPos *pos, Value *dst)
|
||||
{
|
||||
return newNode(AST_XMLFUNCQUAL, pos,
|
||||
"right", right,
|
||||
"computed", BooleanValue(computed),
|
||||
dst);
|
||||
}
|
||||
|
||||
bool
|
||||
NodeBuilder::xmlQualifiedIdentifier(Value left, Value right, bool computed,
|
||||
TokenPos *pos, Value *dst)
|
||||
|
@ -2280,19 +2291,32 @@ ASTSerializer::expression(JSParseNode *pn, Value *dst)
|
|||
|
||||
case TOK_DBLCOLON:
|
||||
{
|
||||
Value left, right;
|
||||
Value right;
|
||||
|
||||
LOCAL_ASSERT(pn->pn_arity == PN_NAME || pn->pn_arity == PN_BINARY);
|
||||
|
||||
bool computed = pn->pn_arity == PN_BINARY;
|
||||
JSParseNode *pnleft;
|
||||
bool computed;
|
||||
|
||||
return (computed
|
||||
? (expression(pn->pn_left, &left) &&
|
||||
expression(pn->pn_right, &right))
|
||||
: (expression(pn->pn_expr, &left) &&
|
||||
identifier(pn->pn_atom, NULL, &right))) &&
|
||||
builder.xmlQualifiedIdentifier(left, right, computed,
|
||||
&pn->pn_pos, dst);
|
||||
if (pn->pn_arity == PN_BINARY) {
|
||||
computed = true;
|
||||
pnleft = pn->pn_left;
|
||||
if (!expression(pn->pn_right, &right))
|
||||
return false;
|
||||
} else {
|
||||
JS_ASSERT(pn->pn_arity == PN_NAME);
|
||||
computed = false;
|
||||
pnleft = pn->pn_expr;
|
||||
if (!identifier(pn->pn_atom, NULL, &right))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (PN_TYPE(pnleft) == TOK_FUNCTION)
|
||||
return builder.xmlFunctionQualifiedIdentifier(right, computed, &pn->pn_pos, dst);
|
||||
|
||||
Value left;
|
||||
return expression(pnleft, &left) &&
|
||||
builder.xmlQualifiedIdentifier(left, right, computed, &pn->pn_pos, dst);
|
||||
}
|
||||
|
||||
case TOK_AT:
|
||||
|
|
|
@ -93,6 +93,7 @@ function blockPatt(patt) program([exprStmt(funExpr(null, [], blockStmt([blockStm
|
|||
var xmlAnyName = Pattern({ type: "XMLAnyName" });
|
||||
|
||||
function xmlQualId(left, right, computed) Pattern({ type: "XMLQualifiedIdentifier", left: left, right: right, computed: computed })
|
||||
function xmlFuncQualId(right, computed) Pattern({ type: "XMLFunctionQualifiedIdentifier", right: right, computed: computed })
|
||||
function xmlAttrSel(id) Pattern({ type: "XMLAttributeSelector", attribute: id })
|
||||
function xmlFilter(left, right) Pattern({ type: "XMLFilterExpression", left: left, right: right })
|
||||
function xmlPointTag(contents) Pattern({ type: "XMLPointTag", contents: contents })
|
||||
|
@ -741,6 +742,8 @@ assertExpr("x::[foo()]", xmlQualId(ident("x"), callExpr(ident("foo"), []), true)
|
|||
assertExpr("*::*", xmlQualId(xmlAnyName, ident("*"), false));
|
||||
assertExpr("*::[foo]", xmlQualId(xmlAnyName, ident("foo"), true));
|
||||
assertExpr("*::[foo()]", xmlQualId(xmlAnyName, callExpr(ident("foo"), []), true));
|
||||
assertExpr("function::x", xmlFuncQualId(ident("x"), false));
|
||||
assertExpr("function::[foo]", xmlFuncQualId(ident("foo"), true));
|
||||
assertExpr("@foo", xmlAttrSel(ident("foo")));
|
||||
assertExpr("x.(p)", xmlFilter(ident("x"), ident("p")));
|
||||
assertExpr("<{foo}/>", xmlPointTag([xmlEscape(ident("foo"))]));
|
||||
|
|
Загрузка…
Ссылка в новой задаче