// ECMA-262 14.1 Function Definition public Node parseFunctionSourceElements() { Node statement; List<Node> body = new List<Node>(); Token token; string directive; Token firstRestricted = null; List<string> oldLabelSet; bool oldInIteration; bool oldInSwitch, oldInFunctionBody; int oldParenthesisCount; Node node = new Node(); expect("{"); while (startIndex < length) { if (lookahead.type != TokenType.StringLiteral) { break; } token = lookahead; statement = parseStatementListItem(); body.Add(statement); if (statement.expression.type != Syntax.Literal) { // this is not directive break; } directive = source.Substring(token.start + 1, token.end - 1); if (directive == "use strict") { strict = true; if (firstRestricted != null) { tolerateUnexpectedToken(firstRestricted, Messages.StrictOctalLiteral); } } else { if (firstRestricted == null && token.octal) { firstRestricted = token; } } } oldLabelSet = state.labelSet; oldInIteration = state.inIteration; oldInSwitch = state.inSwitch; oldInFunctionBody = state.inFunctionBody; oldParenthesisCount = state.parenthesizedCount; state.labelSet = new List<string>(); state.inIteration = false; state.inSwitch = false; state.inFunctionBody = true; state.parenthesizedCount = 0; while (startIndex < length) { if (match("}")) { break; } body.Add(parseStatementListItem()); } expect("}"); state.labelSet = oldLabelSet; state.inIteration = oldInIteration; state.inSwitch = oldInSwitch; state.inFunctionBody = oldInFunctionBody; state.parenthesizedCount = oldParenthesisCount; return node.finishBlockStatement(body); }
public Node parseBlock() { List<Node> block; Node node = new Node(); expect("{"); block = parseStatementList(); expect("}"); return node.finishBlockStatement(block); }