MCPcopy Create free account
hub / github.com/mozilla/rhino / nameOrLabel

Method nameOrLabel

rhino/src/main/java/org/mozilla/javascript/Parser.java:2410–2466  ·  view source on GitHub ↗

Found a name in a statement context. If it's a label, we gather up any following labels and the next non-label statement into a LabeledStatement "bundle" and return that. Otherwise we parse an expression and return it wrapped in an ExpressionStatement.

()

Source from the content-addressed store, hash-verified

2408 * Otherwise we parse an expression and return it wrapped in an {@link ExpressionStatement}.
2409 */
2410 private AstNode nameOrLabel() throws IOException {
2411 if (currentToken != Token.NAME) throw codeBug();
2412 int pos = ts.tokenBeg;
2413
2414 // set check for label and call down to primaryExpr
2415 currentFlaggedToken |= TI_CHECK_LABEL;
2416 AstNode expr = expr(false);
2417
2418 if (expr.getType() != Token.LABEL) {
2419 AstNode n = new ExpressionStatement(expr, !insideFunctionBody());
2420 n.setLineColumnNumber(expr.getLineno(), expr.getColumn());
2421 return n;
2422 }
2423
2424 LabeledStatement bundle = new LabeledStatement(pos);
2425 recordLabel((Label) expr, bundle);
2426 bundle.setLineColumnNumber(expr.getLineno(), expr.getColumn());
2427 // look for more labels
2428 AstNode stmt = null;
2429 while (peekToken() == Token.NAME) {
2430 currentFlaggedToken |= TI_CHECK_LABEL;
2431 expr = expr(false);
2432 if (expr.getType() != Token.LABEL) {
2433 stmt = new ExpressionStatement(expr, !insideFunctionBody());
2434 autoInsertSemicolon(stmt);
2435 break;
2436 }
2437 recordLabel((Label) expr, bundle);
2438 }
2439
2440 // no more labels; now parse the labeled statement
2441 try {
2442 currentLabel = bundle;
2443 if (stmt == null) {
2444 stmt = statementHelper();
2445 int ntt = peekToken();
2446 if (ntt == Token.COMMENT
2447 && stmt.getLineno()
2448 == scannedComments.get(scannedComments.size() - 1).getLineno()) {
2449 stmt.setInlineComment(scannedComments.get(scannedComments.size() - 1));
2450 consumeToken();
2451 }
2452 }
2453 } finally {
2454 currentLabel = null;
2455 // remove the labels for this statement from the global set
2456 for (Label lb : bundle.getLabels()) {
2457 labelSet.remove(lb.getName());
2458 }
2459 }
2460
2461 // If stmt has parent assigned its position already is relative
2462 // (See bug #710225)
2463 bundle.setLength(stmt.getParent() == null ? getNodeEnd(stmt) - pos : getNodeEnd(stmt));
2464 bundle.setStatement(stmt);
2465 return bundle;
2466 }
2467

Callers 1

statementHelperMethod · 0.95

Calls 15

codeBugMethod · 0.95
exprMethod · 0.95
insideFunctionBodyMethod · 0.95
getLinenoMethod · 0.95
recordLabelMethod · 0.95
peekTokenMethod · 0.95
autoInsertSemicolonMethod · 0.95
statementHelperMethod · 0.95
setInlineCommentMethod · 0.95
consumeTokenMethod · 0.95
getLabelsMethod · 0.95
getParentMethod · 0.95

Tested by

no test coverage detected