/[suikacvs]/messaging/manakai/lib/Message/DOM/XMLParser.dis
Suika

Contents of /messaging/manakai/lib/Message/DOM/XMLParser.dis

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations) (download)
Sat Dec 31 12:21:15 2005 UTC (18 years, 10 months ago) by wakaba
Branch: MAIN
Changes since 1.3: +1079 -252 lines
++ manakai/lib/Message/DOM/ChangeLog	31 Dec 2005 12:20:20 -0000
2005-12-31  Wakaba  <wakaba@suika.fam.cx>

	* DOMCore.dis (DOMError.location): Returns an empty |DOMLocator|
	if it is not provided.

	* XMLParser.dis: Parsing methods to skip document
	type declaration is added.

1 wakaba 1.1 Module:
2     @QName: MDOM|XMLParser
3     @Namespace:
4     http://suika.fam.cx/~wakaba/archive/2004/dom/xml-parser#
5    
6     @FullName:
7     @@lang:en
8     @@@: XML Parser
9    
10     @DISCore:author: DISCore|Wakaba
11     @License: license|Perl+MPL
12     @Date:
13 wakaba 1.4 $Date: 2005/12/29 10:21:42 $
14 wakaba 1.1
15     @DefaultFor: ManakaiDOM|ManakaiDOMLatest
16    
17     @Require:
18     @@Module:
19     @@@QName: MDOM|DOMLS
20     @@@WithFor: ManakaiDOM|ManakaiDOMLatest
21    
22     Namespace:
23     @dis:
24     http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#dis--
25     @DOMCore:
26     http://suika.fam.cx/~wakaba/archive/2004/8/18/dom-core#
27     @DOMMain:
28     http://suika.fam.cx/~wakaba/archive/2004/dom/main#
29     @dx:
30     http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/Error/DOMException#
31     @ecore:
32     http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/Error/Core/
33     @f:
34     http://suika.fam.cx/~wakaba/archive/2004/dom/feature#
35     @idl:
36     http://suika.fam.cx/~wakaba/archive/2004/dis/IDL#
37     @infoset:
38     http://www.w3.org/2001/04/infoset#
39     @lang:
40     http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#
41     @license:
42     http://suika.fam.cx/~wakaba/archive/2004/8/18/license#
43     @LSEV:
44     http://www.w3.org/2002/DOMLS
45     @ManakaiDOM:
46     http://suika.fam.cx/~wakaba/archive/2004/8/18/manakai-dom#
47     @ManakaiDOMLS:
48     http://suika.fam.cx/~wakaba/archive/2004/mdom-ls#
49     @MDOM:
50     http://suika.fam.cx/~wakaba/archive/2004/8/18/manakai-dom#ManakaiDOM.
51     @MDOMX:
52     http://suika.fam.cx/~wakaba/archive/2004/8/4/manakai-dom-exception#
53     @rdf:
54     http://www.w3.org/1999/02/22-rdf-syntax-ns#
55     @rdfs:
56     http://www.w3.org/2000/01/rdf-schema#
57     @t:
58     http://suika.fam.cx/~wakaba/archive/2004/dom/tree#
59     @xml:
60     http://www.w3.org/XML/1998/namespace
61     @xmlns:
62     http://www.w3.org/2000/xmlns/
63     @xp:
64     http://suika.fam.cx/~wakaba/archive/2004/dom/xml-parser#
65    
66     ## -- Features
67    
68     ElementTypeBinding:
69     @Name: FeatureDef
70     @ElementType:
71     dis:ResourceDef
72     @ShadowContent:
73     @@rdf:type: f|Feature
74     @@For: =ManakaiDOM|all
75    
76     ElementTypeBinding:
77     @Name: FeatureVerDef
78     @ElementType:
79     dis:ResourceDef
80     @ShadowContent:
81     @@rdf:type: f|Feature
82    
83     ElementTypeBinding:
84     @Name: featureQName
85     @ElementType:
86     f:name
87     @ShadowContent:
88     @@ContentType: DISCore|QName
89    
90     ResourceDef:
91     @QName: DOMString
92     @AliasFor: DOMMain|DOMString
93     @For: ManakaiDOM|DOM
94    
95     ResourceDef:
96     @QName: Node
97     @AliasFor: t|Node
98     @For: ManakaiDOM|DOM
99    
100     ResourceDef:
101     @QName: Element
102     @AliasFor: t|Element
103     @For: ManakaiDOM|DOM
104    
105     ResourceDef:
106     @QName: Document
107     @AliasFor: t|Document
108     @For: ManakaiDOM|DOM
109    
110     ElementTypeBinding:
111     @Name: ClsDef
112     @ElementType:
113     dis:ResourceDef
114     @ShadowContent:
115     @@rdf:type:
116     @@@@: dis|MultipleResource
117     @@@ForCheck: !ManakaiDOM|ForIF !ManakaiDOM|ForClass
118     @@resourceFor:
119     @@@@: ManakaiDOM|ForClass
120     @@@ForCheck: ManakaiDOM|ManakaiDOM !=ManakaiDOM|ManakaiDOM
121     @@For: ManakaiDOM|DOM3
122     @@For: =ManakaiDOM|ManakaiDOM
123    
124     @@rdf:type:
125     @@@@: DISLang|Class
126     @@@ForCheck: ManakaiDOM|ForClass
127    
128     ElementTypeBinding:
129     @Name: ClsQName
130     @ElementType:
131     dis:QName
132     @ShadowContent:
133     @@ForCheck: ManakaiDOM|ForClass
134    
135     ElementTypeBinding:
136     @Name: ClsISA
137     @ElementType:
138     dis:ISA
139     @ShadowContent:
140     @@ForCheck: ManakaiDOM|ForClass
141    
142     ElementTypeBinding:
143     @Name: nullCase
144     @ElementType:
145     dis:ResourceDef
146     @ShadowContent:
147     @@rdf:type: ManakaiDOM|InCase
148     @@Value:
149     @@@is-null:1
150    
151     ResourceDef:
152     @QName: LSParser
153     @AliasFor: DOMLS|LSParser
154     @For: ManakaiDOM|DOM3
155    
156     ClsDef:
157     @ClsQName: ManakaiXMLParser
158    
159     @Implement: DOMLS|LSParser
160    
161     @f:implements:
162     @@@: DOMLS|LSFeature30
163     @@For: ManakaiDOM|DOM3
164    
165     @DISLang:role: DOMLS|ParserRole
166    
167 wakaba 1.3 @enDesc:
168     Note that the <Class::ManakaiXMLParser> reports any XML errors
169     (syntax errors and / or well-formedness constraint errors)
170     via the <IF::DOMCore:error-handler> registered to
171     the <A::DOMLS:LSParser.domConfig> object. Each error has
172     its <A::DOMCore:DOMError.severity>, either <C::DOMCore:SEVERITY_ERROR>
173     or <C::DOMCore:SEVERITY_FATAL_ERROR>. However, their semantics
174     are slight different from the ones of <QUOTE::error> and
175     <QUOTE::fatal error> in XML; in this implemenetation,
176     <C::DOMCore:SEVERITY_ERROR> implies that the parsing process
177     can effectively be continued to detect more errors while
178     <C::DOMCore:SEVERITY_FATAL_ERROR> implies that the error
179     is serious so that the result document tree and any errors
180     might be far from the ones obtained when the error would not
181     be found.
182    
183 wakaba 1.1 @Attr:
184     @@Name: domConfig
185     @@enDesc:
186     The configuration of the parser.
187    
188     @@Get:
189     @@@Type: DOMCore|DOMConfiguration
190     @@@enDesc: The DOM configuration object.
191     @@@PerlDef:
192     __CODE{DOMCore|getConfigObject::
193     $target => $self,
194     $targetHash => $self,
195     $targetType => {<IFName::LSParser>},
196     $result => $r,
197     }__;
198    
199     @Method:
200     @@ManakaiDOM:isForInternal:1
201     @@ForCheck: ManakaiDOM|ForClass
202     @@Operator: DISPerl|NewMethod
203     @@enDesc:
204     Creates a new instance of the object.
205     @@Param:
206     @@@Name: impl
207     @@@Type: DOMLS|GLSImplementation
208     @@@enDesc:
209     The implementation from which the parser is created.
210     @@Param:
211     @@@Name: features
212     @@@Type: DOMString
213     @@@dis:actualType: f|FeaturesString
214     @@@enDesc:
215     The set of features requested for the parser.
216     @@Return:
217     @@@Type: DOMMain|DOMObject
218     @@@dis:actualType: LSParser
219     @@@enDesc:
220     The newly created parser.
221     @@@PerlDef:
222     $r = bless {
223     <H::DOMCore:implementation> => $impl,
224     }, $self;
225    
226     @Method:
227     @@Name: parseString
228     @@enImplNote:
229     Non-standard - to be removed
230    
231     @@Param:
232     @@@Name: sourceText
233     @@@Type: DOMString
234     @@Return:
235     @@@Type: Document
236     @@@PerlDef:
237    
238     $self->{char} = [];
239     $self->{token} = [];
240     $self->{source} = $sourceText;
241 wakaba 1.3 $self->{xml_version} = '1.0';
242     $self->{standalone} = false;
243     ## Well-formedness constraint Entity Declared takes effect?
244     $self->{line} = 1;
245     $self->{column} = 1;
246 wakaba 1.1
247     __DEEP{
248     $r = $self->_parse_DocumentEntity
249     ($self->{<H::DOMCore:implementation>});
250     }__;
251    
252     @Method:
253     @@Name: shiftChar
254     @@ManakaiDOM:isForInternal:1
255     @@ForCheck: ManakaiDOM|ForClass
256     @@enDesc:
257     Returns the next character.
258     @@Return:
259     @@@Type: idl|long||ManakaiDOM|all
260     @@@enDesc:
261     The code position number of the next character, if any,
262     or <CODE::-2>.
263     @@@PerlDef:
264     if (@{$self->{char}}) {
265     $r = shift @{$self->{char}};
266     } else {
267     my $char = substr ($self->{source}, pos ($self->{source}), 1);
268     pos ($self->{source})++;
269    
270     if (length $char) {
271     $r = ord $char;
272 wakaba 1.3 if ($r == 0x000A) {
273     $self->{line}++;
274     $self->{column} = 1;
275     } elsif ($r == 0x000D) {
276     my $next_char = substr ($self->{source},
277     pos ($self->{source}), 1);
278     if ($next_char eq "\x0A") {
279     pos ($self->{source})++;
280     $self->{column} = 1;
281     } elsif ($next_char eq "\x85") {
282     if ($self->{xml_version} eq '1.1') {
283     pos ($self->{source})++;
284     $self->{column} = 1;
285     } else {
286     $self->{column} = 0;
287     }
288     } else {
289     $self->{column} = 1;
290     }
291     $r = 0x000A;
292     $self->{line}++;
293     } elsif (
294     not ((0x0020 <= $r and $r <= 0x007E) or
295     (0x00A0 <= $r and $r <= 0xD7FF) or
296     (0xE000 <= $r and $r <= 0xFFFD) or
297     (0x10000 <= $r and $r <= 0x10FFFF)) and
298     $r != 0x0009 and $r != 0x0085 and
299     not ($self->{xml_version} eq '1.0' and
300     (0x007F <= $r and $r <= 0x009F))
301     ) {
302     my $location = {
303     utf32_offset => pos ($self->{source}),
304     line_number => $self->{line},
305     column_number => $self->{column},
306     };
307     my $continue = __DOMCore:ERROR{xp|wf-legal-literal-character::
308     DOMCore|location => {$location},
309     xp|character-number => {$r},
310     }__;
311     unless ($continue) {
312     __EXCEPTION{DOMLS|PARSE_ERR}__;
313     }
314     $self->{has_error} = true;
315     $self->{column}++;
316     } elsif ($r == 0x0085 or $r == 0x2028) {
317     $r = 0x000A if $self->{xml_version} eq '1.1';
318     $self->{line}++;
319     $self->{column} = 1;
320     } else {
321     $self->{column}++;
322     }
323 wakaba 1.1 } else {
324     $r = -1;
325     }
326     }
327    
328     @Method:
329     @@ManakaiDOM:isForInternal: 1
330     @@Operator: ManakaiDOM|MUErrorHandler
331     @@enDesc:
332     When a <IF::ecore|ErrorInterface||ManakaiDOM|Perl> is <Perl::report>ed,
333     then this method is invoked.
334    
335     The method calls the <cfg::DOMCore|error-handler> if the error is of
336     <IF::DOMCore|DOMError>. Otherwise, the error is re-thrown so that
337     corresponding <Perl::catch> clause, if any, can catch the error.
338     @@Param:
339     @@@Name: err
340     @@@Type: ecore|ErrorInterface||ManakaiDOM|Perl
341     @@@enDesc:
342     The reported error object.
343     @@Return:
344     @@@Type: DISPerl|Any
345     @@@enDesc:
346     If the <P::err> is a <IF::DOMCore|DOMError>, then the return value
347     of the error handler.
348    
349     {NOTE:: If the error is thrown, the method never returns.
350     }
351     @@@nullCase:
352     @@@@enDesc:
353     No error handler.
354     @@@PerlDef:
355     if ($err->isa (<IFName::DOMCore|DOMError||ManakaiDOM|ManakaiDOM>)) {
356     __DEEP{
357     A: {
358     my $cfg = $self-><AG::LSParser.domConfig>;
359     my $h = $cfg-><M::DOMCore|DOMConfiguration.getParameter>
360     ('error-handler');
361     $r = $h-><M::DOMCore|DOMErrorHandler.handleError> ($err);
362     } # A
363     }__;
364     } else {
365     $err-><M::ecore|ErrorInterface||ManakaiDOM|Perl.throw>;
366     }
367    
368     @DISPerl:dpgDef:
369    
370     /*
371     XML Document Entity
372    
373     document := prolog element *Misc
374     - *Char RestrictedChar *Char ;; [1]
375     */
376     rule DocumentEntity ($impl) : standalone {
377     my $doc : return;
378    
379     lang:Perl {
380     $doc = $impl-><M::DOMImpl.createDocument>;
381     $doc-><AS::Document.strictErrorChecking> (false);
382     }
383    
384     /*
385     prolog := XMLDecl? *Misc [doctypedecl *Misc] ;; [22]
386     */
387     ?lexmode 'DocumentStart';
388    
389 wakaba 1.3 ~? (XDO) {
390     &_XMLDeclaration_ ($doc => $doc);
391    
392     ~ (PIC) {
393     ?lexmode DocumentProlog;
394     } else {
395     ?lexmode DocumentProlog;
396     }
397     } else {
398     ?lexmode 'DocumentProlog';
399     }
400 wakaba 1.1
401     // *Misc
402 wakaba 1.2 ~* (CDO) {
403 wakaba 1.1 &_CommentDeclaration_ ($doc => $doc, $parent => $doc);
404    
405     ~ (MDC) {
406     ?lexmode DocumentProlog;
407     } else {
408     ?lexmode DocumentProlog;
409     }
410     } (PIO) {
411     &_ProcessingInstruction_ ($doc => $doc, $parent => $doc);
412    
413     ~ (PIC) {
414     ?lexmode 'DocumentProlog';
415     } else {
416     ?lexmode DocumentProlog;
417     }
418     } (S) {
419     //
420     }
421    
422     // doctypedecl
423     ~? (MDO) {
424     &_DocumentTypeDeclaration_ ($doc => $doc);
425    
426 wakaba 1.3 ~ (MDC) {
427     ?lexmode DocumentMisc;
428     } else {
429     ?lexmode DocumentMisc;
430     }
431     } else {
432     lang:Perl {
433     $self->{standalone} = true;
434     }
435     ?lexmode DocumentMisc;
436 wakaba 1.1 }
437    
438     // *Misc
439 wakaba 1.2 ~* (CDO) {
440 wakaba 1.1 &_CommentDeclaration_ ($doc => $doc, $parent => $doc);
441    
442     ~ (MDC) {
443     ?lexmode DocumentMisc;
444     } else {
445     ?lexmode DocumentMisc;
446     }
447     } (PIO) {
448     &_ProcessingInstruction_ ($doc => $doc, $parent => $doc);
449    
450     ~ (PIC) {
451     ?lexmode 'DocumentMisc';
452     } else {
453     ?lexmode DocumentMisc;
454     }
455     } (S) {
456     //
457     }
458    
459     // Document element
460     ~ (STAGO) {
461     &Element_ ($doc => $doc, $parent => $doc)
462     : unshift-current-token;
463     ~ (TAGC) {
464     ?lexmode DocumentEnd;
465     } else {
466     ?lexmode DocumentEnd;
467     }
468     } else {
469     ?lexmode 'DocumentEnd';
470     }
471    
472     // *Misc
473 wakaba 1.2 ~* (CDO) {
474 wakaba 1.1 &_CommentDeclaration_ ($doc => $doc, $parent => $doc);
475    
476     ~ (MDC) {
477     ?lexmode DocumentEnd;
478     } else {
479     ?lexmode DocumentEnd;
480     }
481     } (PIO) {
482     &_ProcessingInstruction_ ($doc => $doc, $parent => $doc);
483     ~ (PIC) {
484     ?lexmode 'DocumentEnd';
485     } else {
486     ?lexmode DocumentEnd;
487     }
488     } (S) {
489     //
490     }
491    
492     ~ (#EOF) { }
493    
494     lang:Perl {
495     if ($self->{has_error}) {
496     __EXCEPTION{DOMLS|PARSE_ERR::
497     }__;
498     }
499    
500     $doc-><AS::Document.strictErrorChecking> (true);
501     }
502     } // DocumentEntity
503    
504     /*
505     XML Declaration
506    
507     XMLDecl := '<?xml' VersionInfo
508     [EncodingDecl]
509     [SDDecl]
510     [S] '?>' ;; [23]
511    
512     NOTE: XML declaration is optional in XML 1.0
513     while it is required in XML 1.1.
514     */
515 wakaba 1.3 rule _XMLDeclaration_ ($doc) {
516     ?lexmode XMLDeclaration;
517    
518     ~ (S) { }
519    
520     ~ (Name == 'version') {
521     ~? (S) { }
522     ~ (VI) { }
523     ~? (S) { }
524 wakaba 1.1
525 wakaba 1.3 my $ver;
526     my $bad_token;
527    
528     ~ (LIT) {
529     ?lexmode AttributeValueLiteral;
530    
531     ~ (STRING) {
532     lang:Perl ($version => $token.value) {
533     $ver = $version;
534     $bad_token = $token;
535     }
536     }
537    
538     ~ (LIT) {
539     ?lexmode XMLDeclaration;
540     }
541     } (LITA) {
542     ?lexmode AttributeValueLiteralA;
543    
544     ~ (STRING) {
545     lang:Perl ($version => $token.value) {
546     $ver = $version;
547     $bad_token = $token;
548     }
549     }
550    
551     ~ (LITA) {
552     ?lexmode XMLDeclaration;
553     }
554     }
555    
556     lang:Perl : has-error {
557     unless ($ver eq '1.0' or $ver eq '1.1') {
558     my $location;
559     __CODE{xp|get-location-from-token::
560     $token => {$bad_token},
561     $result => {$location},
562     }__;
563     my $continue = __DOMCore:ERROR{xp|wf-unsupported-xml-version::
564     DOMCore|location => {$location},
565     xp|parent => {$doc},
566     infoset|version => {$ver},
567     xp|error-token => {$bad_token},
568     }__;
569     unless ($continue) {
570     __EXCEPTION{DOMLS|PARSE_ERR}__;
571     }
572     $self->{has_error} = true;
573     }
574     $doc-><AS::Document.xmlVersion> ($ver);
575     $self->{xml_version} = $ver;
576     }
577    
578     ~? (S) { }
579 wakaba 1.1 }
580    
581 wakaba 1.3 ~? (Name == 'encoding') {
582     ~? (S) { }
583     ~ (VI) { }
584     ~? (S) { }
585    
586     my $ver;
587     my $bad_token;
588    
589     ~ (LIT) {
590     ?lexmode AttributeValueLiteral;
591    
592     ~ (STRING) {
593     lang:Perl ($version => $token.value) {
594     $ver = $version;
595     $bad_token = $token;
596     }
597     }
598    
599     ~ (LIT) {
600     ?lexmode XMLDeclaration;
601     }
602     } (LITA) {
603     ?lexmode AttributeValueLiteralA;
604    
605     ~ (STRING) {
606     lang:Perl ($version => $token.value) {
607     $ver = $version;
608     $bad_token = $token;
609     }
610     }
611    
612     ~ (LITA) {
613     ?lexmode XMLDeclaration;
614     }
615     }
616    
617     lang:Perl : has-error {
618     unless ($ver =~ /\A[A-Za-z][A-Za-z0-9._-]*\z/) {
619     my $location;
620     __CODE{xp|get-location-from-token::
621     $token => {$bad_token},
622     $result => {$location},
623     }__;
624     my $continue = __DOMCore:ERROR{xp|wf-malformed-enc-name::
625     DOMCore|location => {$location},
626     xp|parent => {$doc},
627     xp|name => {$ver},
628     xp|error-token => {$bad_token},
629     }__;
630     unless ($continue) {
631     __EXCEPTION{DOMLS|PARSE_ERR}__;
632     }
633     $self->{has_error} = true;
634     }
635     $doc-><AS::Document.xmlEncoding> ($ver);
636     }
637    
638     ~? (S) { }
639 wakaba 1.1 }
640 wakaba 1.3
641     ~? (Name == 'standalone') {
642     ~? (S) { }
643     ~ (VI) { }
644     ~? (S) { }
645    
646     my $ver;
647     my $bad_token;
648    
649     ~ (LIT) {
650     ?lexmode AttributeValueLiteral;
651    
652     ~ (STRING) {
653     lang:Perl ($version => $token.value) {
654     $ver = $version;
655     $bad_token = $token;
656     }
657     }
658    
659     ~ (LIT) {
660     ?lexmode XMLDeclaration;
661     }
662     } (LITA) {
663     ?lexmode AttributeValueLiteralA;
664    
665     ~ (STRING) {
666     lang:Perl ($version => $token.value) {
667     $ver = $version;
668     $bad_token = $token;
669     }
670     }
671 wakaba 1.1
672 wakaba 1.3 ~ (LITA) {
673     ?lexmode XMLDeclaration;
674     }
675     }
676    
677     lang:Perl : has-error {
678     unless ($ver eq 'yes' or $ver eq 'no') {
679     my $location;
680     __CODE{xp|get-location-from-token::
681     $token => {$bad_token},
682     $result => {$location},
683     }__;
684     my $continue = __DOMCore:ERROR{xp|wf-malformed-xml-standalone::
685     DOMCore|location => {$location},
686     xp|parent => {$doc},
687     xp|name => {$ver},
688     xp|error-token => {$bad_token},
689     }__;
690     unless ($continue) {
691     __EXCEPTION{DOMLS|PARSE_ERR}__;
692     }
693     $self->{has_error} = true;
694     }
695     $doc-><AS::Document.xmlStandalone> ($ver);
696     $self->{standalone} = true if $ver eq 'yes';
697     }
698    
699     ~? (S) { }
700     }
701    
702     // ~ (PIC) { }
703     } // _XMLDeclaration_
704 wakaba 1.1
705     /*
706     Comment Declaration
707    
708     Comment := '<!--' *(Char - '-' / '-' (Char - '-'))
709     '-->' ;; [15]
710 wakaba 1.4 */
711 wakaba 1.1 rule _CommentDeclaration_ ($doc, $parent) {
712     ?lexmode 'CommentDeclaration';
713    
714     ~? (STRING) {
715     lang:Perl ($data => $token.value) {
716     my $com = $doc-><M::Document.createComment> ($data);
717     $parent-><M::Node.appendChild> ($com);
718     }
719     } else {
720     lang:Perl {
721     my $com = $doc-><M::Document.createComment> ('');
722     $parent-><M::Node.appendChild> ($com);
723     }
724     }
725    
726     ~ (COM) {
727     ?lexmode MarkupDeclaration;
728     } else {
729     ?lexmode MarkupDeclaration;
730     }
731    
732     // ~ (MDC) { }
733 wakaba 1.4 } // _CommentDeclaration
734     _
735     rule _CommentDeclarationDTD ($doc) {
736     ?lexmode 'CommentDeclaration';
737    
738     ~? (STRING) {
739     //
740     }
741    
742     ~ (COM) {
743     ?lexmode MarkupDeclaration;
744     } else {
745     ?lexmode MarkupDeclaration;
746     }
747    
748     ~ (MDC) {
749     ?lexmode DTD;
750     } else {
751     ?lexmode DTD;
752     }
753     } // _CommentDeclarationDTD
754    
755 wakaba 1.1 /*
756     Processing Instruction
757    
758     PI := '<?' PITarget [S *Char - *Char '?>' *Char]
759     '?>' ;; [16]
760     */
761     rule _ProcessingInstruction_ ($doc, $parent) {
762     ?lexmode 'PIName';
763    
764     my $pi;
765    
766     ~ (Name) {
767 wakaba 1.3 lang:Perl ($name => $token.value) : has-error {
768 wakaba 1.1 if (lc $name eq 'xml') {
769 wakaba 1.3 my $location;
770     __CODE{xp|get-location-from-token::
771     $token => {$token},
772     $result => {$location},
773     }__;
774     my $continue = __DOMCore:ERROR{xp|wf-pi-target-is-xml::
775     xp|name => {$name},
776     DOMCore|location => {$location},
777     xp|parent => {$parent},
778     }__;
779     unless ($continue) {
780     __EXCEPTION{DOMLS|PARSE_ERR::
781     }__;
782     }
783     $self->{has_error} = true;
784 wakaba 1.1 }
785     ## TODO: Namespace well-formedness
786     $pi = $doc-><M::Document.createProcessingInstruction>
787     ($name);
788     }
789     }
790    
791     ~ (S) {
792     ?lexmode 'PIData';
793    
794     my $tdata;
795    
796     ~? (DATA) {
797     lang:Perl ($data => $token.value) {
798     $tdata = $data;
799     }
800     } else {
801     lang:Perl {
802     $tdata = '';
803     }
804     }
805    
806     lang:Perl {
807     $pi-><AS::Node.nodeValue> ($tdata);
808     }
809     }
810    
811     lang:Perl {
812     $parent-><M::Node.appendChild> ($pi);
813     ## TODO: PIs in document type declaration subsets
814     }
815    
816     // ~ (PIC) { }
817     } // _ProcessingInstruction_
818 wakaba 1.4
819     rule _ProcessingInstructionDTD ($doc) {
820     ?lexmode 'PIName';
821    
822     ~ (Name) {
823    
824     }
825    
826     ~ (S) {
827     ?lexmode 'PIData';
828    
829     ~? (DATA) {
830    
831     }
832     }
833    
834     ~ (PIC) {
835     ?lexmode DTD;
836     } else {
837     ?lexmode DTD;
838     }
839     } // _ProcessingInstructionDTD
840 wakaba 1.1
841     /*
842     Element content parsing mode
843    
844     element := EmptyElemTag /
845     STag content ETag ;; [39]
846     content := (CharData / element / Reference / CDSect /
847     PI / Comment) ;; [43]
848     */
849     rule Element_ ($doc, $parent) : standalone {
850     ?lexmode 'ElementContent';
851    
852     my $node; // Current "parent" node
853     my $nodes; // Node stack (w/o $current_node)
854     my $type; // Current "parent" element type QName
855     my $types; // Element type stack (w/o $current_type)
856     my $ns; // Current in-scope namespace bindings
857     my $nses; // Namespace binding stack (w/o $current_ns)
858    
859     lang:Perl {
860     $node = $parent;
861     $nodes = [];
862     $type = '';
863     $types = [];
864     $ns = {
865     xml => <Q::xml:>,
866     xmlns => <Q::xmlns:>,
867     };
868     $nses = [];
869     }
870    
871     ~* : name => CONTENT
872     (CharData) {
873     // Character data
874     lang:Perl ($data => $token.value) {
875     $node-><M::Node.appendChild>
876     ($doc-><M::Document.createTextNode> ($data));
877     }
878     } (STAGO) {
879     // Start tag or empty element tag
880    
881     ?lexmode 'StartTag';
882    
883     ~ (Name) {
884     my $attrs;
885     lang:Perl ($name => $token.value) {
886     push @{$types}, $type;
887     $type = $name;
888     $attrs = {};
889     }
890    
891     ~? (S) {
892     &AttributeSpecificationList
893     ($doc => $doc, $attrs => $attrs);
894     }
895    
896     my $el;
897    
898     lang:Perl {
899     push @{$nses}, $ns;
900     $ns = {%$ns};
901    
902     my %gattr;
903     my %lattr;
904     for my $atqname (keys %$attrs) {
905     my ($pfx, $lname) = split /:/, $atqname;
906     if (defined $lname) { ## Global attribute
907     ## TODO: Namespace well-formedness (lname is NCName)
908     if ($pfx eq 'xmlns') {
909     my $nsuri = $attrs->{$atqname}->{value};
910     if ($lname eq 'xml' and
911     $nsuri ne <Q::xml:>) {
912     ## TODO: error
913     } elsif ($lname eq 'xmlns') {
914     ## TODO: error
915     }
916     if ($nsuri eq '') {
917     ## TODO: error in XML 1.0
918     } elsif ($nsuri eq <Q::xml:> and
919     $lname ne 'xml') {
920     ## TODO: error
921     } elsif ($nsuri eq <Q::xmlns:>) {
922     ## TODO: error
923     }
924     $ns->{$lname} = $attrs->{$atqname}->{value};
925     delete $ns->{$lname} unless length $ns->{$lname};
926     } elsif ($pfx eq '') {
927     ## TODO: pfx is not NCName error
928     } else {
929     if ($gattr{$pfx}->{$lname}) {
930     ## TODO: Namespace well-formedness error
931     }
932     }
933     $gattr{$pfx}->{$lname} = $attrs->{$atqname};
934     } else { ## Local attribute
935     if ($pfx eq 'xmlns') {
936     $ns->{''} = $attrs->{xmlns}->{value};
937     delete $ns->{''} unless length $ns->{''};
938     } else {
939     $lattr{$pfx} = $attrs->{$atqname};
940     }
941     }
942     }
943    
944     my ($pfx, $lname) = split /:/, $type;
945     my $nsuri;
946     ## TODO: lname is NCName?
947     if (defined $lname) { ## Prefixed namespace
948     if ($pfx eq '') {
949     ## TODO: pfx is not NCName error
950     }
951     if (defined $ns->{$pfx}) {
952     $nsuri = $ns->{$pfx};
953     } else {
954     ## TODO: namespace ill-formed
955     }
956     } else { ## Default namespace
957     $nsuri = $ns->{''};
958     }
959    
960     $el = $doc-><M::Document.createElementNS>
961     ($nsuri, $type);
962    
963     if ($attrs->{xmlns}) {
964     my $attr = $doc-><M::Document.createAttributeNS>
965     (<Q::xmlns:>, 'xmlns');
966     for (@{$attrs->{xmlns}->{nodes}}) {
967     $attr-><M::Node.appendChild> ($_);
968     }
969     $el-><M::Element.setAttributeNodeNS> ($attr);
970     }
971    
972     for my $lname (keys %lattr) {
973     my $attr = $doc-><M::Document.createAttributeNS>
974     (null, $lname);
975     for (@{$lattr{$lname}->{nodes}}) {
976     $attr-><M::Node.appendChild> ($_);
977     }
978     $el-><M::Element.setAttributeNodeNS> ($attr);
979     }
980    
981     for my $pfx (keys %gattr) {
982     for my $lname (keys %{$gattr{$pfx}}) {
983     my $attr = $doc-><M::Document.createAttributeNS>
984     ($ns->{$pfx}, $pfx.':'.$lname);
985     for (@{$gattr{$pfx}->{$lname}->{nodes}}) {
986     $attr-><M::Node.appendChild> ($_);
987     }
988     $el-><M::Element.setAttributeNodeNS> ($attr);
989     }
990     }
991    
992     $node-><M::Node.appendChild> ($el);
993     }
994    
995     ~ (TAGC) {
996     lang:Perl {
997     push @{$nodes}, $node;
998     $node = $el;
999     }
1000     ?lexmode ElementContent;
1001     } (MTAGC) {
1002     lang:Perl {
1003     $ns = pop @{$nses};
1004     $type = pop @{$types};
1005     }
1006     ?lexmode ElementContent;
1007     } else {
1008     ?lexmode ElementContent;
1009     }
1010     } else {
1011     ?lexmode ElementContent;
1012     }
1013    
1014     } (ETAGO) {
1015     // End tag
1016    
1017     ?lexmode 'EndTag';
1018    
1019     my $is_docel;
1020    
1021     ~ (Name) {
1022 wakaba 1.3 lang:Perl ($name => $token.value) : has-error {
1023 wakaba 1.1 if ($name eq $type) {
1024     $type = pop @{$types};
1025     if ($type eq '') {
1026     $is_docel = true;
1027     }
1028     $node = pop @{$nodes};
1029     $ns = pop @{$nses};
1030     } else {
1031 wakaba 1.3 my $location;
1032     __CODE{xp|get-location-from-token::
1033     $token => $token,
1034     $result => $location,
1035     }__;
1036     my $continue = __DOMCore:ERROR{xp|wf-element-type-match::
1037     DOMCore:location => {$location},
1038     xp|token => {$token},
1039     xp|expected-element-type => {$type},
1040     xp|actual-element-type => {$name},
1041     xp|node => {$node},
1042     }__;
1043     unless ($continue) {
1044     __EXCEPTION{DOMLS|PARSE_ERR}__;
1045     }
1046     $self->{has_error} = true;
1047 wakaba 1.1 }
1048     }
1049     }
1050    
1051     ~? (S) { }
1052    
1053     if-true ($is_docel) {
1054 wakaba 1.3 lang:Perl : has-error {
1055 wakaba 1.1 if (@{$types}) {
1056 wakaba 1.3 my $location;
1057     __CODE{xp|get-location-from-token::
1058     $token => $token,
1059     $result => $location,
1060     }__;
1061     for my $type (reverse @{$types}) {
1062     my $continue = __DOMCore:ERROR{xp|wf-no-end-tag::
1063     DOMCore:location => {$location},
1064     xp|token => {$token},
1065     xp|expected-element-type => {$type},
1066     xp|node => {$node},
1067     }__;
1068     unless ($continue) {
1069     __EXCEPTION{DOMLS|PARSE_ERR}__;
1070     }
1071     $node = shift @{$nodes};
1072     }
1073     $self->{has_error} = true;
1074 wakaba 1.1 }
1075     }
1076     return;
1077     }
1078    
1079     ~ (TAGC) {
1080     ?lexmode ElementContent;
1081     } else {
1082     ?lexmode 'ElementContent';
1083     }
1084    
1085     } (HCRO) {
1086     &_HexadecimalCharacterReference_
1087     ($doc => $doc, $parent => $node);
1088    
1089     ~ (REFC) {
1090     ?lexmode 'ElementContent';
1091     } else {
1092     ?lexmode ElementContent;
1093     }
1094     } (CRO) {
1095     &_NumericCharacterReference_
1096     ($doc => $doc, $parent => $node);
1097    
1098     ~ (REFC) {
1099     ?lexmode 'ElementContent';
1100     } else {
1101     ?lexmode ElementContent;
1102     }
1103     } (ERO) {
1104     &_GeneralEntityReference_
1105     ($doc => $doc, $parent => $node);
1106    
1107     ~ (REFC) {
1108     ?lexmode 'ElementContent';
1109     } else {
1110     ?lexmode ElementContent;
1111     }
1112     } (CDO) {
1113     &_CommentDeclaration_ ($doc => $doc, $parent => $node);
1114    
1115     ~ (MDC) {
1116     ?lexmode ElementContent;
1117     } else {
1118     ?lexmode ElementContent;
1119     }
1120     } (CDSO) {
1121     &_CDATASection_ ($doc => $doc, $parent => $node);
1122    
1123     ~ (MSE) {
1124     ?lexmode 'ElementContent';
1125     } else {
1126     ?lexmode ElementContent;
1127     }
1128     } (PIO) {
1129     &_ProcessingInstruction_ ($doc => $doc, $parent => $node);
1130    
1131     ~ (PIC) {
1132     ?lexmode 'ElementContent';
1133     } else {
1134     ?lexmode ElementContent;
1135     }
1136     }
1137 wakaba 1.3
1138     ~ (#NONE) { }
1139 wakaba 1.1 } // Element_
1140    
1141     rule AttributeSpecificationList ($doc, $attrs)
1142     : standalone
1143     {
1144     ?lexmode 'StartTag';
1145    
1146     my $i;
1147     lang:Perl {
1148     $i = 0;
1149     }
1150    
1151     ~* (Name) {
1152     my $atqname;
1153     lang:Perl ($name => $token.value) {
1154     $atqname = $name;
1155     }
1156    
1157     my $vals;
1158     lang:Perl {
1159     if ($attrs->{$atqname}) {
1160 wakaba 1.3 my $location;
1161     __CODE{xp|get-location-from-token::
1162     $token => $token,
1163     $result => $location,
1164     }__;
1165     my $continue = __DOMCore:ERROR{xp|wf-unique-att-spec::
1166     DOMCore:location => {$location},
1167     xp|token => {$token},
1168     xp|name => {$atqname},
1169     }__;
1170     unless ($continue) {
1171     __EXCEPTION{DOMLS|PARSE_ERR}__;
1172     }
1173     $self->{has_error} = true;
1174 wakaba 1.1 }
1175    
1176     $vals = $attrs->{$atqname} = {
1177     nodes => [],
1178     value => '',
1179     index => $i++,
1180     };
1181     }
1182 wakaba 1.3
1183     ~? (S) { }
1184     ~ (VI) { }
1185     ~? (S) { }
1186 wakaba 1.1
1187     ~ (LIT) {
1188     &_AttributeValueSpecification_
1189     ($doc => $doc, $vals => $vals);
1190    
1191     ~ (LIT) {
1192     ?lexmode StartTag;
1193     } else {
1194     ?lexmode StartTag;
1195     }
1196     } (LITA) {
1197     &_AttributeValueSpecificationA_
1198     ($doc => $doc, $vals => $vals);
1199    
1200     ~ (LITA) {
1201     ?lexmode StartTag;
1202     } else {
1203     ?lexmode StartTag;
1204     }
1205     }
1206     } (S) : separator : terminator? { }
1207     } // AttributeSpecificationList
1208    
1209     rule _AttributeValueSpecification_ ($doc, $vals) {
1210     // ~ (LIT) { }
1211     ?lexmode 'AttributeValueLiteral';
1212    
1213     ~* (STRING) {
1214     lang:Perl ($value => $token.value) {
1215     $value =~ s/[\x09\x0A\x0D]/ /g;
1216     my $text = $doc-><M::Document.createTextNode> ($value);
1217     push @{$vals->{nodes}}, $text;
1218     $vals->{value} .= $value;
1219     }
1220     } (HCRO) {
1221     &_HexadecimalCharacterReferenceV_
1222     ($doc => $doc, $vals => $vals);
1223    
1224     ~ (REFC) {
1225     ?lexmode AttributeValueLiteral;
1226     } else {
1227     ?lexmode AttributeValueLiteral;
1228     }
1229     } (CRO) {
1230     &_NumericCharacterReferenceV_
1231     ($doc => $doc, $vals => $vals);
1232    
1233     ~ (REFC) {
1234     ?lexmode AttributeValueLiteral;
1235     } else {
1236     ?lexmode AttributeValueLiteral;
1237     }
1238     } (ERO) {
1239     // TODO: Attribute value normalization
1240     &_GeneralEntityReferenceV_
1241     ($doc => $doc, $vals => $vals);
1242    
1243     ~ (REFC) {
1244     ?lexmode AttributeValueLiteral;
1245     } else {
1246     ?lexmode AttributeValueLiteral;
1247     }
1248     }
1249    
1250     // ~ (LIT) { } (LITA) { }
1251     } // _AttributeValueSpecification_
1252    
1253     rule _AttributeValueSpecificationA_ ($doc, $vals) {
1254     // ~ (LITA) { }
1255     ?lexmode 'AttributeValueLiteralA';
1256    
1257     ~* (STRING) {
1258     lang:Perl ($value => $token.value) {
1259     $value =~ s/[\x09\x0A\x0D]/ /g;
1260     my $text = $doc-><M::Document.createTextNode> ($value);
1261     push @{$vals->{nodes}}, $text;
1262     $vals->{value} .= $value;
1263     }
1264     } (HCRO) {
1265     &_HexadecimalCharacterReferenceV_
1266     ($doc => $doc, $vals => $vals);
1267    
1268     ~ (REFC) {
1269     ?lexmode AttributeValueLiteralA;
1270     } else {
1271     ?lexmode AttributeValueLiteralA;
1272     }
1273     } (CRO) {
1274     &_NumericCharacterReferenceV_
1275     ($doc => $doc, $vals => $vals);
1276    
1277     ~ (REFC) {
1278     ?lexmode AttributeValueLiteralA;
1279     } else {
1280     ?lexmode AttributeValueLiteralA;
1281     }
1282     } (ERO) {
1283     // TODO: Attribute value normalization
1284     &_GeneralEntityReferenceV_
1285     ($doc => $doc, $vals => $vals);
1286    
1287     ~ (REFC) {
1288     ?lexmode AttributeValueLiteralA;
1289     } else {
1290     ?lexmode AttributeValueLiteralA;
1291     }
1292     }
1293    
1294     // ~ (LITA) { }
1295     } // _AttributeValueSpecificationA_
1296    
1297     /*
1298     CDATA Section Content Parsing Mode
1299     */
1300     rule _CDATASection_ ($doc, $parent) {
1301     ?lexmode 'CDATASectionContent';
1302    
1303     my $cdata;
1304    
1305 wakaba 1.2 ~? (CData) {
1306 wakaba 1.1 lang:Perl ($data => $token.value) {
1307     $cdata = $data;
1308     }
1309     } else {
1310     lang:Perl {
1311     $cdata = '';
1312     }
1313     }
1314    
1315     lang:Perl {
1316     my $cdsect = $doc-><M::Document.createCDATASection>
1317     ($cdata);
1318     $parent-><M::Node.appendChild> ($cdsect);
1319     }
1320    
1321     // ~ (MSE) { }
1322     } // _CDATASection_
1323    
1324     rule _NumericCharacterReference_ ($doc, $parent) {
1325     ?lexmode 'NumericCharacterReference';
1326    
1327     ~ (NUMBER) {
1328 wakaba 1.3 lang:Perl ($num => $token.value) : has-error {
1329     $num += 0;
1330     unless (
1331     ($self->{xml_version} eq '1.0' and
1332     ((0x0020 <= $num and $num <= 0xD7FF) or
1333     (0xE000 <= $num and $num <= 0xFFFD) or
1334     (0x10000 <= $num and $num <= 0x10FFFF) or
1335     $num == 0x9 or $num == 0xA or $num == 0xD)) or
1336     ($self->{xml_version} eq '1.1' and
1337     ((0x0001 <= $num and $num <= 0xD7FF) or
1338     (0xE000 <= $num and $num <= 0xFFFD) or
1339     (0x10000 <= $num and $num <= 0x10FFFF)))
1340     ) {
1341     my $location;
1342     __CODE{xp|get-location-from-token::
1343     $token => $token,
1344     $result => $location,
1345     }__;
1346     my $continue = __DOMCore:ERROR{xp|wf-legal-character::
1347     DOMCore:location => {$location},
1348     xp|token => {$token},
1349     xp|character-number => {$num},
1350     xp|parent => {$parent},
1351     }__;
1352     unless ($continue) {
1353     __EXCEPTION{DOMLS|PARSE_ERR}__;
1354     }
1355     $self->{has_error} = true;
1356     }
1357     my $ncr = $doc-><M::Document.createTextNode> (chr $num);
1358 wakaba 1.1 $parent-><M::Node.appendChild> ($ncr);
1359     }
1360     }
1361    
1362     // ~ (REFC) { }
1363     } // _NumericCharacterReference_
1364    
1365     rule _NumericCharacterReferenceV_ ($doc, $vals) {
1366     ?lexmode 'NumericCharacterReference';
1367    
1368     ~ (NUMBER) {
1369 wakaba 1.3 lang:Perl ($num => $token.value) : has-error {
1370     $num += 0;
1371     unless (
1372     ($self->{xml_version} eq '1.0' and
1373     ((0x0020 <= $num and $num <= 0xD7FF) or
1374     (0xE000 <= $num and $num <= 0xFFFD) or
1375     (0x10000 <= $num and $num <= 0x10FFFF) or
1376     $num == 0x9 or $num == 0xA or $num == 0xD)) or
1377     ($self->{xml_version} eq '1.1' and
1378     ((0x0001 <= $num and $num <= 0xD7FF) or
1379     (0xE000 <= $num and $num <= 0xFFFD) or
1380     (0x10000 <= $num and $num <= 0x10FFFF)))
1381     ) {
1382     my $location;
1383     __CODE{xp|get-location-from-token::
1384     $token => $token,
1385     $result => $location,
1386     }__;
1387     my $continue = __DOMCore:ERROR{xp|wf-legal-character::
1388     DOMCore:location => {$location},
1389     xp|token => {$token},
1390     xp|character-number => {$num},
1391     }__;
1392     unless ($continue) {
1393     __EXCEPTION{DOMLS|PARSE_ERR}__;
1394     }
1395     $self->{has_error} = true;
1396     }
1397 wakaba 1.1 my $ncr = $doc-><M::Document.createTextNode>
1398     (my $char = chr (0+$num));
1399     push @{$vals->{nodes}}, $ncr;
1400     $vals->{value} .= $char;
1401     }
1402     }
1403    
1404     // ~ (REFC) { }
1405     } // _NumericCharacterReferenceV_
1406    
1407     rule _HexadecimalCharacterReference_ ($doc, $parent) {
1408     ?lexmode 'HexadecimalCharacterReference';
1409    
1410     ~ (Hex) {
1411 wakaba 1.3 lang:Perl ($num => $token.value) : has-error {
1412     $num += 0;
1413     unless (
1414     ($self->{xml_version} eq '1.0' and
1415     ((0x0020 <= $num and $num <= 0xD7FF) or
1416     (0xE000 <= $num and $num <= 0xFFFD) or
1417     (0x10000 <= $num and $num <= 0x10FFFF) or
1418     $num == 0x9 or $num == 0xA or $num == 0xD)) or
1419     ($self->{xml_version} eq '1.1' and
1420     ((0x0001 <= $num and $num <= 0xD7FF) or
1421     (0xE000 <= $num and $num <= 0xFFFD) or
1422     (0x10000 <= $num and $num <= 0x10FFFF)))
1423     ) {
1424     my $location;
1425     __CODE{xp|get-location-from-token::
1426     $token => $token,
1427     $result => $location,
1428     }__;
1429     my $continue = __DOMCore:ERROR{xp|wf-legal-character::
1430     DOMCore:location => {$location},
1431     xp|token => {$token},
1432     xp|character-number => {$num},
1433     xp|parent => {$parent},
1434     }__;
1435     unless ($continue) {
1436     __EXCEPTION{DOMLS|PARSE_ERR}__;
1437     }
1438     $self->{has_error} = true;
1439     }
1440 wakaba 1.1 my $ncr = $doc-><M::Document.createTextNode>
1441     (chr hex $num);
1442     $parent-><M::Node.appendChild> ($ncr);
1443     }
1444     }
1445    
1446     // ~ (REFC) { }
1447     } // _HexadecimalCharacterReference_
1448    
1449 wakaba 1.3 rule _HexadecimalCharacterReferenceV_ ($doc, $vals) {
1450 wakaba 1.1 ?lexmode 'HexadecimalCharacterReference';
1451    
1452     ~ (Hex) {
1453 wakaba 1.3 lang:Perl ($num => $token.value) : has-error {
1454     $num += 0;
1455     unless (
1456     ($self->{xml_version} eq '1.0' and
1457     ((0x0020 <= $num and $num <= 0xD7FF) or
1458     (0xE000 <= $num and $num <= 0xFFFD) or
1459     (0x10000 <= $num and $num <= 0x10FFFF) or
1460     $num == 0x9 or $num == 0xA or $num == 0xD)) or
1461     ($self->{xml_version} eq '1.1' and
1462     ((0x0001 <= $num and $num <= 0xD7FF) or
1463     (0xE000 <= $num and $num <= 0xFFFD) or
1464     (0x10000 <= $num and $num <= 0x10FFFF)))
1465     ) {
1466     my $location;
1467     __CODE{xp|get-location-from-token::
1468     $token => $token,
1469     $result => $location,
1470     }__;
1471     my $continue = __DOMCore:ERROR{xp|wf-legal-character::
1472     DOMCore:location => {$location},
1473     xp|token => {$token},
1474     xp|character-number => {$num},
1475     }__;
1476     unless ($continue) {
1477     __EXCEPTION{DOMLS|PARSE_ERR}__;
1478     }
1479     $self->{has_error} = true;
1480     }
1481 wakaba 1.1 my $ncr = $doc-><M::Document.createTextNode>
1482     (my $char = chr hex $num);
1483     push @{$vals->{nodes}}, $ncr;
1484     $vals->{value} .= $char;
1485     }
1486     }
1487    
1488     // ~ (REFC) { }
1489     } // _HexadecimalCharacterReferenceV_
1490    
1491     rule _GeneralEntityReference_ ($doc, $parent) {
1492     // TODO: Expansion
1493     ?lexmode 'EntityReference';
1494    
1495     ~ (Name) {
1496     lang:Perl ($name => $token.value) {
1497     ## TODO: Namespace well-formedness
1498     ## TODO: Entity declared constraints
1499     my $er = $doc-><M::Document.createEntityReference>
1500     ($name);
1501     $parent-><M::Node.appendChild> ($er);
1502     }
1503     }
1504    
1505     // ~ (REFC) { }
1506     } // _GeneralEntityReference_
1507    
1508     rule _GeneralEntityReferenceV_ ($doc, $vals) {
1509     // TODO: Expansion
1510     ?lexmode 'EntityReference';
1511    
1512     ~ (Name) {
1513     lang:Perl ($name => $token.value) {
1514     ## TODO: Namespace well-formedness
1515     ## TODO: Entity declared constraints
1516     my $er = $doc-><M::Document.createEntityReference>
1517     ($name);
1518     push @{$vals->{nodes}}, $er;
1519     }
1520     }
1521    
1522     // ~ (REFC) { }
1523     } // _GeneralEntityReferenceV_
1524    
1525     /*
1526 wakaba 1.4 Document Type Declaration
1527 wakaba 1.1 */
1528 wakaba 1.4 rule _DocumentTypeDeclaration_ ($doc) {
1529     ?lexmode MarkupDeclaration;
1530    
1531     ~ (Name == 'DOCTYPE') { }
1532    
1533     ~ (S) { }
1534    
1535     // Document type name
1536     ~ (Name) {
1537    
1538     }
1539    
1540     ~? (S) {
1541     ~? (Name == 'PUBLIC') {
1542     ~ (S) { }
1543    
1544     &PubidLiteral ($doc => $doc);
1545    
1546     ~ (S) { }
1547    
1548     &SystemLiteral ($doc => $doc);
1549    
1550     ~? (S) { }
1551     } (Name == 'SYSTEM') {
1552     ~ (S) { }
1553    
1554     &SystemLiteral ($doc => $doc);
1555    
1556     ~? (S) { }
1557     }
1558     }
1559    
1560     ~? (DSO) {
1561     &InternalSubset ($doc => $doc);
1562    
1563     ~ (DSC) {
1564     ?lexmode MarkupDeclaration;
1565     } else {
1566     ?lexmode MarkupDeclaration;
1567     }
1568    
1569     ~? (S) { }
1570     }
1571    
1572     // TODO: set $self->{standalone} true if only internal subset
1573     // with no param ref
1574    
1575     // ~ (MDC) { }
1576     } // _DocumentTypeDeclaration_
1577    
1578     rule PubidLiteral ($doc) {
1579     ~ (LIT) {
1580     ?lexmode SystemLiteral;
1581    
1582     ~? (STRING) {
1583     // TODO: Charrange check & normalization is required
1584    
1585     }
1586    
1587     ~ (LIT) {
1588     ?lexmode MarkupDeclaration;
1589     } else {
1590     ?lexmode MarkupDeclaration;
1591     }
1592     } (LITA) {
1593     ?lexmode SystemLiteralA;
1594    
1595     ~? (STRING) {
1596     // TODO: Charrange check & normalization is required
1597    
1598     }
1599    
1600     ~ (LITA) {
1601     ?lexmode MarkupDeclaration;
1602     } else {
1603     ?lexmode MarkupDeclaration;
1604     }
1605     }
1606     } // PubidLiteral
1607    
1608     rule SystemLiteral ($doc) {
1609     ~ (LIT) {
1610     ?lexmode SystemLiteral;
1611     &_SystemLiteral ($doc => $doc);
1612     } (LITA) {
1613     ?lexmode SystemLiteralA;
1614     &_SystemLiteral ($doc => $doc);
1615     }
1616     } // SystemLiteral
1617    
1618     rule _SystemLiteral ($doc) {
1619     ~? (STRING) {
1620    
1621     }
1622    
1623     ~ (LIT) {
1624     ?lexmode MarkupDeclaration;
1625     } (LITA) {
1626     ?lexmode MarkupDeclaration;
1627     } else {
1628     ?lexmode MarkupDeclaration;
1629     }
1630     } // _SystemLiteral
1631    
1632     /*
1633     DTD Internal Subset
1634    
1635     intSubset := *(markupdecl / DeclSep) ;; [28b]
1636     */
1637     rule InternalSubset ($doc) {
1638     ?lexmode DTD;
1639    
1640     ~* (MDO) {
1641     ?lexmode MarkupDeclaration;
1642    
1643     ~ (Name == 'ELEMENT') {
1644     &_ElementDeclaration ($doc => $doc);
1645     } (Name == 'ATTLIST') {
1646     &_AttlistDeclaration ($doc => $doc);
1647     } (Name == 'ENTITY') {
1648     &_EntityDeclaration ($doc => $doc);
1649     } (Name == 'NOTATION') {
1650     &_NotationDeclaration ($doc => $doc);
1651     }
1652     } (S) {
1653     //
1654     } (CDO) {
1655     &_CommentDeclarationDTD ($doc => $doc);
1656     } (PIO) {
1657     &_ProcessingInstructionDTD ($doc => $doc);
1658     } (PERO) {
1659     ?lexmode EntityReference;
1660    
1661     ~ (Name) {
1662    
1663     }
1664    
1665     ~ (REFC) {
1666     ?lexmode DTD;
1667     } else {
1668     ?lexmode DTD;
1669     }
1670     }
1671     } // InternalSubset
1672    
1673     rule _ElementDeclaration ($doc) {
1674     // ~ (MDO) { }
1675     // ?lexmode MarkupDeclaration
1676     // ~ (Name == 'Element') { }
1677    
1678     ~ (S) { }
1679    
1680     ~ (Name) {
1681    
1682     }
1683    
1684     ?lexmode ElementDeclaration;
1685    
1686     ~ (S) { }
1687    
1688     // contentspec
1689     ~ (MGO) {
1690     &_ContentModel ($doc => $doc);
1691     } (Name == 'EMPTY') {
1692    
1693     } (Name == 'ANY') {
1694    
1695     }
1696    
1697     ~? (S) { }
1698    
1699     ~ (MDC) {
1700     ?lexmode DTD;
1701     } else {
1702     ?lexmode DTD;
1703     }
1704     } // _ElementDeclaration
1705    
1706     rule _ContentModel ($doc) {
1707     // ~ (MGO) { }
1708    
1709     ~? (S) { }
1710    
1711     ~ (Name) {
1712     // Element content model
1713     &_ModelGroup ($doc => $doc)
1714     : unshift-current-token;
1715    
1716     ~? (OPT) {
1717    
1718     } (REP) {
1719    
1720     } (PLUS) {
1721    
1722     }
1723    
1724     } (MDO) {
1725     &_ModelGroup ($doc => $doc)
1726     : unshift-current-token;
1727    
1728     ~? (OPT) {
1729    
1730     } (REP) {
1731    
1732     } (PLUS) {
1733    
1734     }
1735    
1736     } (PCDATA) {
1737     // Mixed content declaration
1738     ~? (S) { }
1739    
1740     ~* (OR) {
1741     ~? (S) { }
1742    
1743     ~ (Name) {
1744    
1745     }
1746    
1747     ~? (S) { }
1748     }
1749    
1750     ~ (MGC) { }
1751    
1752     ~? (REP) {
1753    
1754     } else {
1755     // TODO: error if |Name|
1756     }
1757    
1758    
1759     }
1760     } // _ContentModel
1761    
1762     rule _ModelGroup ($doc)
1763     : standalone
1764     : recursive
1765     {
1766     // ~ (MGO) { }
1767     // ~? (S) { }
1768    
1769     &ContentParticle ($doc => $doc);
1770    
1771     ~? (S) { }
1772    
1773     ~? (OR) {
1774     ~? (S) { }
1775    
1776     &ContentParticle ($doc => $doc);
1777    
1778     ~? (S) { }
1779    
1780     ~* (OR) {
1781     ~? (S) { }
1782    
1783     &ContentParticle ($doc => $doc);
1784    
1785     ~? (S) { }
1786     }
1787    
1788     } (SEQ) {
1789     ~? (S) { }
1790    
1791     &ContentParticle ($doc => $doc);
1792    
1793     ~? (S) { }
1794    
1795     ~* (SEQ) {
1796     ~? (S) { }
1797    
1798     &ContentParticle ($doc => $doc);
1799    
1800     ~? (S) { }
1801     }
1802    
1803     }
1804    
1805     ~ (MGC) { }
1806     } // _ModelGroup
1807    
1808     rule ContentParticle ($doc) {
1809     ~ (Name) {
1810    
1811     } (MGO) {
1812     ~? (S) { }
1813    
1814     &_ModelGroup ($doc => $doc);
1815     }
1816    
1817     ~? (OPT) {
1818    
1819     } (REP) {
1820    
1821     } (PLUS) {
1822    
1823     }
1824     } // ContentParticle
1825    
1826     rule _AttlistDeclaration ($doc) {
1827     // ~ (MDO) { }
1828     // ~ (Name == 'ATTLIST') { }
1829    
1830     ?lexmode AttlistDeclaration;
1831    
1832     ~ (S) { }
1833    
1834     ~ (Name) {
1835    
1836     }
1837    
1838     ~? (S) { }
1839    
1840     ~* (Name) {
1841    
1842     ~ (S) { }
1843    
1844     // AttType
1845     ~ (Name == 'NOTATION') {
1846     ~ (S) { }
1847    
1848     ~ (EGO) {
1849     ~? (S) { }
1850    
1851     ~ (Name) {
1852    
1853     ~? (S) { }
1854     } (OR) : separator {
1855     ~? (S) { }
1856     }
1857    
1858     ~ (EGC) { }
1859     }
1860     } (Name) {
1861     // TODO: check keyword
1862    
1863     } (EGO) {
1864     ?lexmode Enumeration;
1865    
1866     ~? (S) { }
1867    
1868     ~ (Nmtoken) {
1869    
1870     ~? (S) { }
1871     } (OR) : separator {
1872     ~? (S) { }
1873     }
1874    
1875     ~ (EGC) {
1876     ?lexmode AttlistDeclaration;
1877     } else {
1878     ?lexmode AttlistDeclaration;
1879     }
1880    
1881     }
1882    
1883     ~ (S) { }
1884    
1885     // DefaultDecl
1886     ~ (RNI) {
1887     ~ (Name == 'REQUIRED') {
1888    
1889     } (Name == 'IMPLIED') {
1890    
1891     } (Name == 'FIXED') {
1892     ~ (S) { }
1893    
1894     ~ (LIT) {
1895     my $vals;
1896     lang:Perl {
1897     $vals = [];
1898     }
1899    
1900     &_AttributeValueSpecification_ ($doc => $doc, $vals => $vals);
1901    
1902     ~ (LIT) {
1903     ?lexmode AttlistDeclaration;
1904     } else {
1905     ?lexmode AttlistDeclaration;
1906     }
1907     } (LITA) {
1908     my $vals;
1909     lang:Perl {
1910     $vals = [];
1911     }
1912    
1913     &_AttributeValueSpecificationA_ ($doc => $doc, $vals => $vals);
1914    
1915     ~ (LIT) {
1916     ?lexmode AttlistDeclaration;
1917     } else {
1918     ?lexmode AttlistDeclaration;
1919     }
1920     }
1921     }
1922    
1923     } (LIT) {
1924     my $vals;
1925     lang:Perl {
1926     $vals = [];
1927     }
1928    
1929     &_AttributeValueSpecification_ ($doc => $doc, $vals => $vals);
1930    
1931     ~ (LIT) {
1932     ?lexmode AttlistDeclaration;
1933     } else {
1934     ?lexmode AttlistDeclaration;
1935     }
1936     } (LITA) {
1937     my $vals;
1938     lang:Perl {
1939     $vals = [];
1940     }
1941    
1942     &_AttributeValueSpecificationA_ ($doc => $doc, $vals => $vals);
1943    
1944     ~ (LITA) {
1945     ?lexmode AttlistDeclaration;
1946     } else {
1947     ?lexmode AttlistDeclaration;
1948     }
1949     }
1950    
1951     } (S) : separator : terminator? {
1952     //
1953     }
1954    
1955     ~ (MDC) {
1956     ?lexmode DTD;
1957     } else {
1958     ?lexmode DTD;
1959     }
1960     } // _AttlistDeclaration
1961    
1962     rule _EntityDeclaration ($doc) {
1963     // ~ (MDO) { }
1964     // ~ (Name == ENTITY) { }
1965    
1966     ~ (S) { }
1967    
1968     ~? (PERO) {
1969     ~ (S) { }
1970     }
1971    
1972     ~ (Name) {
1973    
1974     }
1975    
1976     ~ (S) { }
1977    
1978     ~ (LIT) {
1979     &_EntityValue ($doc => $doc);
1980     } (LITA) {
1981     &_EntityValueA ($doc => $doc);
1982     } (Name == 'PUBLIC') {
1983     ~ (S) { }
1984    
1985     &PubidLiteral ($doc => $doc);
1986    
1987     ~ (S) { }
1988    
1989     &SystemLiteral ($doc => $doc);
1990     } (Name == 'SYSTEM') {
1991     ~ (S) { }
1992    
1993     &SystemLiteral ($doc => $doc);
1994     }
1995    
1996     ~? (S) {
1997     ~? (Name == 'NDATA') {
1998     // TODO: error if parameter entity
1999    
2000     ~ (S) { }
2001    
2002     ~ (Name) {
2003    
2004     }
2005    
2006     ~? (S) { }
2007     }
2008     }
2009    
2010     ~ (MDC) {
2011     ?lexmode DTD;
2012     } else {
2013     ?lexmode DTD;
2014     }
2015     } // _EntityDeclaration
2016    
2017     rule _NotationDeclaration ($doc) {
2018     // ~ (MDO) { }
2019     // ~ (Name == NOTATION) { }
2020    
2021     ~ (S) { }
2022    
2023     ~ (Name) {
2024    
2025     }
2026    
2027     ~ (S) { }
2028    
2029     ~ (Name == 'PUBLIC') {
2030     ~ (S) { }
2031    
2032     &PubidLiteral ($doc => $doc);
2033    
2034     ~? (S) {
2035     ~? (LIT) {
2036     ?lexmode SystemLiteral;
2037     &_SystemLiteral ($doc => $doc);
2038    
2039     ~? (S) { }
2040     } (LITA) {
2041     ?lexmode SystemLiteralA;
2042     &_SystemLiteral ($doc => $doc);
2043    
2044     ~? (S) { }
2045     }
2046     }
2047     } (Name == 'SYSTEM') {
2048     ~ (S) { }
2049    
2050     &SystemLiteral ($doc => $doc);
2051    
2052     ~? (S) { }
2053     }
2054    
2055     ~ (MDC) {
2056     ?lexmode DTD;
2057     } else {
2058     ?lexmode DTD;
2059     }
2060     } // _NotationDeclaration
2061    
2062     rule _EntityValue ($doc) {
2063     ?lexmode EntityValue;
2064    
2065     my $vals;
2066     lang:Perl {
2067     $vals = [];
2068     }
2069    
2070     ~* (STRING) {
2071    
2072     } (PERO) {
2073     ?lexmode EntityDeclaration;
2074    
2075     ~ (Name) {
2076    
2077     }
2078    
2079     ~ (REFC) {
2080     ?lexmode EntityValue;
2081     } else {
2082     ?lexmode EntityValue;
2083     }
2084     } (HCRO) {
2085     &_HexadecimalCharacterReferenceV_
2086     ($doc => $doc, $vals => $vals);
2087    
2088     ~ (REFC) {
2089     ?lexmode EntityValue;
2090     } else {
2091     ?lexmode EntityValue;
2092     }
2093     } (CRO) {
2094     &_NumericCharacterReferenceV_
2095     ($doc => $doc, $vals => $vals);
2096    
2097     ~ (REFC) {
2098     ?lexmode EntityValue;
2099     } else {
2100     ?lexmode EntityValue;
2101     }
2102     } (ERO) {
2103     &_GeneralEntityReferenceV_
2104     ($doc => $doc, $vals => $vals);
2105    
2106     ~ (REFC) {
2107     ?lexmode EntityValue;
2108     } else {
2109     ?lexmode EntityValue;
2110     }
2111     }
2112    
2113     ~ (LIT) {
2114     ?lexmode MarkupDeclaration;
2115     } (LITA) {
2116     ?lexmode MarkupDeclaration;
2117     } else {
2118     ?lexmode MarkupDeclaration;
2119     }
2120     } // _EntityValue
2121    
2122     rule _EntityValueA ($doc) {
2123     ?lexmode EntityValueA;
2124    
2125     my $vals;
2126     lang:Perl {
2127     $vals = [];
2128     }
2129    
2130     ~* (STRING) {
2131    
2132     } (PERO) {
2133     ?lexmode EntityDeclaration;
2134    
2135     ~ (Name) {
2136    
2137     }
2138    
2139     ~ (REFC) {
2140     ?lexmode EntityValueA;
2141     } else {
2142     ?lexmode EntityValueA;
2143     }
2144     } (HCRO) {
2145     &_HexadecimalCharacterReferenceV_
2146     ($doc => $doc, $vals => $vals);
2147    
2148     ~ (REFC) {
2149     ?lexmode EntityValueA;
2150     } else {
2151     ?lexmode EntityValueA;
2152     }
2153     } (CRO) {
2154     &_NumericCharacterReferenceV_
2155     ($doc => $doc, $vals => $vals);
2156    
2157     ~ (REFC) {
2158     ?lexmode EntityValueA;
2159     } else {
2160     ?lexmode EntityValueA;
2161     }
2162     } (ERO) {
2163     &_GeneralEntityReferenceV_
2164     ($doc => $doc, $vals => $vals);
2165    
2166     ~ (REFC) {
2167     ?lexmode EntityValueA;
2168     } else {
2169     ?lexmode EntityValueA;
2170     }
2171     }
2172    
2173     ~ (LITA) {
2174     ?lexmode MarkupDeclaration;
2175     } else {
2176     ?lexmode MarkupDeclaration;
2177     }
2178     } // _EntityValueA
2179    
2180    
2181     /*
2182     XML Name
2183     */
2184     lexmode NameChar {
2185     $NameStartChar10 := [
2186     '_' ':'
2187     // Letter
2188     // BaseChar
2189     U+0041..U+005A U+0061..U+007A U+00C0..U+00D6
2190     U+00D8..U+00F6 U+00F8..U+00FF U+0100..U+0131
2191     U+0134..U+013E U+0141..U+0148 U+014A..U+017E
2192     U+0180..U+01C3 U+01CD..U+01F0 U+01F4..U+01F5
2193     U+01FA..U+0217 U+0250..U+02A8 U+02BB..U+02C1
2194     U+0386 U+0388..U+038A U+038C U+038E..U+03A1
2195     U+03A3..U+03CE U+03D0..U+03D6 U+03DA U+03DC
2196     U+03DE U+03E0 U+03E2..U+03F3 U+0401..U+040C
2197     U+040E..U+044F U+0451..U+045C U+045E..U+0481
2198     U+0490..U+04C4 U+04C7..U+04C8 U+04CB..U+04CC
2199     U+04D0..U+04EB U+04EE..U+04F5 U+04F8..U+04F9
2200     U+0531..U+0556 U+0559 U+0561..U+0586
2201     U+05D0..U+05EA U+05F0..U+05F2 U+0621..U+063A
2202     U+0641..U+064A U+0671..U+06B7 U+06BA..U+06BE
2203     U+06C0..U+06CE U+06D0..U+06D3 U+06D5
2204     U+06E5..U+06E6 U+0905..U+0939 U+093D
2205     U+0958..U+0961 U+0985..U+098C U+098F..U+0990
2206     U+0993..U+09A8 U+09AA..U+09B0 U+09B2
2207     U+09B6..U+09B9 U+09DC..U+09DD U+09DF..U+09E1
2208     U+09F0..U+09F1 U+0A05..U+0A0A U+0A0F..U+0A10
2209     U+0A13..U+0A28 U+0A2A..U+0A30 U+0A32..U+0A33
2210     U+0A35..U+0A36 U+0A38..U+0A39 U+0A59..U+0A5C
2211     U+0A5E U+0A72..U+0A74 U+0A85..U+0A8B U+0A8D
2212     U+0A8F..U+0A91 U+0A93..U+0AA8 U+0AAA..U+0AB0
2213     U+0AB2..U+0AB3 U+0AB5..U+0AB9 U+0ABD U+0AE0
2214     U+0B05..U+0B0C U+0B0F..U+0B10 U+0B13..U+0B28
2215     U+0B2A..U+0B30 U+0B32..U+0B33 U+0B36..U+0B39
2216     U+0B3D U+0B5C..U+0B5D U+0B5F..U+0B61
2217     U+0B85..U+0B8A U+0B8E..U+0B90 U+0B92..U+0B95
2218     U+0B99..U+0B9A U+0B9C U+0B9E..U+0B9F
2219     U+0BA3..U+0BA4 U+0BA8..U+0BAA U+0BAE..U+0BB5
2220     U+0BB7..U+0BB9 U+0C05..U+0C0C U+0C0E..U+0C10
2221     U+0C12..U+0C28 U+0C2A..U+0C33 U+0C35..U+0C39
2222     U+0C60..U+0C61 U+0C85..U+0C8C U+0C8E..U+0C90
2223     U+0C92..U+0CA8 U+0CAA..U+0CB3 U+0CB5..U+0CB9
2224     U+0CDE U+0CE0..U+0CE1 U+0D05..U+0D0C
2225     U+0D0E..U+0D10 U+0D12..U+0D28 U+0D2A..U+0D39
2226     U+0D60..U+0D61 U+0E01..U+0E2E U+0E30
2227     U+0E32..U+0E33 U+0E40..U+0E45 U+0E81..U+0E82
2228     U+0E84 U+0E87..U+0E88 U+0E8A U+0E8D
2229     U+0E94..U+0E97 U+0E99..U+0E9F U+0EA1..U+0EA3
2230     U+0EA5 U+0EA7 U+0EAA..U+0EAB U+0EAD..U+0EAE
2231     U+0EB0 U+0EB2..U+0EB3 U+0EBD U+0EC0..U+0EC4
2232     U+0F40..U+0F47 U+0F49..U+0F69 U+10A0..U+10C5
2233     U+10D0..U+10F6 U+1100 U+1102..U+1103
2234     U+1105..U+1107 U+1109 U+110B..U+110C
2235     U+110E..U+1112 U+113C U+113E U+1140 U+114C
2236     U+114E U+1150 U+1154..U+1155 U+1159
2237     U+115F..U+1161 U+1163 U+1165 U+1167 U+1169
2238     U+116D..U+116E U+1172..U+1173 U+1175 U+119E
2239     U+11A8 U+11AB U+11AE..U+11AF U+11B7..U+11B8
2240     U+11BA U+11BC..U+11C2 U+11EB U+11F0 U+11F9
2241     U+1E00..U+1E9B U+1EA0..U+1EF9 U+1F00..U+1F15
2242     U+1F18..U+1F1D U+1F20..U+1F45 U+1F48..U+1F4D
2243     U+1F50..U+1F57 U+1F59 U+1F5B U+1F5D
2244     U+1F5F..U+1F7D U+1F80..U+1FB4 U+1FB6..U+1FBC
2245     U+1FBE U+1FC2..U+1FC4 U+1FC6..U+1FCC
2246     U+1FD0..U+1FD3 U+1FD6..U+1FDB U+1FE0..U+1FEC
2247     U+1FF2..U+1FF4 U+1FF6..U+1FFC U+2126
2248     U+212A..U+212B U+212E U+2180..U+2182
2249     U+3041..U+3094 U+30A1..U+30FA U+3105..U+312C
2250     U+AC00..U+D7A3
2251     // Ideographic
2252     U+4E00..U+9FA5 U+3007 U+3021..U+3029
2253     ];
2254     $NameChar10 := [
2255     '.' '-' '_' ':'
2256     // Letter
2257     // BaseChar
2258     U+0041..U+005A U+0061..U+007A U+00C0..U+00D6
2259     U+00D8..U+00F6 U+00F8..U+00FF U+0100..U+0131
2260     U+0134..U+013E U+0141..U+0148 U+014A..U+017E
2261     U+0180..U+01C3 U+01CD..U+01F0 U+01F4..U+01F5
2262     U+01FA..U+0217 U+0250..U+02A8 U+02BB..U+02C1
2263     U+0386 U+0388..U+038A U+038C U+038E..U+03A1
2264     U+03A3..U+03CE U+03D0..U+03D6 U+03DA U+03DC
2265     U+03DE U+03E0 U+03E2..U+03F3 U+0401..U+040C
2266     U+040E..U+044F U+0451..U+045C U+045E..U+0481
2267     U+0490..U+04C4 U+04C7..U+04C8 U+04CB..U+04CC
2268     U+04D0..U+04EB U+04EE..U+04F5 U+04F8..U+04F9
2269     U+0531..U+0556 U+0559 U+0561..U+0586
2270     U+05D0..U+05EA U+05F0..U+05F2 U+0621..U+063A
2271     U+0641..U+064A U+0671..U+06B7 U+06BA..U+06BE
2272     U+06C0..U+06CE U+06D0..U+06D3 U+06D5
2273     U+06E5..U+06E6 U+0905..U+0939 U+093D
2274     U+0958..U+0961 U+0985..U+098C U+098F..U+0990
2275     U+0993..U+09A8 U+09AA..U+09B0 U+09B2
2276     U+09B6..U+09B9 U+09DC..U+09DD U+09DF..U+09E1
2277     U+09F0..U+09F1 U+0A05..U+0A0A U+0A0F..U+0A10
2278     U+0A13..U+0A28 U+0A2A..U+0A30 U+0A32..U+0A33
2279     U+0A35..U+0A36 U+0A38..U+0A39 U+0A59..U+0A5C
2280     U+0A5E U+0A72..U+0A74 U+0A85..U+0A8B U+0A8D
2281     U+0A8F..U+0A91 U+0A93..U+0AA8 U+0AAA..U+0AB0
2282     U+0AB2..U+0AB3 U+0AB5..U+0AB9 U+0ABD U+0AE0
2283     U+0B05..U+0B0C U+0B0F..U+0B10 U+0B13..U+0B28
2284     U+0B2A..U+0B30 U+0B32..U+0B33 U+0B36..U+0B39
2285     U+0B3D U+0B5C..U+0B5D U+0B5F..U+0B61
2286     U+0B85..U+0B8A U+0B8E..U+0B90 U+0B92..U+0B95
2287     U+0B99..U+0B9A U+0B9C U+0B9E..U+0B9F
2288     U+0BA3..U+0BA4 U+0BA8..U+0BAA U+0BAE..U+0BB5
2289     U+0BB7..U+0BB9 U+0C05..U+0C0C U+0C0E..U+0C10
2290     U+0C12..U+0C28 U+0C2A..U+0C33 U+0C35..U+0C39
2291     U+0C60..U+0C61 U+0C85..U+0C8C U+0C8E..U+0C90
2292     U+0C92..U+0CA8 U+0CAA..U+0CB3 U+0CB5..U+0CB9
2293     U+0CDE U+0CE0..U+0CE1 U+0D05..U+0D0C
2294     U+0D0E..U+0D10 U+0D12..U+0D28 U+0D2A..U+0D39
2295     U+0D60..U+0D61 U+0E01..U+0E2E U+0E30
2296     U+0E32..U+0E33 U+0E40..U+0E45 U+0E81..U+0E82
2297     U+0E84 U+0E87..U+0E88 U+0E8A U+0E8D
2298     U+0E94..U+0E97 U+0E99..U+0E9F U+0EA1..U+0EA3
2299     U+0EA5 U+0EA7 U+0EAA..U+0EAB U+0EAD..U+0EAE
2300     U+0EB0 U+0EB2..U+0EB3 U+0EBD U+0EC0..U+0EC4
2301     U+0F40..U+0F47 U+0F49..U+0F69 U+10A0..U+10C5
2302     U+10D0..U+10F6 U+1100 U+1102..U+1103
2303     U+1105..U+1107 U+1109 U+110B..U+110C
2304     U+110E..U+1112 U+113C U+113E U+1140 U+114C
2305     U+114E U+1150 U+1154..U+1155 U+1159
2306     U+115F..U+1161 U+1163 U+1165 U+1167 U+1169
2307     U+116D..U+116E U+1172..U+1173 U+1175 U+119E
2308     U+11A8 U+11AB U+11AE..U+11AF U+11B7..U+11B8
2309     U+11BA U+11BC..U+11C2 U+11EB U+11F0 U+11F9
2310     U+1E00..U+1E9B U+1EA0..U+1EF9 U+1F00..U+1F15
2311     U+1F18..U+1F1D U+1F20..U+1F45 U+1F48..U+1F4D
2312     U+1F50..U+1F57 U+1F59 U+1F5B U+1F5D
2313     U+1F5F..U+1F7D U+1F80..U+1FB4 U+1FB6..U+1FBC
2314     U+1FBE U+1FC2..U+1FC4 U+1FC6..U+1FCC
2315     U+1FD0..U+1FD3 U+1FD6..U+1FDB U+1FE0..U+1FEC
2316     U+1FF2..U+1FF4 U+1FF6..U+1FFC U+2126
2317     U+212A..U+212B U+212E U+2180..U+2182
2318     U+3041..U+3094 U+30A1..U+30FA U+3105..U+312C
2319     U+AC00..U+D7A3
2320     // Ideographic
2321     U+4E00..U+9FA5 U+3007 U+3021..U+3029
2322     // Digit
2323     U+0030..U+0039 U+0660..U+0669 U+06F0..U+06F9
2324     U+0966..U+096F U+09E6..U+09EF U+0A66..U+0A6F
2325     U+0AE6..U+0AEF U+0B66..U+0B6F U+0BE7..U+0BEF
2326     U+0C66..U+0C6F U+0CE6..U+0CEF U+0D66..U+0D6F
2327     U+0E50..U+0E59 U+0ED0..U+0ED9 U+0F20..U+0F29
2328     // CombiningChar
2329     U+0300..U+0345 U+0360..U+0361 U+0483..U+0486
2330     U+0591..U+05A1 U+05A3..U+05B9 U+05BB..U+05BD
2331     U+05BF U+05C1..U+05C2 U+05C4 U+064B..U+0652
2332     U+0670 U+06D6..U+06DC U+06DD..U+06DF
2333     U+06E0..U+06E4 U+06E7..U+06E8 U+06EA..U+06ED
2334     U+0901..U+0903 U+093C U+093E..U+094C U+094D
2335     U+0951..U+0954 U+0962..U+0963 U+0981..U+0983
2336     U+09BC U+09BE U+09BF U+09C0..U+09C4
2337     U+09C7..U+09C8 U+09CB..U+09CD U+09D7
2338     U+09E2..U+09E3 U+0A02 U+0A3C U+0A3E U+0A3F
2339     U+0A40..U+0A42 U+0A47..U+0A48 U+0A4B..U+0A4D
2340     U+0A70..U+0A71 U+0A81..U+0A83 U+0ABC
2341     U+0ABE..U+0AC5 U+0AC7..U+0AC9 U+0ACB..U+0ACD
2342     U+0B01..U+0B03 U+0B3C U+0B3E..U+0B43
2343     U+0B47..U+0B48 U+0B4B..U+0B4D U+0B56..U+0B57
2344     U+0B82..U+0B83 U+0BBE..U+0BC2 U+0BC6..U+0BC8
2345     U+0BCA..U+0BCD U+0BD7 U+0C01..U+0C03
2346     U+0C3E..U+0C44 U+0C46..U+0C48 U+0C4A..U+0C4D
2347     U+0C55..U+0C56 U+0C82..U+0C83 U+0CBE..U+0CC4
2348     U+0CC6..U+0CC8 U+0CCA..U+0CCD U+0CD5..U+0CD6
2349     U+0D02..U+0D03 U+0D3E..U+0D43 U+0D46..U+0D48
2350     U+0D4A..U+0D4D U+0D57 U+0E31 U+0E34..U+0E3A
2351     U+0E47..U+0E4E U+0EB1 U+0EB4..U+0EB9
2352     U+0EBB..U+0EBC U+0EC8..U+0ECD U+0F18..U+0F19
2353     U+0F35 U+0F37 U+0F39 U+0F3E U+0F3F
2354     U+0F71..U+0F84 U+0F86..U+0F8B U+0F90..U+0F95
2355     U+0F97 U+0F99..U+0FAD U+0FB1..U+0FB7 U+0FB9
2356     U+20D0..U+20DC U+20E1 U+302A..U+302F U+3099
2357     U+309A
2358     // Extender
2359     U+00B7 U+02D0 U+02D1 U+0387 U+0640 U+0E46
2360     U+0EC6 U+3005 U+3031..U+3035 U+309D..U+309E
2361     U+30FC..U+30FE
2362     ];
2363 wakaba 1.1
2364     $NameStartChar11 := [
2365     ':' '_'
2366     'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M'
2367     'N' 'O' 'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' 'X' 'Y' 'Z'
2368     'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm'
2369     'n' 'o' 'p' 'q' 'r' 's' 't' 'u' 'v' 'w' 'x' 'y' 'z'
2370     U+00C0..U+00D6 U+00D8..U+00F6 U+00F8..U+02FF
2371     U+0370..U+037D U+037F..U+1FFF U+200C..U+200D
2372     U+2070..U+218F U+2C00..U+2FEF U+3001..U+D7FF
2373     U+F900..U+FDCF U+FDF0..U+FFFD U+10000..U+EFFFF
2374     ];
2375     $NameChar11 := [
2376     '-' '.' '0' '1' '2' '3' '4' '5' '6' '7' '8' '9'
2377     U+00B7 U+0300..U+036F U+203F..U+2040
2378     // NameStartChar
2379     ':' '_'
2380     'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M'
2381     'N' 'O' 'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' 'X' 'Y' 'Z'
2382     'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm'
2383     'n' 'o' 'p' 'q' 'r' 's' 't' 'u' 'v' 'w' 'x' 'y' 'z'
2384     U+00C0..U+00D6 U+00D8..U+00F6 U+00F8..U+02FF
2385     U+0370..U+037D U+037F..U+1FFF U+200C..U+200D
2386     U+2070..U+218F U+2C00..U+2FEF U+3001..U+D7FF
2387     U+F900..U+FDCF U+FDF0..U+FFFD U+10000..U+EFFFF
2388     ];
2389 wakaba 1.4 } // NameChar
2390    
2391     lexmode Name
2392     : extends => 'NameChar'
2393     {
2394 wakaba 1.1 Name : value := $NameStartChar11 $NameChar11*;
2395     } // Name
2396 wakaba 1.4
2397     lexmode Nmtoken
2398     : extends => 'NameChar'
2399     {
2400     Nmtoken : value := $NameChar11*;
2401     } // Nmtoken
2402 wakaba 1.1
2403     /*
2404     Space
2405     */
2406     lexmode S {
2407     S := [U+0009 U+000A U+000D U+0020]+;
2408     } // S
2409    
2410     /*
2411     Document end scanning mode
2412     */
2413     lexmode DocumentEnd
2414     : standalone
2415     : extends => 'S'
2416     {
2417     /*
2418     Processing instruction
2419     */
2420     PIO := ['<'] ['?'];
2421    
2422     /*
2423     Comment declaration
2424     */
2425     CDO := ['<'] ['!'] ['-'] ['-'];
2426     } // DocumentEnd
2427    
2428     /*
2429     Document misc scanning mode
2430    
2431     This mode scans |Misc| constructions as well
2432     as document element's start tag.
2433     */
2434     lexmode DocumentMisc
2435     : standalone
2436     : extends => 'DocumentEnd'
2437     {
2438     /*
2439     Document element start tag
2440     */
2441     STAGO := ['<'];
2442     } // DocumentMisc
2443    
2444     /*
2445     Document prolog scanning mode
2446     */
2447     lexmode DocumentProlog
2448     : standalone
2449     : extends => 'DocumentMisc'
2450     {
2451     /*
2452     |DOCTYPE| declaration
2453     */
2454     MDO := ['<'] ['!'];
2455     } // DocumentProlog
2456    
2457     /*
2458     Document start scanning mode
2459     */
2460     lexmode DocumentStart
2461     : initial
2462     : standalone
2463     : extends => 'DocumentProlog'
2464     {
2465     /*
2466     XML declaration
2467     */
2468     XDO := ['<'] ['?'] ['x'] ['m'] ['l'];
2469     } // DocumentStart
2470    
2471     /*
2472     Comment declaration scanning mode
2473     */
2474     lexmode CommentDeclaration
2475     : standalone
2476     {
2477     /*
2478     Comment close
2479     */
2480     COM := ['-'] ['-'];
2481    
2482     /*
2483     Comment data
2484     */
2485     $string := ['-']? [^'-'];
2486     STRING : value := $string+;
2487     } // CommentDeclaration
2488    
2489     /*
2490     Processing instruction name and |S| scanning mode
2491     */
2492     lexmode PIName
2493     : standalone
2494     : extends => 'Name'
2495     : extends => 'S'
2496     {
2497     /*
2498     Processing instruction close
2499     */
2500     PIC := ['?'] ['>'];
2501     } // PIName
2502    
2503     /*
2504     Processing instruction data scanning mode
2505     */
2506     lexmode PIData
2507     : standalone
2508     {
2509     /*
2510     Processing instruction close
2511     */
2512     PIC := ['?'] ['>'];
2513    
2514     /*
2515     Processing instruction target data
2516     */
2517 wakaba 1.2 ?default-token DATA : value;
2518 wakaba 1.1 } // PIData
2519    
2520     /*
2521     Content of element scanning mode
2522     */
2523     lexmode ElementContent
2524     : standalone
2525     {
2526     /*
2527     Start tag open
2528     */
2529     STAGO := ['<'];
2530    
2531     /*
2532     End tag open
2533     */
2534     ETAGO := ['<'] ['/'];
2535    
2536     /*
2537     Hexadecimal character reference open
2538     */
2539     HCRO := ['&'] ['#'] ['x'];
2540    
2541     /*
2542     Numeric character reference open
2543     */
2544     CRO := ['&'] ['#'];
2545    
2546     /*
2547     General entity reference open
2548     */
2549     ERO := ['&'];
2550    
2551     /*
2552     Comment declaration open
2553     */
2554     CDO := ['<'] ['!'] ['-'] ['-'];
2555    
2556     /*
2557     CDATA section open
2558     */
2559     CDSO := ['<'] ['!'] ['[']
2560     ['C'] ['D'] ['A'] ['T'] ['A'] ['['];
2561    
2562     /*
2563     Processing instruction open
2564     */
2565     PIO := ['<'] ['?'];
2566 wakaba 1.2
2567     /*
2568     Markup section end
2569     */
2570     MSE := [']'] [']'] ['>'];
2571    
2572     /*
2573     Character data
2574     */
2575     /*
2576     Character data and/or |MSE|
2577     */
2578     ?default-token CharData : value;
2579 wakaba 1.1 } // ElementContent
2580    
2581     /*
2582     CDATA section content scanning mode
2583     */
2584     lexmode CDATASectionContent
2585     : standalone
2586     {
2587     /*
2588     Markup section end
2589     */
2590     MSE := [']'] [']'] ['>'];
2591    
2592     /*
2593     Character data
2594 wakaba 1.2 */
2595     ?default-token CData : value;
2596 wakaba 1.1 } // CDATASectionContent
2597    
2598     lexmode EntityReference
2599     : standalone
2600     : extends => 'Name'
2601     {
2602     /*
2603     Reference close
2604     */
2605     REFC := [';'];
2606     } // EntityReference
2607    
2608     lexmode NumericCharacterReference
2609     : standalone
2610     {
2611     /*
2612     Decimal number
2613     */
2614     $digit := ['0' '1' '2' '3' '4' '5' '6' '7' '8' '9'];
2615     NUMBER : value := $digit+;
2616    
2617     /*
2618     Reference close
2619     */
2620     REFC := [';'];
2621     } // NumericCharacterReference
2622    
2623     lexmode HexadecimalCharacterReference
2624     : standalone
2625     {
2626     /*
2627     Hexadecimal number
2628     */
2629     $hexdigit := ['0' '1' '2' '3' '4' '5' '6' '7' '8' '9'
2630     'A' 'B' 'C' 'D' 'E' 'F'
2631     'a' 'b' 'c' 'd' 'e' 'f'];
2632     Hex : value := $hexdigit+;
2633    
2634     /*
2635     Reference close
2636     */
2637     REFC := [';'];
2638     } // HexadecimalCharacterReference
2639    
2640 wakaba 1.3 lexmode XMLDeclaration
2641     : standalone
2642     : extends => 'Name'
2643     : extends => 'S'
2644     {
2645    
2646     /*
2647     Value indicator
2648     */
2649     VI := ['='];
2650    
2651     /*
2652     Literal open
2653     */
2654     LIT := ['"'];
2655     LITA := [U+0027];
2656    
2657     /*
2658     Processing instruction close
2659     */
2660     PIC := ['?'] ['>'];
2661     } // XMLDeclaration
2662    
2663 wakaba 1.1 lexmode StartTag
2664     : standalone
2665     : extends => 'Name'
2666     : extends => 'S'
2667     {
2668    
2669     /*
2670     Value indicator
2671     */
2672     VI := ['='];
2673    
2674     /*
2675     Literal open
2676     */
2677     LIT := ['"'];
2678     LITA := [U+0027];
2679    
2680     /*
2681     Tag close
2682     */
2683     TAGC := ['>'];
2684    
2685     /*
2686     Empty element tag close
2687     */
2688     MTAGC := ['/'] ['>'];
2689     } // StartTag
2690    
2691     lexmode EndTag
2692     : standalone
2693     : extends => 'Name'
2694     : extends => 'S'
2695     {
2696     /*
2697     Tag close
2698     */
2699     TAGC := ['>'];
2700     } // EndTag
2701    
2702     lexmode AttributeValueLiteral_ {
2703     ERO := ['&'];
2704     CRO := ['&'] ['#'];
2705     HCRO := ['&'] ['#'] ['x'];
2706     } // AttributeValueLiteral_
2707    
2708     lexmode AttributeValueLiteral
2709     : standalone
2710     : extends => 'AttributeValueLiteral_'
2711     {
2712     LIT := ['"'];
2713 wakaba 1.3 STRING : value := [^'"' '&' '<']+;
2714 wakaba 1.1 } // AttributeValueLiteral
2715    
2716     lexmode AttributeValueLiteralA
2717     : standalone
2718     : extends => 'AttributeValueLiteral_'
2719     {
2720 wakaba 1.4 LITA := [U+0027];
2721 wakaba 1.3 STRING : value := [^U+0027 '&' '<']+;
2722 wakaba 1.1 } // AttributeValueLiteralA
2723 wakaba 1.4
2724     lexmode EntityValue_ {
2725     PERO := ['%'];
2726     ERO := ['&'];
2727     CRO := ['&'] ['#'];
2728     HCRO := ['&'] ['#'] ['x'];
2729     } // EntityValue_
2730    
2731     lexmode EntityValue
2732     : standalone
2733     : extends => 'EntityValue_'
2734     {
2735     LIT := ['"'];
2736     STRING : value := [^'"' '&' '%']+;
2737     } // EntityValue
2738    
2739     lexmode EntityValueA
2740     : standalone
2741     : extends => 'EntityValue_'
2742     {
2743     LITA := [U+0027];
2744     STRING : value := [^U+0027 '&' '%']+;
2745     } // EntityValueA
2746    
2747     lexmode SystemLiteral
2748     : standalone
2749     {
2750     LIT := ['"'];
2751     ?default-token STRING : value;
2752     } // SystemLiteral
2753    
2754     lexmode SystemLiteralA
2755     : standalone
2756     {
2757     LITA := [U+0027];
2758     ?default-token STRING : value;
2759     } // SystemLiteralA
2760    
2761     lexmode DTD
2762     : standalone
2763     : extends => 'S'
2764     {
2765     /*
2766     Markup declaration open
2767     */
2768     MDO := ['<'] ['!'];
2769    
2770     /*
2771     Comment declaration open
2772     */
2773     CDO := ['<'] ['!'] ['-'] ['-'];
2774    
2775     /*
2776     Processing instruction open
2777     */
2778     PIO := ['<'] ['?'];
2779    
2780     /*
2781     Parameter entity reference open
2782     */
2783     PERO := ['%'];
2784    
2785     /*
2786     Declaration subset close
2787     */
2788     DSC := [']'];
2789    
2790     /*
2791     Contition section open
2792     */
2793     CSO := ['<'] ['!'] ['['];
2794     } // DTD
2795    
2796     /*
2797     Markup declaration scanning mode
2798    
2799     This mode is used to recognize |MDC| that terminates
2800     a comment declaration as well as the base |lexmode|
2801     for e.g. document type declaration scanning mode.
2802     */
2803     lexmode MarkupDeclaration
2804     : standalone
2805     : extends => 'Name'
2806     : extends => 'S'
2807     {
2808     /*
2809     Markup declaration close
2810     */
2811     MDC := ['>'];
2812    
2813     /*
2814     Literal open
2815     */
2816     LIT := ['"'];
2817    
2818     /*
2819     Alternative literal open
2820     */
2821     LITA := [U+0027];
2822    
2823     /*
2824     Parameter entity reference open
2825     */
2826     PERO := ['%'];
2827    
2828     /*
2829     Declaration subset open
2830     */
2831     DSO := ['['];
2832     } // MarkupDeclaration
2833    
2834     lexmode ElementDeclaration
2835     : standalone
2836     : extends => 'MarkupDeclaration'
2837     {
2838     /*
2839     Model group open
2840     */
2841     MGO := ['('];
2842    
2843     /*
2844     Model group close
2845     */
2846     MGC := [')'];
2847    
2848     /*
2849     Reserved name indicator
2850     */
2851     RNI := ['#'];
2852    
2853     /*
2854     Occurence indicators
2855     */
2856     OPT := ['?'];
2857     REP := ['*'];
2858     PLUS := ['+'];
2859    
2860     /*
2861     Connectors
2862     */
2863     OR := ['|'];
2864     SEQ := [','];
2865     } // ElementDeclaration
2866    
2867     lexmode AttlistDeclaration
2868     : standalone
2869     : extends => 'MarkupDeclaration'
2870     {
2871     /*
2872     Enumeration group open
2873     */
2874     EGO := ['('];
2875    
2876     /*
2877     Enumeration group close
2878     */
2879     EGC := [')'];
2880    
2881     /*
2882     Enumeration choice delimiter
2883     */
2884     OR := ['|'];
2885    
2886     /*
2887     Reserved name indicator
2888     */
2889     RNI := ['#'];
2890     } // AttlistDeclaration
2891    
2892     lexmode Enumeration
2893     : standalone
2894     : extends => 'Nmtoken'
2895     : extends => 'S'
2896     {
2897     /*
2898     Enumeration group close
2899     */
2900     EGC := [')'];
2901    
2902     /*
2903     Enumeration choice delimiter
2904     */
2905     OR := ['|'];
2906     } // Enumeration
2907    
2908 wakaba 1.1
2909     token-error default : default {
2910     lang:Perl {
2911 wakaba 1.3 my $location;
2912     __CODE{xp|get-location-from-token::
2913     $token => {$token},
2914     $result => {$location},
2915     }__;
2916     my $continue = __DOMCore:ERROR{xp|wf-syntax-error::
2917 wakaba 1.1 xp|error-token => {$token},
2918     DOMCore|location => {$location},
2919     }__;
2920     unless ($continue) {
2921     __EXCEPTION{DOMLS|PARSE_ERR::
2922     }__;
2923     }
2924     $self->{has_error} = true;
2925     }
2926     } // default
2927     ##ManakaiXMLParser
2928    
2929 wakaba 1.3 ResourceDef:
2930     @QName: xp|get-location-from-token
2931     @rdf:type: DISPerl|BlockCode
2932     @enDesc:
2933     Creates a <IF::DOMCore:DOMLocator> object from a token.
2934     @PerlDef:
2935     $result = {
2936     utf32_offset => pos ($self->{source}),
2937     };
2938     @For: ManakaiDOM|ManakaiDOM3
2939 wakaba 1.1
2940     ElementTypeBinding:
2941     @Name: RuleDef
2942     @ElementType:
2943     dis:ResourceDef
2944     @ShadowContent:
2945     @@ForCheck: ManakaiDOM|ForClass
2946     @@rdf:type: Muf2003|RuleDefClass
2947    
2948     ElementTypeBinding:
2949     @Name: RuleParam
2950     @ElementType:
2951     dis:ResourceDef
2952     @ShadowContent:
2953     @@rdf:type: Muf2003|RuleParameter
2954    
2955     ElementTypeBinding:
2956     @Name: enImplNote
2957     @ElementType:
2958     dis:ImplNote
2959     @ShadowContent:
2960     @@lang:en
2961    
2962     ElementTypeBinding:
2963     @Name: ErrDef
2964     @ElementType:
2965     dis:ResourceDef
2966     @ShadowContent:
2967     @@rdf:type: DOMCore|DOMErrorType
2968     @@For: ManakaiDOM|DOM3
2969     @@ecore:textFormatter: ManakaiXMLParserExceptionFormatter
2970    
2971 wakaba 1.3 ElementTypeBinding:
2972     @Name: WFErrDef
2973     @ElementType:
2974     dis:ResourceDef
2975     @ShadowContent:
2976     @@rdf:type: DOMCore|DOMErrorType
2977     @@For: ManakaiDOM|DOM3
2978     @@ecore:textFormatter: ManakaiXMLParserExceptionFormatter
2979    
2980     WFErrDef:
2981     @QName: xp|wf-syntax-error
2982     @enDesc:
2983     The entity does not match to the production rule; it is not
2984     well-formed.
2985     @DOMCore:severity: DOMCore|SEVERITY_FATAL_ERROR
2986     @enMufDef:
2987     |%xp-error-token-type;|%xp-error-token-value
2988     (prefix => { (|}, suffix => {|)}); is not
2989     allowed%xp-error-lines (prefix => { (|}, suffix => {|)});
2990     @ecore:hasParameter:
2991     @@@: xp|error-token
2992     @@enDesc:
2993     The token that is not allowed.
2994    
2995     WFErrDef:
2996     @QName: xp|wf-pi-target-is-xml
2997     @enDesc:
2998     A processing instruction has its <CODE::PITarget> of
2999     <XML::xml> (in any case) which is not allowed.
3000     @DOMCore:severity: DOMCore|SEVERITY_ERROR
3001     @enMufDef:
3002     Processing instruction target name cannot be |%p
3003     (name => {<Q::xp|name>});|
3004     @ecore:hasParameter:
3005     @@@: xp|error-token
3006     @@enDesc:
3007     The token that contains the name.
3008     @ecore:hasParameter:
3009     @@@: xp|name
3010     @@enDesc:
3011     A string that is specified as target name of the
3012     processing instruction.
3013     @ecore:hasParameter: xp|parent
3014    
3015     WFErrDef:
3016     @QName: xp|wf-no-end-tag
3017     @DOMCore:severity: DOMCore|SEVERITY_ERROR
3018     @enDesc:
3019     An end-tag is not found.
3020     @enMufDef:
3021     End-tag |</%p (name => {<Q::xp|expected-element-type>});>| is required
3022     @ecore:hasParameter: xp|error-token
3023     @ecore:hasParameter:
3024     @@@: xp|node
3025     @@enDesc:
3026     The element node that is not closed.
3027     @ecore:hasParameter:
3028     @@@: xp|expected-element-type
3029     @@enDesc:
3030     The element type name of the element that is not closed.
3031    
3032     WFErrDef:
3033     @QName: xp|wf-unsupported-xml-version
3034     @DOMCore:severity: DOMCore|SEVERITY_ERROR
3035     @enDesc:
3036     The XML version specified in the version declaration is not supported.
3037     @enMufDef:
3038     XML version |%p (name => {<Q::infoset|version>});| is not supported
3039     @ecore:hasParameter: xp|bad-token
3040     @ecore:hasParameter:
3041     @@@: xp|parent
3042     @@enDesc:
3043     The document node.
3044     @ecore:hasParameter:
3045     @@@: infoset|version
3046     @@enDesc:
3047     The specified XML version.
3048    
3049     WFErrDef:
3050     @QName: xp|wf-malformed-enc-name
3051     @DOMCore:severity: DOMCore|SEVERITY_ERROR
3052     @enDesc:
3053     An <XA::encoding> pseudo-attribute value does not match
3054     to the procduction rule <CODE::EncName>.
3055     @enMufDef:
3056     Encoding name |%p (name => {<Q::xp|name>});| is not allowed
3057     @ecore:hasParameter: xp|error-token
3058     @ecore:hasParameter:
3059     @@@: xp|parent
3060     @@enDesc: The document node.
3061     @ecore:hasParameter:
3062     @@@: xp|name
3063     @@enDesc:
3064     The <XA::encoding> value.
3065    
3066     WFErrDef:
3067     @QName: xp|wf-malformed-xml-standalone
3068     @DOMCore:severity: DOMCore|SEVERITY_ERROR
3069     @enDesc:
3070     An <XA::standalone> pseudo-attribute value is neither <XML::yes>
3071     or <XML::no>.
3072     @enMufDef:
3073     |standalone| pseudo-attribute value |%p (name => {<Q::xp|name>});|
3074     is not allowed
3075     @ecore:hasParameter: xp|error-token
3076     @ecore:hasParameter:
3077     @@@: xp|parent
3078     @@enDesc: The document node.
3079     @ecore:hasParameter:
3080     @@@: xp|name
3081     @@enDesc:
3082     The <XA::standalone> value.
3083    
3084     WFErrDef:
3085     @QName: xp|wf-legal-literal-character
3086     @DOMCore:severity: DOMCore|SEVERITY_ERROR
3087     @enDesc:
3088     Each character in XML entity must match to the production
3089     rule <CODE::Char - RestrictedChar>.
3090     @enMufDef:
3091     Character %character-code-point
3092     (v => {<Q::xp|character-number>}); is not allowed
3093     @ecore:hasParameter:
3094     @@@: xp|character-number
3095     @@enDesc:
3096     The code position of the character being referred.
3097    
3098     WFErrDef:
3099     @QName: xp|wf-element-type-match
3100     @DOMCore:severity: DOMCore|SEVERITY_FATAL_ERROR
3101 wakaba 1.1 @enDesc:
3102 wakaba 1.3 The <CODE::Name> in an element's end-tag must match the element type
3103     in the start-tag.
3104     @enMufDef:
3105     End-tag |</%p (name => {<Q::xp|actual-element-type>});>| does
3106     not match to start-tag |<%p (name => {<Q::xp|expected-element-type>});>|
3107     @ecore:hasParameter: xp|error-token
3108     @ecore:hasParameter:
3109     @@@: xp|node
3110     @@enDesc:
3111     The current opening element node.
3112     @ecore:hasParameter:
3113     @@@: xp|expected-element-type
3114     @@enDesc:
3115     The element type name of the current element.
3116     @ecore:hasParameter:
3117     @@@: xp|actual-element-type
3118     @@enDesc:
3119     The <CODE::Name> occurs in the end-tag.
3120    
3121     WFErrDef:
3122     @QName: xp|wf-unique-att-spec
3123 wakaba 1.1 @DOMCore:severity: DOMCore|SEVERITY_ERROR
3124 wakaba 1.3 @enDesc:
3125     An attribute name <kwd:MUST-NOT> appear more than once in
3126     the same start-tag or empty-element tag.
3127 wakaba 1.1 @enMufDef:
3128 wakaba 1.3 Attribute |%p (name => {<Q::xp|name>});| is specified more
3129     than once in the same tag
3130     @ecore:hasParameter: xp|error-token
3131     @ecore:hasParameter:
3132     @@@: xp|name
3133     @@enDesc:
3134     The name of the attribute.
3135    
3136     WFErrDef:
3137     @QName: xp|wf-legal-character
3138     @DOMCore:severity: DOMCore|SEVERITY_ERROR
3139     @enDesc:
3140     Characters referred to using character references <kwd:MUST>
3141     match the production for <CODE::Char>.
3142     @enMufDef:
3143     Reference to character %character-code-point
3144     (v => {<Q::xp|character-number>}); is not allowed
3145     @ecore:hasParameter: xp|error-token
3146     @ecore:hasParameter:
3147     @@@: xp|character-number
3148     @@enDesc:
3149     The code position of the character being referred.
3150     @ecore:hasParameter:
3151     @@@: xp|parent
3152     @@enDesc:
3153     The parent node in which the character reference has
3154     occurred, if available.
3155 wakaba 1.1
3156 wakaba 1.3 XWParam:
3157 wakaba 1.1 @QName: xp|error-token
3158     @enDesc:
3159     The token where the parser found an error.
3160    
3161 wakaba 1.3 XWParam:
3162     @QName: xp|name
3163     @enDesc:
3164     A name.
3165    
3166     XWParam:
3167     @QName: xp|parent
3168     @enDesc:
3169     The parent node in which the error occurs.
3170    
3171     XWParam:
3172     @QName: xp|node
3173     @enDesc:
3174     The current node.
3175    
3176     XWParam:
3177     @QName: xp|actual-element-type
3178     @enDesc:
3179     The actual element type name occured in the source.
3180    
3181     XWParam:
3182     @QName: xp|expected-element-type
3183 wakaba 1.1 @enDesc:
3184 wakaba 1.3 The element type name expected.
3185    
3186     XWParam:
3187     @QName: xp|character-number
3188     @enDesc:
3189     The character code position.
3190    
3191     ElementTypeBinding:
3192     @Name: XWParam
3193     @ElementType:
3194     dis:ResourceDef
3195     @ShadowContent:
3196     @@For: =ManakaiDOM|all
3197     @@rdf:type: ecore|Parameter
3198 wakaba 1.1
3199     ElementTypeBinding:
3200     @Name:enMufDef
3201     @ElementType:
3202     ecore:defaultMessage
3203     @ShadowContent:
3204     @@lang:en
3205     @@ContentType:
3206     lang:muf
3207    
3208     ResourceDef:
3209     @QName: DOMImpl
3210     @AliasFor: DOMCore|DOMImplementation
3211     @For: ManakaiDOM|DOM
3212    
3213     ElementTypeBinding:
3214     @Name: Attr
3215     @ElementType:
3216     dis:ResourceDef
3217     @ShadowContent:
3218     @@rdf:type: DISLang|Attribute
3219     @@ForCheck: !=ManakaiDOM|ManakaiDOM
3220    
3221     ElementTypeBinding:
3222     @Name: Get
3223     @ElementType:
3224     dis:ResourceDef
3225     @ShadowContent:
3226     @@rdf:type: DISLang|AttributeGet
3227    
3228     ElementTypeBinding:
3229     @Name: Set
3230     @ElementType:
3231     dis:ResourceDef
3232     @ShadowContent:
3233     @@rdf:type: DISLang|AttributeSet
3234    
3235     ElementTypeBinding:
3236     @Name: enDesc
3237     @ElementType:
3238     dis:Description
3239     @ShadowContent:
3240     @@lang:en
3241    
3242     ElementTypeBinding:
3243     @Name: Method
3244     @ElementType:
3245     dis:ResourceDef
3246     @ShadowContent:
3247     @@rdf:type: DISLang|Method
3248     @@For: !=ManakaiDOM|ManakaiDOM
3249    
3250     ElementTypeBinding:
3251     @Name: Return
3252     @ElementType:
3253     dis:ResourceDef
3254     @ShadowContent:
3255     @@rdf:type: DISLang|MethodReturn
3256    
3257     ElementTypeBinding:
3258     @Name: Param
3259     @ElementType:
3260     dis:ResourceDef
3261     @ShadowContent:
3262     @@rdf:type: DISLang|MethodParameter
3263    
3264     ElementTypeBinding:
3265     @Name: PerlDef
3266     @ElementType:
3267     dis:Def
3268     @ShadowContent:
3269     @@ContentType: lang|Perl
3270    
3271     ElementTypeBinding:
3272     @Name: PropDef
3273     @ElementType:
3274     dis:ResourceDef
3275     @ShadowContent:
3276     @@rdf:type: rdf|Property
3277    
3278     ClsDef:
3279     @ClsQName: ManakaiXMLParserExceptionFormatter
3280    
3281     @ClsISA: ecore|MUErrorFormatter||ManakaiDOM|Perl
3282    
3283     @RuleDef:
3284     @@Name: xp-error-token-type
3285     @@enDesc:
3286     The type of the token the parser is encountered.
3287    
3288     @@Method:
3289     @@@Name: after
3290     @@@Param:
3291     @@@@Name: name
3292     @@@@Type: DOMString
3293     @@@@enDesc: The name of the method.
3294     @@@Param:
3295     @@@@Name: p
3296     @@@@Type: DISPerl|HASH
3297     @@@@enDesc: The set of the parameters to the method.
3298     @@@Param:
3299     @@@@Name: o
3300     @@@@Type: DISPerl|HASH
3301     @@@@enDesc: The option value.
3302     @@@Return:
3303     @@@@PerlDef:
3304     $p->{-result} = $o->{<H::xp|error-token>}->{type}
3305     if defined $o->{<H::xp|error-token>}->{type};
3306    
3307     @RuleDef:
3308     @@Name: xp-error-token-value
3309     @@enDesc:
3310     The value of the token the parser is encountered, if any.
3311    
3312     @@Method:
3313     @@@Name: after
3314     @@@Param:
3315     @@@@Name: name
3316     @@@@Type: DOMString
3317     @@@@enDesc: The name of the method.
3318     @@@Param:
3319     @@@@Name: p
3320     @@@@Type: DISPerl|HASH
3321     @@@@enDesc: The set of the parameters to the method.
3322     @@@Param:
3323     @@@@Name: o
3324     @@@@Type: DISPerl|HASH
3325     @@@@enDesc: The option value.
3326     @@@Return:
3327     @@@@PerlDef:
3328     $p->{-result} = $o->{<H::xp|error-token>}->{value}
3329     if defined $o->{<H::xp|error-token>}->{value};
3330    
3331     @RuleDef:
3332     @@Name: xp-error-lines
3333     @@enDesc:
3334     A copy of fragment of the source text that contains the line
3335     where the error occurred, if available.
3336    
3337     @@Method:
3338     @@@Name: after
3339     @@@Param:
3340     @@@@Name: name
3341     @@@@Type: DOMString
3342     @@@@enDesc: The name of the method.
3343     @@@Param:
3344     @@@@Name: p
3345     @@@@Type: DISPerl|HASH
3346     @@@@enDesc: The set of the parameters to the method.
3347     @@@Param:
3348     @@@@Name: o
3349     @@@@Type: DISPerl|HASH
3350     @@@@enDesc: The option value.
3351     @@@Return:
3352     @@@@PerlDef:
3353     my $pos = $o-><AG::DOMCore|DOMError.location>
3354     -><AG::DOMCore|DOMLocator.utf32Offset>;
3355     if ($pos > -1) {
3356 wakaba 1.3 my $src = \($o->{<H::ecore|object>}->{source});
3357 wakaba 1.1 my $start = $pos;
3358     $start = rindex ($$src, "\x0A", $start - 1) for 0..2;
3359     $start++;
3360     my $end = $pos;
3361     $end = index ($$src, "\x0A", $end + 1) for 0..2;
3362     $end = length $$src if $end < 0;
3363     $p->{-result} = substr $$src, $start, $end - $start;
3364     }
3365 wakaba 1.3
3366     @RuleDef:
3367     @@Name: character-code-point
3368     @@enDesc:
3369     The character code position, in <CODE::U+<VAR::HHHH>> notation.
3370    
3371     @@Method:
3372     @@@Name: after
3373     @@@Param:
3374     @@@@Name: name
3375     @@@@Type: DOMString
3376     @@@@enDesc: The name of the method.
3377     @@@Param:
3378     @@@@Name: p
3379     @@@@Type: DISPerl|HASH
3380     @@@@enDesc: The set of the parameters to the method.
3381     @@@Param:
3382     @@@@Name: o
3383     @@@@Type: DISPerl|HASH
3384     @@@@enDesc: The option value.
3385     @@@RuleParam:
3386     @@@@Name: v
3387     @@@@Type: DISPerl|Number
3388     @@@@enDesc:
3389     The name of the error parameter that contains the character code.
3390     @@@Return:
3391     @@@@PerlDef:
3392     $p->{-result} = sprintf 'U+%04X', $o->{$p->{v}};
3393 wakaba 1.1 ##XMLParserExceptionFormatter

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24