Esempio n. 1
0
        internal override bool TryGetToken(ref string text, out TokenBase token)
        {
            token = null;
            TokenBase arguments;
            bool      lambda = false;

            if (!new ArgumentListToken('(', ')', null).TryGetToken(ref text, out arguments))
            {
                lambda = true;
                if (!new ArgumentListToken(true, '(', ')').TryGetToken(ref text, out arguments))
                {
                    return(false);
                }
            }
            string temp = text.TrimStart();

            if (!temp.StartsWith("=>"))
            {
                return(false);
            }
            temp = temp.Substring(2).TrimStart();
            TokenBase method;

            if (!EquationTokenizer.TryEvaluateExpression(temp, out method))
            {
                return(false);
            }
            text  = "";
            token = new LambdaToken()
            {
                Arguments = arguments as ArgumentListToken, Value = method, Lambda = lambda
            };
            return(true);
        }
Esempio n. 2
0
        internal override bool TryGetToken(ref string text, out TokenBase token, bool requireReturnValue = true)
        {
            token = null;
            string temp = text;
            var    op   = default(Operator);

            if (temp.Length < 2)
            {
                return(false);
            }
            if (temp[0] != '=')
            {
                if (temp[1] != '=' || temp.Length < 3)
                {
                    return(false);
                }
                for (int i = (int)Operator.Multiply; i <= (int)Operator.Subtract; ++i)
                {
                    if (EquationTokenizer.representations[i][0] == temp[0])
                    {
                        op = (Operator)i;
                    }
                }
                for (int i = (int)Operator.BitwiseAnd; i <= (int)Operator.BitwiseXor; ++i)
                {
                    if (EquationTokenizer.representations[i][0] == temp[0])
                    {
                        op = (Operator)i;
                    }
                }
                if (op == default(Operator))
                {
                    return(false);
                }
            }

            if (op == default(Operator))
            {
                temp = temp.Substring(1).TrimStart();
            }
            else
            {
                temp = temp.Substring(2).TrimStart();
            }
            TokenBase valToken;

            if (!EquationTokenizer.TryEvaluateExpression(temp, out valToken))
            {
                return(false);
            }
            text  = "";
            token = new AssignmentToken()
            {
                Value = valToken, Operator = op
            };
            return(true);
        }
        internal override bool TryGetToken(ref string text, out TokenBase token, bool requireReturnValue = true)
        {
            token = null;
            string temp = text;

            if (temp.Length == 0 || (!Char.IsLetter(temp[0]) && temp[0] != '_'))
            {
                return(false);
            }
            int count = 1;

            while (count < temp.Length && (Char.IsLetterOrDigit(temp[count]) || temp[count] == '_'))
            {
                ++count;
            }
            string name = temp.Substring(0, count);

            MemberInfo info = null;

            if (type != null)
            {
                info = type.GetMember(name).FirstOrDefault();
                if (info == null)
                {
                    return(false);
                }
            }
            else
            {
                string    nameTemp = "$" + name;
                TokenBase tokenTemp;
                if (!new ParameterToken().TryGetToken(ref nameTemp, out tokenTemp))
                {
                    return(false);
                }
            }

            temp = temp.Substring(count).TrimStart();
            if (temp.Length == 0 || temp[0] != '=')
            {
                return(false);
            }
            temp = temp.Substring(1).TrimStart();
            TokenBase valToken;

            if (!EquationTokenizer.TryEvaluateExpression(temp, out valToken))
            {
                return(false);
            }
            text  = "";
            token = new LambdaAssignmentToken(null)
            {
                Name = name, Member = info, Value = valToken
            };
            return(true);
        }
Esempio n. 4
0
        internal override bool TryGetToken(ref string text, out TokenBase token)
        {
            token = null;
            bool inQuotes = false;
            int  brackets = 0;
            int  i        = 0;
            int  qPos     = -1;

            while (true)
            {
                if (i >= text.Length - 1)
                {
                    return(false);
                }
                if (i > 0 && text[i] == '\'' && text[i - 1] != '\\')
                {
                    inQuotes = !inQuotes;
                }
                else if (!inQuotes)
                {
                    if (text[i] == '(')
                    {
                        ++brackets;
                    }
                    else if (text[i] == ')')
                    {
                        --brackets;
                    }
                    else if (brackets == 0 && text[i] == '?' && text[i + 1] == '?')
                    {
                        qPos = i;
                        break;
                    }
                }
                ++i;
            }
            TokenBase left, right;

            if (!EquationTokenizer.TryEvaluateExpression(text.Substring(0, qPos).Trim(), out left))
            {
                return(false);
            }
            if (!EquationTokenizer.TryEvaluateExpression(text.Substring(qPos + 2).Trim(), out right))
            {
                return(false);
            }
            token = new NullCoalesceOperatorToken()
            {
                Condition = left, OnNull = right
            };
            text = "";
            return(true);
        }
Esempio n. 5
0
        internal override bool TryGetToken(ref string text, out TokenBase token, bool requireReturnValue = true)
        {
            token = null;
            if (!text.TrimStart().StartsWith("("))
            {
                return(false);
            }
            bool inQuotes = false;
            int  brackets = 0;
            int  i        = 0;

            while (true)
            {
                if (i >= text.Length)
                {
                    return(false);
                }
                if (i > 0 && text[i] == '\'' && text[i - 1] != '\\')
                {
                    inQuotes = !inQuotes;
                }
                else if (!inQuotes)
                {
                    if (text[i] == '(')
                    {
                        ++brackets;
                    }
                    else if (text[i] == ')')
                    {
                        --brackets;
                        if (brackets == 0)
                        {
                            break;
                        }
                    }
                }
                ++i;
            }
            TokenBase valToken;

            if (!EquationTokenizer.TryEvaluateExpression(text.Substring(1, i - 1), out valToken))
            {
                return(false);
            }
            text  = text.Substring(i + 1);
            token = new BracketedToken()
            {
                Value = valToken
            };
            return(true);
        }
        internal override bool TryGetToken(ref string text, out TokenBase token, bool requireReturnValue = true)
        {
            token = null;
            var           list = new List <TokenBase>();
            List <string> split;
            string        temp = text;

            if (!TrySplitByCommas(ref temp, open, close, out split))
            {
                return(false);
            }
            foreach (string str in split)
            {
                TokenBase newToken;
                string    s = str.Trim();
                if (allowSubLists && s.StartsWith(open.ToString()) && s.EndsWith(close.ToString()))
                {
                    if (new ArgumentListToken(open, close).TryGetToken(ref s, out newToken))
                    {
                        list.Add(newToken);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (findAssignments)
                {
                    if (new LambdaAssignmentToken(assignmentType).TryGetToken(ref s, out newToken))
                    {
                        list.Add(newToken);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (allowTypeCasts)
                {
                    if (new TypeCastToken(false).TryGetToken(ref s, out newToken))
                    {
                        string    nameTemp = "$" + s;
                        TokenBase tokenTemp;
                        if (!new ParameterToken().TryGetToken(ref nameTemp, out tokenTemp) || !String.IsNullOrWhiteSpace(nameTemp))
                        {
                            return(false);
                        }
                        (newToken as TypeCastToken).Target = tokenTemp;
                        list.Add(newToken);
                    }
                    else
                    {
                        string    nameTemp = "$" + s;
                        TokenBase tokenTemp;
                        if (!new ParameterToken().TryGetToken(ref nameTemp, out tokenTemp) || !String.IsNullOrWhiteSpace(nameTemp))
                        {
                            return(false);
                        }
                        list.Add(tokenTemp);
                    }
                }
                else
                {
                    if (EquationTokenizer.TryEvaluateExpression(str.Trim(), out newToken))
                    {
                        list.Add(newToken);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            token = new ArgumentListToken('\0', '\0')
            {
                Arguments = list.ToArray()
            };
            text = temp;
            return(true);
        }
Esempio n. 7
0
        internal override bool TryGetToken(ref string text, out TokenBase token)
        {
            token = null;
            bool inQuotes = false;
            int  brackets = 0;
            int  count    = 0;
            int  i        = 0;
            int  qPos     = -1;
            int  cPos     = -1;

            while (true)
            {
                if (i >= text.Length)
                {
                    return(false);
                }
                if (i > 0 && text[i] == '\'' && text[i - 1] != '\\')
                {
                    inQuotes = !inQuotes;
                }
                else if (!inQuotes)
                {
                    if (text[i] == '(')
                    {
                        ++brackets;
                    }
                    else if (text[i] == ')')
                    {
                        --brackets;
                    }
                    else if (brackets == 0)
                    {
                        if (text[i] == '?' && (i >= text.Length - 1 || (text[i + 1] != '.' && text[i + 1] != '[')))
                        {
                            if (count == 0)
                            {
                                qPos = i;
                            }
                            ++count;
                        }
                        else if (text[i] == ':')
                        {
                            --count;
                            if (count < 0)
                            {
                                return(false);
                            }
                            if (count == 0)
                            {
                                cPos = i;
                                break;
                            }
                        }
                    }
                }
                ++i;
            }
            TokenBase left, middle, right;

            if (!EquationTokenizer.TryEvaluateExpression(text.Substring(0, qPos).Trim(), out left))
            {
                return(false);
            }
            if (!EquationTokenizer.TryEvaluateExpression(text.Substring(qPos + 1, cPos - qPos - 1).Trim(), out middle))
            {
                return(false);
            }
            if (!EquationTokenizer.TryEvaluateExpression(text.Substring(cPos + 1).Trim(), out right))
            {
                return(false);
            }
            token = new TernaryOperatorToken()
            {
                Condition = left, OnTrue = middle, OnFalse = right
            };
            text = "";
            return(true);
        }