GDL 연습 2: 가상 템플릿에서 상속

운동

2바이트를 사용하여 1개의 유니코드 문자를 나타내도록 인코딩되는 유니코드 문자열을 허용하는 데이터 형식을 정의합니다. 그런 다음, 이전에 정의된 가상 템플릿에서 상속되는 가상이 아닌 템플릿을 정의합니다. 연습 1에서 만든 스키마를 수정하지 마세요. 샘플 GDL 데이터 파일을 만들고 스키마가 올바르게 적용되었는지 확인합니다. 스키마를 준수하지 않는 샘플 GDL 데이터 파일을 만들고 오류가 검색되었는지 확인합니다.

솔루션

다음 두 템플릿은 유니코드 데이터 형식을 정의합니다.

*Include: MasterTemplate.gdl
 
*Template:  XML_STRING
{
    *Type:  DATATYPE
    *DataType:   XML_TYPE
    *XMLDataType: "string"
}
*Template:  NORMAL_STRING
{
    *Type:  DATATYPE
    *DataType:   FILTER_TYPE
    *ElementType:  XML_STRING
    *FilterTypeName: "NORMAL_STRING"
}

다음 템플릿은 연습 1에 정의된 템플릿에서 상속됩니다. *Command라는 구문과 세 가지 유형의 특성이 있습니다. *이름 (루트 수준에 표시됨), *CommandName (*Command 구문 내에 나타날 수 있음), *UniName (두 컨텍스트 내에 나타날 수 있음).

*Template:  COMMAND
{
    *Name:  "*Command"
    *Inherits: CONSTRUCTS
    *Instances:  <ANY>
}
*Template:  ROOT_NAME
{
    *Name:  "*Name"
    *Inherits: ROOT_ATTRIB
    *ValueType:  NORMAL_STRING
}
*Template:  CMD_NAME
{
    *Name:  "*CommandName"
    *Inherits: CONSTRUCT_ATTRIB
    *ValueType:  NORMAL_STRING
}
*Template:  UNIVERSAL_NAME
{
    *Name:  "*UniName"
    *Inherits: FREEFLOAT
    *ValueType:  NORMAL_STRING
}

다음 GDL 파일은 지정된 스키마를 준수합니다.

*Name: "can only appear at root level"
*UniName:  "can appear anywhere"
*Command: X
{
    *CommandName:  "May only appear within a command"
    *UniName:  "can appear anywhere, even in a command"
    *Command: nested
    {
        *CommandName:  "nested commands are ok."
        *UniName:  "template defined a recursive nesting" 100 %
    }
}

다음 GDL 파일은 지정된 스키마를 준수하지 않습니다.

*CommandName:  "Error! May only appear within a command"
*Command: X
{
    *Name: "Error! can only appear at root level"
}