Exemple #1
0
        public override ResultColumn Clone()
        {
            var ret = new ResultExpr((Expr)_value.Clone(), _hasAs, _aliasName, this.Comments.Clone());

            ret.Attachment = this.Attachment;
            return(ret);
        }
 void IVisitor.VisitBefore(ResultExpr resultExpr)
 {
     this.ParentExists(resultExpr);
 }
 void IVisitor.VisitAfter(ResultExpr resultExpr)
 {
     this.ParentExists(resultExpr);
 }
Exemple #4
0
        public static Result Parse(string text)
        {
            var result = new Result();

            if (string.IsNullOrEmpty(text))
            {
                return(result);
            }

            var names     = result.m_NamesExpr;
            var types     = result.types;
            var labels    = result.labels;
            var builder   = new System.Text.StringBuilder(64);
            var loopguard = 0;
            var condition = LogicalOperator.And;
            var not       = false;
            var exact     = false;

            var n = 0;

            while (n < text.Length)
            {
                if (++loopguard > 10000)
                {
                    break;
                }

                SkipWhiteSpace(text, ref n);
                if (n + 1 < text.Length)
                {
                    if (text[n] == '&' && text[n + 1] == '&')
                    {
                        n        += 2;
                        condition = LogicalOperator.And;
                        exact     = false;
                        continue;
                    }

                    if (text[n] == '|' && text[n + 1] == '|')
                    {
                        n        += 2;
                        condition = LogicalOperator.Or;
                        exact     = false;
                        continue;
                    }

                    if (text[n] == '=' && text[n + 1] == '=')
                    {
                        n    += 2;
                        exact = true;
                        continue;
                    }

                    if (text[n] == '!') // && !char.IsWhiteSpace(text[n+1]))
                    {
                        n  += 1;
                        not = true;
                        continue;
                    }

                    if (text[n] == '\"' || text[n] == '„')
                    {
                        GetNextQuotedWord(text, ref n, builder);
                        if (builder.Length > 0)
                        {
                            if (names.Count > 0 && condition == LogicalOperator.Or)
                            {
                                names[names.Count - 1].Op = LogicalOperator.Or;
                            }
                            var r = new ResultExpr();
                            r.Op    = condition;
                            r.Text  = builder.ToString().Trim();
                            r.Not   = not;
                            r.Exact = exact;
                            names.Add(r);
                            builder.Length = 0;
                            not            = false;
                            condition      = LogicalOperator.And;
                        }
                        continue;
                    }

                    if (text[n + 1] == ':')
                    {
                        if (text[n] == 't' || text[n] == 'T') // type
                        {
                            n += 2;
                            SkipWhiteSpace(text, ref n);
                            GetNextWord(text, ref n, builder);
                            if (builder.Length > 0)
                            {
                                var type = builder.ToString().Trim();
                                if (string.Compare(type, "prefab", StringComparison.OrdinalIgnoreCase) == 0)
                                {
                                    type = "GameObject";
                                }
                                types.Add(type);
                                builder.Length = 0;
                                continue;
                            }
                        }
                        else if (text[n] == 'l' || text[n] == 'L') // label
                        {
                            n += 2;
                            SkipWhiteSpace(text, ref n);
                            GetNextWord(text, ref n, builder);
                            if (builder.Length > 0)
                            {
                                labels.Add(builder.ToString().Trim());
                                builder.Length = 0;
                                continue;
                            }
                        }
                    }
                }

                GetNextWord(text, ref n, builder);
                if (builder.Length > 0)
                {
                    if (names.Count > 0 && condition == LogicalOperator.Or)
                    {
                        names[names.Count - 1].Op = LogicalOperator.Or;
                    }
                    var r = new ResultExpr();
                    r.Op    = condition;
                    r.Text  = builder.ToString().Trim();
                    r.Not   = not;
                    r.Exact = exact;
                    names.Add(r);
                    builder.Length = 0;
                    not            = false;
                    condition      = LogicalOperator.And;
                    continue;
                }
            }

            //builder.Length = 0;
            //for (n = 0; n < names.Count; ++n)
            //    builder.AppendLine("Name: " + names[n]);
            //for (n = 0; n < types.Count; ++n)
            //    builder.AppendLine("Type: " + types[n]);
            //for (n = 0; n < labels.Count; ++n)
            //    builder.AppendLine("Label: " + labels[n]);

            foreach (var v in result.m_NamesExpr)
            {
                result.names.Add(v.Text);
            }

            // sort by operator. AND first, OR second
            var nam = new List <ResultExpr>();

            foreach (var v in result.m_NamesExpr)
            {
                if (v.Op == LogicalOperator.And)
                {
                    nam.Add(v);
                }
            }
            foreach (var v in result.m_NamesExpr)
            {
                if (v.Op == LogicalOperator.Or)
                {
                    nam.Add(v);
                }
            }
            result.m_NamesExpr = nam;

            //foreach (var e in result.NamesExpr)
            //    UnityEngine.Debug.Log("Op: " + e.Op + (e.Not ? " not " : "") + (e.Exact ? " exact " : "") + ", " + e.Text);

            return(result);
        }