This commit is contained in:
parent
4a057c47e4
commit
d25785984d
@ -19,6 +19,7 @@ use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
fmt::{self, Display},
|
||||
path::Path,
|
||||
rc::Rc,
|
||||
sync::Arc,
|
||||
};
|
||||
@ -35,12 +36,46 @@ pub struct Law {
|
||||
}
|
||||
|
||||
impl Law {
|
||||
pub fn from_config(path: &str) -> Result<Law, Error> {
|
||||
/// Creates a `Law` instance from a configuration file.
|
||||
///
|
||||
/// This function initializes the law processing pipeline by loading configurations from the
|
||||
/// specified path, parsing law texts based on these configurations, and assembling a `Law`
|
||||
/// object. The configuration file is expected to define how law texts should be parsed and
|
||||
/// processed.
|
||||
///
|
||||
/// # Parameters
|
||||
///
|
||||
/// - `path`: A path to the configuration file. This can be any type that implements the
|
||||
/// `AsRef<Path>` trait, allowing for flexible path specifications (e.g., `&str`, `String`,
|
||||
/// `Path`, or `PathBuf`).
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Returns a `Result` that, on success, contains the `Law` constructed from the provided
|
||||
/// configuration and parsed law texts. On failure, it returns an `Error` indicating what went
|
||||
/// wrong during the process.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function can return an `Error` in the following scenarios:
|
||||
///
|
||||
/// - If loading the configuration from the specified path fails (e.g., file not found,
|
||||
/// permission issues, or invalid file format). - If the parsing of law texts encounters an
|
||||
/// error or if the construction of the `Law` object based on the parsed data fails.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use risp::law::Law;
|
||||
///
|
||||
/// let law = Law::from_config("./data/configs/abgb.toml").unwrap();
|
||||
/// ```
|
||||
pub fn from_config<P: AsRef<Path>>(path: P) -> Result<Law, Error> {
|
||||
let (law_id, mut builder, parser) = Config::load(path)?;
|
||||
let pars = parse(law_id).unwrap();
|
||||
let pars = parse(law_id)?;
|
||||
|
||||
for par in pars {
|
||||
let cont = parser.parse(&par, &mut builder).unwrap();
|
||||
let cont = parser.parse(&par, &mut builder)?;
|
||||
if !cont {
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user