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:
-
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.
-
It’s reusable — Other tools (linters, documentation generators, IDE plugins) can parse service definitions without pulling in proc-macro dependencies.
-
Separation of concerns — The grammar is pure parsing;
roam-macroshandles the proc-macro machinery;roam-codegenhandles 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§
- Angle
Token Tree - Parses either a
TokenTreeor<...>grouping. - DocAttribute
- Generic
Params - 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
- Method
Param - Method
Params - Parse
Error - Error type for parsing.
- Path
With Generics - RawAttribute
- RefSelf
- Return
Type - Service
Method - Service
Trait - Type
Path - TypeRef
- Type
Tuple - Where
Clause
Enums§
Traits§
- ToTokens
- unsynn defines its own
ToTokenstrait to be able to implement it for std container types. This is similar to theToTokensfrom the quote crate but adds some extra methods and is implemented for more types. Moreover theto_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.