import java.util.*; import java.io.*; import edu.neu.ccs.demeter.dj.*; //****************************************************************************** // Basic definitions //****************************************************************************** Main = . Preprocessor = . Lookup = . 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 = "<" [ 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) ">" [ 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) ">" [ 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) ">" [ 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) ">" [ lookahead (@4@) Annotation ] [ lookahead (@4@) SimpleType ] L4List(ConstrainingFacet) List(AttributeItem) " NSRef ] "restriction>". ConstrainingFacet : lookahead (@4@) Duration | lookahead (@4@) Encoding | 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@) Period | lookahead (@4@) Precision | lookahead (@4@) Scale | lookahead (@4@) Whitespace. Duration = "<" [ NSRef ] "duration" List(AttrValue) RestOfDuration. RestOfDuration : EmptyDuration | NonEmptyDuration. EmptyDuration = "/>". NonEmptyDuration = ">" [ Annotation ] " NSRef ] "duration>". Encoding = "<" [ NSRef ] "encoding" List(AttrValue) RestOfEncoding. RestOfEncoding : EmptyEncoding | NonEmptyEncoding. EmptyEncoding = "/>". NonEmptyEncoding = ">" [ Annotation ] " NSRef ] "encoding>". 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>". Period = "<" [ NSRef ] "period" List(AttrValue) RestOfPeriod. RestOfPeriod : EmptyPeriod | NonEmptyPeriod. EmptyPeriod = "/>". NonEmptyPeriod = ">" [ Annotation ] " NSRef ] "period>". Precision = "<" [ NSRef ] "precision" List(AttrValue) RestOfPrecision. RestOfPrecision : EmptyPrecision | NonEmptyPrecision. EmptyPrecision = "/>". NonEmptyPrecision = ">" [ Annotation ] " NSRef ] "precision>". Scale = "<" [ NSRef ] "scale" List(AttrValue) RestOfScale. RestOfScale : EmptyScale | NonEmptyScale. EmptyScale = "/>". NonEmptyScale = ">" [ Annotation ] " NSRef ] "scale>". Whitespace = "<" [ NSRef ] "whitespace" List(AttrValue) RestOfWhitespace. RestOfWhitespace : EmptyWhitespace | NonEmptyWhitespace. EmptyWhitespace = "/>". NonEmptyWhitespace = ">" [ Annotation ] " NSRef ] "whitespace>". Extension = "<" [ NSRef ] "extension" List(AttrValue) ">" [ lookahead (@4@) Annotation ] 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 | lookahead (@4@) AnyContent. 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>". AnyContent = "<" [ NSRef ] "any" List(AttrValue) RestOfAnyContent. RestOfAnyContent : EmptyAnyContent | NonEmptyAnyContent. EmptyAnyContent = "/>". NonEmptyAnyContent = ">" List(Word) " NSRef ] "any>". 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. DataElement = "DataElement". ClassPart : AttrClassPart | ElementClassPart common Constraint. AttrClassPart = "AttrClassPart". ElementClassPart = "ElementClassPart". GlobalGroup = "GlobalGroup" String List(DataElement). GlobalAttrGroup = "GlobalAttrGroup" String List(DataElement). DataClass = "DataClass" String String boolean "(" List(String) ")" "(" List(AttrClassPart) ")" "(" List(ElementClassPart) ")" [ String ] List(GroupConstraint). GroupConstraint = "GroupConstraint" char List(String). Constraint = "Constraint" int int ["minV" String] ["minI" Boolean] ["maxV" String] ["maxI" Boolean] ["pat" String]. //****************************************************************************** // PART 3: Definitions of visitors for traversing the schema object and // CD-definition object //****************************************************************************** SchemaVisitor = CDDef extends Visitor. CDPrintVisitor = String extends Visitor. BehPrintVisitor : BehDJPrintVisitor | BehDemeterJPrintVisitor common String extends Visitor. BehDJPrintVisitor = "DJ". BehDemeterJPrintVisitor = "DEMETERJ".