Skip to content

Instantly share code, notes, and snippets.

@michaelwu
Created June 15, 2015 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelwu/eefab99e7bd879470f4c to your computer and use it in GitHub Desktop.
Save michaelwu/eefab99e7bd879470f4c to your computer and use it in GitHub Desktop.
webidl.rustpeg
// http://heycam.github.io/webidl/#idl-grammar
integer
= "-"? [1-9] [0-9]*
/ "-"? "0" [Xx] [0-9A-Fa-f]+
/ "-"? "0" [0-7]*
float
= "-"? significand exponent?
/ "-"? [0-9]+ exponent
significand
= [0-9]+ "." [0-9]*
/ [0-9]* "." [0-9]+
exponent
= [Ee] [+-]? [0-9]+
identifier
= "_"? [A-Za-z] [0-9A-Z_a-z-]*
string
= "\"" [^"]* "\""
whitespace
= [\t\n\\e ]+
comment
= "//" [^\n]* [\n]
/ "/*" comment_content
comment_content
= "*/"
/ . comment_content
ws
= whitespace ws
/ comment ws
/ ""
other_
= [^\t\n\r 0-9A-Za-z]
#[pub]
definitions
= extended_attribute_list ws definition ws definitions
/ ""
definition
= callback_or_interface
/ partial
/ dictionary
/ enum
/ typedef
/ implements_statement
callback_or_interface
= "callback" ws callback_rest_or_interface
/ interface
callback_rest_or_interface
= callback_rest
/ interface
interface
= "interface" ws identifier ws inheritance ws "{" ws interface_members ws "}" ws ";"
partial
= "partial" ws partial_definition
partial_definition
= partial_interface
/ partial_dictionary
partial_interface
= "interface" ws identifier ws "{" ws interface_members ws "}" ws ";"
interface_members
= extended_attribute_list ws interface_member ws interface_members
/ ""
interface_member
= const
/ operation
/ serializer
/ stringifier
/ static_member
/ iterable
/ readonly_member
/ read_write_attribute
/ read_write_maplike
/ read_write_setlike
dictionary
= "dictionary" ws identifier ws inheritance ws "{" ws dictionary_members "}" ws ";"
dictionary_members
= extended_attribute_list ws dictionary_member ws dictionary_members
/ ""
dictionary_member
= required ws type ws identifier ws default ws ";"
required
= "required"
/ ""
partial_dictionary
= "dictionary" ws identifier ws "{" ws dictionary_members ws "}" ws ";"
default
= "=" ws default_value
/ ""
default_value
= const_value
/ string
/ "[" "]"
inheritance
= ":" ws identifier
/ ""
enum
= "enum" ws identifier ws "{" ws enum_value_list ws "}" ws ";"
enum_value_list
= string ws enum_value_list_comma
enum_value_list_comma
= "," ws enum_value_list_string
/ ""
enum_value_list_string
= string ws enum_value_list_comma
/ ""
callback_rest
= identifier ws "=" ws return_type ws "(" ws argument_list ws ")" ws ";"
typedef
= "typedef" ws type ws identifier ws ";"
implements_statement
= identifier ws "implements" ws identifier ws ";"
const
= "const" ws const_type ws identifier ws "=" ws const_value ws ";"
const_value
= boolean_literal
/ float_literal
/ integer
/ "null"
boolean_literal
= "true"
/ "false"
float_literal
= float
/ "-Infinity"
/ "Infinity"
/ "NaN"
serializer
= "serializer" ws serializer_rest
serializer_rest
= operation_rest
/ "=" ws serialization_pattern
/ ""
serialization_pattern
= "{" ws serialization_pattern_map ws "}"
/ "[" ws serialization_pattern_list ws "]"
/ identifier
serialization_pattern_map
= "getter"
/ "inherit" ws identifiers
/ identifier ws identifiers
/ ""
serialization_pattern_list
= "getter"
/ identifier ws identifiers
/ ""
stringifier
= "stringifier" ws stringifier_rest
stringifier_rest
= readonly ws attribute_rest
/ return_type ws operation_rest
/ ";"
static_member
= "static" ws static_member_rest
static_member_rest
= readonly ws attribute_rest
/ return_type ws operation_rest
readonly_member
= "readonly" ws readonly_member_rest
readonly_member_rest
= attribute_rest
/ read_write_maplike
/ read_write_setlike
read_write_attribute
= "inherit" ws readonly ws attribute_rest
/ attribute_rest
attribute_rest
= "attribute" ws type ws attribute_name ws ";"
attribute_name
= attribute_name_keyword
/ identifier
attribute_name_keyword
= "required"
inherit
= "inherit"
/ ""
readonly
= "readonly"
/ ""
operation
= return_type ws operation_rest
/ special_operation
special_operation
= special ws specials ws return_type ws operation_rest
specials
= special ws specials
/ ""
special
= "getter"
/ "setter"
/ "deleter"
/ "legacycaller"
operation_rest
= optional_identifier ws "(" ws argument_list ws ")" ws ";"
optional_identifier
= identifier
/ ""
argument_list
= argument ws arguments
/ ""
arguments
= "," ws argument ws arguments
/ ""
argument
= extended_attribute_list ws optional_or_required_argument
optional_or_required_argument
= "optional" ws type ws argument_name ws default
/ type ws ellipsis ws argument_name
argument_name
= argument_name_keyword
/ identifier
ellipsis
= "..."
/ ""
iterable
= "iterable" ws "<" ws type ws optional_type ws ">" ws ";"
/ "legacyiterable" ws "<" ws type ws ">" ws ";"
optional_type
= "," ws type
/ ""
read_write_maplike
= maplike_rest
read_write_setlike
= setlike_rest
maplike_rest
= "maplike" ws "<" ws type ws "," ws type ws ">" ws ";"
setlike_rest
= "setlike" ws "<" ws type ws ">" ws ";"
extended_attribute_list
= "[" ws extended_attribute ws extended_attributes ws "]"
/ ""
extended_attributes
= "," extended_attribute extended_attributes
/ ""
extended_attribute
= "(" ws extended_attribute_inner ws ")" ws extended_attribute_rest
/ "[" ws extended_attribute_inner ws "]" ws extended_attribute_rest
/ "{" ws extended_attribute_inner ws "}" ws extended_attribute_rest
/ other ws extended_attribute_rest
extended_attribute_rest
= extended_attribute
/ ""
extended_attribute_inner
= "(" ws extended_attribute_inner ws ")" ws extended_attribute_inner
/ "[" ws extended_attribute_inner ws "]" ws extended_attribute_inner
/ "{" ws extended_attribute_inner ws "}" ws extended_attribute_inner
/ other_or_comma ws extended_attribute_inner
/ ""
other
= integer
/ float
/ identifier
/ string
/ other_
/ "-"
/ "-Infinity"
/ "."
/ "..."
/ ":"
/ ";"
/ "<"
/ "="
/ ">"
/ "?"
/ "ByteString"
/ "Date"
/ "DOMString"
/ "Infinity"
/ "NaN"
/ "RegExp"
/ "USVString"
/ "any"
/ "boolean"
/ "byte"
/ "double"
/ "false"
/ "float"
/ "long"
/ "null"
/ "object"
/ "octet"
/ "or"
/ "optional"
/ "sequence"
/ "short"
/ "true"
/ "unsigned"
/ "void"
/ argument_name_keyword
/ buffer_related_type
argument_name_keyword
= "attribute"
/ "callback"
/ "const"
/ "deleter"
/ "dictionary"
/ "enum"
/ "getter"
/ "implements"
/ "inherit"
/ "interface"
/ "iterable"
/ "legacycaller"
/ "legacyiterable"
/ "maplike"
/ "partial"
/ "required"
/ "serializer"
/ "setlike"
/ "setter"
/ "static"
/ "stringifier"
/ "typedef"
/ "unrestricted"
other_or_comma
= other
/ ","
type
= single_type
/ union_type ws type_suffix
single_type
= non_any_type
/ "any" ws type_suffix_starting_with_array
union_type
= "(" ws union_member_type ws "or" ws union_member_type ws union_member_types ws ")"
union_member_type
= non_any_type
/ union_type ws type_suffix
/ "any" ws "[" ws "]" ws type_suffix
union_member_types
= "or" ws union_member_type ws union_member_types
/ ""
non_any_type
= primitive_type ws type_suffix
/ promise_type ws null
/ "ByteString" ws type_suffix
/ "DOMString" ws type_suffix
/ "USVString" ws type_suffix
/ identifier ws type_suffix
/ "sequence" ws "<" ws type ws ">" ws null
/ "object" ws type_suffix
/ "Date" ws type_suffix
/ "RegExp" ws type_suffix
/ "Error" ws type_suffix
/ "DOMException" ws type_suffix
/ buffer_related_type ws type_suffix
buffer_related_type
= "ArrayBuffer"
/ "DataView"
/ "Int8Array"
/ "Int16Array"
/ "Int32Array"
/ "Uint8Array"
/ "Uint16Array"
/ "Uint32Array"
/ "Uint8ClampedArray"
/ "Float32Array"
/ "Float64Array"
const_type
= primitive_type ws null
/ identifier ws null
primitive_type
= unsigned_integer_type
/ unrestricted_float_type
/ "boolean"
/ "byte"
/ "octet"
unrestricted_float_type
= "unrestricted" ws float_type
/ float_type
float_type
= "float"
/ "double"
unsigned_integer_type
= "unsigned" ws integer_type
/ integer_type
integer_type
= "short"
/ "long" ws optional_long
optional_long
= "long"
/ ""
promise_type
= "Promise" ws "<" ws return_type ws ">"
type_suffix
= "[" ws "]" ws type_suffix
/ "?" ws type_suffix_starting_with_array
/ ""
type_suffix_starting_with_array
= "[" ws "]" ws type_suffix
/ ""
null
= "?"
/ ""
return_type
= type
/ "void"
identifier_list
= identifier ws identifiers
identifiers
= "," identifier ws identifiers
/ ""
extended_attribute_no_args
= identifier
extended_attribute_arg_list
= identifier ws "(" ws argument_list ws ")"
extended_attribute_ident
= identifier ws "=" ws identifier
extended_attribute_ident_list
= identifier ws "=" ws "(" ws identifier_list ws ")"
extended_attribute_named_arg_list
= identifier ws "=" ws identifier ws "(" ws argument_list ws ")"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment