use of org.mozilla.javascript.ast.EmptyExpression in project st-js by st-js.
the class RhinoJavaScriptWriter method printList.
/**
* <p>printList.</p>
*
* @param items a {@link java.util.List} object.
* @param param a {@link java.lang.Boolean} object.
*/
protected <T extends AstNode> void printList(List<T> items, Boolean param) {
int max = items.size();
int count = 0;
for (AstNode item : items) {
visitorSupport.accept(item, this, param);
if (count < max - 1) {
count++;
print(", ");
} else if (item instanceof EmptyExpression) {
print(",");
}
}
}
use of org.mozilla.javascript.ast.EmptyExpression in project HL4A by HL4A.
the class IRFactory method transformXmlLiteral.
private Node transformXmlLiteral(XmlLiteral node) {
// a literal like <foo>{bar}</foo> is rewritten as
// new XML("<foo>" + bar + "</foo>");
Node pnXML = new Node(Token.NEW, node.getLineno());
List<XmlFragment> frags = node.getFragments();
XmlString first = (XmlString) frags.get(0);
boolean anon = first.getXml().trim().startsWith("<>");
pnXML.addChildToBack(createName(anon ? "XMLList" : "XML"));
Node pn = null;
for (XmlFragment frag : frags) {
if (frag instanceof XmlString) {
String xml = ((XmlString) frag).getXml();
decompiler.addName(xml);
if (pn == null) {
pn = createString(xml);
} else {
pn = createBinary(Token.ADD, pn, createString(xml));
}
} else {
XmlExpression xexpr = (XmlExpression) frag;
boolean isXmlAttr = xexpr.isXmlAttribute();
Node expr;
decompiler.addToken(Token.LC);
if (xexpr.getExpression() instanceof EmptyExpression) {
expr = createString("");
} else {
expr = transform(xexpr.getExpression());
}
decompiler.addToken(Token.RC);
if (isXmlAttr) {
// Need to put the result in double quotes
expr = createUnary(Token.ESCXMLATTR, expr);
Node prepend = createBinary(Token.ADD, createString("\""), expr);
expr = createBinary(Token.ADD, prepend, createString("\""));
} else {
expr = createUnary(Token.ESCXMLTEXT, expr);
}
pn = createBinary(Token.ADD, pn, expr);
}
}
pnXML.addChildToBack(pn);
return pnXML;
}
use of org.mozilla.javascript.ast.EmptyExpression in project HL4A by HL4A.
the class Parser method arrayLiteral.
/**
* May return an {@link ArrayLiteral} or {@link ArrayComprehension}.
*/
private AstNode arrayLiteral() throws IOException {
if (currentToken != Token.LB)
codeBug();
int pos = ts.tokenBeg, end = ts.tokenEnd;
List<AstNode> elements = new ArrayList<AstNode>();
ArrayLiteral pn = new ArrayLiteral(pos);
boolean after_lb_or_comma = true;
int afterComma = -1;
int skipCount = 0;
for (; ; ) {
int tt = peekToken();
if (tt == Token.COMMA) {
consumeToken();
afterComma = ts.tokenEnd;
if (!after_lb_or_comma) {
after_lb_or_comma = true;
} else {
elements.add(new EmptyExpression(ts.tokenBeg, 1));
skipCount++;
}
} else if (tt == Token.RB) {
consumeToken();
// for ([a,] in obj) is legal, but for ([a] in obj) is
// not since we have both key and value supplied. The
// trick is that [a,] and [a] are equivalent in other
// array literal contexts. So we calculate a special
// length value just for destructuring assignment.
end = ts.tokenEnd;
pn.setDestructuringLength(elements.size() + (after_lb_or_comma ? 1 : 0));
pn.setSkipCount(skipCount);
if (afterComma != -1)
warnTrailingComma(pos, elements, afterComma);
break;
} else if (tt == Token.FOR && !after_lb_or_comma && elements.size() == 1) {
return arrayComprehension(elements.get(0), pos);
} else if (tt == Token.EOF) {
reportError("msg.no.bracket.arg");
break;
} else {
if (!after_lb_or_comma) {
reportError("msg.no.bracket.arg");
}
elements.add(assignExpr());
after_lb_or_comma = false;
afterComma = -1;
}
}
for (AstNode e : elements) {
pn.addElement(e);
}
pn.setLength(end - pos);
return pn;
}
use of org.mozilla.javascript.ast.EmptyExpression in project HL4A by HL4A.
the class Parser method parenExpr.
private AstNode parenExpr() throws IOException {
boolean wasInForInit = inForInit;
inForInit = false;
try {
Comment jsdocNode = getAndResetJsDoc();
int lineno = ts.lineno;
int begin = ts.tokenBeg;
AstNode e = (peekToken() == Token.RP ? new EmptyExpression(begin) : expr());
if (peekToken() == Token.FOR) {
return generatorExpression(e, begin);
}
ParenthesizedExpression pn = new ParenthesizedExpression(e);
if (jsdocNode == null) {
jsdocNode = getAndResetJsDoc();
}
if (jsdocNode != null) {
pn.setJsDocNode(jsdocNode);
}
mustMatchToken(Token.RP, "msg.no.paren");
if (e.getType() == Token.EMPTY && peekToken() != Token.ARROW) {
reportError("msg.syntax");
return makeErrorNode();
}
pn.setLength(ts.tokenEnd - pn.getPosition());
pn.setLineno(lineno);
return pn;
} finally {
inForInit = wasInForInit;
}
}
use of org.mozilla.javascript.ast.EmptyExpression in project st-js by st-js.
the class RhinoJavaScriptBuilder method binary.
/**
* {@inheritDoc}
*/
@Override
public AstNode binary(BinaryOperator operator, Iterable<AstNode> operands) {
// this is to deal with the COMMA operator who can have less than two operands
if (Iterables.isEmpty(operands)) {
return new EmptyExpression();
}
if (Iterables.size(operands) == 1) {
return operands.iterator().next();
}
InfixExpression list = new InfixExpression();
list.setOperator(operator.getJavaScript());
Iterator<AstNode> it = operands.iterator();
list.setLeft(it.next());
list.setRight(it.next());
while (it.hasNext()) {
InfixExpression tmpIncrements = new InfixExpression();
tmpIncrements.setOperator(operator.getJavaScript());
tmpIncrements.setLeft(list);
tmpIncrements.setRight(it.next());
list = tmpIncrements;
}
return list;
}
Aggregations