Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,245 @@
2009-02-23 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs : added "Anything" which is used in error recovery
support.
2007-12-14 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs : For ContainsText() (for interleave text/text
constraint check), element pattern should return false.
Fixed bug #347945.
2007-04-18 Atsushi Enomoto <atsushi@ximian.com>
* RdpPatterns.cs : inside elements, reset oneOrMore[Group] flags in
CheckConstraints().
2006-02-02 Atsushi Enomoto <atsushi@ximian.com>
* RdpPatterns.cs : After profiling in depth, finally I found the
source of the worst perf. problem in the code - return x for
(choice x x).
It now validates 5MB of OpenDocument specification content.xml,
which only Jing could do.
2006-01-16 Atsushi Enomoto <atsushi@ximian.com>
* RdpObjects.cs : fixed warnings.
2006-01-16 Atsushi Enomoto <atsushi@ximian.com>
* RdpPatterns.cs : RdpOneOrMore.EmptyTextDeriv() should be "override".
RdpList.EmptyTextDeriv() (which was also virtual incorrectly) was
removed since the code was in wrong assumption.
* Util.cs : debug string now contains data and dataExcept info.
2006-01-15 Atsushi Enomoto <atsushi@ximian.com>
* RdpPatterns.cs : lazy evaluate Group branches. If left hand is
notAllowed, the returned value is always NotAllowed, no need to
compute another branch.
2006-01-13 Atsushi Enomoto <atsushi@ximian.com>
* RdpObjects.cs, RdpPatterns.cs : introduced "IsContextDependent"
optimization; when a pattern is (namespace) context independent
(almost all cases except for QName validation), new TextDeriv()
overload that takes MemoizationStore memoizes TextDeriv results.
2006-01-12 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs :
Introduced EmptyTextDeriv() so that the results could be memoized.
2006-01-10 Atsushi Enomoto <atsushi@ximian.com>
* RdpPatterns.cs :
- Added StartAttDeriv(), EndAttDeriv() and IsTextValueDependent.
(See corresponding changes in RelaxngValidatingReader.cs).
- Added a bunch of derivative method overloads to receive
MemoizationStore and memoize results efficiently.
2006-01-05 Atsushi Enomoto <atsushi@ximian.com>
* RdpPatterns.cs :
- Fixed RdpPattern.TextDeriv() and MixedTextDeriv() to not allow
whitespaces incorrectly.
- Fixed MixedTextDeriv() to not require string argument.
- Erased commented code.
- in listDerivInternal(), skip empty strings.
- ValueMatch() should allow whitespaces if the pattern is nullable
(as defined in derivative).
- Replaced MakeChoice()/MakeGroup()/MakeInterleave()/MakeAfter()
in TextOnlyDeriv() and MixedTextDeriv(). They should not be
constructions but should be functions (thus, member methods).
- Fixed Nullable in RdpData and RdpValue to conform to the
derivative algorithm (it incorrectly extended to return false
for RELAX NG predefined datatypes).
2006-01-04 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs :
- Implemented textOnlyDeriv and mixedTextDeriv of "memoization".
Details are described in the "derivative" algorithm:
http://www.thaiopensource.com/relaxng/derivative.html#Memoization
- Added MakeChoiceLeaf() to implement "choice-leaves":
http://www.thaiopensource.com/relaxng/derivative.html#Avoiding_exponential_blowup
- To intern effectively, reorder choice and interleave contents by
hash code.
- Avoid extra pattern creation with related to empty and notAllowed
as one hand of binary branches.
2006-01-03 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs : reduced RdpFlip instantiation. Share patternPool
only when it does not exist.
2006-01-03 Atsushi Enomoto <atsushi@ximian.com>
* Util.cs, RdpPatterns.cs : optimization. Removed extraneous
delegate instantiation. Avoid using enum for HashTable keys.
2005-12-27 Atsushi Enomoto <atsushi@ximian.com>
* Util.cs RdpObjects.cs RdpContentType.cs RdpNameClasses.cs
RdpPatterns.cs :
... and svn:eol-style as well, since there is exactly no one else
who develops this assembly and messes no one else.
2005-12-27 Atsushi Enomoto <atsushi@ximian.com>
* Util.cs RdpObjects.cs RdpContentType.cs RdpNameClasses.cs
RdpPatterns.cs :
Ugh, seems like svn server shows different diffs than that of
client. Anyways here I fixed all mixed line endings.
2005-12-27 Atsushi Enomoto <atsushi@ximian.com>
* RdpPatterns.cs : in ValueMatch() it should not strip whitespaces
which could be validated. This fixes test #256/2.i.xml.
2005-12-27 Atsushi Enomoto <atsushi@ximian.com>
* RdpPatterns.cs : oneOrMore ancestor check for anyName/nsName in
section 7.3 was missing. This fixes test #357, #358 and #359.
* RdpNameClass.cs : added HasInfiniteName property to RdpNameClass.
2005-12-27 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs, RdpUtil.cs : reimplemented name class analysis to
not create extraneous QName instances. This also fixes some weird
bugs (test #362 and #363).
2005-12-27 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs : Checking interleave restriction in section 7.4 with
PatternType was not insufficient. Now I use ContainsText(). It fixes
testcase #371.
2005-12-20 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs : cache ContentType and save speed.
2005-09-20 Atsushi Enomoto <atsushi@ximian.com>
* Util.cs : Added name class analysis support. The algorithm is at
http://www.thaiopensource.com/relaxng/nameclass.html .
* RdpPattern.cs :
- added CheckNameOverlap() for group and interleave to do name class
analysis (spec 7.3 and 7.4).
- Removed CheckAttributeDuplicates(). Now name class analysis is
implemented in CheckNameOverlap().
- Added additional bool parameter to GetLabels() to collect
RdpNameClass instances instead of XmlQualifiedName instances.
2005-07-31 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs : GetLabels() for RdpGroup should check attributes
when the left branch is not nullable (it works like an interleave).
Implemented spec 7.3 attribute check (though not enabled for now).
2005-04-11 Atsushi Enomoto <atsushi@ximian.com>
* Util.cs : tiny debug string fix.
2005-03-01 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs : In "textDeriv(group p1 p2) s", "nullable p1" is
incorrectly computed as "nullable p".
2005-02-06 Atsushi Enomoto <atsushi@ximian.com>
* RdpObjects.cs : provide error type name. removed commented code block.
2005-02-06 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs : MakeOneOrMore() did not always set up internal table.
2004-12-06 Atsushi Enomoto <atsushi@ximian.com>
* Util.cs : trivial debug string fix.
* RdpPattern.cs : trivial formatting fix.
2004-12-06 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs : The last attribute stuff broke usual validation wrt
global attributes.
2004-12-06 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs : fixed setupTable(). Avoid boxing.
2004-12-05 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs : RdpAttribute now omits value check when the argument
value is null. It is useful to get labels.
2004-12-05 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs : added GetLabels().
2004-06-25 Atsushi Enomoto <atsushi@ximian.com>
* RdpContentType.cs, RdpNameClass.cs, RdpObjects.cs, RdpPatterns.cs,
Util.cs : added novell license term.
2004-06-21 Atsushi Enomoto <atsushi@ximian.com>
* RdpPatterns.cs : Fixed ExpandRef() that caused incorrect nest error.
2004-06-17 Atsushi Enomoto <atsushi@ximian.com>
* RdpPatterns.cs : Quick workaround for infinite loop happening in
some kind of recursive expansion.
2004-03-12 Atsushi Enomoto <atsushi@ximian.com>
* RdpPatterns.cs : Fixed TextDeriv() to allow whitespace text nodes
except for Data and Value (though they are overridden).
2004-02-25 Atsushi Enomoto <atsushi@ximian.com>
* Added RdpContextType.cs.
* RdpNameClasses.cs,
RdpObjects.cs,
RdpPatterns.cs,
Util.cs : radical design change (too many things to write up).
2003-05-19 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
* RdpPattern.cs : Some method name capitalization.
Fixed RdpInterleave.StartTagOpenDeriv() which is logically incorrect.
2003-05-05 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
* RdpPattern.cs : added RdpAttribute.expandRef(). UnresolvedRef had
remained in attribute patterns.
2003-04-29 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
* Started.
* added ChangeLog, RdpNameClasses.cs, RdpObjects.cs, RdpPatterns.cs
and Util.cs.

View File

@@ -0,0 +1,42 @@
//
// RdpContentType.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// See RELAX NG spec 7.2
//
// Copyright (c) 2004 Novell Inc.
// All rights reserved
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Commons.Xml.Relaxng.Derivative
{
public enum RdpContentType {
Invalid = 0,
Empty = 1,
Complex = 2,
Simple = 4
}
}

View File

@@ -0,0 +1,237 @@
//
// Commons.Xml.Relaxng.Derivative.RdpNameClasses.cs
//
// Author:
// Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
//
// 2003 Atsushi Enomoto "No rights reserved."
//
// Copyright (c) 2004 Novell Inc.
// All rights reserved
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Xml;
namespace Commons.Xml.Relaxng.Derivative
{
public enum RdpNameClassType
{
None = 0,
AnyName = 1,
AnyNameExcept = 2,
NsName = 3,
NsNameExcept = 4,
Name = 5,
NameClassChoice = 6
}
public abstract class RdpNameClass
{
public abstract bool HasInfiniteName { get; }
public abstract RdpNameClassType NameClassType { get; }
public abstract bool Contains (string name, string ns);
}
public class RdpAnyName : RdpNameClass
{
static RdpAnyName instance;
static RdpAnyName ()
{
instance = new RdpAnyName ();
}
public static RdpAnyName Instance {
get { return instance; }
}
private RdpAnyName () {}
public override bool HasInfiniteName {
get { return true; }
}
public override RdpNameClassType NameClassType {
get { return RdpNameClassType.AnyName; }
}
public override bool Contains (string name, string ns)
{
return true;
}
}
public class RdpAnyNameExcept : RdpNameClass
{
RdpNameClass except;
public RdpAnyNameExcept (RdpNameClass except)
{
this.except = except;
}
public override bool HasInfiniteName {
get { return true; }
}
public override RdpNameClassType NameClassType {
get { return RdpNameClassType.AnyNameExcept; }
}
public RdpNameClass ExceptNameClass {
get { return except; }
}
public override bool Contains (string name, string ns)
{
return (except == null) || !except.Contains (name, ns);
}
}
public class RdpNsName : RdpNameClass
{
string ns;
public RdpNsName (string ns)
{
this.ns = ns;
}
public override bool HasInfiniteName {
get { return true; }
}
public override RdpNameClassType NameClassType {
get { return RdpNameClassType.NsName; }
}
public string NamespaceURI {
get { return ns; }
}
public override bool Contains (string name, string ns)
{
return NamespaceURI == ns;
}
}
public class RdpNsNameExcept : RdpNsName
{
string ns;
RdpNameClass except;
public RdpNsNameExcept (string ns, RdpNameClass except)
: base (ns)
{
this.ns = ns;
this.except = except;
}
public override bool HasInfiniteName {
get { return true; }
}
public override RdpNameClassType NameClassType {
get { return RdpNameClassType.NsNameExcept; }
}
public RdpNameClass ExceptNameClass {
get { return except; }
}
public override bool Contains (string name, string ns)
{
return this.ns == ns &&
(except == null || !except.Contains (name, ns));
}
}
public class RdpName : RdpNameClass
{
string local;
string ns;
public RdpName (string local, string ns)
{
this.ns = ns;
this.local = local;
}
public override bool HasInfiniteName {
get { return false; }
}
public override RdpNameClassType NameClassType {
get { return RdpNameClassType.Name; }
}
public string NamespaceURI {
get { return ns; }
}
public string LocalName {
get { return local; }
}
public override bool Contains (string name, string ns)
{
return this.ns == ns && this.local == name;
}
}
public class RdpNameClassChoice : RdpNameClass
{
RdpNameClass l;
RdpNameClass r;
public RdpNameClassChoice (RdpNameClass l, RdpNameClass r)
{
this.l = l;
this.r = r;
}
public override bool HasInfiniteName {
get { return l.HasInfiniteName || r.HasInfiniteName; }
}
public override RdpNameClassType NameClassType {
get { return RdpNameClassType.NameClassChoice; }
}
public RdpNameClass LValue {
get { return l; }
}
public RdpNameClass RValue {
get { return r; }
}
public override bool Contains (string name, string ns)
{
return l.Contains (name, ns) || r.Contains (name, ns);
}
}
}

View File

@@ -0,0 +1,114 @@
//
// Commons.Xml.Relaxng.Derivative.RdpObjects.cs
//
// Author:
// Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
//
// 2003 Atsushi Enomoto "No rights reserved."
//
// Copyright (c) 2004 Novell Inc.
// All rights reserved
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Xml;
namespace Commons.Xml.Relaxng.Derivative
{
///
/// Datatype Related Classes
///
public class RdpParamList : ArrayList
{
public RdpParamList () : base ()
{
}
}
public class RdpParam
{
public RdpParam (string localName, string value)
{
this.localName = localName;
this.value = value;
}
string value;
public string Value {
get { return this.value; }
}
string localName;
public string LocalName {
get { return localName; }
}
}
public class RdpDatatype
{
//RelaxngDatatypeProvider provider;
string localName;
string ns;
RelaxngDatatype datatype;
public RdpDatatype (string ns, string localName, RelaxngParamList parameters, RelaxngDatatypeProvider provider)
{
this.ns = ns;
this.localName = localName;
//this.provider = provider;
if (provider == null)
provider = RelaxngMergedProvider.DefaultProvider;
datatype = provider.GetDatatype (localName, ns, parameters);
if (datatype == null) {
throw new RelaxngException (String.Format ("Invalid datatype was found for namespace '{0}' and local name '{1}'", ns, localName));
}
}
public string NamespaceURI {
get { return ns; }
}
public string LocalName {
get { return localName; }
}
public bool IsContextDependent {
get { return datatype.IsContextDependent; }
}
public virtual bool IsAllowed (string value, XmlReader reader)
{
return datatype.IsValid (value, reader);
}
public virtual bool IsTypeEqual (string s1, string s2, XmlReader reader)
{
return datatype.CompareString (s1, s2, reader);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,409 @@
//
// Commons.Xml.Relaxng.Derivative.Util.cs
//
// Author:
// Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
//
// 2003 Atsushi Enomoto "No rights reserved."
//
// Copyright (c) 2004 Novell Inc.
// All rights reserved
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Xml;
using QName = System.Xml.XmlQualifiedName;
namespace Commons.Xml.Relaxng.Derivative
{
public class RdpUtil
{
public static char[] WhitespaceChars = " \t\r\n".ToCharArray ();
internal static RdpBinaryFunction AfterFunction =
new RdpBinaryFunction (After);
internal static RdpBinaryFunction GroupFunction =
new RdpBinaryFunction (Group);
internal static RdpBinaryFunction InterleaveFunction =
new RdpBinaryFunction (Interleave);
// Generating simplified pattern status (similar to XML representation).
#region Debug
private static string DebugNameClass (RdpNameClass n)
{
switch (n.NameClassType) {
case RdpNameClassType.Name:
RdpName nm = (RdpName)n;
return "<name ns='" + nm.NamespaceURI + "'>"
+ nm.LocalName + "</name>\n";
case RdpNameClassType.NsName:
return "<nsName ns='" + ((RdpNsName)n).NamespaceURI + "'/>\n";
case RdpNameClassType.NameClassChoice:
RdpNameClassChoice nc = (RdpNameClassChoice) n;
return "<choice>" + DebugNameClass (nc.LValue) + DebugNameClass (nc.RValue) + "</choice>";
default:
return "<" + n.NameClassType.ToString () + "/>\n";
}
}
internal static string DebugRdpPattern (RdpPattern p, Hashtable visitedPattern)
{
if (p is RdpText)
return "<text/>\n";
if (p is RdpEmpty)
return "<empty/>\n";
if (p is RdpNotAllowed)
return "<notAllowed/>\n";
if (visitedPattern.Contains (p))
return "<" + p.PatternType + " ref='" + p.GetHashCode () + "'/>";
visitedPattern.Add (p, p);
string intl = "(id=" + p.GetHashCode () + ") ";
RdpAbstractSingleContent s = p as RdpAbstractSingleContent;
if (s != null)
intl = DebugRdpPattern (s.Child, visitedPattern);
RdpAbstractBinary b = p as RdpAbstractBinary;
if (b != null)
intl = DebugRdpPattern (b.LValue, visitedPattern) +
DebugRdpPattern (b.RValue, visitedPattern);
RdpData data = p as RdpData;
if (data != null)
intl = String.Format ("name={0},ns={1},type={2} {3}",
data.Datatype.LocalName,
data.Datatype.NamespaceURI,
data.Datatype.GetType (),
data is RdpDataExcept ? DebugRdpPattern (((RdpDataExcept) data).Except, visitedPattern) : String.Empty);
RdpValue value = p as RdpValue;
if (value != null)
intl = String.Format ("name={0},ns={1},value={2} type={3}",
value.Datatype.LocalName,
value.Datatype.NamespaceURI,
value.Value,
value.Datatype.GetType ());
RdpElement el = p as RdpElement;
if (el != null)
intl = DebugNameClass (el.NameClass) +
DebugRdpPattern (el.Children, visitedPattern);
RdpAttribute at = p as RdpAttribute;
if (at != null)
intl = DebugNameClass (at.NameClass) +
DebugRdpPattern (at.Children, visitedPattern);
string str = String.Format ("<{0} id='id{1}'>\n{2}\n</{0}>",
p.PatternType.ToString (),
p.GetHashCode (),
intl);
return str;
}
#endregion
// contains :: NameClass -> QName -> Bool
internal static bool Contains (RdpNameClass nc, string name, string ns)
{
return nc.Contains (name, ns);
}
// nullable :: Pattern -> Bool
internal static bool Nullable (RdpPattern p)
{
return p.Nullable;
}
/*
// childDeriv :: Context -> Pattern -> ChildNode -> Pattern
internal static RdpPattern ChildDeriv (RdpContext ctx, RdpPattern p, RdpChildNode child)
{
return p.ChildDeriv (child);
}
*/
// textDeriv :: Context -> Pattern -> String -> Pattern
internal static RdpPattern TextDeriv (XmlReader reader, RdpPattern p, string s)
{
return p.TextDeriv (s, reader);
}
// listDeriv :: Context -> Pattern -> [String] -> Pattern
internal static RdpPattern ListDeriv (XmlReader reader, RdpPattern p, string [] list)
{
return p.ListDeriv (list, 0, reader);
}
// choice :: Pattern -> Pattern -> Pattern
internal static RdpPattern Choice (RdpPattern p1, RdpPattern p2)
{
return p1.Choice (p2);
}
// group :: Pattern -> Pattern -> Pattern
internal static RdpPattern Group (RdpPattern p1, RdpPattern p2)
{
return p1.Group (p2);
}
// interleave :: Pattern -> Pattern -> Pattern
internal static RdpPattern Interleave (RdpPattern p1, RdpPattern p2)
{
return p1.Interleave (p2);
}
// after :: Pattern -> Pattern -> Pattern
internal static RdpPattern After (RdpPattern p1, RdpPattern p2)
{
return p1.After (p2);
}
// datatypeAllows :: Datatype -> ParamList -> String -> Context -> Bool
internal static bool DatatypeAllows (RdpDatatype dt, string value, XmlReader reader)
{
return dt.IsAllowed (value, reader);
}
// datatypeEqual :: Datatype -> String -> Context -> String -> Context -> Bool
internal static bool DatatypeEqual (RdpDatatype dt, string value1, string value2, XmlReader reader)
{
return dt.IsTypeEqual (value1, value2, reader);
}
#if false
// normalizeWhitespace :: String -> String
internal static string NormalizeString (string s)
{
throw new NotImplementedException ();
}
#endif
#if false
// applyAfter :: (Pattern -> Pattern) -> Pattern -> Pattern
internal static RdpPattern ApplyAfter (RdpApplyAfterHandler h, RdpPattern p)
{
if (p is RdpAfter)
return After (p.LValue, h (p.RValue));
}
#endif
#region Validation Core
// startTagOpenDeriv :: Pattern -> QName -> Pattern
// TODO remains: Interleave, OneOrMore, Group, After
internal static RdpPattern StartTagOpenDeriv (RdpPattern pattern, string name, string ns)
{
return pattern.StartTagOpenDeriv (name, ns);
}
/*
// attsDeriv :: Context -> Pattern -> [AttributeNode] -> Pattern
// [implemented in RdpPattern]
internal static RdpPattern AttsDeriv (RdpPattern p, RdpAttributes attributes)
{
return p.AttsDeriv (attributes);
}
*/
// attDeriv :: Context -> Pattern -> AttributeNode -> Pattern
// [all implemented]
internal static RdpPattern AttDeriv (XmlReader reader,
RdpPattern p, string name, string ns, string value)
{
return p.AttDeriv (name, ns, value, reader);
}
// valueMatch :: Context -> Pattern -> String -> Bool
// [implemented in RdpPattern]
internal static bool ValueMatch (RdpPattern p, string s, XmlReader reader)
{
return p.ValueMatch (s, reader);
}
// startTagCloseDeriv :: Pattern -> Pattern
// [implemented]
internal static RdpPattern StartTagCloseDeriv (RdpPattern p)
{
return p.StartTagCloseDeriv ();
}
// oneOrMore :: Pattern -> Pattern
// [implemented in RdpPattern]
internal static RdpPattern OneOrMore (RdpPattern p)
{
return p.OneOrMore ();
}
// writespace :: String -> Bool
// [implemented here]
internal static bool Whitespace (string s)
{
return s.Trim (WhitespaceChars).Length == 0;
}
// endTagDeriv :: Pattern -> Pattern
// [implemented]
internal static RdpPattern EndTagDeriv (RdpPattern p)
{
return p.EndTagDeriv ();
}
// Name class analysis
internal static bool NamesOverlap (RdpPattern p1,
RdpPattern p2, bool checkElements)
{
if (p1 == p2)
return true;
RdpAbstractBinary bp1 = p1 as RdpAbstractBinary;
if (bp1 != null)
return NamesOverlap (bp1.LValue, p2, checkElements)
|| NamesOverlap (bp1.RValue, p2, checkElements);
RdpOneOrMore rp1 = p1 as RdpOneOrMore;
if (rp1 != null)
return NamesOverlap (rp1.Child, p2, checkElements);
RdpAttribute ap1 = p1 as RdpAttribute;
if (ap1 != null)
return NamesOverlap (p2, ap1.NameClass, checkElements);
if (!checkElements)
return false;
RdpElement ep1 = p1 as RdpElement;
if (ep1 != null)
return NamesOverlap (p2, ep1.NameClass, checkElements);
return false;
}
// Name class analysis
static bool NamesOverlap (RdpPattern p1,
RdpNameClass n, bool checkElements)
{
RdpAbstractBinary bp1 = p1 as RdpAbstractBinary;
if (bp1 != null)
return NamesOverlap (bp1.LValue, n, checkElements)
|| NamesOverlap (bp1.RValue, n, checkElements);
RdpOneOrMore rp1 = p1 as RdpOneOrMore;
if (rp1 != null)
return NamesOverlap (rp1.Child, n, checkElements);
RdpAttribute ap1 = p1 as RdpAttribute;
if (ap1 != null)
return NameClassOverlap (ap1.NameClass, n);
if (!checkElements)
return false;
RdpElement ep1 = p1 as RdpElement;
if (ep1 != null)
return NameClassOverlap (ep1.NameClass, n);
return false;
}
internal static bool NameClassOverlap (RdpNameClass n1, RdpNameClass n2)
{
Hashtable names = new Hashtable ();
GetNameClassRepresentatives (n1, names);
GetNameClassRepresentatives (n2, names);
foreach (QName qn in names.Keys)
if (NameClassBothContain (n1, n2, qn))
return true;
return false;
}
static QName illegalQName = new QName ("", "\x1");
static void GetNameClassRepresentatives (
RdpNameClass n, Hashtable names)
{
if (n is RdpAnyName) {
names [illegalQName] = illegalQName;
return;
}
RdpAnyNameExcept exc = n as RdpAnyNameExcept;
if (exc != null) {
GetNameClassRepresentatives (exc.ExceptNameClass, names);
names [illegalQName] = illegalQName;
return;
}
RdpNsName ns = n as RdpNsName;
if (ns != null) {
QName nn = new QName (String.Empty, ns.NamespaceURI);
names [nn] = nn;
return;
}
RdpNsNameExcept nse = n as RdpNsNameExcept;
if (nse != null) {
GetNameClassRepresentatives (nse.ExceptNameClass, names);
QName nn = new QName (String.Empty, nse.NamespaceURI);
names [nn] = nn;
return;
}
RdpName name = n as RdpName;
if (name != null) {
QName qname = new QName (name.LocalName, name.NamespaceURI);
names [qname] = qname;
return;
}
else {
RdpNameClassChoice c = (RdpNameClassChoice) n;
GetNameClassRepresentatives (c.LValue, names);
GetNameClassRepresentatives (c.RValue, names);
return;
}
}
static bool NameClassBothContain (
RdpNameClass n1, RdpNameClass n2, QName qn)
{
return Contains (n1, qn.Name, qn.Namespace) &&
Contains (n2, qn.Name, qn.Namespace);
}
#endregion
}
public delegate RdpPattern RdpBinaryFunction (RdpPattern p1, RdpPattern p2);
class RdpFlip
{
RdpBinaryFunction func;
RdpPattern arg;
public RdpFlip (RdpBinaryFunction func, RdpPattern p)
{
this.func = func;
this.arg = p;
}
public RdpPattern Apply (RdpPattern p)
{
return func (p, arg);
}
}
}