コード例 #1
0
        static MemberInvocationReference ParseInvocation(string text, ref int p, Type type, IReference instance)
        {
            TokenKind token;
            MemberInvocationReference mir = null;

            while (true)
            {
                int prev = p;
                token = ScanName(text, ref p);
                var name = text.Substring(prev, p - prev).TrimEnd();

                switch (token)
                {
                case TokenKind.Dot:
                case TokenKind.OpenParens:
                    break;

                case TokenKind.CloseParens:
                    return(new MemberInvocationReference(type, name)
                    {
                        Instance = instance
                    });

                case TokenKind.End:
                    if (mir == null || name.Length != 0)
                    {
                        throw new InvalidProjectFileException(string.Format("Invalid static method invocation syntax '{0}'", text.Substring(p)));
                    }

                    return(mir);

                default:
                    throw new NotImplementedException();
                }

                instance = mir = new MemberInvocationReference(type, name)
                {
                    Instance = instance
                };

                if (type != null)
                {
                    if (!IsMethodAllowed(type, name))
                    {
                        throw new InvalidProjectFileException(string.Format("The function '{0}' on type '{1}' has not been enabled for execution", name, type.FullName));
                    }

                    type = null;
                }

                if (token == TokenKind.OpenParens)
                {
                    ++p;
                    mir.Arguments = ParseArguments(text, ref p);
                }

                if (p < text.Length && text [p] == '.')
                {
                    ++p;
                    continue;
                }

                return(mir);
            }
        }
コード例 #2
0
ファイル: Expression.cs プロジェクト: zhangf911/NoahGameFrame
        static MemberInvocationReference ParseInvocation(string text, ref int p, Type type, IReference instance)
        {
            var           open_parens = text.IndexOf('(', p);
            string        name;
            int           end;
            List <string> args;

            //
            // Is it method or property
            //
            if (open_parens > 0)
            {
                name = text.Substring(p, open_parens - p);

                //
                // It can be instance method on static property
                //
                if (name.IndexOf('.') > 0)
                {
                    var names = name.Split('.');
                    int i;
                    for (i = 0; i < names.Length - 1; ++i)
                    {
                        instance = new MemberInvocationReference(type, names [i])
                        {
                            Instance = instance
                        };
                    }

                    type = null;
                    name = names [i];
                }
                ++open_parens;
                args = ParseArguments(text, ref open_parens);
                end  = text.IndexOf(')', open_parens);
            }
            else
            {
                end = text.IndexOf(')', p);
                if (end < 0)
                {
                    throw new InvalidProjectFileException(string.Format("Invalid static method invocation syntax '{0}'", text.Substring(p)));
                }

                name = text.Substring(p, end - p);

                //
                // It can be instance member on static property
                //
                if (name.IndexOf('.') > 0)
                {
                    var names = name.Split('.');
                    int i;
                    for (i = 0; i < names.Length - 1; ++i)
                    {
                        instance = new MemberInvocationReference(type, names [i])
                        {
                            Instance = instance
                        };
                    }

                    type = null;
                    name = names [i];
                }

                args = null;
            }

            name = name.TrimEnd();
            if (!IsMethodAllowed(type, name))
            {
                throw new InvalidProjectFileException(string.Format("The function '{0}' on type '{1}' has not been enabled for execution", name, type.FullName));
            }

            p = end + 1;
            return(new MemberInvocationReference(type, name)
            {
                Arguments = args,
                Instance = instance
            });
        }