1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//! This crate reads Liberty format files, commonly used by
//! [EDA](https://en.wikipedia.org/wiki/Electronic_design_automation) tools to describe library
//! cells (including standard cells, hard IP, etc.).
//!
//! # Example
//!
//! ```
//! use liberty_parse::parse_lib;
//!
//! let lib_str = r#"
//! library(sample) {
//!     cell(AND2) {
//!         area: 1;
//!     }
//! }
//! "#;
//!
//! for lib in parse_lib(lib_str).unwrap() {
//!     println!("Library '{}' has {} cells", lib.name, lib.cells.len());
//!     let area = lib
//!         .cells
//!         .get("AND2")
//!         .and_then(|c| c.simple_attributes.get("area"))
//!         .map_or(-1.0, |v| v.float());
//!     println!("Cell AND2 has area: {}", area);
//! }
//! ```

pub mod ast;
pub mod liberty;
mod error;
mod parser;

pub use ast::{ParseResult, Value};

pub use error::Error;

/// Parse a string slice into a [liberty::Liberty] struct
pub fn parse_lib(contents: &str) -> ParseResult<liberty::Liberty> {
    Ok(liberty::Liberty::from_ast(ast::LibertyAst::from_string(
        contents,
    )?))
}