Exemple #1
0
        private Tuple <bool, Expr> IsMatch(FluentPluginHelper helper, Type type, Token klass, Token instance, Token prop, Token method)
        {
            var memberName = string.Empty;
            var rootVar    = string.Empty;
            var match      = false;
            var nameToken  = klass;

            // 1. Class property
            if (klass != null && prop != null)
            {
                rootVar = klass.Text;
                if (helper.IsClassProp(type, prop.Text))
                {
                    memberName = prop.Text;
                    match      = true;
                }
            }
            // 2. Class method
            else if (klass != null && method != null)
            {
                rootVar = type.Name;
                if (helper.IsClassMethod(type, method.Text))
                {
                    memberName = method.Text;
                    match      = true;
                }
            }
            // 3. Instance property
            else if (instance != null && prop != null)
            {
                rootVar = instance.Text;
                if (helper.IsInstanceProp(type, prop.Text))
                {
                    memberName = prop.Text;
                    match      = true;
                    nameToken  = instance;
                }
            }
            // 4. Instance method
            else if (instance != null && method != null)
            {
                rootVar = instance.Text;
                if (helper.IsInstanceMethod(type, method.Text))
                {
                    memberName = method.Text;
                    match      = true;
                    nameToken  = instance;
                }
            }
            if (!match)
            {
                return(new Tuple <bool, Expr>(false, null));
            }

            var varExp = Exprs.Ident(rootVar, null);
            var memExp = Exprs.MemberAccess(varExp, memberName, false, null);

            return(new Tuple <bool, Expr>(memberName != null, memExp));
        }
Exemple #2
0
        /* ****************************************************************************************
         * The following syntax can be supported via this Fluent expression combinator
         *
         * 1. activate user.
         * 2. move file "c:\temp.txt".
         * 3. file "c:\temp.txt" exists.
         * 3. run program "msbuild.exe", solution: 'comlib.sln', mode: "debug", style: "rebuild all".
         *
         * 1. <method> <class> .
         * 2. <method> <class> <arg1> <arg2> .
         * 3. <class>  <arg1>  <method> .
         * 3. <method> <class> <arg1>, <arg1_name> : <arg1_value>, <arg2_name> : <arg2_value> .
         *
         ***************************************************************************************** */
        /// <summary>
        /// Parses the fluent expression.
        /// </summary>
        /// <returns></returns>
        public override Expr Parse()
        {
            var  ctx    = _parser.Context;
            var  helper = new FluentPluginHelper(ctx);
            var  token  = _tokenIt.NextToken;
            Expr mexp   = null;
            Tuple <Type, Expr> matchResult = null;

            // 1. Check if instance variable.
            if (helper.IsInstance(token.Token))
            {
                matchResult = Match("instance", FluentPart.Instance);
                mexp        = matchResult.Item2;
            }
            // 2. Check if class
            else if (helper.IsClass(token.Token))
            {
                matchResult = Match("class", FluentPart.Class);
                mexp        = matchResult.Item2;
            }
            // 3. Has to be method or prop
            else
            {
                matchResult = Match("method", FluentPart.Method);
                mexp        = matchResult.Item2;
                if (mexp == null)
                {
                    matchResult = Match("prop", FluentPart.Prop);
                    mexp        = matchResult.Item2;
                }
            }
            if (mexp != null)
            {
                // TODO: Performance improvement.
                var memExp = mexp as MemberAccessExpr;
                if (helper.IsClassMethod(matchResult.Item1, memExp.MemberName) || helper.IsInstanceMethod(matchResult.Item1, memExp.MemberName))
                {
                    mexp = ParseParams(mexp);
                }
            }
            return(mexp);
        }
        private Tuple<bool, Expr> IsMatch(FluentPluginHelper helper, Type type, Token klass, Token instance, Token prop, Token method)
        {
            var memberName = string.Empty;
            var rootVar = string.Empty;
            var match = false;
            var nameToken = klass;

            // 1. Class property
            if (klass != null && prop != null)
            {
                rootVar = klass.Text;
                if (helper.IsClassProp(type, prop.Text))
                {
                    memberName = prop.Text;
                    match = true;
                }
            }
            // 2. Class method
            else if (klass != null && method != null)
            {
                rootVar = type.Name;
                if (helper.IsClassMethod(type, method.Text))
                {   
                    memberName = method.Text;
                    match = true;
                }
            }
            // 3. Instance property
            else if (instance != null && prop != null)
            {
                rootVar = instance.Text;
                if (helper.IsInstanceProp(type, prop.Text))
                {
                    memberName = prop.Text;
                    match = true;
                    nameToken = instance;
                }
            }
            // 4. Instance method
            else if (instance != null && method != null)
            {
                rootVar = instance.Text;
                if (helper.IsInstanceMethod(type, method.Text))
                {
                    memberName = method.Text;
                    match = true;
                    nameToken = instance;
                }
            }
            if (!match)
                return new Tuple<bool, Expr>(false, null);

            var varExp = Exprs.Ident(rootVar, null);
            var memExp = Exprs.MemberAccess(varExp, memberName, false, null);
            return new Tuple<bool, Expr>(memberName != null, memExp);
        }
        /* ****************************************************************************************
         * The following syntax can be supported via this Fluent expression combinator
         * 
         * 1. activate user.         
         * 2. move file "c:\temp.txt".
         * 3. file "c:\temp.txt" exists.
         * 3. run program "msbuild.exe", solution: 'comlib.sln', mode: "debug", style: "rebuild all".
         * 
         * 1. <method> <class> .
         * 2. <method> <class> <arg1> <arg2> .
         * 3. <class>  <arg1>  <method> .
         * 3. <method> <class> <arg1>, <arg1_name> : <arg1_value>, <arg2_name> : <arg2_value> .
         * 
        ***************************************************************************************** */
        /// <summary>
        /// Parses the fluent expression.
        /// </summary>
        /// <returns></returns>
        public override Expr Parse()
        {
            var ctx = _parser.Context;
            var helper = new FluentPluginHelper(ctx);
            var token = _tokenIt.NextToken;
            Expr mexp = null;
            Tuple<Type, Expr> matchResult = null;

            // 1. Check if instance variable.
            if (helper.IsInstance(token.Token))
            {
                matchResult = Match("instance", FluentPart.Instance);
                mexp = matchResult.Item2;
            }
            // 2. Check if class 
            else if (helper.IsClass(token.Token))
            {
                matchResult = Match("class", FluentPart.Class);
                mexp = matchResult.Item2;
            }
            // 3. Has to be method or prop
            else
            {
                matchResult = Match("method", FluentPart.Method);
                mexp = matchResult.Item2;
                if(mexp == null)
                {
                    matchResult = Match("prop", FluentPart.Prop);
                    mexp = matchResult.Item2;
                }
            }
            if (mexp != null )
            {
                // TODO: Performance improvement.
                var memExp = mexp as MemberAccessExpr;
                if (helper.IsClassMethod(matchResult.Item1, memExp.MemberName) || helper.IsInstanceMethod(matchResult.Item1, memExp.MemberName))
                {
                    mexp = ParseParams(mexp);    
                }                
            }
            return mexp;
        }