Example #1
0
        public HiddenPowerCriteriaNode(HiddenPowerPowerCriteriaNode power, HiddenPowerTypeCriteriaNode type)
        {
            if (power == null && type == null)
            {
                throw new Exception("空のオブジェクトは許可されていません");
            }

            if (power != null)
            {
                this.power = power;
            }
            if (type != null)
            {
                this.type = type;
            }
        }
        public HiddenPowerCriteriaNode Parse(SymbolIterator iterator)
        {
            if (!iterator.HasValue)
            {
                throw new Exception("Unexpeced EOF");
            }

            HiddenPowerPowerCriteriaNode power = null;
            HiddenPowerTypeCriteriaNode  type  = null;

            var symbol = iterator.GetAndNext();

            if (symbol != ObjectOpen.Instance)
            {
                throw new UnexpectedSymbolException(symbol);
            }

            while (iterator.HasValue)
            {
                symbol = iterator.GetAndNext();

                if (symbol == ObjectClose.Instance)
                {
                    return(new HiddenPowerCriteriaNode(power, type));
                }

                if (symbol is PropertyName p)
                {
                    if (p.Name == "type")
                    {
                        SetField(typeParser, iterator, ref type);
                    }
                    else if (p.Name == "power")
                    {
                        SetField(powerParser, iterator, ref power);
                    }
                    else
                    {
                        throw new UnexpectedSymbolException(symbol);
                    }
                }
                else
                {
                    throw new UnexpectedSymbolException(symbol);
                }

                if (!iterator.HasValue)
                {
                    throw new Exception("Unexpected EOF");
                }

                symbol = iterator.GetAndNext();
                if (symbol == ObjectClose.Instance)
                {
                    return(new HiddenPowerCriteriaNode(power, type));
                }

                if (symbol != Comma.Instance)
                {
                    throw new UnexpectedSymbolException(symbol);
                }
            }

            throw new Exception("Unexpected EOF");
        }