Whatpm::WebIDL - A WebIDL Parser and Conformance Checker
use Whatpm::WebIDL; my $parser = Whatpm::WebIDL::Parser->new; my $onerror = sub { my %arg = @_; warn join "\t", $arg{line}, $arg{column}, $arg{level}, $arg{type}, $arg{text} // '', $arg{value} // ''; }; my $webidl_doc = $parser->parse_char_string ($webidl_string, $onerror); $webidl_doc->check ($onerror);
The Whatpm::WebIDL
module provides a WebIDL parser, as well as a
conformance checker that can be invoked once an IDL fragment has been
parsed.
This is an implementation of W3C Web IDL specification.
The Whatpm::WebIDL
package itself provides no functionality. It
contains various packages including Whatpm::WebIDL::Parser
.
Whatpm::WebIDL::Parser
The Whatpm::WebIDL::Parser
package, which is contained in the
Whatpm::WebIDL
module, defines a class method and an instance
method:
This class method creates a new instance of the WebIDL parser.
This instance method of the $parser method parses a WebIDL fragment and returns its in-memory representation.
The first argument, $webidl_fragment, is the IDL fragment to be parsed. It must be a string of characters (not bytes).
As the second argument, $onerror, a CODE
reference may be
specified. If specified, whenever a parse error is found, or a
warning message is raised, the CODE
is invoked with arguments
describing the error. @@ TODO: ref to degtailed description
Note that the W3C WebIDL specification does not define how invalid
WebIDL fragments are parsed. This parse implements a foward
compatible parsing rule that is similar to the CSS parsing rule; once
a parse error is found, everything until the next ;
character (or
the end-of-file, if there is no ;
character) is ignored, taking
pairs of {
and }
characters into account. If a fragment
prematurely ends inside a block, then a };
sequence that closes the
block is implied. Any error that does not violate the grammer, e.g.
any reference to an undefined interface, does not stop the parser; to
detect such errors, the checker
has to be invoked later.
The returned object, $webidl_doc
, is an in-memory representation of
the prased IDL fragment. It is an instance of the
Whatpm::WebIDL::Definitions
class.
Whatpm::WebIDL::Definitions
An object of the Whatpm::WebIDL::Definitions
class represents a
WebIDL fragment (or Definitions
production in the WebIDL
specification).
This method checks the conformance of the WebIDL objects, $webidl_docs.
@@ TODO: documentation for $onerror and $levels.
WebIDL Editor's Draft <http://dev.w3.org/cvsweb/~checkout~/2006/webapi/WebIDL/Overview.html?content-type=text/html;%20charset=utf-8>
WebHACC::Language::WebIDL
module, as an example of the usage of
this module
<http://suika.fam.cx/gate/cvs/webroot/gate/2007/html/WebHACC/Language/WebIDL.pm>
Wakaba <w@suika.fam.cx>
Copyright 2008 Wakaba <w@suika.fam.cx>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.