import java.util.*; import java.io.*; //****************************************************************************** // Basic definitions //****************************************************************************** Main = . Preprocessor = . Utils = . GenerateBasicMethods = . Formatter = String String String. List(S) ~ {S}. L4List(S) ~ {lookahead {{4}} S}. //****************************************************************************** // PART 1: Definitions of structures implementing the components of the input // XML schema specification //****************************************************************************** NSRef = Ident ":". AttrValue = [ lookahead {{2}} NSRef ] Ident "=" String. Schema = " List(AttrValue) "?>" "<" [ NSRef ] "schema" List(AttrValue) ">" List(SchemaItem) " NSRef ] "schema>". SchemaItem : lookahead {{4}} ImportSchema | lookahead {{4}} IncludeSchema | lookahead {{4}} RedefineSchema | lookahead {{4}} Annotation | lookahead {{4}} AttributeItem | lookahead {{4}} ElementItem | lookahead {{4}} Notation | lookahead {{4}} TypeDef | Comment. ImportSchema = "<" [ NSRef ] "import" List(AttrValue) RestOfImportSchema. RestOfImportSchema : EmptyImportSchema | NonEmptyImportSchema. EmptyImportSchema = "/>". NonEmptyImportSchema = ">" [ Annotation ] " NSRef ] "import>". IncludeSchema = "<" [ NSRef ] "include" List(AttrValue) RestOfIncludeSchema. RestOfIncludeSchema : EmptyIncludeSchema | NonEmptyIncludeSchema. EmptyIncludeSchema = "/>". NonEmptyIncludeSchema = ">" [ Annotation ] " NSRef ] "include>". RedefineSchema = "<" [ NSRef ] "redefine" List(AttrValue) RestOfRedefineSchema. RestOfRedefineSchema : EmptyRedefineSchema | NonEmptyRedefineSchema. EmptyRedefineSchema = "/>". NonEmptyRedefineSchema = ">" List(SchemaItem) " NSRef ] "redefine>". AttributeItem : lookahead {{4}} Attribute | lookahead {{4}} AttributeGroup. Annotation = "<" [ NSRef ] "annotation>" List(AnnotationContent) " NSRef ] "annotation>". AnnotationContent : lookahead {{4}} Appinfo | lookahead {{4}} Documentation. Appinfo = "<" [ NSRef ] "appinfo>" List(AttrValue) " NSRef ] "appinfo>". Documentation = "<" [ NSRef ] "documentation" List(AttrValue) RestOfDocumentation. RestOfDocumentation : EmptyDocumentation | NonEmptyDocumentation. EmptyDocumentation = "/>". NonEmptyDocumentation = ">" [ String ] " NSRef ] "documentation>". Attribute = "<" [ NSRef ] "attribute" List(AttrValue) RestOfAttribute. RestOfAttribute : EmptyAttribute | NonEmptyAttribute. EmptyAttribute = "/>". NonEmptyAttribute = ">" [ lookahead {{4}} Annotation ] [ lookahead {{4}} SimpleType ] " NSRef ] "attribute>". AttributeGroup = "<" [ NSRef ] "attributeGroup" List(AttrValue) RestOfAttrGroup. RestOfAttrGroup : EmptyAttrGroup | NonEmptyAttrGroup. EmptyAttrGroup = "/>". NonEmptyAttrGroup = ">" [ lookahead {{4}} Annotation ] List(AttributeItem) " NSRef ] "attributeGroup>". Element = "<" [ NSRef ] "element" List(AttrValue) RestOfElement. RestOfElement : EmptyElement | NonEmptyElement. EmptyElement = "/>". NonEmptyElement = ">" [ lookahead {{4}} Annotation ] [ lookahead {{4}} TypeDef ] [ lookahead {{4}} Key ] [ lookahead {{4}} Keyref ] [ lookahead {{4}} UniqueSpec ] " NSRef ] "element>". Key = "<" [ NSRef ] "key" List(AttrValue) ">" [ lookahead {{4}} Annotation ] Selector List(Field) " NSRef ] "key>". Keyref = "<" [ NSRef ] "keyref" List(AttrValue) ">" [ lookahead {{4}} Annotation ] Selector List(Field) " NSRef ] "keyref>". UniqueSpec = "<" [ NSRef ] "unique" List(AttrValue) ">" [ lookahead {{4}} Annotation ] Selector List(Field) " NSRef ] "unique>". Selector = "<" [ NSRef ] "selector" List(AttrValue) RestOfSelector. RestOfSelector : EmptySelector | NonEmptySelector. EmptySelector = "/>". NonEmptySelector = ">" [ Annotation ] " NSRef ] "selector>". Field = "<" [ NSRef ] "field" List(AttrValue) RestOfField. RestOfField : EmptyField | NonEmptyField. EmptyField = "/>". NonEmptyField = ">" [ Annotation ] " NSRef ] "field>". ElementGroup = "<" [ NSRef ] "group" List(AttrValue) RestOfElementGroup. RestOfElementGroup : EmptyElementGroup | NonEmptyElementGroup. EmptyElementGroup = "/>". NonEmptyElementGroup = ">" [ lookahead {{4}} Annotation ] List(ElementItem) " NSRef ] "group>". Notation = "<" [ NSRef ] "notation" List(AttrValue) RestOfNotation. RestOfNotation : EmptyNotation | NonEmptyNotation. EmptyNotation = "/>". NonEmptyNotation = ">" [ Annotation ] " NSRef ] "notation>". TypeDef : lookahead {{4}} SimpleType | lookahead {{4}} ComplexType. SimpleType = "<" [ NSRef ] "simpleType" List(AttrValue) ">" [ lookahead {{4}} Annotation ] SimpleTypeVariety " NSRef ] "simpleType>". SimpleTypeVariety = [ lookahead {{4}} ListVariety ] [ lookahead {{4}} UnionVariety ] [ lookahead {{4}} Restriction ]. ListVariety = "<" [ NSRef ] "list" List(AttrValue) RestOfListVariety. RestOfListVariety : EmptyListVariety | NonEmptyListVariety. EmptyListVariety = "/>". NonEmptyListVariety = ">" [ lookahead {{4}} Annotation ] [ lookahead {{4}} SimpleType ] " NSRef ] "list>". UnionVariety = "<" [ NSRef ] "union" List(AttrValue) RestOfUnionVariety. RestOfUnionVariety : EmptyUnionVariety | NonEmptyUnionVariety. EmptyUnionVariety = "/>". NonEmptyUnionVariety = ">" [ lookahead {{4}} Annotation ] [ lookahead {{4}} SimpleType ] " NSRef ] "union>". ComplexType = "<" [ NSRef ] "complexType" List(AttrValue) RestOfComplexType. RestOfComplexType : EmptyComplexType | NonEmptyComplexType. EmptyComplexType = "/>". NonEmptyComplexType = ">" [ lookahead {{4}} Annotation ] ComplexTypeContent List(AttributeItem) " NSRef ] "complexType>". ComplexTypeContent = [ lookahead {{4}} SimpleContent ] [ lookahead {{4}} ComplexContent ] [ lookahead {{4}} ElementItem ]. SimpleContent = "<" [ NSRef ] "simpleContent" List(AttrValue) ">" [ lookahead {{4}} Annotation ] TypeDerivation " NSRef ] "simpleContent>". TypeDerivation : lookahead {{4}} Restriction | lookahead {{4}} Extension. Restriction = "<" [ NSRef ] "restriction" List(AttrValue) RestOfRestriction. RestOfRestriction : EmptyRestriction | NonEmptyRestriction. EmptyRestriction = "/>". NonEmptyRestriction = ">" [ lookahead {{4}} Annotation ] L4List(ConstrainingFacet) [ lookahead {{4}} ElementItem ] List(AttributeItem) " NSRef ] "restriction>". ConstrainingFacet : lookahead {{4}} EnumerationSpec | lookahead {{4}} LengthSpec | lookahead {{4}} MaxExclusive | lookahead {{4}} MaxInclusive | lookahead {{4}} MaxLength | lookahead {{4}} MinExclusive | lookahead {{4}} MinInclusive | lookahead {{4}} MinLength | lookahead {{4}} Pattern | lookahead {{4}} TotalDigits | lookahead {{4}} FractionDigits | lookahead {{4}} Whitespace. EnumerationSpec = "<" [ NSRef ] "enumeration" List(AttrValue) RestOfEnumerationSpec. RestOfEnumerationSpec : EmptyEnumerationSpec | NonEmptyEnumerationSpec. EmptyEnumerationSpec = "/>". NonEmptyEnumerationSpec = ">" [ Annotation ] " NSRef ] "enumeration>". LengthSpec = "<" [ NSRef ] "length" List(AttrValue) RestOfLengthSpec. RestOfLengthSpec : EmptyLengthSpec | NonEmptyLengthSpec. EmptyLengthSpec = "/>". NonEmptyLengthSpec = ">" [ Annotation ] " NSRef ] "length>". MaxExclusive = "<" [ NSRef ] "maxExclusive" List(AttrValue) RestOfMaxExclusive. RestOfMaxExclusive : EmptyMaxExclusive | NonEmptyMaxExclusive. EmptyMaxExclusive = "/>". NonEmptyMaxExclusive = ">" [ Annotation ] " NSRef ] "maxExclusive>". MaxInclusive = "<" [ NSRef ] "maxInclusive" List(AttrValue) RestOfMaxInclusive. RestOfMaxInclusive : EmptyMaxInclusive | NonEmptyMaxInclusive. EmptyMaxInclusive = "/>". NonEmptyMaxInclusive = ">" [ Annotation ] " NSRef ] "maxInclusive>". MaxLength = "<" [ NSRef ] "maxLength" List(AttrValue) RestOfMaxLength. RestOfMaxLength : EmptyMaxLength | NonEmptyMaxLength. EmptyMaxLength = "/>". NonEmptyMaxLength = ">" [ Annotation ] " NSRef ] "maxLength>". MinExclusive = "<" [ NSRef ] "minExclusive" List(AttrValue) RestOfMinExclusive. RestOfMinExclusive : EmptyMinExclusive | NonEmptyMinExclusive. EmptyMinExclusive = "/>". NonEmptyMinExclusive = ">" [ Annotation ] " NSRef ] "minExclusive>". MinInclusive = "<" [ NSRef ] "minInclusive" List(AttrValue) RestOfMinInclusive. RestOfMinInclusive : EmptyMinInclusive | NonEmptyMinInclusive. EmptyMinInclusive = "/>". NonEmptyMinInclusive = ">" [ Annotation ] " NSRef ] "minInclusive>". MinLength = "<" [ NSRef ] "minLength" List(AttrValue) RestOfMinLength. RestOfMinLength : EmptyMinLength | NonEmptyMinLength. EmptyMinLength = "/>". NonEmptyMinLength = ">" [ Annotation ] " NSRef ] "minLength>". Pattern = "<" [ NSRef ] "pattern" List(AttrValue) RestOfPattern. RestOfPattern : EmptyPattern | NonEmptyPattern. EmptyPattern = "/>". NonEmptyPattern = ">" [ Annotation ] " NSRef ] "pattern>". TotalDigits = "<" [ NSRef ] "totalDigits" List(AttrValue) RestOfTotalDigits. RestOfTotalDigits : EmptyTotalDigits | NonEmptyTotalDigits. EmptyTotalDigits = "/>". NonEmptyTotalDigits = ">" [ Annotation ] " NSRef ] "totalDigits>". FractionDigits = "<" [ NSRef ] "fractionDigits" List(AttrValue) RestOfFractionDigits. RestOfFractionDigits : EmptyFractionDigits | NonEmptyFractionDigits. EmptyFractionDigits = "/>". NonEmptyFractionDigits = ">" [ Annotation ] " NSRef ] "fractionDigits>". Whitespace = "<" [ NSRef ] "whitespace" List(AttrValue) RestOfWhitespace. RestOfWhitespace : EmptyWhitespace | NonEmptyWhitespace. EmptyWhitespace = "/>". NonEmptyWhitespace = ">" [ Annotation ] " NSRef ] "whitespace>". Extension = "<" [ NSRef ] "extension" List(AttrValue) RestOfExtension. RestOfExtension : EmptyExtension | NonEmptyExtension. EmptyExtension = "/>". NonEmptyExtension = ">" [ lookahead {{4}} Annotation ] [ lookahead {{4}} ElementItem ] List(AttributeItem) " NSRef ] "extension>". ComplexContent = "<" [ NSRef ] "complexContent" List(AttrValue) ">" [ lookahead {{4}} Annotation ] TypeDerivation " NSRef ] "complexContent>". ElementItem : lookahead {{4}} Element | lookahead {{4}} ElementGroup | lookahead {{4}} AllGroup | lookahead {{4}} ChoiceGroup | lookahead {{4}} SequenceGroup. AllGroup = "<" [ NSRef ] "all" List(AttrValue) ">" [ lookahead {{4}} Annotation ] List(Element) " NSRef ] "all>". ChoiceGroup = "<" [ NSRef ] "choice" List(AttrValue) ">" [ lookahead {{4}} Annotation ] List(ElementItem) " NSRef ] "choice>". SequenceGroup = "<" [ NSRef ] "sequence" List(AttrValue) ">" [ lookahead {{4}} Annotation ] List(ElementItem) " NSRef ] "sequence>". Comment = "". //****************************************************************************** // PART 2: Definitions of data structures for storing the elements, types, etc. // described by the input schema specification //****************************************************************************** CDDef = [ "Root" DataElement ] "(" Hashtable ")" "(" Hashtable ")" Hashtable Hashtable List(DataClass). DataItem : DataElement | ClassPart common String String [ Boolean ]. DataElement = "DataElement" [ Boolean ]. ClassPart : AttrClassPart | ElementClassPart common Constraint. AttrClassPart = "AttrClassPart". ElementClassPart = "ElementClassPart" [ Boolean ]. GlobalAttrGroup = "GlobalAttrGroup" String List(AttrClassPart). DataClass = "DataClass" String String boolean "(" List(SubclassSpec) ")" "(" List(AttrClassPart) ")" "(" List(ElementClassPart) ")" [ "sup" String ] [ "supA" Boolean ] [ "mix" Boolean ]. SubclassSpec = String int. Constraint = "Constraint" int int ["grp" Boolean] ["all" Boolean] ["fix" String] ["def" String] ["id" Boolean] ["idref" Boolean] ["enum" String] ["len" Integer] ["maxL" Integer] ["minL" Integer] ["maxV" String] ["maxI" Boolean] ["minV" String] ["minI" Boolean] ["pat" String] ["dig" Integer] ["frac" Integer] ["ws" String]. //****************************************************************************** // PART 3: Definitions of visitors for traversing the schema object and // CD-definition object //****************************************************************************** visitor SchemaVisitor = CDDef. visitor GenerateCDVisitor = String String. visitor GenerateInitsVisitor = String String. visitor GenerateValidationsVisitor = String String.