tf_parser/
lib.rs

1//! The tf_parser is used to parse Technology(.tf) file, which is a part of [EDA](https://en.wikipedia.org/wiki/Electronic_design_automation) P&R tool.
2//! This file is usually provided by Foundary (like [TSMC](https://en.wikipedia.org/wiki/TSMC),[GF](https://en.wikipedia.org/wiki/GlobalFoundries),
3//! [SMIC](https://en.wikipedia.org/wiki/Semiconductor_Manufacturing_International_Corporation),etc)
4//! to describe basic technology information, technology layer, technology via, design rules, density rules, etc.
5
6//! # Example
7//!```rust
8//!use tf_parser::TfData;
9//!pub fn parse_tf<P>(file_path: P) -> Result<TfData, Box<dyn std::error::Error>>
10//!where
11//!   P: AsRef<Path>,
12//!{
13//!   let tf_data: TfData = fs::read_to_string(file_path)?.parse()?;
14//!   Ok(tf_data)
15//!}
16//!let data = parse_tf("example.tf");
17//!```
18//!
19
20//! # Feature
21//! 1. **Easy Embedded**. With this crate, you can easily embed parse technology file into your EDA toolchain
22//! 2. **Friendly Error Feedback**. The tf_parser use [VerboseError](https://docs.rs/nom/6.1.0/nom/error/struct.VerboseError.html) to locate the error
23//! when it first meets syntax error in the technology file
24
25//! # Limitation
26//! The parser currently just support Synopsys Appolo compatible technology file format. It will meet failure when parsing .techfile for Cadence pdks
27
28pub mod model;
29pub mod parser;
30
31use model::TfData;
32use parser::tf_parser;
33
34use nom::{
35    error::{convert_error, VerboseError},
36    Err, IResult,
37};
38use std::{
39    io::{Error, ErrorKind},
40    str::FromStr,
41};
42
43impl FromStr for TfData {
44    type Err = Error;
45    fn from_str(s: &str) -> Result<Self, Self::Err> {
46        match tf_parser(s) {
47            Ok((_, u)) => Ok(u),
48            Err(Err::Error(e)) => {
49                println!("[TFParser] `VerboseError`:\n{}", convert_error(s, e));
50                Err(Error::new(
51                    ErrorKind::InvalidData,
52                    "Invalid Technology File",
53                ))
54            }
55            _ => Err(Error::new(
56                ErrorKind::InvalidData,
57                "Invalid Technology File",
58            )),
59        }
60    }
61}
62
63pub type TfRes<T, U> = IResult<T, U, VerboseError<T>>;