@@ -9,6 +9,9 @@ use crate::io::{file_util, submission_processing, tmc_zip};
99use crate :: policy:: StudentFilePolicy ;
1010pub use isolang:: Language ;
1111use log:: debug;
12+ use nom:: { bytes:: complete, combinator, error:: ErrorKind , error:: ParseError , sequence, IResult } ;
13+ use once_cell:: sync:: Lazy ;
14+ use regex:: Regex ;
1215use std:: collections:: { HashMap , HashSet } ;
1316use std:: io:: { Read , Seek , Write } ;
1417use std:: path:: { Path , PathBuf } ;
@@ -426,6 +429,43 @@ pub trait LanguagePlugin {
426429 fn get_default_exercise_file_paths ( & self ) -> Vec < PathBuf > {
427430 vec ! [ PathBuf :: from( "test" ) ]
428431 }
432+
433+ fn get_available_points ( & self , exercise_path : & Path ) -> Result < Vec < String > , TmcError > {
434+ let config = self . get_exercise_packaging_configuration ( exercise_path) ?;
435+
436+ //let points_re = Regex::new(r#"(.*)@\s*[pP]oints\s*\(\s*['"](.*)['"]\s*\)"#).unwrap();
437+
438+ let mut points = Vec :: new ( ) ;
439+ for exercise_file_path in config. exercise_file_paths {
440+ let exercise_file_path = exercise_path. join ( exercise_file_path) ;
441+ if !exercise_file_path. exists ( ) {
442+ continue ;
443+ }
444+
445+ // file path may point to a directory of file, walkdir takes care of both
446+ for entry in WalkDir :: new ( exercise_file_path) {
447+ let entry = entry?;
448+ if entry. path ( ) . is_file ( ) {
449+ log:: debug!( "parsing points from {}" , entry. path( ) . display( ) ) ;
450+ let file_contents = file_util:: read_file_to_string ( entry. path ( ) ) ?;
451+
452+ let parser = sequence:: tuple ( (
453+ Self :: line_comment_parser,
454+ Self :: block_comment_parser,
455+ Self :: points_parser,
456+ complete:: take ( 1usize ) ,
457+ ) ) ;
458+ let res: IResult < _ , _ , ( & str , ErrorKind ) > = parser ( & file_contents) ;
459+ let ( rem, ( lc, bc, ps, nc) ) = res. unwrap ( ) ;
460+ }
461+ }
462+ }
463+ Ok ( points)
464+ }
465+
466+ fn line_comment_parser < ' a , E : ParseError < & ' a str > > ( i : & ' a str ) -> IResult < & ' a str , ( ) , E > ;
467+ fn block_comment_parser < ' a , E : ParseError < & ' a str > > ( i : & ' a str ) -> IResult < & ' a str , ( ) , E > ;
468+ fn points_parser < ' a , E : ParseError < & ' a str > > ( i : & ' a str ) -> IResult < & ' a str , & str , E > ;
429469}
430470
431471#[ cfg( test) ]
@@ -486,6 +526,16 @@ mod test {
486526 fn clean ( & self , _path : & Path ) -> Result < ( ) , TmcError > {
487527 unimplemented ! ( )
488528 }
529+
530+ fn line_comment_parser < ' a , E : ParseError < & ' a str > > ( _: & ' a str ) -> IResult < & ' a str , ( ) , E > {
531+ unimplemented ! ( )
532+ }
533+ fn block_comment_parser < ' a , E : ParseError < & ' a str > > ( _: & ' a str ) -> IResult < & ' a str , ( ) , E > {
534+ unimplemented ! ( )
535+ }
536+ fn points_parser < ' a , E : ParseError < & ' a str > > ( _: & ' a str ) -> IResult < & ' a str , & str , E > {
537+ unimplemented ! ( )
538+ }
489539 }
490540
491541 #[ test]
0 commit comments