FIDL语法


英文原文快照


经修改的BNF规则

下文描述的是FIDL源文件的语法,语法使用经修改的BNF格式表示。

非终结符号由逗号分隔的其他符号序列来表示。

  1. nonterminal = list , of , symbols ;

有些符号是终止符号,它们要么是全部大写,要么是用双引号括起来。

  1. another-nonterminal = THESE , ARE , TERMINALS , AND , SO , IS , "this" ;

或者由管道的形式来表示。

  1. choice = this | that | the-other ;

用括号表示选项(0或1)。

  1. optional = ( maybe , these ) , but , definitely , these ;

重复(0或多个)可用括号和星号表示。

  1. zero-or-more = ( list-part )* ;

另外,重复(1或多个)还可用括号和加号表示。

  1. one-or-more = ( list-part )+ ;

符号

在lex处理期间将忽略空格和注释,因此不会出现在后续的语法中,其中注释采用的是C++样式——//直到行尾。

TODO(US-238):最终注释将作为文档生成系统的一部分,使其变得可读。

语法

file是FIDL文档入口符号。

  1. file = library-header , using-list , declaration-list ;
  2. library-header = ( attribute-list ) , "library" , compound-identifier , ";" ;
  3. using-list = ( using | using-declaration )* ;
  4. using-declaration = "using" , IDENTIFIER , "=" , primitive-type , ";" ;
  5. declaration-list = ( declaration , ";" )* ;
  6. compound-identifier = IDENTIFIER ( "." , IDENTIFIER )* ;
  7. using = "using" , compound-identifier , ( "as" , IDENTIFIER ) , ";" ;
  8. declaration = const-declaration | enum-declaration | interface-declaration |
  9. struct-declaration | union-declaration ;
  10. const-declaration = ( attribute-list ) , "const" , type , IDENTIFIER , "=" , constant ;
  11. enum-declaration = ( attribute-list ) , "enum" , IDENTIFIER , ( ":" , integer-type ) ,
  12. "{" , ( enum-member , ";" )+ , "}" ;
  13. enum-member = IDENTIFIER , ( "=" , enum-member-value ) ;
  14. enum-member-value = IDENTIFIER | NUMERIC-LITERAL ;
  15. interface-declaration = ( attribute-list ) , "interface" , IDENTIFIER ,
  16. ( ":" , super-interface-list ) , "{" , ( interface-method , ";" )* , "}" ;
  17. super-interface-list = compound-identifier
  18. | compound-identifier , "," , super-interface-list
  19. interface-method = ordinal , ":" , interface-parameters
  20. interface-parameters = IDENTIFIER , parameter-list , ( "->" , parameter-list )
  21. | "->" , IDENTIFIER , parameter-list
  22. parameter-list = "(" , parameters , ")" ;
  23. parameters = parameter | parameter , "," , parameter-list ;
  24. parameter = type , IDENTIFIER ;
  25. struct-declaration = ( attribute-list ) , "struct" , IDENTIFIER , "{" , ( struct-field , ";" )* , "}" ;
  26. struct-field = type , IDENTIFIER , ( "=" , constant ) ;
  27. union-declaration = ( attribute-list ) , "union" , IDENTIFIER , "{" , ( union-field , ";" )+ , "}" ;
  28. union-field = type , IDENTIFIER ;
  29. attribute-list = "[" , attributes, "]" ;
  30. attributes = attribute | attribute , "," , attribute ;
  31. attribute = IDENTIFIER , ( "=", STRING-LITERAL ) ;
  32. type = identifier-type | array-type | vector-type | string-type | handle-type
  33. | request-type | primitive-type ;
  34. identifier-type = compound-identifier , ( "?" ) ;
  35. array-type = "array" , "<" , type , ">" , ":" , constant ;
  36. vector-type = "vector" , "<" , type , ">" , ( ":" , constant ) , ( "?" ) ;
  37. string-type = "string" , ( ":" , constant ) , ( "?" ) ;
  38. handle-type = "handle" , ( "<" , handle-subtype , ">" ) , ( "?" ) ;
  39. handle-subtype = "process" | "thread" | "vmo" | "channel" | "event" | "port" |
  40. "interrupt" | "log" | "socket" | "resource" | "eventpair" |
  41. "job" | "vmar" | "fifo" | "guest" | "timer" ;
  42. request-type = "request" , "<" , compound-identifier , ">" , ( "?" ) ;
  43. primitive-type = integer-type | "bool" | "float32" | "float64" ;
  44. integer-type = "int8" | "int16" | "int32" | "int64" |
  45. "uint8" | "uint16" | "uint32" | "uint64" ;
  46. constant = compound-identifier | literal ;
  47. ordinal = NUMERIC-LITERAL ;
  48. literal = STRING-LITERAL | NUMERIC-LITERAL | TRUE | FALSE ;