public static bool IsVariable(Literal literal)
 {
     return(literal.description[0] == '[');
 }
        public static bool MatchDescription(Literal n1, Literal n2)
        {
            if (n1.description == Name.UNIVERSAL_STRING ||
                n2.description == Name.UNIVERSAL_STRING)
                return true;

            return n1.description.EqualsIgnoreCase(n2.description);
        }
 public static bool IsVariable(Literal literal)
 {
     return literal.description[0] == '[';
 }
        public static SimpleName BuildNameFromContainedLiteral(SimpleName name, Literal literal)
        {
            if (literal.type != LiteralType.Root)
                return new SimpleName(new Literal[] { literal });

            var i = name.literals.IndexOf(literal);
            var list = name.literals.Skip(i+1).TakeWhile(l => l.depth > literal.depth);
            return new SimpleName(list.Prepend(literal));
        }
        //return the idx jump on the valName or -1 if it can't add the substitution
        private static int FindSubsAux(Literal var, Literal val, SimpleName valName, IDictionary<string, Substitution> bindings)
        {
            string valDescription;
            SimpleName auxName = null;
            if (val.type == LiteralType.Root)
            {
                auxName = SimpleWFN.BuildNameFromContainedLiteral(valName, val);
                valDescription = auxName.ToString();
            }
            else
            {
                valDescription = val.description;
            }

            //check if a binding for the same variable already exists
            Substitution existingSub = null;
            bindings.TryGetValue(var.description, out existingSub);
            if (existingSub != null)
            {
                if (existingSub.Value.ToString().RemoveWhiteSpace().EqualsIgnoreCase("valDescription"))
                    return 1;
                else return -1;
            }
            //if there was no existing binding to the variable
            try
            {
                bindings[var.description] = new Substitution(var.description, valDescription);
                if (var.type == LiteralType.Param && val.type == LiteralType.Root)
                    return auxName.literals.Count;
                else return 1;
            }
            catch (BadSubstitutionException)
            {
                return -1;
            }
        }
 private void ToStringHelper(StringBuilder sb, Literal previous, Literal current)
 {
     if (previous.type == LiteralType.Root)
     {
         sb.Append("(" + current.description);
     }
     if (previous.type == LiteralType.Param && current.type == LiteralType.Param)
     {
         sb.Append(')', previous.depth - current.depth);
         sb.Append("," + current.description);
     }
     if (previous.type == LiteralType.Param && current.type == LiteralType.Root)
     {
         sb.Append(')', previous.depth - current.depth);
         sb.Append("," + current.description);
     }
 }