Skip to main content

ud_ast/
lib.rs

1//! Abstract syntax tree for the `.ud` source language.
2//!
3//! This crate is the source of truth for what `.ud` *looks like*. The
4//! pretty-printer in [`emit`] produces the canonical text form; both
5//! the decompiler (which builds an AST and emits it) and the parser
6//! (which reads text and builds an AST) speak in terms of these types.
7//!
8//! Round-trip property at the source level:
9//!
10//! > For any AST built by a producer, `parse(emit(ast)) == ast`. For
11//! > any text in canonical form, `emit(parse(text)) == text`.
12//!
13//! Producers must therefore avoid AST shapes the pretty-printer would
14//! re-canonicalise into a different shape (e.g. mismatched ordering of
15//! `module.fields`). The pretty-printer is deterministic; the parser
16//! is the source of permissiveness (multiple whitespace conventions,
17//! all canonicalised on emit).
18
19#![allow(clippy::cast_possible_truncation)]
20
21mod emit;
22mod types;
23
24pub use emit::emit;
25pub use types::{
26    AttrValue, Attribute, EpilogueParams, Field, FnDecl, Item, JumpTableEntry, LocalDecl,
27    LocalKind, Module, NoteEntry, Param, PrologueParams, Signature, Stmt, Type, UdFile, Value,
28};