Exemplo n.º 1
0
        public static LexicalTree_NameStructure ParseYesFunction(this IEnumerator <Token> c)
        {
            Token token = c.Current;
            LexicalTree_NameStructure answer = new LexicalTree_NameStructure(token.Content)
            {
                File = token.File, Line = token.Line, Column = token.Column
            };

            switch (token.ToLowerString())
            {
            case "world":
                answer.Structure = StructureDataType.World;
                break;

            case "scenario":
                answer.Structure = StructureDataType.Scenario;
                break;

            case "event":
                answer.Structure = StructureDataType.Event;
                break;

            case "story":
                answer.Structure = StructureDataType.Story;
                break;

            case "fight":
                answer.Structure = StructureDataType.Fight;
                break;

            case "function":
                answer.Structure = StructureDataType.Function;
                break;

            case "deploy":
                answer.Structure = StructureDataType.Deploy;
                break;
            }
            if (!c.MoveNext())
            {
                throw new LexicalTreeConstructionException(token);
            }
            token = c.Current;
            if (token.Type == 1)
            {
                throw new LexicalTreeConstructionException(token);
            }
            answer.Name = token.ToString();
            if (!c.MoveNext())
            {
                throw new LexicalTreeConstructionException(token);
            }
            token = c.Current;
            if (token.Type != 1 || token.IsDoubleSymbol)
            {
                throw new LexicalTreeConstructionException(token);
            }
            if (token.Symbol1 == ':')
            {
                if (!c.MoveNext())
                {
                    throw new LexicalTreeConstructionException(token);
                }
                token          = c.Current;
                answer.Inherit = token.ToString();
                if (!c.MoveNext())
                {
                    throw new LexicalTreeConstructionException(token);
                }
                token = c.Current;
                if (token.Type != 1 || token.IsDoubleSymbol || token.Symbol1 != '{')
                {
                    throw new LexicalTreeConstructionException(token);
                }
                answer.Children.AddRange(c.ParseBlock());
                return(answer);
            }
            else if (token.Symbol1 == '{')
            {
                answer.Inherit = "";
                answer.Children.AddRange(c.ParseBlock());
                return(answer);
            }
            else
            {
                throw new LexicalTreeConstructionException(token);
            }
        }
Exemplo n.º 2
0
        public static LexicalTree_NameStructure ParseNoFunction(this IEnumerator <Token> c)
        {
            var token = c.Current;
            var Block = new LexicalTree_NameStructure(token.Content)
            {
                File = token.File, Line = token.Line, Column = token.Column
            };

            switch (Block.Name)
            {
            case "power":
                Block.Structure = StructureDataType.Power;
                break;

            case "spot":
                Block.Structure = StructureDataType.Spot;
                break;

            case "unit":
                Block.Structure = StructureDataType.Unit;
                break;

            case "class":
                Block.Structure = StructureDataType.Class;
                break;

            case "skill":
                Block.Structure = StructureDataType.Skill;
                break;

            case "skillset":
                Block.Structure = StructureDataType.Skillset;
                break;

            case "race":
                Block.Structure = StructureDataType.Race;
                break;

            case "field":
                Block.Structure = StructureDataType.Field;
                break;

            case "movetype":
                Block.Structure = StructureDataType.Movetype;
                break;

            case "dungeon":
                Block.Structure = StructureDataType.Dungeon;
                break;

            case "voice":
                Block.Structure = StructureDataType.Voice;
                break;

            case "object":
                Block.Structure = StructureDataType.Object;
                break;
            }
            if (!c.MoveNext())
            {
                throw new LexicalTreeConstructionException(token);
            }
            token = c.Current;
            if (token.Type == 1)
            {
                throw new LexicalTreeConstructionException(token);
            }
            Block.Name = token.ToString();
            if (!c.MoveNext())
            {
                throw new LexicalTreeConstructionException(token);
            }
            token = c.Current;
            if (token.Type != 1 || token.IsDoubleSymbol)
            {
                throw new LexicalTreeConstructionException(token);
            }
            if (token.Symbol1 == ':')
            {
                if (!c.MoveNext())
                {
                    throw new LexicalTreeConstructionException(token);
                }
                token = c.Current;
                if (token.Type == 1)
                {
                    throw new LexicalTreeConstructionException(token);
                }
                Block.Inherit = token.ToString();
                if (!c.MoveNext())
                {
                    throw new LexicalTreeConstructionException(token);
                }
                token = c.Current;
                if (token.Type != 1 || token.IsDoubleSymbol || token.Symbol1 != '{')
                {
                    throw new LexicalTreeConstructionException(token);
                }
            }
            else if (token.Symbol1 == '{')
            {
                Block.Inherit = "";
            }
            else
            {
                throw new LexicalTreeConstructionException(token);
            }
            var stack     = new Stack <Token>();
            int leftCount = 1;

            while (c.MoveNext())
            {
                token = c.Current;
                if (token.Symbol1 == '{')
                {
                    ++leftCount; stack.Push(token);
                }
                else if (token.Symbol1 == '}')
                {
                    if (--leftCount == 0)
                    {
                        break;
                    }
                    stack.Push(token);
                }
                else
                {
                    stack.Push(token);
                }
            }
            Block.Children.AddRange(ParseAssigns(stack));
            return(Block);
        }