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

            var symbol = iterator.GetAndNext();

            if (symbol == ListOpen.Instance)
            {
                var list = new List <PokeType>();

                while (iterator.HasValue)
                {
                    symbol = iterator.GetAndNext();
                    if (symbol == ListClose.Instance)
                    {
                        return(new HiddenPowerTypeCriteriaNode(list.ToArray()));
                    }

                    if (symbol is Value v)
                    {
                        list.Add(ParseType(v));
                    }
                    else
                    {
                        throw new UnexpectedSymbolException(symbol);
                    }



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

                    symbol = iterator.GetAndNext();
                    if (symbol == ListClose.Instance)
                    {
                        return(new HiddenPowerTypeCriteriaNode(list.ToArray()));
                    }

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

                throw new Exception("Unexpected EOF");
            }
            else if (symbol is Value v)
            {
                return(new HiddenPowerTypeCriteriaNode(ParseType(v)));
            }
            else
            {
                throw new UnexpectedSymbolException(symbol);
            }
        }
 private static void SetField <TNode>(IParser <TNode> parser, SymbolIterator iterator, ref TNode field)
     where TNode : ICriteriaNode <GCIndividual>
 {
     if (field != null)
     {
         throw new Exception("");
     }
     field = parser.Parse(iterator);
 }
 private static void SetField <TArg, TNode>(ListParser <TArg, TNode> parser, SymbolIterator iterator, ref TNode[] field)
     where TNode : ICriteriaNode <TArg>
 {
     if (field != null)
     {
         throw new Exception("");
     }
     field = parser.Parse(iterator);
 }
Ejemplo n.º 4
0
        public IVsCriteriaNode Parse(SymbolIterator iterator)
        {
            if (!iterator.HasValue)
            {
                throw new Exception("Unexpeced EOF");
            }

            var min = new List <uint>(6);
            var max = new List <uint>(6);

            var symbol = iterator.GetAndNext();

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

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

                if (symbol == ListClose.Instance)
                {
                    return(new IVsCriteriaNode(min.ToArray(), max.ToArray()));
                }

                if (symbol is Value v)
                {
                    ParseIV(v, min, max);
                }
                else
                {
                    throw new UnexpectedSymbolException(symbol);
                }



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

                symbol = iterator.GetAndNext();

                if (symbol == ListClose.Instance)
                {
                    return(new IVsCriteriaNode(min.ToArray(), max.ToArray()));
                }

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

            throw new Exception("Unexpected EOF");
        }
Ejemplo n.º 5
0
        public ICriteriaNode <TArg>[] Parse(SymbolIterator iterator)
        {
            if (!iterator.HasValue)
            {
                throw new Exception("Unexpected EOF");
            }

            if (iterator.Peek != ListOpen.Instance)
            {
                return new[] { parser.Parse(iterator) }
            }
            ;
            iterator.MoveNext();

            var list = new List <ICriteriaNode <TArg> >();

            while (iterator.HasValue)
            {
                if (iterator.Peek == ListClose.Instance)
                {
                    iterator.MoveNext();
                    return(list.ToArray());
                }

                list.Add(parser.Parse(iterator));

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

                var symbol = iterator.GetAndNext();
                if (symbol == ListClose.Instance)
                {
                    return(list.ToArray());
                }

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

            throw new Exception("Unexpected EOF");
        }
Ejemplo n.º 6
0
        public static ICriteriaNode <CoStarterResult> TryParse(string source)
        {
            var it     = new SymbolIterator(ConvertToTokens(source).ConvertToSymbols().GetEnumerator());
            var parser = new ListParser <CoStarterResult>(new CoStarterCriteriaParser());

            try
            {
                var node = new OrCriteriaNode <CoStarterResult>(parser.Parse(it));
                if (it.HasValue)
                {
                    throw new UnexpectedSymbolException(it.GetAndNext());
                }
                return(node);
            }
            catch (Exception e)
            {
                throw new Exception($"{e.Message}{Environment.NewLine}{it.GetUsedSymbols()}<-");
            }
        }
        public HiddenPowerPowerCriteriaNode Parse(SymbolIterator iterator)
        {
            if (!iterator.HasValue)
            {
                throw new Exception("Unexpected EOF");
            }

            var symbol = iterator.GetAndNext();

            if (symbol is Value v)
            {
                if (!uint.TryParse(v.Name, out var p) || p < 30 || 70 < p)
                {
                    throw new Exception("Invalud Value");
                }

                return(new HiddenPowerPowerCriteriaNode(p));
            }
            else
            {
                throw new UnexpectedSymbolException(symbol);
            }
        }
        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");
        }
        public CoStarterCriteriaNode Parse(SymbolIterator iterator)
        {
            if (!iterator.HasValue)
            {
                throw new Exception("Unexpeced EOF");
            }

            IDCriteriaNode[]         id      = null;
            IndividualCriteriaNode[] umbreon = null;
            IndividualCriteriaNode[] espeon  = 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 CoStarterCriteriaNode(id, umbreon, espeon));
                }

                if (symbol is PropertyName p)
                {
                    if (p.Name == "umbreon")
                    {
                        SetField(individualParser, iterator, ref umbreon);
                    }
                    else if (p.Name == "espeon")
                    {
                        SetField(individualParser, iterator, ref espeon);
                    }
                    else if (p.Name == "id")
                    {
                        SetField(idParser, iterator, ref id);
                    }
                    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 CoStarterCriteriaNode(id, umbreon, espeon));
                }

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

            throw new Exception("Unexpected EOF");
        }
Ejemplo n.º 10
0
        public IDCriteriaNode Parse(SymbolIterator iterator)
        {
            if (!iterator.HasValue)
            {
                throw new Exception("Unexpeced EOF");
            }

            IDCriteriaNode node;

            var symbol = iterator.GetAndNext();

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

            symbol = iterator.GetAndNext();

            if (symbol is PropertyName p)
            {
                if (p.Name == "tid")
                {
                    node = new TIDCriteriaNode(decListParser.Parse(iterator));
                }
                else if (p.Name == "shiny")
                {
                    node = new ShinyCriteriaNode(hexListParser.Parse(iterator));
                }
                else if (p.Name == "square")
                {
                    node = new SquareCriteriaNode(hexListParser.Parse(iterator));
                }
                else if (p.Name == "star")
                {
                    node = new StarCriteriaNode(hexListParser.Parse(iterator));
                }
                else
                {
                    throw new UnexpectedSymbolException(symbol);
                }
            }
            else
            {
                throw new UnexpectedSymbolException(symbol);
            }

            symbol = iterator.GetAndNext();
            if (symbol == ObjectClose.Instance)
            {
                return(node);
            }
            if (symbol != Comma.Instance)
            {
                throw new UnexpectedSymbolException(symbol);
            }

            if (iterator.GetAndNext() != ObjectClose.Instance)
            {
                throw new UnexpectedSymbolException(symbol);
            }

            return(node);
        }
        public IndividualCriteriaNode Parse(SymbolIterator iterator)
        {
            if (!iterator.HasValue)
            {
                throw new Exception("Unexpeced EOF");
            }

            //var node = new IndividualCriteriaNode();
            HiddenPowerCriteriaNode[] hiddenPower = null;
            IVsCriteriaNode           ivs         = null;
            NatureCriteriaNode        nature      = 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 IndividualCriteriaNode(ivs, nature, hiddenPower));
                }

                if (symbol is PropertyName p)
                {
                    if (p.Name == "nature")
                    {
                        SetField <GCIndividual, NatureCriteriaNode>(natureParser, iterator, ref nature);
                    }
                    else if (p.Name == "ivs")
                    {
                        SetField <GCIndividual, IVsCriteriaNode>(ivsParser, iterator, ref ivs);
                    }
                    else if (p.Name == "hp")
                    {
                        SetField <GCIndividual, HiddenPowerCriteriaNode>(hiddenPowerParser, iterator, ref hiddenPower);
                    }
                    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 IndividualCriteriaNode(ivs, nature, hiddenPower));
                }

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

            throw new Exception("Unexpected EOF");
        }
Ejemplo n.º 12
0
        public uint[] Parse(SymbolIterator iterator)
        {
            if (!iterator.HasValue)
            {
                throw new Exception("Unexpected EOF");
            }

            var list = new List <uint>();

            var symbol = iterator.GetAndNext();

            if (symbol == ListOpen.Instance)
            {
                while (iterator.HasValue)
                {
                    symbol = iterator.GetAndNext();
                    if (symbol == ListClose.Instance)
                    {
                        return(list.ToArray());
                    }

                    if (symbol is Value v)
                    {
                        list.Add(ParseValue(v));
                    }
                    else
                    {
                        throw new UnexpectedSymbolException(symbol);
                    }



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

                    symbol = iterator.GetAndNext();
                    if (symbol == ListClose.Instance)
                    {
                        return(list.ToArray());
                    }

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

                throw new Exception("Unexpected EOF");
            }
            else if (symbol is Value v)
            {
                list.Add(ParseValue(v));

                return(list.ToArray());
            }
            else
            {
                throw new UnexpectedSymbolException(symbol);
            }
        }