3 // RELAX NG Compact Syntax parser
6 // Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
8 // (C)2003 Atsushi Enomoto
10 // Copyright (c) 2004 Novell Inc.
11 // All rights reserved
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System.Collections;
37 using System.Collections.Specialized;
40 using Commons.Xml.Relaxng;
42 namespace Commons.Xml.Relaxng.Rnc
45 public class RncParser
47 public static RelaxngPattern ParseRnc (TextReader reader)
49 return ParseRnc (reader, new NameTable ());
52 public static RelaxngPattern ParseRnc (TextReader reader, XmlNameTable nameTable)
54 return ParseRnc (reader, nameTable, null);
57 public static RelaxngPattern ParseRnc (TextReader reader, XmlNameTable nameTable, string baseUri)
59 return ParseRnc (reader, nameTable, baseUri, null);
62 public static RelaxngPattern ParseRnc (TextReader reader, XmlNameTable nameTable, string baseUri, string defaultNamespace)
64 return new RncParser (nameTable).Parse (reader, baseUri, defaultNamespace);
67 XmlNamespaceManager nsmgr;
68 XmlNamespaceManager dtnsmgr;
69 string defaultNamespace;
70 static int yacc_verbose_flag;
72 RncTokenizer tokenizer;
74 public RncParser (XmlNameTable nameTable)
76 if (nameTable == null)
77 nameTable = new NameTable ();
78 nsmgr = new XmlNamespaceManager (nameTable);
79 dtnsmgr = new XmlNamespaceManager (nameTable);
80 dtnsmgr.AddNamespace ("xsd", "http://www.w3.org/2001/XMLSchema-datatypes");
81 ErrorOutput = System.IO.TextWriter.Null;
85 get { return tokenizer.Line; }
89 get { return tokenizer.Column; }
92 public string BaseUri {
93 get { return tokenizer.BaseUri; }
96 // note that this is different notion than that of xmlns.
98 public RelaxngPattern Parse (TextReader source)
100 return Parse (source, null);
103 public RelaxngPattern Parse (TextReader source, string baseUri)
105 return Parse (source, baseUri, null);
108 public RelaxngPattern Parse (TextReader source, string baseUri, string defaultNamespace)
110 this.defaultNamespace = defaultNamespace;
111 if (defaultNamespace != null && defaultNamespace.Length != 0)
112 nsmgr.AddNamespace (String.Empty, defaultNamespace);
114 if (Environment.GetEnvironmentVariable ("MONO_RELAXNG_COMPACT_DEBUG") == "yes")
115 debug = new yydebug.yyDebugSimple ();
116 tokenizer = new RncTokenizer (source, baseUri);
117 RelaxngPattern p = (RelaxngPattern) yyparse (tokenizer);
118 if (p is RelaxngGrammar)
119 ((RelaxngGrammar) p).IsSourceCompactSyntax = true;
121 } catch (Exception ex) {
122 throw new RelaxngException (String.Format ("Tokenizer error at line {0}, column {1}: {2}", Line, Column, ex.Message), ex);
126 private void FillLocation (RelaxngElementBase el)
128 el.BaseUri = BaseUri;
129 el.LineNumber = Line;
130 el.LinePosition = Column;
133 private void FillGrammarContent (IList source, IList starts, IList defines, IList divs, IList includes)
135 foreach (RelaxngElementBase elem in source) {
136 if (elem is RelaxngStart)
138 else if (elem is RelaxngDefine)
140 else if (elem is RelaxngDiv)
142 else if (elem is RelaxngInclude)
145 throw new InvalidOperationException ();
149 private XmlQualifiedName SplitQName (XmlNamespaceManager nsmgr, string name)
151 int colon = name.IndexOf (':');
153 return new XmlQualifiedName (name, String.Empty);
154 string local = name.Substring (colon + 1);
155 string prefix = name.Substring (0, colon);
156 return new XmlQualifiedName (local, nsmgr.LookupNamespace (nsmgr.NameTable.Get (prefix)));
159 private void FillElementDefaultNS (RelaxngNameClass nc)
161 RelaxngName name = nc as RelaxngName;
163 if (name.Namespace == null)
164 name.Namespace = defaultNamespace;
167 RelaxngNameChoice choice = nc as RelaxngNameChoice;
168 if (choice != null) {
169 foreach (RelaxngNameClass c in choice.Children)
170 FillElementDefaultNS (c);
174 private void FillAttributeDefaultNS (RelaxngNameClass nc)
176 RelaxngName name = nc as RelaxngName;
178 if (name.Namespace == null)
179 name.Namespace = String.Empty;
182 RelaxngNameChoice choice = nc as RelaxngNameChoice;
183 if (choice != null) {
184 foreach (RelaxngNameClass c in choice.Children)
185 FillAttributeDefaultNS (c);
194 %token KeywordAttribute "attribute"
195 %token KeywordDefault //"default"
196 %token KeywordDatatypes "datatypes"
197 %token KeywordDiv "div"
198 %token KeywordElement "element"
199 %token KeywordEmpty "empty"
200 %token KeywordExternal "external"
201 %token KeywordGrammar "grammar"
202 %token KeywordInclude "include"
203 %token KeywordInherit "inherit"
204 %token KeywordList "list"
205 %token KeywordMixed "mixed"
206 %token KeywordNamespace //"namespace"
207 %token KeywordNotAllowed "notAllowed"
208 %token KeywordParent "parent"
209 %token KeywordStart "start"
210 %token KeywordString //"string"
211 %token KeywordText "text"
212 %token KeywordToken "left"
218 %token CloseCurly "}"
220 %token CloseParen ")"
221 %token OpenBracket "["
222 %token CloseBracket "]"
230 %token AndEquals "&="
231 %token TwoGreaters ">>"
233 %token LiteralSegment
235 %token QuotedIdentifier
239 /* These tokens are parsed by RncTokenizer, since whitespaces between
240 the particles are not allowed. */
250 TopLevel /* returns RelaxngPattern */
251 : Preamble TopLevelBody
253 $$ = (RelaxngPattern) $2;
257 Preamble /* returns null */
268 Decl /* returns null */
269 : KeywordNamespace NamespacePrefix Equal NamespaceURILiteral
272 string prefix = (string) $2;
273 string ns = (string) $4;
274 if (prefix == "local")
275 nsmgr.AddNamespace (String.Empty, ns);
277 nsmgr.AddNamespace (prefix, ns);
280 | KeywordDefault KeywordNamespace Equal NamespaceURILiteral
283 string ns = (string) $4;
284 defaultNamespace = ns;
285 nsmgr.AddNamespace (String.Empty, ns);
288 | KeywordDefault KeywordNamespace NamespacePrefix Equal NamespaceURILiteral
291 string prefix = (string) $3;
292 string ns = (string) $5;
293 defaultNamespace = ns;
294 nsmgr.AddNamespace (String.Empty, ns);
295 nsmgr.AddNamespace (prefix, ns);
298 | KeywordDatatypes DatatypePrefix Equal Literal
301 string prefix = (string) $2;
302 string ns = (string) $4;
303 dtnsmgr.AddNamespace (prefix, ns);
308 NamespacePrefix /* returns string */
309 : IdentifierOrKeyword
315 DatatypePrefix /* returns string */
316 : IdentifierOrKeyword
322 NamespaceURILiteral /* returns string */
329 $$ = defaultNamespace;
333 TopLevelBody /* returns RelaxngPattern */
336 // TODO: Constraint: single element
337 // IList pl = (IList) $1;
338 // if (pl.Count != 1)
339 // throw new RelaxngException ("The number of the top level pattern must be exactly one.");
341 $$ = (RelaxngPattern) $1;
345 RelaxngGrammar g = new RelaxngGrammar ();
347 if (defaultNamespace != null)
348 g.DefaultNamespace = defaultNamespace;
349 RelaxngGrammarContentList list = (RelaxngGrammarContentList) $1;
350 FillGrammarContent (list, g.Starts, g.Defines, g.Divs, g.Includes);
355 Grammar /* returns RelaxngGrammarContentList */
358 $$ = new RelaxngGrammarContentList ();
362 RelaxngGrammarContentList al = (RelaxngGrammarContentList) $2;
364 al.Insert (0, (IGrammarContent) $1);
369 Member /* returns nullable IGrammarContent (RelaxngDiv, RelaxngInclude, RelaxngStart, RelaxngDefine) */
372 $$ = (IGrammarContent) $1;
374 | AnnotationElementNotKeyword
380 AnnotatedComponent /* returns IGrammarContent */
381 : Annotations Component
383 // $$ = ApplyAnnotations ((string) $1, (RelaxngElementBase) $2);
384 $$ = (IGrammarContent) $2;
388 Component /* returns IGrammarContent */
391 $$ = (RelaxngStart) $1;
395 $$ = (RelaxngDefine) $1;
399 $$ = (RelaxngInclude) $1;
403 $$ = (RelaxngDiv) $1;
407 Start /* returns RelaxngStart */
408 : KeywordStart AssignOp Pattern
410 RelaxngStart start = new RelaxngStart ();
411 FillLocation (start);
412 start.Combine = (string) $2;
413 start.Pattern = (RelaxngPattern) $3;
418 Define /* returns RelaxngDefine */
419 : Identifier AssignOp Pattern
421 RelaxngDefine def = new RelaxngDefine ();
423 def.Name = (string) $1;
424 def.Combine = (string) $2;
425 def.Patterns.Add ((RelaxngPattern) $3);
430 AssignOp /* returns string */
445 Include /* returns RelaxngInclude */
446 : KeywordInclude AnyURILiteral OptInherit OptIncludeBody
448 // FIXME: OptInherit is not handled properly.
449 RelaxngInclude include = new RelaxngInclude ();
450 FillLocation (include);
451 include.Href = (string) $2;
452 include.NSContext = (string) $3;
453 FillGrammarContent ((IList) $4, include.Starts, include.Defines, include.Divs, null);
458 AnyURILiteral /* returns string */
461 // Constraints: any URI
466 OptInherit /* returns string */
467 /* The empty value will be handled at Compile() time. */
470 // MakeNsAttribute (LookupDefault (environment));
471 $$ = defaultNamespace;
473 | KeywordInherit Equal IdentifierOrKeyword
475 // MakeNsAttribute (LookupPrefix (environment, $3));
476 $$ = nsmgr.LookupPrefix ((string) $3);
480 OptIncludeBody /* returns IList */
483 $$ = new ArrayList ();
485 | OpenCurly IncludeBody CloseCurly
491 IncludeBody /* returns IList */
494 $$ = new ArrayList ();
496 | IncludeMember IncludeBody
498 ArrayList al = (ArrayList) $2;
504 IncludeMember /* returns RelaxngElementBase */
505 : AnnotatedIncludeComponent
507 $$ = (RelaxngElementBase) $1;
509 | AnnotationElementNotKeyword
511 $$ = (RelaxngElementBase) $1;
515 AnnotatedIncludeComponent /* returns IGrammarContent */
516 : Annotations IncludeComponent
518 // $$ = ApplyAnnotations ((string) $1, (RelaxngElementBase) $2);
519 $$ = (IGrammarContent) $2;
523 IncludeComponent /* returns IGrammarContent */
526 $$ = (RelaxngStart) $1;
530 $$ = (RelaxngDefine) $1;
534 $$ = (RelaxngDiv) $1;
538 Div /* returns RelaxngDiv */
539 : KeywordDiv OpenCurly Grammar CloseCurly
541 RelaxngDiv div = new RelaxngDiv ();
543 FillGrammarContent ((IList) $3, div.Starts, div.Defines, div.Divs, div.Includes);
548 IncludeDiv /* returns RelaxngDiv */
549 : KeywordDiv OpenCurly IncludeBody CloseCurly
551 RelaxngDiv div = new RelaxngDiv ();
553 FillGrammarContent ((IList) $3, div.Starts, div.Defines, div.Divs, div.Includes);
558 Pattern /* returns RelaxngPattern */
562 InnerPattern /* returns RelaxngPattern */
563 /* TODO: applyAnnotations() are omitted */
566 $$ = (RelaxngPattern) $1;
570 RelaxngPatternList list = (RelaxngPatternList) $1;
571 RelaxngChoice choice = new RelaxngChoice ();
572 FillLocation (choice);
573 for (int i = 0; i < list.Count; i++)
574 choice.Patterns.Add (list [i]);
575 // This is said as to return Elements, while ApplyAnnotations() is said to return Element
580 RelaxngPatternList list = (RelaxngPatternList) $1;
581 RelaxngGroup group = new RelaxngGroup ();
582 FillLocation (group);
583 for (int i = 0; i < list.Count; i++)
584 group.Patterns.Add (list [i]);
585 // This is said as to return Elements, while ApplyAnnotations() is said to return Element
590 RelaxngPatternList list = (RelaxngPatternList) $1;
591 RelaxngInterleave interleave = new RelaxngInterleave ();
592 FillLocation (interleave);
593 for (int i = 0; i < list.Count; i++)
594 interleave.Patterns.Add (list [i]);
595 // This is said as to return Elements, while ApplyAnnotations() is said to return Element
598 | AnnotatedDataExcept
600 $$ = (RelaxngData) $1;
604 ParticleChoice /* returns RelaxngPatternList */
605 : Particle Bar Particle
607 RelaxngPatternList list = new RelaxngPatternList ();
608 list.Add ((RelaxngPattern) $1);
609 list.Add ((RelaxngPattern) $3);
612 | Particle Bar ParticleChoice
614 RelaxngPatternList list = (RelaxngPatternList) $3;
615 list.Insert (0, (RelaxngPattern) $1);
620 ParticleGroup /* returns RelaxngPatternList */
621 : Particle Comma Particle
623 RelaxngPatternList list = new RelaxngPatternList ();
624 list.Add ((RelaxngPattern) $1);
625 list.Add ((RelaxngPattern) $3);
628 | Particle Comma ParticleGroup
630 RelaxngPatternList list = (RelaxngPatternList) $3;
631 list.Insert (0, (RelaxngPattern) $1);
636 ParticleInterleave /* returns RelaxngPatternList */
637 : Particle Amp Particle
639 RelaxngPatternList list = new RelaxngPatternList ();
640 list.Add ((RelaxngPattern) $1);
641 list.Add ((RelaxngPattern) $3);
644 | Particle Amp ParticleInterleave
646 RelaxngPatternList list = (RelaxngPatternList) $3;
647 list.Insert (0, (RelaxngPattern) $1);
652 Particle /* returns RelaxngPattern */
656 InnerParticle /* returns RelaxngPattern */
659 // $$ = ApplyAnnotationsGroup (null, (RelaxngPatternList) $1);
662 | RepeatedPrimary FollowAnnotations
664 // FIXME: annotations are not handled
665 RelaxngPattern p = (RelaxngPattern) $1;
666 // RelaxngPatternList l = new RelaxngPatternList ();
673 RepeatedPrimary /* returns RelaxngPattern */
674 : AnnotatedPrimary Asterisk
676 RelaxngZeroOrMore zom = new RelaxngZeroOrMore ();
678 zom.Patterns.Add ((RelaxngPattern) $1);
681 | AnnotatedPrimary Plus
683 RelaxngOneOrMore oom = new RelaxngOneOrMore ();
685 oom.Patterns.Add ((RelaxngPattern) $1);
688 | AnnotatedPrimary Question
690 RelaxngOptional opt = new RelaxngOptional ();
692 opt.Patterns.Add ((RelaxngPattern) $1);
697 AnnotatedPrimary /* returns RelaxngPattern */
698 : LeadAnnotatedPrimary FollowAnnotations
700 // FIXME: handle followAnnotations
705 AnnotatedDataExcept /* returns RelaxngPattern */
706 : LeadAnnotatedDataExcept FollowAnnotations
708 // FIXME: handle followAnnotations
713 LeadAnnotatedDataExcept /* returns RelaxngData */
714 : Annotations DataExcept
720 LeadAnnotatedPrimary /* returns RelaxngPattern */
721 : Annotations Primary
723 // LAMESPEC: This should return Elements, while ApplyAnnotations() returns Element
724 // RelaxngPatternList list = new RelaxngPatternList ();
725 // list.Add ((RelaxngPattern) ApplyAnnotations ((string) $1, (RelaxngPattern) $2));
727 $$ = (RelaxngPattern) $2;
729 | Annotations OpenParen InnerPattern CloseParen
731 // $$ = (RelaxngPatternList) $3;
732 $$ = (RelaxngPattern) $3;
736 Primary /* returns RelaxngPattern */
737 : KeywordElement NameClass OpenCurly Pattern CloseCurly
739 RelaxngNameClass nc = (RelaxngNameClass) $2;
740 RelaxngElement el = new RelaxngElement ();
743 FillElementDefaultNS (el.NameClass);
744 el.Patterns.Add ((RelaxngPattern) $4);
747 | KeywordAttribute NameClass OpenCurly Pattern CloseCurly
749 RelaxngNameClass nc = (RelaxngNameClass) $2;
751 RelaxngAttribute attr = new RelaxngAttribute ();
754 FillAttributeDefaultNS (attr.NameClass);
755 attr.Pattern = (RelaxngPattern) $4;
758 | KeywordMixed OpenCurly Pattern CloseCurly
760 RelaxngMixed mixed = new RelaxngMixed ();
761 FillLocation (mixed);
762 mixed.Patterns.Add ((RelaxngPattern) $3);
765 | KeywordList OpenCurly Pattern CloseCurly
767 RelaxngList list = new RelaxngList ();
769 list.Patterns.Add ((RelaxngPattern) $3);
772 | DatatypeName OptParams
774 RelaxngData data = new RelaxngData ();
776 XmlQualifiedName dtName = (XmlQualifiedName) $1;
777 data.DatatypeLibrary = dtName.Namespace;
778 data.Type = dtName.Name;
779 foreach (RelaxngParam p in (ICollection) $2)
780 data.ParamList.Add (p);
784 | DatatypeName DatatypeValue
786 RelaxngValue value = new RelaxngValue ();
787 FillLocation (value);
788 XmlQualifiedName dtName = (XmlQualifiedName) $1;
789 if (dtName.Namespace != RelaxngGrammar.NamespaceURI)
790 value.DatatypeLibrary = dtName.Namespace;
791 value.Type = dtName.Name;
792 value.Value = (string) $2;
798 RelaxngValue value = new RelaxngValue ();
799 FillLocation (value);
800 value.Value = (string) $1;
802 // RELAX NG default type
803 value.Type = "string";
804 value.DatatypeLibrary = String.Empty;
810 RelaxngEmpty empty = new RelaxngEmpty ();
811 FillLocation (empty);
816 RelaxngNotAllowed na = new RelaxngNotAllowed ();
822 RelaxngText text = new RelaxngText ();
828 RelaxngRef r = new RelaxngRef ();
830 r.Name = (string) $1;
835 RelaxngParentRef pref = new RelaxngParentRef ();
837 pref.Name = (string) $2;
840 | KeywordGrammar OpenCurly Grammar CloseCurly
842 RelaxngGrammar g = new RelaxngGrammar ();
844 FillGrammarContent ((IList) $3, g.Starts, g.Defines, g.Divs, g.Includes);
847 | KeywordExternal AnyURILiteral OptInherit
849 RelaxngExternalRef extref = new RelaxngExternalRef ();
850 FillLocation (extref);
851 extref.Href = (string) $2;
852 extref.NSContext = (string) $3;
857 DataExcept /* returns RelaxngData */
858 : DatatypeName OptParams Minus LeadAnnotatedPrimary
860 XmlQualifiedName type = (XmlQualifiedName) $1;
861 RelaxngData data = new RelaxngData ();
863 data.Type = type.Name;
864 data.DatatypeLibrary = type.Namespace;
865 foreach (RelaxngParam p in (RelaxngParamList) $2)
866 data.ParamList.Add (p);
867 data.Except = new RelaxngExcept ();
868 FillLocation (data.Except);
869 data.Except.Patterns.Add ((RelaxngPattern) $4);
874 Ref /* returns string */
881 string cname = (string) $1;
882 $$ = SplitQName (dtnsmgr, cname);
886 $$ = new XmlQualifiedName ("string", String.Empty);
890 $$ = new XmlQualifiedName ("token", String.Empty);
901 $$ = new RelaxngParamList ();
903 | OpenCurly Params CloseCurly
912 $$ = new RelaxngParamList ();
916 RelaxngParamList al = (RelaxngParamList) $2;
917 al.Insert (0, (RelaxngParam) $1);
922 Param /* returns RelaxngParam */
923 : Annotations IdentifierOrKeyword Equal Literal
925 RelaxngParam prm = new RelaxngParam ();
927 prm.Name = (string) $2;
928 prm.Value = (string) $4;
930 // $$ = ApplyAnnotations ((string) $1, prm);
935 NameClass /* returns RelaxngNameClass */
942 InnerNameClass /* returns RelaxngNameClass */
943 : AnnotatedSimpleNameClass
945 $$ = (RelaxngNameClass) $1;
949 RelaxngNameChoice cho = new RelaxngNameChoice ();
951 RelaxngNameClassList list = (RelaxngNameClassList) $1;
952 for (int i = 0; i < list.Count; i++)
953 cho.Children.Add ((RelaxngNameClass) list [i]);
956 | AnnotatedExceptNameClass
958 $$ = (RelaxngNameClass) $1;
962 NameClassChoice /* returns RelaxngNameClassList */
963 : AnnotatedSimpleNameClass Bar AnnotatedSimpleNameClass
965 RelaxngNameClassList list = new RelaxngNameClassList ();
966 list.Add ((RelaxngNameClass) $1);
967 list.Add ((RelaxngNameClass) $3);
970 | AnnotatedSimpleNameClass Bar NameClassChoice
972 RelaxngNameClassList list = (RelaxngNameClassList) $3;
973 list.Insert (0, (RelaxngNameClass) $1);
978 AnnotatedExceptNameClass /* returns RelaxngNameClass */
979 : LeadAnnotatedExceptNameClass FollowAnnotations
981 $$ = (RelaxngNameClass) $1;
985 LeadAnnotatedExceptNameClass /* returns RelaxngNameClass */
986 : Annotations ExceptNameClass
988 $$ = (RelaxngNameClass) $2;
992 AnnotatedSimpleNameClass /* returns RelaxngNameClass */
993 : LeadAnnotatedSimpleNameClass FollowAnnotations
995 // FIXME: annotations
1000 LeadAnnotatedSimpleNameClass /* returns RelaxngNameClass */
1001 : Annotations SimpleNameClass
1003 // FIXME: applyAnnotations
1004 $$ = (RelaxngNameClass) $2;
1006 | Annotations OpenParen InnerNameClass CloseParen
1013 : NsName Minus LeadAnnotatedSimpleNameClass
1015 RelaxngNsName nsName = new RelaxngNsName ();
1016 FillLocation (nsName);
1017 nsName.Namespace = nsmgr.LookupNamespace ((string) $1);
1018 nsName.Except = new RelaxngExceptNameClass ();
1019 FillLocation (nsName.Except);
1020 nsName.Except.Names.Add ((RelaxngNameClass) $3);
1023 | Asterisk Minus LeadAnnotatedSimpleNameClass
1025 RelaxngAnyName anyName = new RelaxngAnyName ();
1026 FillLocation (anyName);
1027 anyName.Except = new RelaxngExceptNameClass ();
1028 FillLocation (anyName.Except);
1029 anyName.Except.Names.Add ((RelaxngNameClass) $3);
1034 SimpleNameClass /* returns RelaxngNameClass */
1035 : IdentifierOrKeyword
1037 RelaxngName name = new RelaxngName ();
1038 FillLocation (name);
1039 name.LocalName = (string) $1;
1040 name.Namespace = null;
1045 string cname = (string) $1;
1046 XmlQualifiedName qname = SplitQName (nsmgr, cname);
1047 RelaxngName name = new RelaxngName ();
1048 FillLocation (name);
1049 name.LocalName = qname.Name;
1050 name.Namespace = qname.Namespace;
1055 RelaxngNsName nsName = new RelaxngNsName ();
1056 FillLocation (nsName);
1057 nsName.Namespace = nsmgr.LookupNamespace ((string) $1);
1062 RelaxngAnyName anyName= new RelaxngAnyName ();
1063 FillLocation (anyName);
1073 | TwoGreaters AnnotationElement FollowAnnotations
1075 // FIXME: handle them
1080 Annotations /* returns null */
1081 /* FIXME: needed to handle them? */
1086 | Documentations OpenBracket AnnotationContentInAnnotations CloseBracket
1092 // This one is extra to the original syntax rule. Also it and following
1093 // annotation related rules are modified to work fine without ambiguity.
1094 // FIXME: it should reject attributes after elements...
1095 AnnotationContentInAnnotations
1097 | PrefixedName Equal Literal AnnotationContentInAnnotations
1098 | PrefixedName AnnotationAttributesContent AnnotationContentInAnnotations
1099 | IdentifierOrKeyword AnnotationAttributesContent AnnotationContentInAnnotations
1101 // ... but something like this one should be used instead.
1102 AttributableAnnotations
1104 | AttributableAnnotations PrefixedName Equal Literal NonAttributableAnnotations
1107 NonAttributableAnnotations
1109 | PrefixedName AnnotationAttributesContent
1110 | NonAttributableAnnotations IdentifierOrKeyword AnnotationAttributesContent
1115 : ForeignElementName AnnotationAttributesContent
1118 // $$ = Element ($1, $2);
1124 : IdentifierOrKeyword
1126 $$ = new XmlQualifiedName ((string) $1, String.Empty);
1129 // Constraint: RELAX NG namespace URI
1132 // FIXME: due to syntax ambiguity it cannot be included in the creation rules.
1133 AnnotationElementNotKeyword /* null */
1138 AnnotationElementNotKeyword // null
1139 : ForeignElementNameNotKeyword AnnotationAttributeContent
1146 ForeignElementNameNotKeyword // QName
1149 $$ = new XmlQualifiedName ((string) $1, String.Empty);
1153 // Constraint: RELAX NG namespace URI
1154 $$ = (XmlQualifiedName) $1;
1159 AnnotationAttributesContent /* returns null */
1160 : OpenBracket NestedAnnotationContents CloseBracket
1166 // ditto (see also AnnotationContentInAnnotations)
1167 NestedAnnotationContents
1169 | PrefixedName Equal Literal NestedAnnotationContents
1170 | IdentifierOrKeyword Equal Literal NestedAnnotationContents
1171 | PrefixedName AnnotationAttributesContent NestedAnnotationContents
1172 | IdentifierOrKeyword AnnotationAttributesContent NestedAnnotationContents
1174 | Literal NestedAnnotationContents
1177 NestedAnnotationAttributes /* returns null */
1182 | AnyAttributeName Equal Literal NestedAnnotationAttributes
1184 // Constraint: duplicate attributes
1187 // $$ = Attribute ($1, $2);
1191 AnyAttributeName /* returns XmlQualifiedName */
1192 : IdentifierOrKeyword
1194 $$ = new XmlQualifiedName ((string) $1);
1198 // Constraint: xmlns namespace URI
1199 $$ = (XmlQualifiedName) $1;
1203 AnnotationContent /* returns null */
1208 | NestedAnnotationElement AnnotationContent
1212 | Literal AnnotationContent
1218 NestedAnnotationElement /* returns null */
1219 : AnyElementName AnnotationAttributesContent
1222 // $$ = Element ($1, $2);
1227 AnyElementName /* returns XmlQualifiedName */
1228 : IdentifierOrKeyword
1230 $$ = new XmlQualifiedName ((string) $1, String.Empty);
1234 $$ = (XmlQualifiedName) $1;
1238 PrefixedName /* returns XmlQualifiedName */
1241 // Constraint: annotation inherit
1242 $$ = SplitQName (nsmgr, (string) $1);
1246 Documentations /* returns null */
1251 | Documentation Documentations
1254 // $$ = Element (DocumentationElementName (), Text ((string) $1), $2);
1259 IdentifierOrKeyword /* returns string */
1270 Keyword /* returns string */
1292 Literal /* returns string */
1297 | LiteralSegment Tilde Literal
1299 $$ = (string) $1 + (string) $3;
1303 Identifier /* returns string */