diff --git a/chirp/src/interpret.rs b/chirp/src/interpret.rs index 3bd6e41..8203c1e 100644 --- a/chirp/src/interpret.rs +++ b/chirp/src/interpret.rs @@ -123,13 +123,18 @@ impl<'w, 's, 'a, 'l, 'll, 'r, D: ParseDsl> Interpreter<'w, 's, 'a, 'l, 'll, 'r, pub fn statements(&self, input: &mut &BStr) -> PResult<(), ()> { use winnow::{ ascii, - combinator::{alt, delimited, opt, preceded, separated0, separated_pair, success}, + combinator::{ + alt, delimited, opt, preceded, repeat, separated0, separated_pair, success, + }, token::{one_of, take_till1}, }; // Note: we use `void` to reduce the size of input/output types. It's // a major source of performance problems in winnow. + let line_comment = || preceded(b"//", take_till1(b'\n')); + let repeat = repeat::<_, _, (), _, _>; + let spc_trail = || repeat(.., (line_comment(), ascii::multispace0)); let (spc, spc1, opt) = ( - || ascii::multispace0.void(), + || (ascii::multispace0, spc_trail()).void(), || ascii::multispace1.void(), || opt(b' ').void(), ); diff --git a/chirp/src/parse.rs b/chirp/src/parse.rs index 86e2ec5..6caaf1f 100644 --- a/chirp/src/parse.rs +++ b/chirp/src/parse.rs @@ -181,14 +181,15 @@ pub mod quick { impl<'a> Iterator for ArgIter<'a> { type Item = Result<&'a str, ArgError>; fn next(&mut self) -> Option { - if self.input.is_empty() { - return None; - } - self.count += 1; #[cold] + #[allow(clippy::missing_const_for_fn)] // false positive fn err(_: T) -> ArgError { ArgError::ArgParse } + if self.input.is_empty() { + return None; + } + self.count += 1; if self.count - 1 == 0 { let text = balanced_text.parse_next(&mut self.input).map_err(err); // SAFETY: `ArgIter.input` is always valid utf8 because of the diff --git a/examples/parse_dsl_macro/main.rs b/examples/parse_dsl_macro/main.rs index cdfc3d2..177b949 100644 --- a/examples/parse_dsl_macro/main.rs +++ b/examples/parse_dsl_macro/main.rs @@ -173,10 +173,15 @@ fn main() { let mut world1 = World::new(); let chirp = r#" - row("first row", rules(px(10), pct(11))) { - spawn(rules(pct(20), px(21)), "first child", empty_px 30); - spawn(empty_px 31, "2"); + // Some comments + row( + "first row", // demonstrating + rules(px(10), pct(11)) + ) { // that it is possible + spawn(rules(pct(20), px(21)), "first child", empty_px 30); // to + spawn(empty_px 31, "2"); // add comments } + // To a chirp file column("second element", rules(px(40), pct(41))) { spawn(rules(pct(50), px(51)), empty_px 60, "child3"); spawn(empty_px 61, "so called \"fourth\" child"); @@ -190,10 +195,15 @@ fn main() { let mut state = SystemState::::new(&mut world2); let mut cmds = state.get_mut(&mut world2); dsl! { cmds, - row("first row", rules(px(10), pct(11))) { - spawn(rules(pct(20), px(21)), "first child", empty_px 30); - spawn(empty_px 31, "2"); + // Some comments + row( + "first row", // demonstrating + rules(px(10), pct(11)) + ) { // that it is possible + spawn(rules(pct(20), px(21)), "first child", empty_px 30); // to + spawn(empty_px 31, "2"); // add comments } + // To a chirp file column("second element", rules(px(40), pct(41))) { spawn(rules(pct(50), px(51)), empty_px 60, "child3"); spawn(empty_px 61, "so called \"fourth\" child");