Skip to content

Commit

Permalink
remove deprecated load_fragment[_file] functions
Browse files Browse the repository at this point in the history
The replacement functions have been renamed
load_fragment2 -> load_fragment
load_fragment_file2 -> load_fragment_file
  • Loading branch information
DanielT committed Dec 29, 2024
1 parent cd8a6bf commit 154e00f
Showing 1 changed file with 6 additions and 75 deletions.
81 changes: 6 additions & 75 deletions a2lfile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,38 +230,7 @@ fn load_impl(
/// # Errors
///
/// If reading or parsing of the file fails, the `A2lError` will give details about the problem.
#[deprecated]
pub fn load_fragment(a2ldata: &str) -> Result<Module, A2lError> {
let fixed_a2ldata = format!(r#"fragment "" {a2ldata} /end MODULE"#);
// tokenize the input data
let tokenresult = tokenizer::tokenize(&Filename::from("(fragment)"), 0, &fixed_a2ldata)
.map_err(|tokenizer_error| A2lError::TokenizerError { tokenizer_error })?;
let firstline = tokenresult.tokens.first().map_or(1, |tok| tok.line);
let context = ParseContext {
element: "MODULE".to_string(),
fileid: 0,
line: firstline,
};

// create the parser state object
let mut log_msgs = Vec::<A2lError>::new();
let mut parser = ParserState::new(&tokenresult, &mut log_msgs, false);
parser.set_file_version(A2lVersion::V1_7_1); // doesn't really matter with strict = false

// build the a2l data structures from the tokens
Module::parse(&mut parser, &context, 0)
.map_err(|parser_error| A2lError::ParserError { parser_error })
}

/// load an a2l fragment
///
/// An a2l fragment is just the bare content of a module, without the enclosing PROJECT and MODULE.
/// Because the fragment cannot specify a version, strict parsing is not available.
///
/// # Errors
///
/// If reading or parsing of the file fails, the `A2lError` will give details about the problem.
pub fn load_fragment2(a2ldata: &str, a2ml_spec: Option<String>) -> Result<Module, A2lError> {
pub fn load_fragment(a2ldata: &str, a2ml_spec: Option<String>) -> Result<Module, A2lError> {
let fixed_a2ldata = format!(r#"fragment "" {a2ldata} /end MODULE"#);
// tokenize the input data
let tokenresult = tokenizer::tokenize(&Filename::from("(fragment)"), 0, &fixed_a2ldata)
Expand Down Expand Up @@ -296,25 +265,13 @@ pub fn load_fragment2(a2ldata: &str, a2ml_spec: Option<String>) -> Result<Module
/// # Errors
///
/// If reading or parsing of the file fails, the `A2lError` will give details about the problem.
#[deprecated]
pub fn load_fragment_file<P: AsRef<Path>>(path: P) -> Result<Module, A2lError> {
let pathref = path.as_ref();
let filedata = loader::load(pathref)?;
load_fragment2(&filedata, None)
}

/// load an a2l fragment from a file
///
/// # Errors
///
/// If reading or parsing of the file fails, the `A2lError` will give details about the problem.
pub fn load_fragment_file2<P: AsRef<Path>>(
pub fn load_fragment_file<P: AsRef<Path>>(
path: P,
a2ml_spec: Option<String>,
) -> Result<Module, A2lError> {
let pathref = path.as_ref();
let filedata = loader::load(pathref)?;
load_fragment2(&filedata, a2ml_spec)
load_fragment(&filedata, a2ml_spec)
}

impl A2lFile {
Expand Down Expand Up @@ -638,37 +595,11 @@ mod tests {
#[test]
fn test_load_fagment() {
// an empty string is a valid fragment
let result = load_fragment2("", None);
assert!(result.is_ok());

// load a fragment with some data
let result = load_fragment2(
r#"
/begin MEASUREMENT ASAM.M.SCALAR.UBYTE.IDENTICAL
"Scalar measurement"
UBYTE CM.IDENTICAL 0 0 0 255
ECU_ADDRESS 0x13A00
FORMAT "%5.0" /* Note: Overwrites the format stated in the computation method */
DISPLAY_IDENTIFIER DI.ASAM.M.SCALAR.UBYTE.IDENTICAL /* optional display identifier */
/begin IF_DATA ETK KP_BLOB 0x13A00 INTERN 1 RASTER 2 /end IF_DATA
/end MEASUREMENT"#,
None,
);
assert!(result.is_ok());

// random data is not a valid fragment
let result = load_fragment2("12345", None);
assert!(result.is_err());
}

#[test]
fn test_load_fagment2() {
// an empty string is a valid fragment
let result = load_fragment2("", None);
let result = load_fragment("", None);
assert!(result.is_ok());

// load a fragment with some data
let result = load_fragment2(
let result = load_fragment(
r#"
/begin MEASUREMENT ASAM.M.SCALAR.UBYTE.IDENTICAL
"Scalar measurement"
Expand All @@ -683,7 +614,7 @@ mod tests {
assert!(result.is_ok());

// random data is not a valid fragment
let result = load_fragment2("12345", None);
let result = load_fragment("12345", None);
assert!(result.is_err());
}
}

0 comments on commit 154e00f

Please sign in to comment.