예제 #1
0
 public GrammarToken(Unparser grammar, int start, GrammarToken parent)
 {
     Raw     = "";
     Grammar = grammar;
     Start   = start;
     Parent  = parent;
 }
예제 #2
0
        public void AddChild(GrammarToken child)
        {
            var open = FindLowestOpenToken();

            if (open.Children == null)
            {
                open.Children = new List <GrammarToken>();
            }
            open.Children.Add(child);
            child.Parent = open;
        }
예제 #3
0
        public void ReplaceInnerText(GrammarToken innerToken)
        {
            // Update the Resolved text, replacing inner token Raw with Resolved.
            var start = Resolved.IndexOf(innerToken.Raw);

            if (start < 0 || start >= Resolved.Length)
            {
                return;
            }
            Resolved = Resolved.Substring(0, start) + innerToken.Resolved + Resolved.Substring(start + innerToken.Raw.Length);

            // Update the positions of any IndecesOfInterest relative to replaced text.
            if (innerToken.Raw.Length == innerToken.Resolved.Length)
            {
                return;
            }
            var difference = innerToken.Raw.Length - innerToken.Resolved.Length;

            if (IndecesOfInterest == null || IndecesOfInterest.Count == 0)
            {
                return;
            }
            for (var i = 0; i < IndecesOfInterest.Count; i++)
            {
                if (start <= IndecesOfInterest[i])
                {
                    IndecesOfInterest[i] -= difference;
                    if (IndecesOfInterest[i] < 0)
                    {
                        IndecesOfInterest.RemoveAt(i);
                        i--;
                    }
                }
                else
                {
                    continue;
                }
            }
        }