scarf_syntax/lib.rs
1// =======================================================================
2// lib.rs
3// =======================================================================
4// The top-level collection of CST nodes
5
6//! A SystemVerilog (concrete) syntax tree for representing
7//! [1800-2023](https://ieeexplore.ieee.org/document/10458102) syntax.
8//!
9//! Each syntactic category is represented as a struct or enum with the
10//! same name as appears in Annex A, with additional types as needed for
11//! unnamed alternatives.
12//!
13//! While the tree can be treated as a normal data structure, it can
14//! also be iterated across (depth-first). Iterating produces [`Node`]s,
15//! which reference a specific data structure in the tree
16//!
17//! ```rust
18//! # use scarf_syntax::*;
19//! fn is_always_comb_block<'a, 'b>(node: Node<'a, 'b>) -> bool {
20//! matches!(node, Node::AlwaysConstruct(AlwaysConstruct(AlwaysKeyword::AlwaysComb(_), _)))
21//! }
22//!
23//! fn num_inferred_latches<'a>(source: &SourceText<'a>) -> i32 {
24//! let mut count = 0;
25//! for node in source.find(is_always_comb_block) {
26//! for child_node in node.iter() {
27//! if let Node::BlockingAssignment(_) = child_node {
28//! count += 1;
29//! }
30//! }
31//! }
32//! count
33//! }
34//! ```
35//!
36//! Compiler directives are not supported due to their arbitrary
37//! location/semantics in a syntax tree.
38//!
39//! ## Features
40//!
41//! - `lossless`: Allows for whitespace/comments to be preserved in [`Metadata`]
42
43include!(concat!(env!("OUT_DIR"), "/nodes.rs"));
44include!(concat!(env!("OUT_DIR"), "/id.rs"));
45
46pub mod behavioral_statements;
47pub mod declarations;
48pub mod expressions;
49pub mod general;
50pub mod instantiations;
51pub mod iter;
52pub mod metadata;
53pub mod primitive_instances;
54pub mod source_text;
55pub mod specify_section;
56pub mod udp_declaration_and_instantiation;
57pub use behavioral_statements::*;
58pub use declarations::*;
59pub use expressions::*;
60pub use general::*;
61pub use instantiations::*;
62pub use iter::*;
63pub use metadata::*;
64pub use primitive_instances::*;
65pub use source_text::*;
66pub use specify_section::*;
67pub use udp_declaration_and_instantiation::*;