Dear Wiki user, You have subscribed to a wiki page or wiki category on "Thrift Wiki" for change notification.
The following page has been changed by ChadWalters: http://wiki.apache.org/thrift/ThriftIDL The comment on the change is: Start fleshing out descriptions of the productions ------------------------------------------------------------------------------ ''Under construction'' - Here is a description of the Thrift IDL: + Here is a description of the Thrift IDL. - - {{{Document ::= Header* Definition*}}} - - {{{Header ::= Include | CppInclude | Namespace}}} - - {{{Include ::= 'include' Literal}}} - - {{{CppInclude ::= 'cpp_include' Literal}}} - - {{{Namespace ::= 'namespace' ( ( NamespaceScope Identifier ) |}}}[[BR]] - {{{ ( 'xsd_namespace' Literal ) |}}}[[BR]] - {{{ ( 'php_namespace' Literal ) |}}}[[BR]] - {{{ ( 'smalltalk.category' STIdentifier ) |}}}[[BR]] - {{{ ( 'smalltalk.prefix' Identifier ) )}}} - - {{{NamespaceScope ::= '*' | 'cpp' | 'java' | 'py' | 'perl' | 'rb' | 'cocoa' | 'csharp'}}} - - {{{Definition ::= Const | Typedef | Enum | Senum | Struct | Xception | Service}}} - - {{{Const ::= 'const' FieldType Identifier '=' ConstValue ListSeparator?}}} - - {{{Typedef ::= 'typedef' DefinitionType Identifier}}} - - {{{Enum ::= 'enum' Identifier '{' (Identifier ('=' IntConstant)* ListSeparator?)*}}} - - {{{Senum ::= 'senum' Identifier '{' (Literal ListSeparator?)* }}} - - {{{Struct ::= 'struct' Identifier 'xsd_all'? '{' Field* '}'}}} - - {{{Xception ::= 'exception' Identifier '{' Field* '}' }}} - - {{{Service ::= 'service' Identifier ( 'extends' Identifier )? '{' Function* '}'}}} - - {{{Field ::= FieldID? FieldReq? Identifier ('= ConstValue)? XsdFieldOptions ListSeparator?}}} - - {{{FieldID ::= IntConstant ':'}}} - - {{{XsdFieldOptions ::= 'xsd_optional'? 'xsd_nillable'? XsdAttrs?}}} - - {{{XsdAttrs ::= 'xsd_attrs' '{' Field* '}'}}} - - {{{FieldType ::= Identifier | BaseType | ContainerType}}} - - {{{FieldReq ::= 'required' | 'optional'}}} - - {{{DefinitionType ::= BaseType | ContainerType}}} - - {{{BaseType ::= 'bool' | 'byte' | 'i16' | 'i32' | 'i64' | 'double' |}}}[[BR]] - {{{ 'string' | 'binary' | 'slist'}}} - - {{{ContainerType ::= MapType | SetType | ListType}}} - - {{{MapType ::= 'map' CppType? '<' FieldType ',' FieldType '>'}}} - - {{{SetType ::= 'set' CppType? '<' FieldType '>'}}} - - {{{ListType ::= 'list' '<' FieldType '>' CppType?}}} - - {{{CppType ::= 'cpp_type' Literal}}} - - {{{Function ::= 'async'? FunctionType Identifier '(' Field* ')' Throws? ListSeparator?}}} - - {{{FunctionType ::= FieldType | 'void'}}} - - {{{Throws ::= 'throws' '(' Field* ')'}}} - - {{{ConstValue ::= IntConstant | DoubleConstant | Literal | Identifier | ConstList | ConstMap}}} - - {{{ConstList ::= '[' (ConstValue ListSeparator?)* ']'}}} - - {{{ConstMap ::= '{' (ConstValue ':' ConstValue ListSeparator?)* '}'}}} - - {{{IntConstant ::= ('+' | '-')? Digit+}}} - - {{{DoubleConstant ::= ('+' | '-')? Digit* ('.' Digit+)? ( ('E' | 'e') IntConstant )?}}} - {{{Literal ::= ('"' [^"]* '"') | ("'" [^']* "'")}}} + == Document == - {{{Identifier ::= ( Letter | '_' ) ( Letter | Digit | '.' | '_' )*}}} + Every Thrift document contains 0 or more headers followed by 0 or more definitions. - {{{STIdentifier ::= ( Letter | '_' ) ( Letter | Digit | '.' | '_' | '-' )*}}} + {{{[1] Document ::= Header* Definition*}}} - {{{ListSeparator ::= ',' | ';'}}} + == Header == - {{{Letter ::= ['A'-'Z'] | ['a'-'z']}}} + A header is either a Thrift include, a C++ include, or a namespace declaration. + {{{[2] Header ::= Include | CppInclude | Namespace}}} + + === Thrift Include === + + A Thrift include includes another Thrift document in the current Thrift document. + + {{{[3] Include ::= 'include' Literal}}} + + === C++ Include === + + A C++ include adds a custom C++ include to the output of the C++ code generator for this Thrift document. + + {{{[4] CppInclude ::= 'cpp_include' Literal}}} + + === Namespace === + + A namespace declares which namespaces/package/module/etc. the type definitions in this file will be declared in for the target languages. The namespace scope indicates which language the namespace applies to; a scope of '*' indicates that the namespace applies to all target languages. + + {{{[5] Namespace ::= 'namespace' ( ( NamespaceScope Identifier ) |}}}[[BR]] + {{{ ( 'php_namespace' Literal ) |}}}[[BR]] + {{{ ( 'smalltalk.category' STIdentifier ) |}}}[[BR]] + {{{ ( 'smalltalk.prefix' Identifier ) |}}}[[BR]] + {{{ ( 'xsd_namespace' Literal ) )}}} + + {{{[6] NamespaceScope ::= '*' | 'cpp' | 'java' | 'py' | 'perl' | 'rb' | 'cocoa' | 'csharp'}}} + + + NB: The php_namespace directive will be deprecated at some point in the future in favor of the scoped syntax, but the scoped syntax is not yet supported for PHP. + + NB: Smalltalk has two distinct types of namespace commands. + __Can someone who knows Smalltalk explain why Smalltalk needs two different kinds of namespaces?__ + + NB: The xsd_namespace directive has some purpose internal to Facebook but serves no purpose in Thrift itself. Use of this feature is strongly discouraged + + == Definition == + + {{{[7] Definition ::= Const | Typedef | Enum | Senum | Struct | Exception | Service}}} + + === Const === + + {{{[8] Const ::= 'const' FieldType Identifier '=' ConstValue ListSeparator?}}} + + === Typedef === + + {{{[9] Typedef ::= 'typedef' DefinitionType Identifier}}} + + === Enum === + + {{{[10] Enum ::= 'enum' Identifier '{' (Identifier ('=' IntConstant)* ListSeparator?)*}}} + + === Senum === + + {{{[11] Senum ::= 'senum' Identifier '{' (Literal ListSeparator?)* }}} + + === Struct === + + {{{[12] Struct ::= 'struct' Identifier 'xsd_all'? '{' Field* '}'}}} + + === Exception === + + {{{[13] Exception ::= 'exception' Identifier '{' Field* '}' }}} + + === Service === + + {{{[14] Service ::= 'service' Identifier ( 'extends' Identifier )? '{' Function* '}'}}} + + == Field == + + {{{[15] Field ::= FieldID? FieldReq? Identifier ('= ConstValue)? XsdFieldOptions ListSeparator?}}} + + === Field ID === + + {{{[16] FieldID ::= IntConstant ':'}}} + + === Field Requiredness === + + {{{[17] FieldReq ::= 'required' | 'optional'}}} + + + === XSD Options === + + NB: These have some internal purpose at Facebook but serve no current purpose in Thrift. Use of these options is strongly discouraged. + + {{{[18] XsdFieldOptions ::= 'xsd_optional'? 'xsd_nillable'? XsdAttrs?}}} + + {{{[19] XsdAttrs ::= 'xsd_attrs' '{' Field* '}'}}} + + == Functions == + + {{{[20] Function ::= 'async'? FunctionType Identifier '(' Field* ')' Throws? ListSeparator?}}} + + {{{[21] FunctionType ::= FieldType | 'void'}}} + + {{{[22] Throws ::= 'throws' '(' Field* ')'}}} + + == Types == + + {{{[23] FieldType ::= Identifier | BaseType | ContainerType}}} + + {{{[24] DefinitionType ::= BaseType | ContainerType}}} + + {{{[25] BaseType ::= 'bool' | 'byte' | 'i16' | 'i32' | 'i64' | 'double' |}}}[[BR]] + {{{ 'string' | 'binary' | 'slist'}}} + + {{{[26] ContainerType ::= MapType | SetType | ListType}}} + + {{{[27] MapType ::= 'map' CppType? '<' FieldType ',' FieldType '>'}}} + + {{{[28] SetType ::= 'set' CppType? '<' FieldType '>'}}} + + {{{[29] ListType ::= 'list' '<' FieldType '>' CppType?}}} + + {{{[30] CppType ::= 'cpp_type' Literal}}} + + == Constant Values == + + {{{[31] ConstValue ::= IntConstant | DoubleConstant | Literal | Identifier | ConstList | ConstMap}}} + + {{{[32] ConstList ::= '[' (ConstValue ListSeparator?)* ']'}}} + + {{{[33] ConstMap ::= '{' (ConstValue ':' ConstValue ListSeparator?)* '}'}}} + + {{{[34] IntConstant ::= ('+' | '-')? Digit+}}} + + {{{[35] DoubleConstant ::= ('+' | '-')? Digit* ('.' Digit+)? ( ('E' | 'e') IntConstant )?}}} + + + == Basic Definitions == + + === Literal === + + {{{[36] Literal ::= ('"' [^"]* '"') | ("'" [^']* "'")}}} + + === Identifier === + + {{{[37] Identifier ::= ( Letter | '_' ) ( Letter | Digit | '.' | '_' )*}}} + + {{{[38] STIdentifier ::= ( Letter | '_' ) ( Letter | Digit | '.' | '_' | '-' )*}}} + + === List Separator === + + {{{[39] ListSeparator ::= ',' | ';'}}} + + === Letters and Digits === + + {{{[40] Letter ::= ['A'-'Z'] | ['a'-'z']}}} + - {{{Digit ::= ['0'-'9']}}} + {{{[41] Digit ::= ['0'-'9']}}} = Examples =
