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; } }
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); } }
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) )); }
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))); } }
protected override int?GetChildrenPriority(IUnparser unparser, object astValue, Unparser.Children children, Unparser.Direction direction) { return(children.SumIncludingNullValues(child => unparser.GetPriority(child))); }