Пример #1
0
        public Node parseSwitchStatement(Node node)
        {
            Node discriminant;
            List<Node> cases;
            Node clause;
            bool oldInSwitch;
            bool defaultFound;

            expectKeyword("switch");

            expect("(");

            discriminant = parseExpression();

            expect(")");

            expect("{");

            cases = new List<Node>();

            if (match("}"))
            {
                lex();
                return node.finishSwitchStatement(discriminant, cases);
            }

            oldInSwitch = state.inSwitch;
            state.inSwitch = true;
            defaultFound = false;

            while (startIndex < length)
            {
                if (match("}"))
                {
                    break;
                }
                clause = parseSwitchCase();
                if (clause.test == null)
                {
                    if (defaultFound)
                    {
                        throwError(Messages.MultipleDefaultsInSwitch);
                    }
                    defaultFound = true;
                }
                cases.Add(clause);
            }

            state.inSwitch = oldInSwitch;

            expect("}");

            return node.finishSwitchStatement(discriminant, cases);
        }