/// <summary>
        /// Saves the given script into a text representation.
        /// </summary>
        /// <param name="p_scpScript">The <see cref="IScript"/> to save.</param>
        /// <returns>The text represnetation of the given <see cref="IScript"/>.</returns>
        public string SaveScript(IScript p_scpScript)
        {
            IUnparser upsUnparser = GetUnparser((XmlScript)p_scpScript);
            XElement  xelScript   = upsUnparser.Unparse();

            return(xelScript.ToString());
        }
Beispiel #2
0
        protected override int? GetChildrenPriority(IUnparser unparser, object astValue, Unparser.Children children, Unparser.Direction direction)
        {
            UnparsableAst mainChild = children.Single(childValue => IsMainChild(childValue.BnfTerm));

            if (astValue.GetType() == this.domainType)
                return unparser.GetPriority(mainChild);
            else
            {
                IBnfiTerm mainChildWithDomainType = mainChild.BnfTerm as IBnfiTerm;

                if (mainChildWithDomainType == null || mainChildWithDomainType.DomainType == null)
                {
                    throw new UnparseException(string.Format("Cannot unparse '{0}' (type: '{1}'). BnfTerm '{2}' is not an IBnfiTerm or it has no domain type.",
                        astValue, astValue.GetType().Name, mainChild.BnfTerm));
                }

                int? priority = mainChildWithDomainType.DomainType == typeof(object)
                    ? int.MinValue
                    : 0 - mainChildWithDomainType.DomainType.GetInheritanceDistance(astValue);

                Unparser.tsPriorities.Indent();
                priority.DebugWriteLinePriority(Unparser.tsPriorities, mainChild);
                Unparser.tsPriorities.Unindent();

                return priority;
            }
        }
        /// <summary>
        /// Determines if the given script is valid.
        /// </summary>
        /// <param name="p_scpScript">The script to validate.</param>
        /// <returns><c>true</c> if the given script is valid;
        /// <c>false</c> otherwise.</returns>
        public bool ValidateScript(IScript p_scpScript)
        {
            IUnparser upsUnparser = GetUnparser((XmlScript)p_scpScript);
            XElement  xelScript   = upsUnparser.Unparse();

            return(IsXmlScriptValid(xelScript));
        }
Beispiel #4
0
        protected override int?GetChildrenPriority(IUnparser unparser, object astValue, Unparser.Children children, Unparser.Direction direction)
        {
            UnparsableAst mainChild = children.Single(childValue => IsMainChild(childValue.BnfTerm));

            if (astValue.GetType() == this.domainType)
            {
                return(unparser.GetPriority(mainChild));
            }
            else
            {
                IBnfiTerm mainChildWithDomainType = mainChild.BnfTerm as IBnfiTerm;

                if (mainChildWithDomainType == null || mainChildWithDomainType.DomainType == null)
                {
                    throw new UnparseException(string.Format("Cannot unparse '{0}' (type: '{1}'). BnfTerm '{2}' is not an IBnfiTerm or it has no domain type.",
                                                             astValue, astValue.GetType().Name, mainChild.BnfTerm));
                }

                int?priority = mainChildWithDomainType.DomainType == typeof(object)
                    ? int.MinValue
                    : 0 - mainChildWithDomainType.DomainType.GetInheritanceDistance(astValue);

                Unparser.tsPriorities.Indent();
                priority.DebugWriteLinePriority(Unparser.tsPriorities, mainChild);
                Unparser.tsPriorities.Unindent();

                return(priority);
            }
        }
Beispiel #5
0
        protected override bool TryGetUtokensDirectly(IUnparser unparser, UnparsableAst self, out IEnumerable <UtokenValue> utokens)
        {
            if (this.UtokenizerForUnparse != null)
            {
                utokens = this.UtokenizerForUnparse(unparser.FormatProvider, self, self.AstValue);
                return(true);
            }
            else if (this.isOptionalValue && object.Equals(self.AstValue, this.defaultValue))
            {
                utokens = Enumerable.Empty <UtokenValue>();
                return(true);
            }
            else if (this.inverseValueConverterForUnparse != null)
            {
                /*
                 * NOTE that we *don't have to* check for "this.inverseValueConverterForUnparse != noUnparseByInverse" here because
                 * IUnparsableNonTerminal.GetChildren will call this.inverseValueConverterForUnparse anyway and it will throw an
                 * UnparseException if it equals to NoUnparseByInverse().
                 *
                 * Moreover, we *cannot* check for "this.inverseValueConverterForUnparse != noUnparseByInverse" here properly because
                 * of the usages of the generic versions of NoUnparseByInverse<...>() methods which wrap the original noUnparseByInverse
                 * by calling CastValueConverter.
                 * */

                utokens = null;
                return(false);
            }
            else
            {
                throw new UnparseException(string.Format("Cannot unparse. '{0}' has neither UtokenizerForUnparse nor ValueConverterForUnparse", this.Name));
            }
        }
        /// <summary>
        /// Determines if the given script is valid.
        /// </summary>
        /// <param name="p_scpScript">The script to validate.</param>
        /// <returns><c>true</c> if the given script is valid;
        /// <c>false</c> otherwise.</returns>
        public bool ValidateScript(IScript script)
        {
            IUnparser Unparser  = GetUnparser((XmlScript)script);
            XElement  XelScript = Unparser.Unparse();

            return(IsXmlScriptValid(XelScript));
        }
        /// <summary>
        /// Saves the given script into a text representation.
        /// </summary>
        /// <param name="p_scpScript">The <see cref="IScript"/> to save.</param>
        /// <returns>The text represnetation of the given <see cref="IScript"/>.</returns>
        public string SaveScript(IScript script)
        {
            IUnparser Unparser  = GetUnparser((XmlScript)script);
            XElement  XelScript = Unparser.Unparse();

            return(XelScript.ToString());
        }
Beispiel #8
0
 protected override int?GetChildrenPriority(IUnparser unparser, object astValue, Unparser.Children childrenAtRule, Unparser.Direction direction)
 {
     return(childrenAtRule
            .SumIncludingNullValues(
                (childAtRule, childIndexAtRule) => IsMemberAtRule(new ReferredBnfTermEI(childrenAtRule.ContentIndex, childAtRule.BnfTerm, childIndexAtRule))
                 ? GetBnfTermPriorityForMember(unparser, childAtRule)
                 : unparser.GetPriority(childAtRule)
                ));
 }
Beispiel #9
0
        protected override int?GetChildrenPriority(IUnparser unparser, object astValue, Unparser.Children children, Unparser.Direction direction)
        {
            System.Collections.IEnumerable collection = (System.Collections.IEnumerable)astValue;

            if (collection != null || this.EmptyCollectionHandling == EmptyCollectionHandling.ReturnNull)
            {
                return(1);
            }
            else
            {
                return(null);
            }
        }
Beispiel #10
0
 protected override int?GetChildrenPriority(IUnparser unparser, object astValue, Unparser.Children children, Unparser.Direction direction)
 {
     if (this.isOptionalValue && object.Equals(astValue, this.defaultValue))
     {
         return(0);
     }
     else if (this.value != null)
     {
         return(this.value.Equals(astValue) ? (int?)1 : null);
     }
     else if (this.UtokenizerForUnparse != null)
     {
         return(1);
     }
     else
     {
         return(unparser.GetPriority(GetMainChild(astValue, children)));
     }
 }
Beispiel #11
0
 private static int?GetBnfTermPriorityForMember(IUnparser unparser, UnparsableAst unparsableAst)
 {
     if (unparsableAst.AstValue != null)
     {
         return(1);
     }
     else if (unparsableAst.BnfTerm is BnfiTermCollection && ((BnfiTermCollection)unparsableAst.BnfTerm).EmptyCollectionHandling == EmptyCollectionHandling.ReturnNull)
     {
         return(0);
     }
     else if (unparsableAst.BnfTerm is BnfiTermConversion && ((BnfiTermConversion)unparsableAst.BnfTerm).isOptionalValue)
     {
         return(0);
     }
     else
     {
         return(null);
     }
 }
Beispiel #12
0
 protected override bool TryGetUtokensDirectly(IUnparser unparser, UnparsableAst self, out IEnumerable<UtokenValue> utokens)
 {
     utokens = null;
     return false;
 }
Beispiel #13
0
 protected abstract bool TryGetUtokensDirectly(IUnparser unparser, UnparsableAst self, out IEnumerable <UtokenValue> utokens);
Beispiel #14
0
 bool IUnparsableNonTerminal.TryGetUtokensDirectly(IUnparser unparser, UnparsableAst self, out IEnumerable <UtokenValue> utokens)
 {
     return(TryGetUtokensDirectly(unparser, self, out utokens));
 }
Beispiel #15
0
 protected override int?GetChildrenPriority(IUnparser unparser, object astValue, Unparser.Children children, Unparser.Direction direction)
 {
     return(children.SumIncludingNullValues(child => unparser.GetPriority(child)));
 }
Beispiel #16
0
 int?IUnparsableNonTerminal.GetChildrenPriority(IUnparser unparser, object astValue, Unparser.Children childrenAtRule, Unparser.Direction direction)
 {
     return(GetChildrenPriority(unparser, astValue, childrenAtRule, direction));
 }
Beispiel #17
0
 protected override bool TryGetUtokensDirectly(IUnparser unparser, UnparsableAst self, out IEnumerable <UtokenValue> utokens)
 {
     utokens = null;
     return(false);
 }
Beispiel #18
0
 protected abstract int?GetChildrenPriority(IUnparser unparser, object astValue, Unparser.Children childrenAtRule, Unparser.Direction direction);
Beispiel #19
0
 protected override int?GetChildrenPriority(IUnparser unparser, object astValue, Unparser.Children children, Unparser.Direction direction)
 {
     return(0);
 }