| (* Copyright 2015 The Chromium Authors. All rights reserved. |
| Use of this source code is governed by a BSD-style license that can be |
| found in the LICENSE file. *) |
| |
| (* mojom_file is the root production rule. *) |
| mojom_file = [ module_decl ] , { import_stmt } , { primary_object_decl } ; |
| module_decl = attribute_section , "module" , identifier , ";" ; |
| import_stmt = "import" , STRING_LITERAL , ";" ; |
| primary_object_decl = interface_decl | struct_decl | union_decl | enum_decl | const_decl ; |
| attribute_section = [ "[" , attribute_list , "]" ] ; |
| attribute_list = [ attribute_assignment , { "," , attribute_assignment } ] ; |
| attribute_assignment = NAME , "=" , ( NAME | literal ) ; |
| interface_decl = attribute_section , "interface" , NAME , "{" , interface_body , "}" , ";" ; |
| interface_body = { method_decl | enum_decl | const_decl } ; |
| method_decl = attribute_section , NAME , [ ORDINAL ] , "(" , parameter_list , ")" , response_decl , ";" ; |
| response_decl = [ "=>" , "(" , parameter_list , ")" ] ; |
| parameter_list = [ parameter_decl { "," , parameter_decl } ] ; |
| parameter_decl = attribute_section , typespec , NAME , [ ORDINAL ] ; |
| struct_decl = attribute_section , "struct" , NAME , "{" , struct_body , "}" , ";" ; |
| struct_body = { struct_field_decl | enum_decl | const_decl } ; |
| struct_field_decl = attribute_section , typespec , NAME , [ ORDINAL ] , default_value_assignment , ";" ; |
| union_decl = attribute_section , "union" , NAME , "{" , union_body , "}" , ";" ; |
| union_body = { union_field_decl } ; |
| union_field_decl = attribute_section , typespec , NAME , [ ORDINAL ] , ";" ; |
| default_value_assignment = [ "=" , constant ] ; |
| enum_decl = attribute_section , "enum" , NAME , "{" , enum_value_list , [ "," ] , "}" , ";" ; |
| enum_value_list = enum_value , { "," , enum_value } ; |
| enum_value = attribute_section , NAME , [ "=" , ( identifier | int_literal ) ] ; |
| const_decl = "const" , typespec , NAME , "=" , constant , ";" ; |
| typespec = nonnullable_typespec , [ "?" ] ; |
| nonnullable_typespec = basictypespec | map_typespec | array_typespec |
| | fixed_array_typespec | interface_request_typespec ; |
| basictypespec = handle_typespec | identifier ; |
| handle_typespec = "handle" , [ "<" , NAME , ">" ] ; |
| array_typespec = "array" , "<" , typespec , ">" ; |
| fixed_array_typespec = "array" , "<" , typespec , "," , INT_CONST_DEC , ">" ; |
| map_typespec = "map" , "<" , identifier , "," , typespec , ">" ; |
| interface_request_typespec = identifier , "&" ; |
| constant = identifier | literal ; |
| identifier = NAME , [ "." , identifier ] ; |
| literal = "default" | "true" | "false" | int_literal |
| | float_literal | STRING_LITERAL ; |
| float_literal = [ "-" | "+" ] , FLOAT_CONST ; |
| int_literal = [ "-" | "+" ] , int_const ; |
| int_const = INT_CONST_DEC | INT_CONST_HEX ; |
| |
| (* Capitalized names are terminals expressed as regular expressions. *) |
| ORDINAL = @[0-9]+ |
| |
| (* character constants (K&R2: A.2.5.2) *) |
| STRING_LITERAL = "([^"\\\n]|(\\(([a-zA-Z._~!=&\^\-\\?'"])|(\d+)|(x[0-9a-fA-F]+))))*" |
| |
| (* integer constants (K&R2: A.2.5.1) *) |
| INT_CONST_HEX = 0[xX][0-9a-fA-F]+ |
| INT_CONST_DEC = 0|([1-9][0-9]*) |
| |
| (* floating constants (K&R2: A.2.5.3) *) |
| FLOAT_CONST = ((((([0-9]*\.[0-9]+)|([0-9]+\.))([eE][-+]?[0-9]+)?)|([0-9]+([eE][-+]?[0-9]+)))) |
| |
| (* valid C identifiers (K&R2: A.2.3) |
| Some names are reserved. That is indicated by their literal use in the grammar |
| above. *) |
| NAME = [a-zA-Z_][0-9a-zA-Z_]* |