Skip to content

Commit 980c42c

Browse files
committed
temp
1 parent c60de94 commit 980c42c

File tree

5 files changed

+64
-46
lines changed

5 files changed

+64
-46
lines changed

tmc-langs-cli/src/error.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use std::path::PathBuf;
2+
use thiserror::Error;
3+
4+
#[derive(Debug, Error)]
5+
#[error("Invalid token. Deleted credentials file at {path}")]
6+
pub struct InvalidTokenError {
7+
pub path: PathBuf,
8+
pub source: anyhow::Error,
9+
}

tmc-langs-framework/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ serde = { version = "1", features = ["derive"] }
1515
serde_yaml = "0.8"
1616
zip = "0.5"
1717
schemars = "0.7"
18+
once_cell = "1"
19+
nom = "5"
1820

1921
[dev-dependencies]
2022
env_logger = "0.7"

tmc-langs-framework/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub mod policy;
99

1010
use domain::TmcProjectYml;
1111
pub use error::TmcError;
12+
pub use nom;
1213
pub use plugin::LanguagePlugin;
1314
pub use policy::StudentFilePolicy;
1415
pub use zip;

tmc-langs-framework/src/plugin.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ use crate::io::{file_util, submission_processing, tmc_zip};
99
use crate::policy::StudentFilePolicy;
1010
pub use isolang::Language;
1111
use log::debug;
12+
use nom::{bytes::complete, combinator, error::ErrorKind, error::ParseError, sequence, IResult};
13+
use once_cell::sync::Lazy;
14+
use regex::Regex;
1215
use std::collections::{HashMap, HashSet};
1316
use std::io::{Read, Seek, Write};
1417
use 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]

tmc-langs-util/src/task_executor.rs

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -191,52 +191,7 @@ pub fn find_exercise_directories(exercise_path: &Path) -> Vec<PathBuf> {
191191

192192
/// Parses available exercise points from the exercise without compiling it.
193193
pub fn get_available_points(exercise_path: &Path) -> Result<Vec<String>, UtilError> {
194-
let plugin = get_language_plugin(exercise_path)?;
195-
let config = plugin.get_exercise_packaging_configuration(exercise_path)?;
196-
197-
let points_re = Regex::new(r#"(.*)@\s*[pP]oints\s*\(\s*['"](.*)['"]\s*\)"#).unwrap();
198-
let mut points = Vec::new();
199-
for exercise_file_path in config.exercise_file_paths {
200-
let exercise_file_path = exercise_path.join(exercise_file_path);
201-
if !exercise_file_path.exists() {
202-
continue;
203-
}
204-
205-
// file path may point to a directory of file, walkdir takes care of both
206-
for entry in WalkDir::new(exercise_file_path) {
207-
let entry = entry?;
208-
if entry.path().is_file() {
209-
log::debug!("parsing points from {}", entry.path().display());
210-
let file_contents = file_util::read_file_to_string(entry.path())?;
211-
212-
let mut in_comment = false;
213-
for line in file_contents.lines() {
214-
let start = line.trim_start();
215-
// skip commented lines
216-
if start.starts_with("//") || start.starts_with('#') {
217-
continue;
218-
}
219-
if start.starts_with("/*") {
220-
in_comment = true;
221-
}
222-
if !in_comment {
223-
if let Some(captures) = points_re.captures(line) {
224-
let first_end = captures[1].trim_end();
225-
if !first_end.ends_with("//")
226-
&& !first_end.ends_with('#')
227-
&& !first_end.ends_with("/*")
228-
{
229-
points.push(captures[2].to_string());
230-
}
231-
}
232-
}
233-
if start.ends_with("*/") {
234-
in_comment = false;
235-
}
236-
}
237-
}
238-
}
239-
}
194+
let points = get_language_plugin(exercise_path)?.get_available_points(exercise_path)?;
240195
Ok(points)
241196
}
242197

@@ -251,6 +206,7 @@ pub fn get_available_points(exercise_path: &Path) -> Result<Vec<String>, UtilErr
251206
fn run_tests(&self, path: &Path) -> Result<RunResult, TmcError> {}
252207
fn check_code_style(&self, path: &Path, locale: Language) -> Result<Option<ValidationResult>, TmcError> {}
253208
fn prepare_stub(&self, exercise_path: &Path, repo_path: &Path, dest_path: &Path) -> Result<(), TmcError> {}
209+
fn get_available_points(&self, exercise_path: &Path) -> Result<Vec<String>, TmcError> {}
254210
)]
255211
enum Plugin {
256212
CSharp(CSharpPlugin),

0 commit comments

Comments
 (0)