File: PrologParser.java

package info (click to toggle)
lib-xp-java 0.5-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,652 kB
  • ctags: 2,424
  • sloc: java: 8,085; makefile: 53; sh: 17; xml: 7
file content (770 lines) | stat: -rw-r--r-- 23,866 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
package com.jclark.xml.tok;

/**
 * Parses the prolog of an XML document.
 * A <code>PrologParser</code> object represents the state of a parse
 * of the prolog.
 * It operates on the tokens returned
 * by <code>Encoding.tokenizeProlog</code>.
 * It does not build any data structures to represent the information
 * in the prolog; instead it tells the caller the action needed
 * for each token.
 * The state of the parse can be saved by using the <code>clone</code>
 * method.
 * @version $Revision: 1.8 $ $Date: 1998/10/30 02:25:20 $
 */
public class PrologParser implements Cloneable {
  public static final int ACTION_NONE = 0;
  public static final int ACTION_XML_DECL = ACTION_NONE + 1;
  public static final int ACTION_TEXT_DECL = ACTION_XML_DECL + 1;
  public static final int ACTION_PI = ACTION_TEXT_DECL + 1;
  public static final int ACTION_COMMENT = ACTION_PI + 1;
  public static final int ACTION_DOCTYPE_NAME = ACTION_COMMENT + 1;
  public static final int ACTION_DOCTYPE_SYSTEM_ID = ACTION_DOCTYPE_NAME + 1;
  public static final int ACTION_DOCTYPE_PUBLIC_ID = ACTION_DOCTYPE_SYSTEM_ID + 1;
  public static final int ACTION_DOCTYPE_SUBSET = ACTION_DOCTYPE_PUBLIC_ID + 1;
  public static final int ACTION_DOCTYPE_CLOSE = ACTION_DOCTYPE_SUBSET + 1;
  public static final int ACTION_GENERAL_ENTITY_NAME = ACTION_DOCTYPE_CLOSE + 1;
  public static final int ACTION_PARAM_ENTITY_NAME = ACTION_GENERAL_ENTITY_NAME + 1;
  public static final int ACTION_ENTITY_VALUE_WITH_PEREFS = ACTION_PARAM_ENTITY_NAME + 1;
  public static final int ACTION_ENTITY_VALUE_NO_PEREFS = ACTION_ENTITY_VALUE_WITH_PEREFS + 1;
  public static final int ACTION_ENTITY_SYSTEM_ID = ACTION_ENTITY_VALUE_NO_PEREFS + 1;
  public static final int ACTION_ENTITY_PUBLIC_ID = ACTION_ENTITY_SYSTEM_ID + 1;
  public static final int ACTION_ENTITY_NOTATION_NAME = ACTION_ENTITY_PUBLIC_ID + 1;
  public static final int ACTION_NOTATION_NAME = ACTION_ENTITY_NOTATION_NAME + 1;
  public static final int ACTION_NOTATION_SYSTEM_ID = ACTION_NOTATION_NAME + 1;
  public static final int ACTION_NOTATION_PUBLIC_ID = ACTION_NOTATION_SYSTEM_ID + 1;
  public static final int ACTION_ATTRIBUTE_NAME = ACTION_NOTATION_PUBLIC_ID + 1;
  public static final int ACTION_ATTRIBUTE_TYPE_CDATA = ACTION_ATTRIBUTE_NAME + 1;
  public static final int ACTION_ATTRIBUTE_TYPE_ID = ACTION_ATTRIBUTE_TYPE_CDATA + 1;
  public static final int ACTION_ATTRIBUTE_TYPE_IDREF = ACTION_ATTRIBUTE_TYPE_ID + 1;
  public static final int ACTION_ATTRIBUTE_TYPE_IDREFS = ACTION_ATTRIBUTE_TYPE_IDREF + 1;
  public static final int ACTION_ATTRIBUTE_TYPE_ENTITY = ACTION_ATTRIBUTE_TYPE_IDREFS + 1;
  public static final int ACTION_ATTRIBUTE_TYPE_ENTITIES = ACTION_ATTRIBUTE_TYPE_ENTITY + 1;
  public static final int ACTION_ATTRIBUTE_TYPE_NMTOKEN = ACTION_ATTRIBUTE_TYPE_ENTITIES + 1;
  public static final int ACTION_ATTRIBUTE_TYPE_NMTOKENS = ACTION_ATTRIBUTE_TYPE_NMTOKEN + 1;
  public static final int ACTION_ATTRIBUTE_ENUM_VALUE = ACTION_ATTRIBUTE_TYPE_NMTOKENS + 1;
  public static final int ACTION_ATTRIBUTE_NOTATION_VALUE = ACTION_ATTRIBUTE_ENUM_VALUE + 1;
  public static final int ACTION_ATTLIST_ELEMENT_NAME = ACTION_ATTRIBUTE_NOTATION_VALUE + 1;
  public static final int ACTION_IMPLIED_ATTRIBUTE_VALUE = ACTION_ATTLIST_ELEMENT_NAME + 1;
  public static final int ACTION_REQUIRED_ATTRIBUTE_VALUE = ACTION_IMPLIED_ATTRIBUTE_VALUE + 1;
  public static final int ACTION_DEFAULT_ATTRIBUTE_VALUE = ACTION_REQUIRED_ATTRIBUTE_VALUE + 1;
  public static final int ACTION_FIXED_ATTRIBUTE_VALUE = ACTION_DEFAULT_ATTRIBUTE_VALUE + 1;
  public static final int ACTION_ELEMENT_NAME = ACTION_FIXED_ATTRIBUTE_VALUE + 1;
  public static final int ACTION_CONTENT_ANY = ACTION_ELEMENT_NAME + 1;
  public static final int ACTION_CONTENT_EMPTY = ACTION_CONTENT_ANY + 1;
  public static final int ACTION_CONTENT_PCDATA = ACTION_CONTENT_EMPTY + 1;
  public static final int ACTION_GROUP_OPEN = ACTION_CONTENT_PCDATA + 1;
  public static final int ACTION_GROUP_CLOSE = ACTION_GROUP_OPEN + 1;
  public static final int ACTION_GROUP_CLOSE_REP = ACTION_GROUP_CLOSE + 1;
  public static final int ACTION_GROUP_CLOSE_OPT = ACTION_GROUP_CLOSE_REP + 1;
  public static final int ACTION_GROUP_CLOSE_PLUS = ACTION_GROUP_CLOSE_OPT + 1;
  public static final int ACTION_GROUP_CHOICE = ACTION_GROUP_CLOSE_PLUS + 1;
  public static final int ACTION_GROUP_SEQUENCE = ACTION_GROUP_CHOICE + 1;
  public static final int ACTION_CONTENT_ELEMENT = ACTION_GROUP_SEQUENCE + 1;
  public static final int ACTION_CONTENT_ELEMENT_REP = ACTION_CONTENT_ELEMENT + 1;
  public static final int ACTION_CONTENT_ELEMENT_OPT = ACTION_CONTENT_ELEMENT_REP + 1;
  public static final int ACTION_CONTENT_ELEMENT_PLUS = ACTION_CONTENT_ELEMENT_OPT + 1;
  public static final int ACTION_OUTER_PARAM_ENTITY_REF = ACTION_CONTENT_ELEMENT_PLUS + 1;
  public static final int ACTION_INNER_PARAM_ENTITY_REF = ACTION_OUTER_PARAM_ENTITY_REF + 1;
  public static final int ACTION_IGNORE_SECT = ACTION_INNER_PARAM_ENTITY_REF + 1;
  public static final int ACTION_DECL_CLOSE = ACTION_IGNORE_SECT + 1;

  private static final byte prolog0 = 0;
  private static final byte prolog1 = prolog0 + 1;
  private static final byte prolog2 = prolog1 + 1;
  private static final byte doctype0 = prolog2 + 1;
  private static final byte doctype1 = doctype0 + 1;
  private static final byte doctype2 = doctype1 + 1;
  private static final byte doctype3 = doctype2 + 1;
  private static final byte doctype4 = doctype3 + 1;
  private static final byte doctype5 = doctype4 + 1;
  private static final byte internalSubset = doctype5 + 1;
  private static final byte entity0 = internalSubset + 1;
  private static final byte entity1 = entity0 + 1;
  private static final byte entity2 = entity1 + 1;
  private static final byte entity3 = entity2 + 1;
  private static final byte entity4 = entity3 + 1;
  private static final byte entity5 = entity4 + 1;
  private static final byte entity6 = entity5 + 1;
  private static final byte entity7 = entity6 + 1;
  private static final byte entity8 = entity7 + 1;
  private static final byte entity9 = entity8 + 1;
  private static final byte notation0 = entity9 + 1;
  private static final byte notation1 = notation0 + 1;
  private static final byte notation2 = notation1 + 1;
  private static final byte notation3 = notation2 + 1;
  private static final byte notation4 = notation3 + 1;
  private static final byte attlist0 = notation4 + 1;
  private static final byte attlist1 = attlist0 + 1;
  private static final byte attlist2 = attlist1 + 1;
  private static final byte attlist3 = attlist2 + 1;
  private static final byte attlist4 = attlist3 + 1;
  private static final byte attlist5 = attlist4 + 1;
  private static final byte attlist6 = attlist5 + 1;
  private static final byte attlist7 = attlist6 + 1;
  private static final byte attlist8 = attlist7 + 1;
  private static final byte attlist9 = attlist8 + 1;
  private static final byte element0 = attlist9 + 1;
  private static final byte element1 = element0 + 1;
  private static final byte element2 = element1 + 1;
  private static final byte element3 = element2 + 1;
  private static final byte element4 = element3 + 1;
  private static final byte element5 = element4 + 1;
  private static final byte element6 = element5 + 1;
  private static final byte element7 = element6 + 1;
  private static final byte declClose = element7 + 1;
  private static final byte externalSubset0 = declClose + 1;
  private static final byte externalSubset1 = externalSubset0 + 1;
  private static final byte condSect0 = externalSubset1 + 1;
  private static final byte condSect1 = condSect0 + 1;
  private static final byte condSect2 = condSect1 + 1;

  private byte state;
  private int groupLevel;
  private int includeLevel;
  private byte connector[] = new byte[2];
  private boolean documentEntity;

  public static final byte PROLOG = 0;
  public static final byte EXTERNAL_ENTITY = 1;
  public static final byte INTERNAL_ENTITY = 2;

  public PrologParser(byte type) {
    switch (type) {
    case PROLOG:
      documentEntity = true;
      state = prolog0;
      break;
    case EXTERNAL_ENTITY:
      documentEntity = false;
      state = externalSubset0;
      break;
    case INTERNAL_ENTITY:
      documentEntity = false;
      state = externalSubset1;
      break;
    default:
      throw new IllegalArgumentException();
    }
  }

  public final void end() throws PrologSyntaxException {
    switch (state) {
    case prolog0:
    case prolog1:
    case prolog2:
      break;
    case externalSubset0:
    case externalSubset1:
      if (includeLevel == 0)
	break;
      /* fall through */
    default:
      throw new PrologSyntaxException();
    }
  }

  public int action(int tok, byte[] buf, int start, int end, Encoding enc) throws PrologSyntaxException {
    switch (state) {
    case prolog0:
      state = prolog1;
      if (tok == Encoding.TOK_XML_DECL)
	return ACTION_XML_DECL;
      /* fall through */
    case prolog1:
      if (tok == Encoding.TOK_DECL_OPEN
	  && enc.matchesXMLString(buf,
				  start + 2 * enc.getMinBytesPerChar(),
				  end,
				  "DOCTYPE")) {
	state = doctype0;
	return ACTION_NONE;
      }
      /* fall through */
    case prolog2:
      switch (tok) {
      case Encoding.TOK_PI:
	return ACTION_PI;
      case Encoding.TOK_COMMENT:
	return ACTION_COMMENT;
      }
      break;
    case doctype0:
      if (tok == Encoding.TOK_NAME) {
	state = doctype1;
	return ACTION_DOCTYPE_NAME;
      }
      break;
    case doctype1:
      switch (tok) {
      case Encoding.TOK_OPEN_BRACKET:
	state = internalSubset;
	return ACTION_DOCTYPE_SUBSET;
      case Encoding.TOK_DECL_CLOSE:
	state = prolog2;
	return ACTION_DOCTYPE_CLOSE;
      case Encoding.TOK_NAME:
	if (enc.matchesXMLString(buf, start, end, "SYSTEM")) {
	  state = doctype3;
	  return ACTION_NONE;
	}
	if (enc.matchesXMLString(buf, start, end, "PUBLIC")) {
	  state = doctype2;
	  return ACTION_NONE;
	}
	break;
      }
      break;
    case doctype2:
      if (tok == Encoding.TOK_LITERAL) {
	state = doctype3;
	return ACTION_DOCTYPE_PUBLIC_ID;
      }
      break;
    case doctype3:
      if (tok == Encoding.TOK_LITERAL) {
	state = doctype4;
	return ACTION_DOCTYPE_SYSTEM_ID;
      }
      break;
    case doctype4:
      switch (tok) {
      case Encoding.TOK_OPEN_BRACKET:
	state = internalSubset;
	return ACTION_DOCTYPE_SUBSET;
      case Encoding.TOK_DECL_CLOSE:
	state = prolog2;
	return ACTION_DOCTYPE_CLOSE;
      }
      break;
    case doctype5:
      if (tok == Encoding.TOK_DECL_CLOSE) {
	state = prolog2;
	return ACTION_DOCTYPE_CLOSE;
      }
      break;
    case externalSubset0:
      state = externalSubset1;
      if (tok == Encoding.TOK_XML_DECL)
	return ACTION_TEXT_DECL;
      /* fall through */
    case externalSubset1:
      switch (tok) {
      case Encoding.TOK_COND_SECT_OPEN:
	state = condSect0;
	return ACTION_NONE;
      case Encoding.TOK_COND_SECT_CLOSE:
	if (includeLevel == 0)
	  break;
	--includeLevel;
	return ACTION_NONE;
      case Encoding.TOK_CLOSE_BRACKET:
	throw new PrologSyntaxException();
      }
      /* fall through */
    case internalSubset:
      switch (tok) {
      case Encoding.TOK_DECL_OPEN:
	if (enc.matchesXMLString(buf,
				 start + 2 * enc.getMinBytesPerChar(),
				 end,
				 "ENTITY")) {
	  state = entity0;
	  return ACTION_NONE;
	}
	if (enc.matchesXMLString(buf,
				 start + 2 * enc.getMinBytesPerChar(),
				 end,
				 "ATTLIST")) {
	  state = attlist0;
	  return ACTION_NONE;
	}
	if (enc.matchesXMLString(buf,
				 start + 2 * enc.getMinBytesPerChar(),
				 end,
				 "ELEMENT")) {
	  state = element0;
	  return ACTION_NONE;
	}
	if (enc.matchesXMLString(buf,
				 start + 2 * enc.getMinBytesPerChar(),
				 end,
				 "NOTATION")) {
	  state = notation0;
	  return ACTION_NONE;
	}
	break;
      case Encoding.TOK_PI:
	return ACTION_PI;
      case Encoding.TOK_COMMENT:
	return ACTION_COMMENT;
      case Encoding.TOK_PARAM_ENTITY_REF:
	return ACTION_OUTER_PARAM_ENTITY_REF;
      case Encoding.TOK_CLOSE_BRACKET:
	state = doctype5;
	return ACTION_NONE;
      }
      break;
    case entity0:
      switch (tok) {
      case Encoding.TOK_PERCENT:
	state = entity1;
	return ACTION_NONE;
      case Encoding.TOK_NAME:
	state = entity2;
	return ACTION_GENERAL_ENTITY_NAME;
      }
      break;
    case entity1:
      if (tok == Encoding.TOK_NAME) {
	state = entity7;
	return ACTION_PARAM_ENTITY_NAME;
      }
      break;
    case entity2:
      switch (tok) {
      case Encoding.TOK_NAME:
	if (enc.matchesXMLString(buf, start, end, "SYSTEM")) {
	  state = entity4;
	  return ACTION_NONE;
	}
	if (enc.matchesXMLString(buf, start, end, "PUBLIC")) {
	  state = entity3;
	  return ACTION_NONE;
	}
	break;
      case Encoding.TOK_LITERAL:
	state = declClose;
	return documentEntity ? ACTION_ENTITY_VALUE_NO_PEREFS : ACTION_ENTITY_VALUE_WITH_PEREFS;
      }
      break;
    case entity3:
      if (tok == Encoding.TOK_LITERAL) {
	state = entity4;
	return ACTION_ENTITY_PUBLIC_ID;
      }
      break;
    case entity4:
      if (tok == Encoding.TOK_LITERAL) {
	state = entity5;
	return ACTION_ENTITY_SYSTEM_ID;
      }
      break;
    case entity5:
      switch (tok) {
      case Encoding.TOK_DECL_CLOSE:
	state = documentEntity ? internalSubset : externalSubset1;
	return ACTION_DECL_CLOSE;
      case Encoding.TOK_NAME:
	if (enc.matchesXMLString(buf, start, end, "NDATA")) {
	  state = entity6;
	  return ACTION_NONE;
	}
	break;
      }
      break;
    case entity6:
      switch (tok) {
      case Encoding.TOK_NAME:
	state = declClose;
	return ACTION_ENTITY_NOTATION_NAME;
      }
      break;
    case entity7:
      switch (tok) {
      case Encoding.TOK_NAME:
	if (enc.matchesXMLString(buf, start, end, "SYSTEM")) {
	  state = entity9;
	  return ACTION_NONE;
	}
	if (enc.matchesXMLString(buf, start, end, "PUBLIC")) {
	  state = entity8;
	  return ACTION_NONE;
	}
	break;
      case Encoding.TOK_LITERAL:
	state = declClose;
	return documentEntity ? ACTION_ENTITY_VALUE_NO_PEREFS : ACTION_ENTITY_VALUE_WITH_PEREFS;
      }
      break;
    case entity8:
      if (tok == Encoding.TOK_LITERAL) {
	state = entity9;
	return ACTION_ENTITY_PUBLIC_ID;
      }
      break;
    case entity9:
      if (tok == Encoding.TOK_LITERAL) {
	state = declClose;
	return ACTION_ENTITY_SYSTEM_ID;
      }
      break;
    case notation0:
      if (tok == Encoding.TOK_NAME) {
	state = notation1;
	return ACTION_NOTATION_NAME;
      }
      break;
    case notation1:
      switch (tok) {
      case Encoding.TOK_NAME:
	if (enc.matchesXMLString(buf, start, end, "SYSTEM")) {
	  state = notation3;
	  return ACTION_NONE;
	}
	if (enc.matchesXMLString(buf, start, end, "PUBLIC")) {
	  state = notation2;
	  return ACTION_NONE;
	}
	break;
      }
      break;
    case notation2:
      if (tok == Encoding.TOK_LITERAL) {
	state = notation4;
	return ACTION_NOTATION_PUBLIC_ID;
      }
      break;
    case notation3:
      if (tok == Encoding.TOK_LITERAL) {
	state = declClose;
	return ACTION_NOTATION_SYSTEM_ID;
      }
      break;
    case notation4:
      switch (tok) {
      case Encoding.TOK_LITERAL:
	state = declClose;
	return ACTION_NOTATION_SYSTEM_ID;
      case Encoding.TOK_DECL_CLOSE:
	state = documentEntity ? internalSubset : externalSubset1;
	return ACTION_DECL_CLOSE;
      }
      break;
    case attlist0:
      if (tok == Encoding.TOK_NAME) {
	state = attlist1;
	return ACTION_ATTLIST_ELEMENT_NAME;
      }
      break;
    case attlist1:
      switch (tok) {
      case Encoding.TOK_DECL_CLOSE:
	state = documentEntity ? internalSubset : externalSubset1;
	return ACTION_NONE;
      case Encoding.TOK_NAME:
	state = attlist2;
	return ACTION_ATTRIBUTE_NAME;
      }
      break;
    case attlist2:
      switch (tok) {
      case Encoding.TOK_NAME:
	for (int i = 0; i < attributeTypes.length; i++)
	  if (enc.matchesXMLString(buf, start, end, attributeTypes[i])) {
	    state = attlist8;
	    return ACTION_ATTRIBUTE_TYPE_CDATA + i;
	  }
	if (enc.matchesXMLString(buf, start, end, "NOTATION")) {
	  state = attlist5;
	  return ACTION_NONE;
	}
	break;
      case Encoding.TOK_OPEN_PAREN:
	groupLevel = 1;
	state = attlist3;
	return ACTION_NONE;
      }
      break;
    case attlist3:
      switch (tok) {
      case Encoding.TOK_NMTOKEN:
      case Encoding.TOK_NAME:
	state = attlist4;
	return ACTION_ATTRIBUTE_ENUM_VALUE;
      }
      break;
    case attlist4:
      switch (tok) {
      case Encoding.TOK_CLOSE_PAREN:
	state = attlist8;
	groupLevel = 0;
	return ACTION_NONE;
      case Encoding.TOK_OR:
	state = attlist3;
	return ACTION_NONE;
      }
      break;
    case attlist5:
      if (tok == Encoding.TOK_OPEN_PAREN) {
	state = attlist6;
	groupLevel = 1;
	return ACTION_NONE;
      }
      break;
    case attlist6:
      if (tok == Encoding.TOK_NAME) {
	state = attlist7;
	return ACTION_ATTRIBUTE_NOTATION_VALUE;
      }
      break;
    case attlist7:
      switch (tok) {
      case Encoding.TOK_CLOSE_PAREN:
	groupLevel = 0;
	state = attlist8;
	return ACTION_NONE;
      case Encoding.TOK_OR:
	state = attlist6;
	return ACTION_NONE;
      }
      break;
      /* default value */
    case attlist8:
      switch (tok) {
      case Encoding.TOK_POUND_NAME:
	if (enc.matchesXMLString(buf,
				 start + enc.getMinBytesPerChar(),
				 end,
				 "IMPLIED")) {
	  state = attlist1;
	  return ACTION_IMPLIED_ATTRIBUTE_VALUE;
	}
	if (enc.matchesXMLString(buf,
				 start + enc.getMinBytesPerChar(),
				 end,
				 "REQUIRED")) {
	  state = attlist1;
	  return ACTION_REQUIRED_ATTRIBUTE_VALUE;
	}
	if (enc.matchesXMLString(buf,
				 start + enc.getMinBytesPerChar(),
				 end,
				 "FIXED")) {
	  state = attlist9;
	  return ACTION_NONE;
	}
	break;
      case Encoding.TOK_LITERAL:
	state = attlist1;
	return ACTION_DEFAULT_ATTRIBUTE_VALUE;
      }
      break;
    case attlist9:
      if (tok == Encoding.TOK_LITERAL) {
	state = attlist1;
	return ACTION_FIXED_ATTRIBUTE_VALUE;
      }
      break;
    case element0:
      if (tok == Encoding.TOK_NAME) {
	state = element1;
	return ACTION_ELEMENT_NAME;
      }
      break;
    case element1:
      switch (tok) {
      case Encoding.TOK_NAME:
	if (enc.matchesXMLString(buf, start, end, "EMPTY")) {
	  state = declClose;
	  return ACTION_CONTENT_EMPTY;
	}
	if (enc.matchesXMLString(buf, start, end, "ANY")) {
	  state = declClose;
	  return ACTION_CONTENT_ANY;
	}
	break;
      case Encoding.TOK_OPEN_PAREN:
	state = element2;
	groupLevel = 1;
	connector[0] = (byte)0;
	return ACTION_GROUP_OPEN;
      }
      break;
    case element2:
      switch (tok) {
      case Encoding.TOK_POUND_NAME:
	if (enc.matchesXMLString(buf,
				 start + enc.getMinBytesPerChar(),
				 end,
				 "PCDATA")) {
	  state = element3;
	  return ACTION_CONTENT_PCDATA;
	}
	break;
      case Encoding.TOK_OPEN_PAREN:
	groupLevel = 2;
	connector[1] = (byte)0;
	state = element6;
	return ACTION_GROUP_OPEN;
      case Encoding.TOK_NAME:
	state = element7;
	return ACTION_CONTENT_ELEMENT;
      case Encoding.TOK_NAME_QUESTION:
	state = element7;
	return ACTION_CONTENT_ELEMENT_OPT;
      case Encoding.TOK_NAME_ASTERISK:
	state = element7;
	return ACTION_CONTENT_ELEMENT_REP;
      case Encoding.TOK_NAME_PLUS:
	state = element7;
	return ACTION_CONTENT_ELEMENT_PLUS;
      }
      break;
    case element3:
      switch (tok) {
      case Encoding.TOK_CLOSE_PAREN:
      case Encoding.TOK_CLOSE_PAREN_ASTERISK:
	groupLevel = 0;
	state = declClose;
	return ACTION_GROUP_CLOSE_REP;
      case Encoding.TOK_OR:
	state = element4;
	return ACTION_GROUP_CHOICE;
      }
      break;
    case element4:
      if (tok == Encoding.TOK_NAME) {
	state = element5;
	return ACTION_CONTENT_ELEMENT;
      }
      break;
    case element5:
      switch (tok) {
      case Encoding.TOK_CLOSE_PAREN_ASTERISK:
	groupLevel = 0;
	state = declClose;
	return ACTION_GROUP_CLOSE_REP;
      case Encoding.TOK_OR:
	state = element4;
	return ACTION_GROUP_CHOICE;
      }
      break;
    case element6:
      switch (tok) {
      case Encoding.TOK_OPEN_PAREN:
	if (groupLevel >= connector.length) {
	  byte[] tem = new byte[connector.length << 1];
	  System.arraycopy(connector, 0, tem, 0, connector.length);
	  connector = tem;
	}
	connector[groupLevel] = (byte)0;
	groupLevel += 1;
	return ACTION_GROUP_OPEN;
      case Encoding.TOK_NAME:
	state = element7;
	return ACTION_CONTENT_ELEMENT;
      case Encoding.TOK_NAME_QUESTION:
	state = element7;
	return ACTION_CONTENT_ELEMENT_OPT;
      case Encoding.TOK_NAME_ASTERISK:
	state = element7;
	return ACTION_CONTENT_ELEMENT_REP;
      case Encoding.TOK_NAME_PLUS:
	state = element7;
	return ACTION_CONTENT_ELEMENT_PLUS;
      }
      break;
    case element7:
      switch (tok) {
      case Encoding.TOK_CLOSE_PAREN:
	groupLevel -= 1;
	if (groupLevel == 0)
	  state = declClose;
	return ACTION_GROUP_CLOSE;
      case Encoding.TOK_CLOSE_PAREN_ASTERISK:
	groupLevel -= 1;
	if (groupLevel == 0)
	  state = declClose;
	return ACTION_GROUP_CLOSE_REP;
      case Encoding.TOK_CLOSE_PAREN_QUESTION:
	groupLevel -= 1;
	if (groupLevel == 0)
	  state = declClose;
	return ACTION_GROUP_CLOSE_OPT;
      case Encoding.TOK_CLOSE_PAREN_PLUS:
	groupLevel -= 1;
	if (groupLevel == 0)
	  state = declClose;
	return ACTION_GROUP_CLOSE_PLUS;
      case Encoding.TOK_COMMA:
	state = element6;
	if (connector[groupLevel - 1] == (byte)'|')
	  break;
	connector[groupLevel - 1] = (byte)',';
	return ACTION_GROUP_SEQUENCE;
      case Encoding.TOK_OR:
	state = element6;
	if (connector[groupLevel - 1] == (byte)',')
	  break;
	connector[groupLevel - 1] = (byte)'|';
	return ACTION_GROUP_CHOICE;
      }
      break;
    case declClose:
      if (tok == Encoding.TOK_DECL_CLOSE) {
	state = documentEntity ? internalSubset : externalSubset1;
	return ACTION_DECL_CLOSE;
      }
      break;
    case condSect0:
      if (tok == Encoding.TOK_NAME) {
	if (enc.matchesXMLString(buf, start, end, "INCLUDE")) {
	  state = condSect1;
	  return ACTION_NONE;
	}
	if (enc.matchesXMLString(buf, start, end, "IGNORE")) {
	  state = condSect2;
	  return ACTION_NONE;
	}
      }
      break;
    case condSect1:
      if (tok == Encoding.TOK_OPEN_BRACKET) {
	state = externalSubset1;
	includeLevel++;
	return ACTION_NONE;
      }
      break;
    case condSect2:
      if (tok == Encoding.TOK_OPEN_BRACKET) {
	state = externalSubset1;
	return ACTION_IGNORE_SECT;
      }
      break;
    }
    if (tok == Encoding.TOK_PROLOG_S)
      return ACTION_NONE;
    if (tok == Encoding.TOK_PARAM_ENTITY_REF && !documentEntity)
      return ACTION_INNER_PARAM_ENTITY_REF;
    throw new PrologSyntaxException();
  }

  public Object clone() {
    try {
      PrologParser copy = (PrologParser)super.clone();
      copy.connector = new byte[connector.length];
      System.arraycopy(connector, 0, copy.connector, 0, groupLevel);
      return copy;
    }
    catch (CloneNotSupportedException e) {
      throw new InternalError();
    }
  }

  public final int getGroupLevel() {
    return groupLevel;
  }

  private static final String[] attributeTypes = {
    "CDATA",
    "ID",
    "IDREF",
    "IDREFS",
    "ENTITY",
    "ENTITIES",
    "NMTOKEN",
    "NMTOKENS",
  };
}