Esempio n. 1
0
 /// <summary>
 /// Given a tree, set the tags on the leaf nodes if they are not
 /// already set.
 /// </summary>
 /// <remarks>
 /// Given a tree, set the tags on the leaf nodes if they are not
 /// already set.  Do this by using the preterminal's value as a tag.
 /// </remarks>
 public static void SetLeafTagsIfUnset(Tree tree)
 {
     if (tree.IsPreTerminal())
     {
         Tree leaf = tree.Children()[0];
         if (!(leaf.Label() is IHasTag))
         {
             return;
         }
         IHasTag label = (IHasTag)leaf.Label();
         if (label.Tag() == null)
         {
             label.SetTag(tree.Value());
         }
     }
     else
     {
         foreach (Tree child in tree.Children())
         {
             SetLeafTagsIfUnset(child);
         }
     }
 }
        // It's okay to not support the fromString operation
        private static void ValidateHasTag(string type, IHasTag lab, string tag)
        {
            NUnit.Framework.Assert.AreEqual(type + " does not have tag it was constructed with", lab.Tag(), tag);
            string newVal = "feijoa";

            lab.SetTag(newVal);
            NUnit.Framework.Assert.AreEqual(type + " does not have tag set with setTag", newVal, lab.Tag());
            // restore value
            lab.SetTag(tag);
        }