Web::IDL::Parser
A Web IDL parser
SYNOPSIS
use Web::IDL::Parser;
$parser = Web::IDL::Parser->new;
$parser->parse_char_string ($idl_fragment);
warn Dumper $parser->parsed_struct;
DESCRIPTION
The Web::IDL::Parser
module provides a Web IDL parser.
METHODS
Following methods are available:
$parser = Web::IDL::Parser->new
-
Create a new Web IDL parser object.
$parser->onerror ($code)
$code = $parser->onerror
-
Get or set the error handler for the parser. Any parse error, as well as warning and additional processing information, is reported to the handler. See
<https://github.com/manakai/data-errors/blob/master/doc/onerror.txt>
for details of error handling.The value should not be set while the parser is running. If the value is changed, the result is undefined.
$parser->parse_char_string ($input)
-
Parse a string of character as a Web IDL fragment. The parsed result can be then accessed by the
parsed_struct
method. Any parse error is reported through theonerror
handler. $parsed = $parser->parsed_struct
-
If the previous invocation of the
parse_char_string
method succeeded, the parsed data structure of the input Web IDL fragment is returned. Otherwise,undef
is returned.Please note that the parsed result might contain Web IDL conformance error, e.g. its interface names can be duplicated, or a referenced type might not be defined at all.
DATA STRUCTURE
The parsed data structure is a hash reference, with a key/value pair: definitions
. Its value is an array reference containing definitions.
A definition is a hash reference with following key/value pairs:
- index
-
The index in the input character string at which the first character for the definition appears.
- definition_name
-
Type of the definition:
interface
,namespace
,dictionary
,enum
, orcallback
.Note that the
definition_name
for acallback interface
isinterface
. - partial
-
Whether the definition has the
partial
keyword or not. - callback
-
Whether the definition is an interface and it has the
callback
keyword or not. Note that for a non-interface callback, this value is false. - mixin
-
Whether the definition is an interface mixin definition or not.
- name
-
The name of the defined construct.
- super_name
-
The name of the member from which the member inherits, if any.
- members
-
The array reference containing the members of the definition, if applicable.
- value_items
-
The array reference of the allowed string values associated with the definition, if applicable. Items are hash references with a key/value pair whose key is
type_string
and value is the string value. - arguments
-
The array reference of the arguments for the definition, if applicable.
- extended_attributes
-
The array reference of the extended attributes for the definition, if any.
In addition, the type key/value pairs whose target is the definition are also available if applicable.
A member is a hash reference with following key/value pairs:
- index
-
The index in the input character string at which the first character for the member appears.
- member_type
-
The type of the member:
attribute
,operation
,const
,iterable
,legacyiterable
,maplike
,setlike
, ordictionary_member
. - name
-
The name of the member, if applicable.
- readonly, inherit, static
- getter, setter, deleter, stringifier
- required
-
Whether the keyword is set to the member or not.
- value
-
The builtin value associated with the member, if applicable. One of:
true
,false
,null
,Infinity
,-Infinity
, orNaN
. - value_float
-
The value associated with the member, as a float, if applicable.
- value_integer
-
The value associated with the member, as a integer, if applicable.
- value_string
-
The value associated with the member, as a string, if applicable.
- value_name
-
The value associated with the member, as an identifier, if applicable.
- value_empty_sequence
-
If specified, the value is an empty sequence.
- arguments
-
The array reference of the arguments for the member, if applicable.
- type1
- type2
-
The type(s) specified in the member, in an
iterable
or similar kind of member, if any. If specified, the value is a hash reference whose key/value pairs are the type key/value pairs whose target is the first or second type of the member. - extended_attributes
-
The array reference of the extended attributes for the member, if any.
In addition, the type key/value pairs whose target is the member are also available if applicable.
An argument is a hash reference with following key/value pairs:
- index
-
The index in the input character string at which the first character for the argument appears.
- name
-
The name of the argument.
- optional
-
Whether the argument is optional or not.
- value
-
The builtin value associated with the argument, if any. One of:
true
,false
,null
,Infinity
,-Infinity
, orNaN
. - value_float
-
The value associated with the argument, as a float, if any.
- value_integer
-
The value associated with the argument, as an integer, if any.
- value_string
-
The value associated with the argument, as a string, if any.
- variadic
-
Whether there is the
...
token or not. - extended_attributes
-
The array reference of the extended attributes for the argument, if any.
In addition, the type key/value pairs whose target is the argument are also available if applicable.
An extended attribute is a hash reference with following key/value pairs:
- index
-
The index in the input character string at which the first character for the extended attribute appears.
- name
-
The name of the extended attribute.
- arguments
-
The array reference of the arguments for the extended attribute, if any.
- value_names
-
The array reference of the argument identifiers for the extended attribute, if any.
The type key/value pairs are as follows:
- type
-
The Web IDL builtin type associated with the target, such as
long
,any
,void
,unsigned long
,unrestricted double
(where spaces are represented by a U+0020 character), if any. - type_name
-
The name of the Web IDL type associated with the target, if any.
- type_nullable
-
Whether the Web IDL type associated with the target is nullable or not.
- type_array
-
A hash reference if the Web IDL type associated with the target is an array whose item type is represented by the other type key/value pairs. The hash reference can contain the type key/value pairs, which represents that the array type is in fact an inner type of another type.
For example, a Web IDL type
T[]?[]
is represented as:{ "type_name": "T", "type_array": { "type_nullable": 1, "type_array": {} } }
- type_parameterized
-
The hash reference representing the prameterized Web IDL type of the target, if any.
- type_outer
-
The type of the parameterized type, such as
sequence
andPromise
, if the hash reference containing the key/value pair represents a parameterized Web IDL type of the target.
Hash references might also contain key/value pairs id
, spec
, and obsolete
, corresponding to non-standard directives [*id="..."*]
, [*spec=...*]
, and [*obsolete*]
. These directives are only used for internal processing of <https://github.com/manakai/data-web-defs>
and are not (and should not) be used elsewhere.
SPECIFICATION
- WEBIDL
-
Web IDL
<https://heycam.github.io/webidl/>
.
In this implementation, extended attributes MUST be in one of various forms shown in the Web IDL specification.
AUTHOR
Wakaba <wakaba@suikawiki.org>.
LICENSE
Copyright 2014-2018 Wakaba <wakaba@suikawiki.org>.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.