Ejemplo n.º 1
0
        private static bool IsTypeDeclaration(AbideScriptToken token)
        {
            if (token == null)
            {
                return(false);
            }

            switch (token.Token)
            {
            case "struct":
            case "class":
            case "enum":
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        public AbideScriptStatement ReadStatement()
        {
            List <AbideScriptToken> tokens = new List <AbideScriptToken>();

            if (SkipThenPeek() != -1)
            {
                var token = ReadToken();
                tokens.Add(token);

                switch (token.Token)
                {
                case "global":
                case "internal":
                case "familial":
                case "local":
                    if (reader.Peek() != -1)
                    {
                        var followingToken = ReadToken();
                        SkipWhitespace();

                        if (IsTypeDeclaration(followingToken))
                        {
                        }
                        else
                        {
                            if (followingToken.Token == "const")
                            {
                                tokens.Add(followingToken);
                                followingToken = ReadToken();
                            }

                            var           firstToken       = followingToken;
                            StringBuilder typeTokenBuilder = new StringBuilder();
                            switch (followingToken.Token)
                            {
                            case "string":
                            case "char":
                            case "sbyte":
                            case "byte":
                            case "short":
                            case "ushort":
                            case "int":
                            case "uint":
                            case "long":
                            case "ulong":
                            case "float":
                            case "double":
                            case "bool":
                                typeTokenBuilder.Append(followingToken.Token);
                                break;

                            case "function":
                                typeTokenBuilder.Append(followingToken.Token);
                                if (SkipThenPeek() == '(')
                                {
                                    typeTokenBuilder.Append(ReadToken().Token);
                                }
                                break;

                            default:
                                while (SkipThenPeek() == '.')
                                {
                                    typeTokenBuilder.Append(ReadToken().Token);
                                    if (SkipThenPeek() != -1)
                                    {
                                        typeTokenBuilder.Append(ReadToken().Token);
                                    }
                                }
                                break;
                            }

                            var typeToken = new AbideScriptToken(typeTokenBuilder.ToString(), firstToken.LineNumber, firstToken.LinePosition);
                            tokens.Add(typeToken);

                            if (IsValidObjectNameCharacter((char)SkipThenPeek()))
                            {
                                var nameToken = ReadToken();
                                tokens.Add(nameToken);
                            }

                            if (SkipThenPeek() == ';')
                            {
                                tokens.Add(ReadToken());
                            }

                            else if (SkipThenPeek() == '=')
                            {
                                tokens.Add(ReadToken());

                                var valueToken = ReadToken();
                                tokens.Add(valueToken);

                                if (valueToken.Token.StartsWith('('))
                                {
                                    if (SkipThenPeek() == '=')
                                    {
                                        var lambdaToken = ReadToken();

                                        if (lambdaToken.Token == "=>")
                                        {
                                            tokens.Add(ReadToken());
                                        }
                                    }
                                }

                                if (SkipThenPeek() == ';')
                                {
                                    tokens.Add(ReadToken());
                                }
                            }
                        }
                    }
                    break;

                case "namespace":
                    if (reader.Peek() != -1)
                    {
                        tokens.Add(ReadToken());
                    }
                    if (reader.Peek() != -1)
                    {
                        tokens.Add(ReadToken());
                    }
                    break;

                case "include":
                    if (reader.Peek() != -1)
                    {
                        tokens.Add(ReadToken());
                    }
                    if (reader.Peek() == ';')
                    {
                        tokens.Add(ReadToken());
                    }
                    break;
                }
            }

            return(new AbideScriptStatement(tokens));
        }