Skip to main content

Crate compactp_ast

Crate compactp_ast 

Source
Expand description

Typed AST wrappers for the Compact language.

This crate provides zero-cost typed access to the lossless CST produced by compactp_parser. Each AST type is a newtype over SyntaxNode that exposes typed accessor methods for navigating the tree. No allocation or cloning is required – AST nodes are simply views into the existing CST.

The crate depends only on compactp_syntax (not compactp_parser), so the AST layer works over rowan SyntaxNode values regardless of how they were produced.

§Usage

use compactp_ast::{AstNode, Item, SourceFile};
use compactp_syntax::SyntaxNode;

// `compactp_parser` builds the green tree from source:
let result = compactp_parser::parse(source);
let root = SyntaxNode::new_root(result.green);
let file = SourceFile::cast(root).expect("root should be SOURCE_FILE");

for item in file.items() {
    match item {
        Item::CircuitDef(c) => {
            let _ = c.name();
        }
        _ => {}
    }
}

Re-exports§

pub use expr::Expr;
pub use nodes::*;

Modules§

expr
Expression AST types and the Expr sum-type enum.
nodes
All AST node types except expressions (which live in crate::expr).

Enums§

SyntaxKind
All syntax kinds for the Compact language.

Traits§

AstNode
Trait implemented by all typed AST node wrappers.

Type Aliases§

SyntaxNode
Rowan syntax node specialized to Compact’s SyntaxKind set.
SyntaxToken
Rowan syntax token specialized to Compact’s SyntaxKind set.