tree: bd6e0a16ef73fa6025dd229b061c58f70b360665 [path history] [tgz]
  1. test/
  2. test_util/
  3. api.rs
  4. ast.rs
  5. BUILD.gn
  6. deparse_values.rs
  7. errors.rs
  8. lib_core.rs
  9. lib_pub.rs
  10. pack.rs
  11. parse_messages.rs
  12. parse_primitives.rs
  13. parse_values.rs
  14. parsing_attribute.rs
  15. parsing_trait.rs
  16. README.md
mojo/public/rust/mojom_parser/README.md

This crate contains an implementation of a safe, simple, and generic Mojom parser written in Rust.

This crate is still in extremely active development! We're still figuring out the final shape and how it will fit into the overall rust mojo bindings.

FOR_RELEASE: These comments indicate TODOs that should be addressed before we finalize the minimum viable product for the rust bindings. For example, fill this out more!

Genericity

A key goal of this parser is to be agnostic to the actual Mojom files that it parses. Unlike the bindings for other languages, which generate specialized parsing code for each type in each Mojom file, this parser works for all of them (at the cost of performance).

This is achieved by representing the parser's inputs and outputs as miniature ASTs: rust enums that describe the possible types and values a Mojom file could describe. For each Mojom file, the bindings generator will be responsible for generating a corresponding rust type, and mapping it to/from the enums, but the generator will not have to write any parsing code itself.

Crate structure

  • lib.rs: The crate root, which serves only to define the API of the crate via exports.
  • ast.rs: Defines the abstract syntax of mojom types and values.
  • pack.rs: Translates mojom types to their wire format.
  • parse_*: Defines various levels of parsing functionality:
    • parse_primitives: Basic parsers, which return primitive datatypes
    • parse_values: Parsers which take a single encoded datatype (possibly a recursive one like a struct) and return a mojom value.
    • parser_messages: Parsers for entire mojom messages.