xref: /DragonReach/src/parse/parse_target/mod.rs (revision ea330323f68db57353801959d67cbd8e0031aa18)
1 use super::graph::Graph;
2 use super::parse_util::UnitParseUtil;
3 
4 use crate::error::parse_error::ParseError;
5 use crate::manager::UnitManager;
6 
7 use std::string::ToString;
8 
9 pub struct TargetParser;
10 
11 impl TargetParser {
12     /// @brief 解析Service类型Unit的
13     ///
14     /// 从path解析Service类型Unit
15     ///
16     /// @param path 需解析的文件路径
17     ///
18     /// @return 成功则返回Ok(Rc<ServiceUnit>),否则返回Err
19     pub fn parse(path: &str) -> Result<usize, ParseError> {
20         //预先检查是否存在循环依赖
21         let mut graph = Graph::construct_graph(path.to_string())?;
22         let ret = graph.topological_sort()?;
23         for p in ret {
24             let _temp_unit = UnitParseUtil::parse_unit_no_type(&p)?;
25         }
26 
27         let result = UnitManager::get_id_with_path(path).unwrap();
28         return Ok(result);
29     }
30 }
31