Skip to content

Commit edceabb

Browse files
authored
Merge pull request #136 from rage/hidden
implement HIDDEN FILE, BEGIN HIDDEN and END HIDDEN markers for exercises
2 parents 1ee7b54 + fd797af commit edceabb

File tree

7 files changed

+308
-134
lines changed

7 files changed

+308
-134
lines changed

tmc-langs-framework/src/meta_syntax.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ pub enum MetaString {
2222
String(String),
2323
Stub(String),
2424
Solution(String),
25+
Hidden(String),
2526
SolutionFileMarker,
27+
HiddenFileMarker,
2628
}
2729

2830
/// Contains the needed regexes for a given comment syntax.
@@ -33,6 +35,9 @@ struct MetaSyntax {
3335
solution_end: Regex,
3436
stub_begin: Regex,
3537
stub_end: Regex,
38+
hidden_file: Regex,
39+
hidden_begin: Regex,
40+
hidden_end: Regex,
3641
}
3742

3843
impl MetaSyntax {
@@ -63,13 +68,31 @@ impl MetaSyntax {
6368
let stub_begin =
6469
Regex::new(&format!(r"{}STUB:[\s&&[^\n]]*", comment_start_pattern)).unwrap();
6570
let stub_end = Regex::new(&comment_end_pattern).unwrap();
71+
let hidden_file = Regex::new(&format!(
72+
r"{}HIDDEN\s+FILE{}",
73+
comment_start_pattern, comment_end_pattern
74+
))
75+
.unwrap();
76+
let hidden_begin = Regex::new(&format!(
77+
r"{}BEGIN\s+HIDDEN{}",
78+
comment_start_pattern, comment_end_pattern
79+
))
80+
.unwrap();
81+
let hidden_end = Regex::new(&format!(
82+
r"{}END\s+HIDDEN{}",
83+
comment_start_pattern, comment_end_pattern
84+
))
85+
.unwrap();
6686

6787
Self {
6888
solution_file,
6989
solution_begin,
7090
solution_end,
7191
stub_begin,
7292
stub_end,
93+
hidden_file,
94+
hidden_begin,
95+
hidden_end,
7396
}
7497
}
7598
}
@@ -83,6 +106,7 @@ pub struct MetaSyntaxParser<B: BufRead> {
83106
// used to make sure only the appropriate terminator ends the block
84107
in_stub: Option<&'static MetaSyntax>,
85108
in_solution: bool,
109+
in_hidden: bool,
86110
}
87111

88112
impl<R: Read> MetaSyntaxParser<BufReader<R>> {
@@ -101,6 +125,7 @@ impl<R: Read> MetaSyntaxParser<BufReader<R>> {
101125
reader,
102126
in_stub: None,
103127
in_solution: false,
128+
in_hidden: false,
104129
}
105130
}
106131
}
@@ -172,6 +197,15 @@ impl<B: BufRead> Iterator for MetaSyntaxParser<B> {
172197
} else if meta_syntax.solution_end.is_match(&s) && self.in_solution {
173198
self.in_solution = false;
174199
return self.next();
200+
} else if meta_syntax.hidden_file.is_match(&s) {
201+
log::trace!("hidden file marker");
202+
return Some(Ok(MetaString::HiddenFileMarker));
203+
} else if meta_syntax.hidden_begin.is_match(&s) {
204+
self.in_hidden = true;
205+
return self.next();
206+
} else if meta_syntax.hidden_end.is_match(&s) {
207+
self.in_hidden = false;
208+
return self.next();
175209
}
176210
}
177211
// after processing the line with each meta syntax,
@@ -182,6 +216,9 @@ impl<B: BufRead> Iterator for MetaSyntaxParser<B> {
182216
} else if self.in_stub.is_some() {
183217
log::trace!("stub: '{}'", s);
184218
Some(Ok(MetaString::Stub(s)))
219+
} else if self.in_hidden {
220+
log::trace!("hidden: '{}'", s);
221+
Some(Ok(MetaString::Hidden(s)))
185222
} else {
186223
log::trace!("string: '{}'", s);
187224
Some(Ok(MetaString::String(s)))

0 commit comments

Comments
 (0)