次の方法で共有


GDL 演習 2: 仮想テンプレートから継承する

演習

1 つの Unicode 文字を表すために 2 バイトを使用してエンコードされた Unicode 文字列を受け入れるデータ型を定義します。 次に、前に定義した仮想テンプレートから継承する非仮想テンプレートを定義します。 演習 1 で作成したスキーマは変更しないでください。 例の GDL データ ファイルを作成し、スキーマが正しく適用されていることを確認します。 スキーマに準拠していないサンプル GDL データ ファイルを作成し、エラーが検出されたことを確認します。

ソリューション

次の 2 つのテンプレートは、Unicode データ型を定義します。

*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 という名前のコンストラクトと 3 種類の属性があります。*Name (ルート レベルで表示されます)、*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"
}