implemented the 4.20 and 4.21 simplification rules. updated the results
* relaxng.c: implemented the 4.20 and 4.21 simplification rules.
* result/relaxng/*: updated the results
Daniel
diff --git a/ChangeLog b/ChangeLog
index 2081a67..66830f7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu Feb 20 01:09:24 CET 2003 Daniel Veillard <daniel@veillard.com>
+
+ * relaxng.c: implemented the 4.20 and 4.21 simplification rules.
+ * result/relaxng/*: updated the results
+
Wed Feb 19 18:30:30 CET 2003 Daniel Veillard <daniel@veillard.com>
* relaxng.c: more bugfixes
diff --git a/relaxng.c b/relaxng.c
index a2dbe61..a2bdf53 100644
--- a/relaxng.c
+++ b/relaxng.c
@@ -3777,6 +3777,182 @@
}
/**
+ * xmlRelaxNGCheckRules:
+ * @ctxt: a Relax-NG parser context
+ * @nodes: grammar children nodes
+ *
+ * Check for simplification of empty and notAllowed
+ */
+static void
+xmlRelaxNGSimplify(xmlRelaxNGParserCtxtPtr ctxt,
+ xmlRelaxNGDefinePtr cur,
+ xmlRelaxNGDefinePtr parent) {
+ xmlRelaxNGDefinePtr prev = NULL;
+
+ while (cur != NULL) {
+ if ((cur->type == XML_RELAXNG_REF) ||
+ (cur->type == XML_RELAXNG_PARENTREF)) {
+ if (cur->depth != -3) {
+ cur->depth = -3;
+ xmlRelaxNGSimplify(ctxt, cur->content, cur);
+ }
+ } else if (cur->type == XML_RELAXNG_NOT_ALLOWED) {
+ if ((parent != NULL) &&
+ ((parent->type == XML_RELAXNG_ATTRIBUTE) ||
+ (parent->type == XML_RELAXNG_LIST) ||
+ (parent->type == XML_RELAXNG_GROUP) ||
+ (parent->type == XML_RELAXNG_INTERLEAVE) ||
+ (parent->type == XML_RELAXNG_ONEORMORE) ||
+ (parent->type == XML_RELAXNG_ZEROORMORE))) {
+ parent->type = XML_RELAXNG_NOT_ALLOWED;
+ break;
+ }
+ if ((parent != NULL) &&
+ (parent->type == XML_RELAXNG_CHOICE)) {
+ if (prev == NULL) {
+ if (parent != NULL)
+ parent->content = cur->next;
+ } else
+ prev->next = cur->next;
+ } else
+ prev = cur;
+ } else if (cur->type == XML_RELAXNG_EMPTY){
+ if ((parent != NULL) &&
+ ((parent->type == XML_RELAXNG_ONEORMORE) ||
+ (parent->type == XML_RELAXNG_ZEROORMORE))) {
+ parent->type = XML_RELAXNG_EMPTY;
+ break;
+ }
+ if ((parent != NULL) &&
+ ((parent->type == XML_RELAXNG_GROUP) ||
+ (parent->type == XML_RELAXNG_INTERLEAVE))) {
+ if (prev == NULL) {
+ if (parent != NULL)
+ parent->content = cur->next;
+ } else
+ prev->next = cur->next;
+ } else
+ prev = cur;
+ } else {
+ if (cur->content != NULL)
+ xmlRelaxNGSimplify(ctxt, cur->content, cur);
+ /*
+ * This may result in a simplification
+ */
+ if ((cur->type == XML_RELAXNG_GROUP) ||
+ (cur->type == XML_RELAXNG_INTERLEAVE)) {
+ if (cur->content == NULL)
+ cur->type = XML_RELAXNG_EMPTY;
+ else if (cur->content->next == NULL) {
+ cur->content->next = cur->next;
+ if (prev == NULL) {
+ if (parent != NULL)
+ parent->content = cur->content;
+ } else {
+ prev->next = cur->content;
+ }
+ cur = cur->content;
+ }
+ }
+ /*
+ * the current node may have been transformed back
+ */
+ if ((cur->type == XML_RELAXNG_EXCEPT) &&
+ (cur->content != NULL) &&
+ (cur->content->type == XML_RELAXNG_NOT_ALLOWED)) {
+ if (prev == NULL) {
+ if (parent != NULL)
+ parent->content = cur->next;
+ } else
+ prev->next = cur->next;
+ } else if (cur->type == XML_RELAXNG_NOT_ALLOWED) {
+ if ((parent != NULL) &&
+ ((parent->type == XML_RELAXNG_ATTRIBUTE) ||
+ (parent->type == XML_RELAXNG_LIST) ||
+ (parent->type == XML_RELAXNG_GROUP) ||
+ (parent->type == XML_RELAXNG_INTERLEAVE) ||
+ (parent->type == XML_RELAXNG_ONEORMORE) ||
+ (parent->type == XML_RELAXNG_ZEROORMORE))) {
+ parent->type = XML_RELAXNG_NOT_ALLOWED;
+ break;
+ }
+ if ((parent != NULL) &&
+ (parent->type == XML_RELAXNG_CHOICE)) {
+ if (prev == NULL) {
+ if (parent != NULL)
+ parent->content = cur->next;
+ } else
+ prev->next = cur->next;
+ } else
+ prev = cur;
+ } else if (cur->type == XML_RELAXNG_EMPTY){
+ if ((parent != NULL) &&
+ ((parent->type == XML_RELAXNG_ONEORMORE) ||
+ (parent->type == XML_RELAXNG_ZEROORMORE))) {
+ parent->type = XML_RELAXNG_EMPTY;
+ break;
+ }
+ if ((parent != NULL) &&
+ ((parent->type == XML_RELAXNG_GROUP) ||
+ (parent->type == XML_RELAXNG_INTERLEAVE) ||
+ (parent->type == XML_RELAXNG_CHOICE))) {
+ if (prev == NULL) {
+ if (parent != NULL)
+ parent->content = cur->next;
+ } else
+ prev->next = cur->next;
+ } else
+ prev = cur;
+ } else {
+ prev = cur;
+ }
+ }
+ cur = cur->next;
+ }
+}
+
+#if 0
+/**
+ * xmlRelaxNGCheckRules:
+ * @ctxt: a Relax-NG parser context
+ * @nodes: grammar children nodes
+ * @state: a state
+ *
+ * Check for rules in
+ *
+ * Returns 0 if check passed, and -1 in case of error
+ */
+static int
+xmlRelaxNGCheckRules(xmlRelaxNGParserCtxtPtr ctxt,
+ xmlRelaxNGDefinePtr cur, int depth) {
+ int ret = 0;
+
+ while ((ret == 0) && (cur != NULL)) {
+ if ((cur->type == XML_RELAXNG_REF) ||
+ (cur->type == XML_RELAXNG_PARENTREF)) {
+ if (cur->depth == -1) {
+ cur->depth = depth;
+ ret = xmlRelaxNGCheckCycles(ctxt, cur->content, depth);
+ cur->depth = -2;
+ } else if (depth == cur->depth) {
+ if (ctxt->error != NULL)
+ ctxt->error(ctxt->userData,
+ "Detected a cycle in %s references\n", cur->name);
+ ctxt->nbErrors++;
+ return(-1);
+ }
+ } else if (cur->type == XML_RELAXNG_ELEMENT) {
+ ret = xmlRelaxNGCheckCycles(ctxt, cur->content, depth + 1);
+ } else {
+ ret = xmlRelaxNGCheckCycles(ctxt, cur->content, depth);
+ }
+ cur = cur->next;
+ }
+ return(ret);
+}
+#endif
+
+/**
* xmlRelaxNGParseGrammar:
* @ctxt: a Relax-NG parser context
* @nodes: grammar children nodes
@@ -3888,6 +4064,7 @@
ctxt->define = olddefine;
if (schema->topgrammar->start != NULL) {
xmlRelaxNGCheckCycles(ctxt, schema->topgrammar->start, 0);
+ xmlRelaxNGSimplify(ctxt, schema->topgrammar->start, NULL);
}
#ifdef DEBUG
diff --git a/result/relaxng/spec1_err b/result/relaxng/spec1_err
index 99cf052..cd80a7d 100644
--- a/result/relaxng/spec1_err
+++ b/result/relaxng/spec1_err
@@ -1 +1 @@
-Unimplemented block at relaxng.c:5697
+Unimplemented block at relaxng.c:5874
diff --git a/result/relaxng/tutor10_1_4.err b/result/relaxng/tutor10_1_4.err
index d553dca..e661d73 100644
--- a/result/relaxng/tutor10_1_4.err
+++ b/result/relaxng/tutor10_1_4.err
@@ -1,4 +1,4 @@
-error detected at relaxng.c:5881
+error detected at relaxng.c:6058
Expecting a namespace for element foo
-error detected at relaxng.c:6462
+error detected at relaxng.c:6639
extra data on the document
diff --git a/result/relaxng/tutor10_1_5.err b/result/relaxng/tutor10_1_5.err
index 0310479..814058f 100644
--- a/result/relaxng/tutor10_1_5.err
+++ b/result/relaxng/tutor10_1_5.err
@@ -1,4 +1,4 @@
-error detected at relaxng.c:5886
+error detected at relaxng.c:6063
Expecting element foo has wrong namespace: expecting http://www.example.com
-error detected at relaxng.c:6462
+error detected at relaxng.c:6639
extra data on the document
diff --git a/result/relaxng/tutor10_1_6.err b/result/relaxng/tutor10_1_6.err
index 0310479..814058f 100644
--- a/result/relaxng/tutor10_1_6.err
+++ b/result/relaxng/tutor10_1_6.err
@@ -1,4 +1,4 @@
-error detected at relaxng.c:5886
+error detected at relaxng.c:6063
Expecting element foo has wrong namespace: expecting http://www.example.com
-error detected at relaxng.c:6462
+error detected at relaxng.c:6639
extra data on the document
diff --git a/result/relaxng/tutor10_2_3.err b/result/relaxng/tutor10_2_3.err
index 79a821f..74b3d65 100644
--- a/result/relaxng/tutor10_2_3.err
+++ b/result/relaxng/tutor10_2_3.err
@@ -1,4 +1,4 @@
-error detected at relaxng.c:5898
+error detected at relaxng.c:6075
Expecting no namespace for element foo
-error detected at relaxng.c:6462
+error detected at relaxng.c:6639
extra data on the document
diff --git a/result/relaxng/tutor10_2_4.err b/result/relaxng/tutor10_2_4.err
index 79a821f..74b3d65 100644
--- a/result/relaxng/tutor10_2_4.err
+++ b/result/relaxng/tutor10_2_4.err
@@ -1,4 +1,4 @@
-error detected at relaxng.c:5898
+error detected at relaxng.c:6075
Expecting no namespace for element foo
-error detected at relaxng.c:6462
+error detected at relaxng.c:6639
extra data on the document
diff --git a/result/relaxng/tutor10_7_3.err b/result/relaxng/tutor10_7_3.err
index 2b28114..fbb50a8 100644
--- a/result/relaxng/tutor10_7_3.err
+++ b/result/relaxng/tutor10_7_3.err
@@ -1,2 +1,2 @@
-error detected at relaxng.c:6092
+error detected at relaxng.c:6269
Extra content for element addressBook: card
diff --git a/result/relaxng/tutor10_8_3.err b/result/relaxng/tutor10_8_3.err
index 2b28114..fbb50a8 100644
--- a/result/relaxng/tutor10_8_3.err
+++ b/result/relaxng/tutor10_8_3.err
@@ -1,2 +1,2 @@
-error detected at relaxng.c:6092
+error detected at relaxng.c:6269
Extra content for element addressBook: card
diff --git a/result/relaxng/tutor11_2_2.err b/result/relaxng/tutor11_2_2.err
index 91c4f3e..9cae4df 100644
--- a/result/relaxng/tutor11_2_2.err
+++ b/result/relaxng/tutor11_2_2.err
@@ -1,2 +1,2 @@
-error detected at relaxng.c:6105
+error detected at relaxng.c:6282
Invalid attribute foo for element card
diff --git a/result/relaxng/tutor11_2_3.err b/result/relaxng/tutor11_2_3.err
index 8d7f898..f24944b 100644
--- a/result/relaxng/tutor11_2_3.err
+++ b/result/relaxng/tutor11_2_3.err
@@ -1,2 +1,2 @@
-error detected at relaxng.c:6105
+error detected at relaxng.c:6282
Invalid attribute b for element card
diff --git a/result/relaxng/tutor12_1_err b/result/relaxng/tutor12_1_err
index 99cf052..cd80a7d 100644
--- a/result/relaxng/tutor12_1_err
+++ b/result/relaxng/tutor12_1_err
@@ -1 +1 @@
-Unimplemented block at relaxng.c:5697
+Unimplemented block at relaxng.c:5874
diff --git a/result/relaxng/tutor3_2_1.err b/result/relaxng/tutor3_2_1.err
index 5e5a24c..4327550 100644
--- a/result/relaxng/tutor3_2_1.err
+++ b/result/relaxng/tutor3_2_1.err
@@ -1,4 +1,4 @@
-error detected at relaxng.c:5873
+error detected at relaxng.c:6050
Expecting element name, got email
-error detected at relaxng.c:6092
+error detected at relaxng.c:6269
Extra content for element card: email
diff --git a/result/relaxng/tutor3_5_2.err b/result/relaxng/tutor3_5_2.err
index 2b28114..fbb50a8 100644
--- a/result/relaxng/tutor3_5_2.err
+++ b/result/relaxng/tutor3_5_2.err
@@ -1,2 +1,2 @@
-error detected at relaxng.c:6092
+error detected at relaxng.c:6269
Extra content for element addressBook: card
diff --git a/result/relaxng/tutor3_7_err b/result/relaxng/tutor3_7_err
index f7198a5..9a41395 100644
--- a/result/relaxng/tutor3_7_err
+++ b/result/relaxng/tutor3_7_err
@@ -1,2 +1,2 @@
-error detected at relaxng.c:6462
+error detected at relaxng.c:6639
extra data on the document
diff --git a/result/relaxng/tutor5_3_1.err b/result/relaxng/tutor5_3_1.err
index 9f72a68..1b1d92f 100644
--- a/result/relaxng/tutor5_3_1.err
+++ b/result/relaxng/tutor5_3_1.err
@@ -1,6 +1,6 @@
-error detected at relaxng.c:6256
+error detected at relaxng.c:6433
Element bad has child elements
-error detected at relaxng.c:6039
+error detected at relaxng.c:6216
Expecting an element got 3 type
-error detected at relaxng.c:6092
+error detected at relaxng.c:6269
Extra content for element bad: text
diff --git a/result/relaxng/tutor6_1_3.err b/result/relaxng/tutor6_1_3.err
index 8d8f0ba..3ef6a41 100644
--- a/result/relaxng/tutor6_1_3.err
+++ b/result/relaxng/tutor6_1_3.err
@@ -1,2 +1,2 @@
-error detected at relaxng.c:6105
+error detected at relaxng.c:6282
Invalid attribute preferredFormat for element card
diff --git a/result/relaxng/tutor6_2_4.err b/result/relaxng/tutor6_2_4.err
index 48ca795..db765b1 100644
--- a/result/relaxng/tutor6_2_4.err
+++ b/result/relaxng/tutor6_2_4.err
@@ -1,2 +1,2 @@
-error detected at relaxng.c:6092
+error detected at relaxng.c:6269
Extra content for element preferredFormat: text
diff --git a/result/relaxng/tutor6_3_1.err b/result/relaxng/tutor6_3_1.err
index 8d8f0ba..3ef6a41 100644
--- a/result/relaxng/tutor6_3_1.err
+++ b/result/relaxng/tutor6_3_1.err
@@ -1,2 +1,2 @@
-error detected at relaxng.c:6105
+error detected at relaxng.c:6282
Invalid attribute preferredFormat for element card
diff --git a/result/relaxng/tutor7_1_2.err b/result/relaxng/tutor7_1_2.err
index cbfe2f8..6e22ca9 100644
--- a/result/relaxng/tutor7_1_2.err
+++ b/result/relaxng/tutor7_1_2.err
@@ -1,6 +1,6 @@
-error detected at relaxng.c:4984
+error detected at relaxng.c:5161
Internal: failed to validate type float
-error detected at relaxng.c:6394
+error detected at relaxng.c:6571
error validating list
-error detected at relaxng.c:6092
+error detected at relaxng.c:6269
Extra content for element vector: text
diff --git a/result/relaxng/tutor7_1_3.err b/result/relaxng/tutor7_1_3.err
index 92eef34..31ed32f 100644
--- a/result/relaxng/tutor7_1_3.err
+++ b/result/relaxng/tutor7_1_3.err
@@ -1,6 +1,6 @@
-error detected at relaxng.c:5224
+error detected at relaxng.c:5401
Extra data in list: 5.6
-error detected at relaxng.c:6394
+error detected at relaxng.c:6571
error validating list
-error detected at relaxng.c:6092
+error detected at relaxng.c:6269
Extra content for element vector: text
diff --git a/result/relaxng/tutor7_2_4.err b/result/relaxng/tutor7_2_4.err
index 7ff321d..3bfb707 100644
--- a/result/relaxng/tutor7_2_4.err
+++ b/result/relaxng/tutor7_2_4.err
@@ -1,4 +1,4 @@
-error detected at relaxng.c:4984
+error detected at relaxng.c:5161
Internal: failed to validate type double
-error detected at relaxng.c:6394
+error detected at relaxng.c:6571
error validating list
diff --git a/result/relaxng/tutor7_3_4.err b/result/relaxng/tutor7_3_4.err
index 9a414cf..9672d11 100644
--- a/result/relaxng/tutor7_3_4.err
+++ b/result/relaxng/tutor7_3_4.err
@@ -1,6 +1,6 @@
-error detected at relaxng.c:5224
+error detected at relaxng.c:5401
Extra data in list: 5.6
-error detected at relaxng.c:6394
+error detected at relaxng.c:6571
error validating list
-error detected at relaxng.c:6092
+error detected at relaxng.c:6269
Extra content for element path: text
diff --git a/result/relaxng/tutor7_3_5.err b/result/relaxng/tutor7_3_5.err
index fbf3e99..c94bf28 100644
--- a/result/relaxng/tutor7_3_5.err
+++ b/result/relaxng/tutor7_3_5.err
@@ -1,6 +1,6 @@
-error detected at relaxng.c:4984
+error detected at relaxng.c:5161
Internal: failed to validate type double
-error detected at relaxng.c:6394
+error detected at relaxng.c:6571
error validating list
-error detected at relaxng.c:6092
+error detected at relaxng.c:6269
Extra content for element path: text
diff --git a/result/relaxng/tutor8_2_4.err b/result/relaxng/tutor8_2_4.err
index bde5901..6e73a99 100644
--- a/result/relaxng/tutor8_2_4.err
+++ b/result/relaxng/tutor8_2_4.err
@@ -1,4 +1,4 @@
-Unimplemented block at relaxng.c:5697
-Unimplemented block at relaxng.c:5697
-error detected at relaxng.c:6092
+Unimplemented block at relaxng.c:5874
+Unimplemented block at relaxng.c:5874
+error detected at relaxng.c:6269
Extra content for element head: meta
diff --git a/result/relaxng/tutor8_2_5.err b/result/relaxng/tutor8_2_5.err
index 7e38529..73526ae 100644
--- a/result/relaxng/tutor8_2_5.err
+++ b/result/relaxng/tutor8_2_5.err
@@ -1,4 +1,4 @@
-error detected at relaxng.c:6033
+error detected at relaxng.c:6210
Expecting an element, got empty
-error detected at relaxng.c:6092
+error detected at relaxng.c:6269
Extra content for element head: meta
diff --git a/result/relaxng/tutor8_2_6.err b/result/relaxng/tutor8_2_6.err
index 240c7f4..d23da38 100644
--- a/result/relaxng/tutor8_2_6.err
+++ b/result/relaxng/tutor8_2_6.err
@@ -1,2 +1,2 @@
-error detected at relaxng.c:6092
+error detected at relaxng.c:6269
Extra content for element head: base
diff --git a/result/relaxng/tutor9_5_2.err b/result/relaxng/tutor9_5_2.err
index 2b28114..fbb50a8 100644
--- a/result/relaxng/tutor9_5_2.err
+++ b/result/relaxng/tutor9_5_2.err
@@ -1,2 +1,2 @@
-error detected at relaxng.c:6092
+error detected at relaxng.c:6269
Extra content for element addressBook: card
diff --git a/result/relaxng/tutor9_5_3.err b/result/relaxng/tutor9_5_3.err
index 2b28114..fbb50a8 100644
--- a/result/relaxng/tutor9_5_3.err
+++ b/result/relaxng/tutor9_5_3.err
@@ -1,2 +1,2 @@
-error detected at relaxng.c:6092
+error detected at relaxng.c:6269
Extra content for element addressBook: card
diff --git a/result/relaxng/tutor9_6_2.err b/result/relaxng/tutor9_6_2.err
index 2b28114..fbb50a8 100644
--- a/result/relaxng/tutor9_6_2.err
+++ b/result/relaxng/tutor9_6_2.err
@@ -1,2 +1,2 @@
-error detected at relaxng.c:6092
+error detected at relaxng.c:6269
Extra content for element addressBook: card
diff --git a/result/relaxng/tutor9_6_3.err b/result/relaxng/tutor9_6_3.err
index 2b28114..fbb50a8 100644
--- a/result/relaxng/tutor9_6_3.err
+++ b/result/relaxng/tutor9_6_3.err
@@ -1,2 +1,2 @@
-error detected at relaxng.c:6092
+error detected at relaxng.c:6269
Extra content for element addressBook: card