Beispiel #1
0
        private void AddNewSyntax(SyntaxObject newObject)
        {
            int newPos = 0;

            this.Elements.Elements.Clear();
            for (int i = 0; i < Syntax.Count; i++)
            {
                if (this.Syntax[i].GetType() == newObject.Syntax[newPos].GetType())
                {
                    Elements.Add(newObject.Elements.Elements[newPos]);
                    if (newObject.Syntax.Count > newPos + 1)
                    {
                        newPos++;
                    }
                    else
                    {
                        for (int j = i + 1; j < Syntax.Count; j++)
                        {
                            Elements.Add("");
                        }
                        return;
                    }
                }
                else
                {
                    Elements.Add("");
                }
            }
        }
Beispiel #2
0
 public void Add(SyntaxObject item)
 {
     Elements.Add(new ElementItem(item));
 }
Beispiel #3
0
 public ElementItem(SyntaxObject syntaxObject) : this()
 {
     this.ElementReference = syntaxObject;
     this.HasValue         = false;
 }
Beispiel #4
0
        public override SyntaxError Check()
        {
            string line = this.Context;

            line = line.Replace(" ", string.Empty);
            int startIndex = 0;

            if (Elements.ElementCount != 0)
            {
                line       = line.Remove(0, Elements[0].Length);
                startIndex = 1;
            }
            else
            {
                startIndex = 0;
            }

            int         i     = 0;
            SyntaxError check = SyntaxError.SyntaxError;

            for (i = startIndex; i < Syntax.Count; i++)
            {
                string element = "";
                if (Syntax[i] is SyntaxObject)
                {
                    check = Syntax[i].Check(line);
                    if (check != SyntaxError.NoError)
                    {
                        break;
                    }
                }
                else
                {
                    if (Syntax[i].Elements.SignCount != 0)
                    {
                        string tmpElement = string.Empty;
                        foreach (string item in Syntax[i].Elements)
                        {
                            if (line != string.Empty)
                            {
                                if (item.Length <= line.Length)
                                {
                                    tmpElement = line.Substring(0, item.Length);
                                }
                            }
                            check = Syntax[i].Check(tmpElement);
                            if (check == SyntaxError.NoError)
                            {
                                element = tmpElement;
                            }
                        }
                        if (element == string.Empty)
                        {
                            break;
                        }
                    }
                    else
                    {
                        //if (i == Syntax.Count - 1)
                        //{
                        //    element = line;
                        //    check = Syntax[i].Check(element);
                        //    if (check != SyntaxError.NoError) break;
                        //}
                        //else
                        {
                            bool isFound = false;
                            for (int j = 1; j <= line.Length; j++)
                            {
                                element = line.Substring(0, j);
                                check   = Syntax[i].Check(element);
                                if (check != SyntaxError.NoError)
                                {
                                    element = element.Remove(element.Length - 1, 1);
                                    break;
                                }

                                if ((i + 1) < Syntax.Count)
                                {
                                    if (Syntax[i + 1] is SyntaxObject)
                                    {
                                        string nextLine = line.Substring(element.Length, line.Length - element.Length);
                                        if (Syntax[i + 1].Check(nextLine) != SyntaxError.NoError)
                                        {
                                            isFound = false;
                                        }
                                        else
                                        {
                                            isFound = true;
                                        }
                                        (Syntax[i + 1] as SyntaxObject).ClearElements();
                                    }
                                    else
                                    {
                                        if (Syntax[i + 1].Elements.SignCount != 0)
                                        {
                                            isFound = CheckNext(line, j, i + 1, element);
                                        }
                                    }
                                }
                                if (isFound)
                                {
                                    break;
                                }
                                if (j >= line.Length - (Syntax.Count - i - 1))
                                {
                                    break;
                                }
                            }
                            if (i != Syntax.Count - 1)
                            {
                                if (!isFound)
                                {
                                    check = SyntaxError.SyntaxError;
                                    break;
                                }
                            }
                        }
                    }
                }
                if (Syntax[i] is SyntaxObject)
                {
                    Elements.Add(Syntax[i] as SyntaxObject);
                }
                else
                {
                    if (Syntax[i] is AbstractSyntaxObject)
                    {
                        Elements.Add(element);
                    }
                }
                line = line.Remove(0, Elements[Elements.ElementCount - 1].Length);
            }

            if (check != SyntaxError.NoError)
            {
                for (int n = 0; n < Syntax.Count; n++)
                {
                    SyntaxObject syntaxObject = Activator.CreateInstance(this.GetType()) as SyntaxObject;
                    syntaxObject.Context = this.Context;
                    syntaxObject.Syntax.Clear();
                    syntaxObject.Syntax.AddRange(this.Syntax);
                    int nullablePos = GetNextNullableElement();
                    if (nullablePos != -1)
                    {
                        syntaxObject.Syntax.RemoveAt(nullablePos);
                        check = syntaxObject.Check();
                        if (check == SyntaxError.NoError)
                        {
                            AddNewSyntax(syntaxObject);
                            line = string.Empty;
                            break;
                        }
                        //else return check;
                    }
                    else
                    {
                        return(check);
                    }
                }
            }

            this.Context = Elements.Context;

            //if (line != string.Empty || !IsFulSyntax()) return SyntaxError.SyntaxError;
            if (!IsFulSyntax())
            {
                return(SyntaxError.SyntaxError);
            }
            return(SyntaxError.NoError);
        }