Skip to main content

Crate roam_macros_parse

Crate roam_macros_parse 

Source
Expand description

Parser grammar for roam RPC service trait definitions.

§This Is Just a Grammar

This crate contains only the unsynn grammar for parsing Rust trait definitions that define roam RPC services. It does not:

  • Generate any code
  • Perform validation
  • Know anything about roam’s wire protocol
  • Have opinions about how services should be implemented

It simply parses syntax like:

pub trait Calculator {
    /// Add two numbers.
    async fn add(&self, a: i32, b: i32) -> i32;
}

…and produces an AST (ServiceTrait) that downstream crates can inspect.

§Why a Separate Crate?

The grammar is extracted into its own crate so that:

  1. It can be tested independently — We use datatest-stable + insta for snapshot testing the parsed AST, which isn’t possible in a proc-macro crate.

  2. It’s reusable — Other tools (linters, documentation generators, IDE plugins) can parse service definitions without pulling in proc-macro dependencies.

  3. Separation of concerns — The grammar is pure parsing; roam-macros handles the proc-macro machinery; roam-codegen handles actual code generation.

§The Bigger Picture

roam-macros-parse     roam-macros              roam-codegen
┌──────────────┐     ┌──────────────┐         ┌──────────────┐
│              │     │              │         │              │
│  unsynn      │────▶│  #[service]  │────────▶│  build.rs    │
│  grammar     │     │  proc macro  │         │  code gen    │
│              │     │              │         │              │
└──────────────┘     └──────────────┘         └──────────────┘
   just parsing         emit metadata          Rust, TS, Go...

Structs§

AngleTokenTree
Parses either a TokenTree or <...> grouping.
DocAttribute
GenericParams
KAsync
Matches: async,
KDoc
Matches: doc,
KFn
Matches: fn,
KMut
Matches: mut,
KPub
Matches: pub,
KSelfKw
Matches: self,
KTrait
Matches: trait,
KWhere
Matches: where,
Lifetime
MethodParam
MethodParams
ParseError
Error type for parsing.
PathWithGenerics
RawAttribute
RefSelf
ReturnType
ServiceMethod
ServiceTrait
TypePath
TypeRef
TypeTuple
WhereClause

Enums§

GenericArgument
Type
Visibility

Traits§

ToTokens
unsynn defines its own ToTokens trait to be able to implement it for std container types. This is similar to the ToTokens from the quote crate but adds some extra methods and is implemented for more types. Moreover the to_token_iter() method is the main entry point for crating an iterator that can be used for parsing.

Functions§

method_ok_and_err_types
Extract Ok and Err types from a return type. Returns (ok_type, Some(err_type)) for Result<T, E>, or (type, None) otherwise.
parse_trait
Parse a trait definition from a token stream.