1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-26 12:25:09 +03:00

more work on the automata interfaces and debug of counted choices added a

* xmlregexp.c xmlschemas.c include/libxml/xmlautomata.h: more work
  on the automata interfaces and debug of counted choices
* test/schemas/* result/schemas/*: added a number of tests
Daniel
This commit is contained in:
Daniel Veillard 2002-04-17 16:28:10 +00:00
parent 8651f5365c
commit b509f1543d
41 changed files with 733 additions and 21 deletions

View File

@ -1,3 +1,9 @@
Wed Apr 17 18:26:07 CEST 2002 Daniel Veillard <daniel@veillard.com>
* xmlregexp.c xmlschemas.c include/libxml/xmlautomata.h: more work
on the automata interfaces and debug of counted choices
* test/schemas/* result/schemas/*: added a number of tests
Wed Apr 17 11:03:03 CEST 2002 Daniel Veillard <daniel@veillard.com>
* xmlschemas.c xmlschemastypes.c include/libxml/xmlschemas.h:

View File

@ -63,7 +63,17 @@ xmlAutomataStatePtr xmlAutomataNewCountTrans(xmlAutomataPtr am,
xmlAutomataStatePtr xmlAutomataNewEpsilon (xmlAutomataPtr am,
xmlAutomataStatePtr from,
xmlAutomataStatePtr to);
int xmlAutomataNewCounter (xmlAutomataPtr am);
xmlAutomataStatePtr xmlAutomataNewCountedTrans(xmlAutomataPtr am,
xmlAutomataStatePtr from,
xmlAutomataStatePtr to,
int counter);
xmlAutomataStatePtr xmlAutomataNewCounterTrans(xmlAutomataPtr am,
xmlAutomataStatePtr from,
xmlAutomataStatePtr to,
int counter);
int xmlAutomataNewCounter (xmlAutomataPtr am,
int min,
int max);
xmlRegexpPtr xmlAutomataCompile (xmlAutomataPtr am);

View File

@ -0,0 +1 @@
./test/schemas/choice_5.xml fails to validate

View File

@ -0,0 +1,24 @@
Type of choice 3 : ./test/schemas/choice_0.xsd:6 :elements
Type of sequence 2 : ./test/schemas/choice_0.xsd:5 :elements
Type of anontype1 : ./test/schemas/choice_0.xsd:4 :elements
Type of sequence 2 : ./test/schemas/choice_0.xsd:5 :elements
Building content model for doc
Content model of doc:
regexp: '(null)'
2 atoms:
00 atom: string once 'a'
01 atom: string once 'b'
4 states:
state: 0, 2 transitions:
trans: atom 0, to 2
trans: atom 1, to 3
state: FINAL 1, 0 transitions:
state: FINAL 2, 1 transitions:
trans: removed
state: FINAL 3, 1 transitions:
trans: removed
0 counters:
Building content model for a
Building content model for b
xmlSchemaValidateCallback: a, a, a
Element doc content check failed

View File

@ -0,0 +1 @@
./test/schemas/choice_6.xml fails to validate

View File

@ -0,0 +1,24 @@
Type of choice 3 : ./test/schemas/choice_0.xsd:6 :elements
Type of sequence 2 : ./test/schemas/choice_0.xsd:5 :elements
Type of anontype1 : ./test/schemas/choice_0.xsd:4 :elements
Type of sequence 2 : ./test/schemas/choice_0.xsd:5 :elements
Building content model for doc
Content model of doc:
regexp: '(null)'
2 atoms:
00 atom: string once 'a'
01 atom: string once 'b'
4 states:
state: 0, 2 transitions:
trans: atom 0, to 2
trans: atom 1, to 3
state: FINAL 1, 0 transitions:
state: FINAL 2, 1 transitions:
trans: removed
state: FINAL 3, 1 transitions:
trans: removed
0 counters:
Building content model for a
Building content model for b
xmlSchemaValidateCallback: a, a, a
Element doc content check failed

View File

@ -0,0 +1 @@
./test/schemas/choice_0.xml validates

View File

@ -0,0 +1,25 @@
Type of choice 3 : ./test/schemas/choice_1.xsd:6 :elements
Type of sequence 2 : ./test/schemas/choice_1.xsd:5 :elements
Type of anontype1 : ./test/schemas/choice_1.xsd:4 :elements
Type of sequence 2 : ./test/schemas/choice_1.xsd:5 :elements
Building content model for doc
Content model of doc:
regexp: '(null)'
2 atoms:
00 atom: string once 'a'
01 atom: string once 'b'
4 states:
state: FINAL 0, 3 transitions:
trans: atom 0, to 2
trans: atom 1, to 3
trans: removed
state: FINAL 1, 0 transitions:
state: FINAL 2, 1 transitions:
trans: removed
state: FINAL 3, 1 transitions:
trans: removed
0 counters:
Building content model for a
Building content model for b
xmlSchemaValidateCallback: a, a, a
Element doc content check succeeded

View File

@ -0,0 +1 @@
./test/schemas/choice_1.xml validates

View File

@ -0,0 +1,25 @@
Type of choice 3 : ./test/schemas/choice_1.xsd:6 :elements
Type of sequence 2 : ./test/schemas/choice_1.xsd:5 :elements
Type of anontype1 : ./test/schemas/choice_1.xsd:4 :elements
Type of sequence 2 : ./test/schemas/choice_1.xsd:5 :elements
Building content model for doc
Content model of doc:
regexp: '(null)'
2 atoms:
00 atom: string once 'a'
01 atom: string once 'b'
4 states:
state: FINAL 0, 3 transitions:
trans: atom 0, to 2
trans: atom 1, to 3
trans: removed
state: FINAL 1, 0 transitions:
state: FINAL 2, 1 transitions:
trans: removed
state: FINAL 3, 1 transitions:
trans: removed
0 counters:
Building content model for a
Building content model for b
xmlSchemaValidateCallback: b, b, b
Element doc content check succeeded

View File

@ -0,0 +1 @@
./test/schemas/choice_2.xml fails to validate

View File

@ -0,0 +1,25 @@
Type of choice 3 : ./test/schemas/choice_1.xsd:6 :elements
Type of sequence 2 : ./test/schemas/choice_1.xsd:5 :elements
Type of anontype1 : ./test/schemas/choice_1.xsd:4 :elements
Type of sequence 2 : ./test/schemas/choice_1.xsd:5 :elements
Building content model for doc
Content model of doc:
regexp: '(null)'
2 atoms:
00 atom: string once 'a'
01 atom: string once 'b'
4 states:
state: FINAL 0, 3 transitions:
trans: atom 0, to 2
trans: atom 1, to 3
trans: removed
state: FINAL 1, 0 transitions:
state: FINAL 2, 1 transitions:
trans: removed
state: FINAL 3, 1 transitions:
trans: removed
0 counters:
Building content model for a
Building content model for b
xmlSchemaValidateCallback: a, a, a
Element doc content check failed

View File

@ -0,0 +1 @@
./test/schemas/choice_3.xml fails to validate

View File

@ -0,0 +1,25 @@
Type of choice 3 : ./test/schemas/choice_1.xsd:6 :elements
Type of sequence 2 : ./test/schemas/choice_1.xsd:5 :elements
Type of anontype1 : ./test/schemas/choice_1.xsd:4 :elements
Type of sequence 2 : ./test/schemas/choice_1.xsd:5 :elements
Building content model for doc
Content model of doc:
regexp: '(null)'
2 atoms:
00 atom: string once 'a'
01 atom: string once 'b'
4 states:
state: FINAL 0, 3 transitions:
trans: atom 0, to 2
trans: atom 1, to 3
trans: removed
state: FINAL 1, 0 transitions:
state: FINAL 2, 1 transitions:
trans: removed
state: FINAL 3, 1 transitions:
trans: removed
0 counters:
Building content model for a
Building content model for b
xmlSchemaValidateCallback: a, a, a
Element doc content check failed

View File

@ -0,0 +1 @@
./test/schemas/choice_4.xml validates

View File

@ -0,0 +1,24 @@
Type of choice 3 : ./test/schemas/choice_1.xsd:6 :elements
Type of sequence 2 : ./test/schemas/choice_1.xsd:5 :elements
Type of anontype1 : ./test/schemas/choice_1.xsd:4 :elements
Type of sequence 2 : ./test/schemas/choice_1.xsd:5 :elements
Building content model for doc
Content model of doc:
regexp: '(null)'
2 atoms:
00 atom: string once 'a'
01 atom: string once 'b'
4 states:
state: FINAL 0, 3 transitions:
trans: atom 0, to 2
trans: atom 1, to 3
trans: removed
state: FINAL 1, 0 transitions:
state: FINAL 2, 1 transitions:
trans: removed
state: FINAL 3, 1 transitions:
trans: removed
0 counters:
Building content model for a
Building content model for b
Element doc content check succeeded

View File

@ -0,0 +1 @@
./test/schemas/choice_5.xml fails to validate

View File

@ -0,0 +1,25 @@
Type of choice 3 : ./test/schemas/choice_1.xsd:6 :elements
Type of sequence 2 : ./test/schemas/choice_1.xsd:5 :elements
Type of anontype1 : ./test/schemas/choice_1.xsd:4 :elements
Type of sequence 2 : ./test/schemas/choice_1.xsd:5 :elements
Building content model for doc
Content model of doc:
regexp: '(null)'
2 atoms:
00 atom: string once 'a'
01 atom: string once 'b'
4 states:
state: FINAL 0, 3 transitions:
trans: atom 0, to 2
trans: atom 1, to 3
trans: removed
state: FINAL 1, 0 transitions:
state: FINAL 2, 1 transitions:
trans: removed
state: FINAL 3, 1 transitions:
trans: removed
0 counters:
Building content model for a
Building content model for b
xmlSchemaValidateCallback: a, a, a
Element doc content check failed

View File

@ -0,0 +1 @@
./test/schemas/choice_6.xml fails to validate

View File

@ -0,0 +1,25 @@
Type of choice 3 : ./test/schemas/choice_1.xsd:6 :elements
Type of sequence 2 : ./test/schemas/choice_1.xsd:5 :elements
Type of anontype1 : ./test/schemas/choice_1.xsd:4 :elements
Type of sequence 2 : ./test/schemas/choice_1.xsd:5 :elements
Building content model for doc
Content model of doc:
regexp: '(null)'
2 atoms:
00 atom: string once 'a'
01 atom: string once 'b'
4 states:
state: FINAL 0, 3 transitions:
trans: atom 0, to 2
trans: atom 1, to 3
trans: removed
state: FINAL 1, 0 transitions:
state: FINAL 2, 1 transitions:
trans: removed
state: FINAL 3, 1 transitions:
trans: removed
0 counters:
Building content model for a
Building content model for b
xmlSchemaValidateCallback: a, a, a
Element doc content check failed

View File

@ -0,0 +1 @@
./test/schemas/choice_0.xml validates

View File

@ -0,0 +1,40 @@
Type of choice 3 : ./test/schemas/choice_2.xsd:6 :elements
Type of sequence 2 : ./test/schemas/choice_2.xsd:5 :elements
Type of anontype1 : ./test/schemas/choice_2.xsd:4 :elements
Type of sequence 2 : ./test/schemas/choice_2.xsd:5 :elements
Building content model for doc
Content model of doc:
regexp: '(null)'
2 atoms:
00 atom: string once 'a'
01 atom: string once 'b'
5 states:
state: 0, 2 transitions:
trans: atom 0, to 3
trans: atom 1, to 4
state: FINAL 1, 0 transitions:
state: 2, 4 transitions:
trans: removed
trans: count based 0, epsilon to 1
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
state: 3, 6 transitions:
trans: removed
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
trans: count based 0, epsilon to 1
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
state: 4, 6 transitions:
trans: removed
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
trans: count based 0, epsilon to 1
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
1 counters:
0: min 0 max 2
Building content model for a
Building content model for b
xmlSchemaValidateCallback: a, a, a
Element doc content check succeeded

View File

View File

@ -0,0 +1,42 @@
Type of choice 3 : ./test/schemas/choice_2.xsd:6 :elements
Type of sequence 2 : ./test/schemas/choice_2.xsd:5 :elements
Type of anontype1 : ./test/schemas/choice_2.xsd:4 :elements
Type of sequence 2 : ./test/schemas/choice_2.xsd:5 :elements
Building content model for doc
Content model of doc:
regexp: '(null)'
2 atoms:
00 atom: string once 'a'
01 atom: string once 'b'
5 states:
state: 0, 2 transitions:
trans: atom 0, to 3
trans: atom 1, to 4
state: FINAL 1, 0 transitions:
state: 2, 4 transitions:
trans: removed
trans: count based 0, epsilon to 1
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
state: 3, 6 transitions:
trans: removed
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
trans: count based 0, epsilon to 1
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
state: 4, 6 transitions:
trans: removed
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
trans: count based 0, epsilon to 1
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
1 counters:
0: min 0 max 2
Building content model for a
Building content model for b
xmlSchemaValidateCallback: b, b, b
Element doc content check succeeded
(nil) : Freed()
xmlMallocBreakpoint reached on block 0

View File

@ -0,0 +1 @@
./test/schemas/choice_2.xml validates

View File

@ -0,0 +1,41 @@
Type of choice 3 : ./test/schemas/choice_2.xsd:6 :elements
Type of sequence 2 : ./test/schemas/choice_2.xsd:5 :elements
Type of anontype1 : ./test/schemas/choice_2.xsd:4 :elements
Type of sequence 2 : ./test/schemas/choice_2.xsd:5 :elements
Building content model for doc
Content model of doc:
regexp: '(null)'
2 atoms:
00 atom: string once 'a'
01 atom: string once 'b'
5 states:
state: 0, 2 transitions:
trans: atom 0, to 3
trans: atom 1, to 4
state: FINAL 1, 0 transitions:
state: 2, 4 transitions:
trans: removed
trans: count based 0, epsilon to 1
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
state: 3, 6 transitions:
trans: removed
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
trans: count based 0, epsilon to 1
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
state: 4, 6 transitions:
trans: removed
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
trans: count based 0, epsilon to 1
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
1 counters:
0: min 0 max 2
Building content model for a
Building content model for b
xmlSchemaValidateCallback: a, a, a
xmlSchemaValidateCallback: b, b, b
Element doc content check succeeded

View File

@ -0,0 +1 @@
./test/schemas/choice_3.xml validates

View File

@ -0,0 +1,41 @@
Type of choice 3 : ./test/schemas/choice_2.xsd:6 :elements
Type of sequence 2 : ./test/schemas/choice_2.xsd:5 :elements
Type of anontype1 : ./test/schemas/choice_2.xsd:4 :elements
Type of sequence 2 : ./test/schemas/choice_2.xsd:5 :elements
Building content model for doc
Content model of doc:
regexp: '(null)'
2 atoms:
00 atom: string once 'a'
01 atom: string once 'b'
5 states:
state: 0, 2 transitions:
trans: atom 0, to 3
trans: atom 1, to 4
state: FINAL 1, 0 transitions:
state: 2, 4 transitions:
trans: removed
trans: count based 0, epsilon to 1
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
state: 3, 6 transitions:
trans: removed
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
trans: count based 0, epsilon to 1
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
state: 4, 6 transitions:
trans: removed
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
trans: count based 0, epsilon to 1
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
1 counters:
0: min 0 max 2
Building content model for a
Building content model for b
xmlSchemaValidateCallback: a, a, a
xmlSchemaValidateCallback: a, a, a
Element doc content check succeeded

View File

@ -0,0 +1 @@
./test/schemas/choice_4.xml fails to validate

View File

@ -0,0 +1,39 @@
Type of choice 3 : ./test/schemas/choice_2.xsd:6 :elements
Type of sequence 2 : ./test/schemas/choice_2.xsd:5 :elements
Type of anontype1 : ./test/schemas/choice_2.xsd:4 :elements
Type of sequence 2 : ./test/schemas/choice_2.xsd:5 :elements
Building content model for doc
Content model of doc:
regexp: '(null)'
2 atoms:
00 atom: string once 'a'
01 atom: string once 'b'
5 states:
state: 0, 2 transitions:
trans: atom 0, to 3
trans: atom 1, to 4
state: FINAL 1, 0 transitions:
state: 2, 4 transitions:
trans: removed
trans: count based 0, epsilon to 1
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
state: 3, 6 transitions:
trans: removed
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
trans: count based 0, epsilon to 1
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
state: 4, 6 transitions:
trans: removed
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
trans: count based 0, epsilon to 1
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
1 counters:
0: min 0 max 2
Building content model for a
Building content model for b
Element doc content check failed

View File

@ -0,0 +1 @@
./test/schemas/choice_5.xml validates

View File

@ -0,0 +1,42 @@
Type of choice 3 : ./test/schemas/choice_2.xsd:6 :elements
Type of sequence 2 : ./test/schemas/choice_2.xsd:5 :elements
Type of anontype1 : ./test/schemas/choice_2.xsd:4 :elements
Type of sequence 2 : ./test/schemas/choice_2.xsd:5 :elements
Building content model for doc
Content model of doc:
regexp: '(null)'
2 atoms:
00 atom: string once 'a'
01 atom: string once 'b'
5 states:
state: 0, 2 transitions:
trans: atom 0, to 3
trans: atom 1, to 4
state: FINAL 1, 0 transitions:
state: 2, 4 transitions:
trans: removed
trans: count based 0, epsilon to 1
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
state: 3, 6 transitions:
trans: removed
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
trans: count based 0, epsilon to 1
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
state: 4, 6 transitions:
trans: removed
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
trans: count based 0, epsilon to 1
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
1 counters:
0: min 0 max 2
Building content model for a
Building content model for b
xmlSchemaValidateCallback: a, a, a
xmlSchemaValidateCallback: b, b, b
xmlSchemaValidateCallback: a, a, a
Element doc content check succeeded

View File

@ -0,0 +1 @@
./test/schemas/choice_6.xml fails to validate

View File

@ -0,0 +1,54 @@
Type of choice 3 : ./test/schemas/choice_2.xsd:6 :elements
Type of sequence 2 : ./test/schemas/choice_2.xsd:5 :elements
Type of anontype1 : ./test/schemas/choice_2.xsd:4 :elements
Type of sequence 2 : ./test/schemas/choice_2.xsd:5 :elements
Building content model for doc
Content model of doc:
regexp: '(null)'
2 atoms:
00 atom: string once 'a'
01 atom: string once 'b'
5 states:
state: 0, 2 transitions:
trans: atom 0, to 3
trans: atom 1, to 4
state: FINAL 1, 0 transitions:
state: 2, 4 transitions:
trans: removed
trans: count based 0, epsilon to 1
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
state: 3, 6 transitions:
trans: removed
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
trans: count based 0, epsilon to 1
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
state: 4, 6 transitions:
trans: removed
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
trans: count based 0, epsilon to 1
trans: counted 0, atom 0, to 3
trans: counted 0, atom 1, to 4
1 counters:
0: min 0 max 2
Building content model for a
Building content model for b
xmlSchemaValidateCallback: a, a, a
xmlSchemaValidateCallback: b, b, b
xmlSchemaValidateCallback: a, a, a
xmlSchemaValidateCallback: a, a, a
xmlSchemaValidateCallback: a, a, a
xmlSchemaValidateCallback: a, a, a
xmlSchemaValidateCallback: a, a, a
xmlSchemaValidateCallback: a, a, a
xmlSchemaValidateCallback: b, b, b
xmlSchemaValidateCallback: a, a, a
xmlSchemaValidateCallback: a, a, a
xmlSchemaValidateCallback: a, a, a
xmlSchemaValidateCallback: a, a, a
xmlSchemaValidateCallback: a, a, a
xmlSchemaValidateCallback: a, a, a
Element doc content check failed

View File

@ -3,7 +3,7 @@
<xs:element name="doc">
<xs:complexType>
<xs:sequence>
<xs:choice minOccurs="1" maxOccurs="unbounded">
<xs:choice minOccurs="1" maxOccurs="1">
<xs:element name="a"/>
<xs:element name="b"/>
</xs:choice>

13
test/schemas/choice_1.xsd Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="doc">
<xs:complexType>
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="1">
<xs:element name="a"/>
<xs:element name="b"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

13
test/schemas/choice_2.xsd Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="doc">
<xs:complexType>
<xs:sequence>
<xs:choice minOccurs="1" maxOccurs="3">
<xs:element name="a"/>
<xs:element name="b"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

View File

@ -0,0 +1,6 @@
<doc>
<a/>
<b/>
<a/>
</doc>

View File

@ -0,0 +1,7 @@
<doc>
<a/>
<b/>
<a/>
<a/>
</doc>

View File

@ -1144,20 +1144,41 @@ xmlFAReduceEpsilonTransitions(xmlRegParserCtxtPtr ctxt, int fromnr,
* Don't remove counted transitions
* Don't loop either
*/
if ((to->trans[transnr].count < 0) &&
(to->trans[transnr].to != fromnr)) {
if (to->trans[transnr].to != fromnr) {
if (to->trans[transnr].count >= 0) {
int newto = to->trans[transnr].to;
xmlRegStateAddTrans(ctxt, from, NULL,
ctxt->states[newto],
-1, to->trans[transnr].count);
} else {
#ifdef DEBUG_REGEXP_GRAPH
printf("Found epsilon trans %d from %d to %d\n",
transnr, tonr, to->trans[transnr].to);
printf("Found epsilon trans %d from %d to %d\n",
transnr, tonr, to->trans[transnr].to);
#endif
xmlFAReduceEpsilonTransitions(ctxt, fromnr,
to->trans[transnr].to, counter);
if (to->trans[transnr].counter >= 0) {
xmlFAReduceEpsilonTransitions(ctxt, fromnr,
to->trans[transnr].to,
to->trans[transnr].counter);
} else {
xmlFAReduceEpsilonTransitions(ctxt, fromnr,
to->trans[transnr].to,
counter);
}
}
}
} else {
int newto = to->trans[transnr].to;
xmlRegStateAddTrans(ctxt, from, to->trans[transnr].atom,
ctxt->states[newto], counter, -1);
if (to->trans[transnr].counter >= 0) {
xmlRegStateAddTrans(ctxt, from, to->trans[transnr].atom,
ctxt->states[newto],
to->trans[transnr].counter, -1);
} else {
xmlRegStateAddTrans(ctxt, from, to->trans[transnr].atom,
ctxt->states[newto], counter, -1);
}
}
}
to->mark = XML_REGEXP_MARK_NORMAL;
@ -1966,7 +1987,7 @@ xmlRegExecPushString(xmlRegExecCtxtPtr exec, const xmlChar *value,
* still have epsilon like transition for counted transitions
* on counters, in that case don't break too early.
*/
if (value == NULL)
if ((value == NULL) && (exec->counts == NULL))
goto rollback;
exec->transcount = 0;
@ -2612,7 +2633,7 @@ xmlFAParseCharClassEsc(xmlRegParserCtxtPtr ctxt) {
} else if ((cur == 's') || (cur == 'S') || (cur == 'i') || (cur == 'I') ||
(cur == 'c') || (cur == 'C') || (cur == 'd') || (cur == 'D') ||
(cur == 'w') || (cur == 'W')) {
xmlRegAtomType type;
xmlRegAtomType type = XML_REGEXP_ANYSPACE;
switch (cur) {
case 's':
@ -3444,9 +3465,78 @@ xmlAutomataNewEpsilon(xmlAutomataPtr am, xmlAutomataStatePtr from,
return(to);
}
#if 0
int xmlAutomataNewCounter (xmlAutomataPtr am);
#endif
/**
* xmlAutomataNewCounter:
* @am: an automata
* @min: the minimal value on the counter
* @max: the maximal value on the counter
*
* Create a new counter
*
* Returns the counter number or -1 in case of error
*/
int
xmlAutomataNewCounter(xmlAutomataPtr am, int min, int max) {
int ret;
if (am == NULL)
return(-1);
ret = xmlRegGetCounter(am);
if (ret < 0)
return(-1);
am->counters[ret].min = min;
am->counters[ret].max = max;
return(ret);
}
/**
* xmlAutomataNewCountedTrans:
* @am: an automata
* @from: the starting point of the transition
* @to: the target point of the transition or NULL
* @counter: the counter associated to that transition
*
* If @to is NULL, this create first a new target state in the automata
* and then adds an epsilon transition from the @from state to the target state
* which will increment the counter provided
*
* Returns the target state or NULL in case of error
*/
xmlAutomataStatePtr
xmlAutomataNewCountedTrans(xmlAutomataPtr am, xmlAutomataStatePtr from,
xmlAutomataStatePtr to, int counter) {
if ((am == NULL) || (from == NULL) || (counter < 0))
return(NULL);
xmlFAGenerateCountedEpsilonTransition(am, from, to, counter);
if (to == NULL)
return(am->state);
return(to);
}
/**
* xmlAutomataNewCounterTrans:
* @am: an automata
* @from: the starting point of the transition
* @to: the target point of the transition or NULL
* @counter: the counter associated to that transition
*
* If @to is NULL, this create first a new target state in the automata
* and then adds an epsilon transition from the @from state to the target state
* which will be allowed only if the counter is within the right range.
*
* Returns the target state or NULL in case of error
*/
xmlAutomataStatePtr
xmlAutomataNewCounterTrans(xmlAutomataPtr am, xmlAutomataStatePtr from,
xmlAutomataStatePtr to, int counter) {
if ((am == NULL) || (from == NULL) || (counter < 0))
return(NULL);
xmlFAGenerateCountedTransition(am, from, to, counter);
if (to == NULL)
return(am->state);
return(to);
}
/**
* xmlAutomataCompile:

View File

@ -2995,12 +2995,43 @@ xmlSchemaBuildAContentModel(xmlSchemaTypePtr type,
* iterate over the subtypes and remerge the end with an
* epsilon transition
*/
subtypes = type->subtypes;
while (subtypes != NULL) {
ctxt->state = start;
xmlSchemaBuildAContentModel(subtypes, ctxt, name);
xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end);
subtypes = subtypes->next;
if (type->maxOccurs == 1) {
subtypes = type->subtypes;
while (subtypes != NULL) {
ctxt->state = start;
xmlSchemaBuildAContentModel(subtypes, ctxt, name);
xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end);
subtypes = subtypes->next;
}
} else {
int counter;
xmlAutomataStatePtr hop;
/*
* use a counter to keep track of the number of transtions
* which went through the choice.
*/
if (type->minOccurs < 1) {
counter = xmlAutomataNewCounter(ctxt->am, 0,
type->maxOccurs - 1);
} else {
counter = xmlAutomataNewCounter(ctxt->am,
type->minOccurs - 1, type->maxOccurs - 1);
}
hop = xmlAutomataNewState(ctxt->am);
subtypes = type->subtypes;
while (subtypes != NULL) {
ctxt->state = start;
xmlSchemaBuildAContentModel(subtypes, ctxt, name);
xmlAutomataNewEpsilon(ctxt->am, ctxt->state, hop);
subtypes = subtypes->next;
}
xmlAutomataNewCountedTrans(ctxt->am, hop, start, counter);
xmlAutomataNewCounterTrans(ctxt->am, hop, end, counter);
}
if (type->minOccurs == 0) {
xmlAutomataNewEpsilon(ctxt->am, start, end);
}
ctxt->state = end;
break;