@@ -10,8 +10,7 @@ pub enum ClipsError {
1010 CreateEnvironmentError ,
1111 ClearError ,
1212 LoadFromStringError ( String ) ,
13- RemoveUDFError ( String ) ,
14- BatchStarError ( String ) ,
13+ BiildParsingError ( String ) ,
1514 LoadOpenFileError ( String ) ,
1615 LoadParsingError ( String ) ,
1716 PutSlotSlotNotFoundError ( String ) ,
@@ -28,8 +27,7 @@ impl Display for ClipsError {
2827 ClipsError :: CreateEnvironmentError => write ! ( f, "Failed to create environment" ) ,
2928 ClipsError :: ClearError => write ! ( f, "Failed to clear environment" ) ,
3029 ClipsError :: LoadFromStringError ( s) => write ! ( f, "Failed to load from string: {s}" ) ,
31- ClipsError :: RemoveUDFError ( s) => write ! ( f, "Failed to remove UDF: {s}" ) ,
32- ClipsError :: BatchStarError ( s) => write ! ( f, "Batch* error: {s}" ) ,
30+ ClipsError :: BiildParsingError ( s) => write ! ( f, "Failed to build construct: {s}" ) ,
3331 ClipsError :: LoadOpenFileError ( s) => write ! ( f, "Failed to open file: {s}" ) ,
3432 ClipsError :: LoadParsingError ( s) => write ! ( f, "Failed to parse file: {s}" ) ,
3533 ClipsError :: PutSlotSlotNotFoundError ( s) => write ! ( f, "Slot not found: {s}" ) ,
@@ -73,6 +71,16 @@ impl Environment {
7371 }
7472 }
7573
74+ pub fn build ( & self , construct : & str ) -> Result < ( ) , ClipsError > {
75+ let construct_cstr = CString :: new ( construct) . unwrap ( ) ;
76+ let build_error = unsafe { clips:: Build ( self . raw , construct_cstr. as_ptr ( ) as * const i8 ) } ;
77+ match build_error {
78+ clips:: BuildError_BE_NO_ERROR => Ok ( ( ) ) ,
79+ clips:: BuildError_BE_PARSING_ERROR => Err ( ClipsError :: LoadParsingError ( construct. to_owned ( ) ) . into ( ) ) ,
80+ _ => unreachable ! ( ) ,
81+ }
82+ }
83+
7684 pub fn reset ( & self ) {
7785 unsafe { clips:: Reset ( self . raw ) } ;
7886 }
@@ -523,4 +531,18 @@ mod tests {
523531
524532 assert_eq ! ( value. load( std:: sync:: atomic:: Ordering :: SeqCst ) , 42 ) ;
525533 }
534+
535+ #[ test]
536+ fn test_build ( ) {
537+ let env = Environment :: new ( ) . unwrap ( ) ;
538+ let result = env. build ( "(deftemplate test_build_template (slot test_slot))" ) ;
539+ assert ! ( result. is_ok( ) ) ;
540+ }
541+
542+ #[ test]
543+ fn test_build_error ( ) {
544+ let env = Environment :: new ( ) . unwrap ( ) ;
545+ let result = env. build ( "(deftemplate test_build_template" ) ;
546+ assert ! ( result. is_err( ) ) ;
547+ }
526548}
0 commit comments