Hi,

I've worked in the past weeks on a possible transformation of the parse tree into a model.

The model: https://codeberg.org/rgherdt/webidl-parser/src/branch/main/webidl/model.scm

An example call: https://codeberg.org/rgherdt/webidl-parser#example-call

I implemented the model mainly with records, but it should be trivial to adapt the code that traverses the parse-tree to generate any data structures we want. This is done
with `tree->model`:

https://codeberg.org/rgherdt/webidl-parser/src/branch/main/webidl/parse-to-model.scm

I also changed the API, so that `parse-webidl-file` and `parse-webidl-string` output the model instead of the tree by default. To get the previous behavior one can
call it with the keyword argument #:output-parse-tree set to #t.

Since I wrote this with hoot's needs in mind, I would be happy to make any changes needed. Let me know if you have any improvement suggestions or ideas of a possible target code
to be generated out of it. BTW I'm also reachable on libera: rgherdt


Regards,

Ricardo G. Herdt


Am 06.06.2025 22:23 schrieb Thompson, David:
Hi Ricardo,

On Fri, Jun 6, 2025 at 3:36 PM Ricardo G. Herdt <r.he...@posteo.de> wrote:

Hi,

Motivated by this discussion I took the chance to have some fun writing
parsers and
wrote one for Web IDL files in Guile:

https://codeberg.org/rgherdt/webidl-parser

Wow, this is awesome!!!

Actually there are two parsers involved. The first reads the
WebIDL-grammar and generates parts of
the main parser for IDL files. But that's an implementation detail :) .
See README.md.

For now the result is an s-expression based parse tree, with some
simplifications to make
working with it easier. I could develop it further to simplify even more
or help generating
bindings or something like that. If you have ideas of what target
bindings could look like let me know. Right
now I'm not sure what information of IDL-described APIs are relevant for
binding generation, so I will
postpone work on it until needed.

I did some tests with IDL references from
https://github.com/w3c/webref/tree/curated. Most of them
work, with two exceptions due a possible inconsistency in the spec, as
noted in my README.
Solving it should be trivial though. Some IDLs I got from Gecko are
problematic, since they have #ifdef
directives and stuff like that, which are not expected by the grammar.
Adapting the lexer shouldn't be difficult,
just let me know if that's needed.

I hope to find some time to take this library for a spin soon. Maybe
sometime in the next couple of weeks. I'll let you know if I run into
any trouble or have questions.

This is one huge step towards having Scheme libraries for a whole
bunch of Web APIs!

Thanks again,

- Dave

Reply via email to