From c4de983cde7cc86f86491366f0917c7601353372 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Mon, 20 May 2024 16:20:54 -0700 Subject: [PATCH] Make eval comment parsing more consistent Now `-- $>foo` is accepted as an eval comment in addition to `-- $> foo`. --- docs/comment-evaluation.md | 3 ++- src/ghci/parse/eval.rs | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/comment-evaluation.md b/docs/comment-evaluation.md index 3accdca6..11f15fd6 100644 --- a/docs/comment-evaluation.md +++ b/docs/comment-evaluation.md @@ -53,7 +53,8 @@ Single-line eval comments have the following grammar: ``` [ \t]* # Leading whitespace -"-- $> " # Eval comment marker +"-- $>" # Eval comment marker +[ \t]* # Optional whitespace [^\n]+ \n # Rest of line ``` diff --git a/src/ghci/parse/eval.rs b/src/ghci/parse/eval.rs index 36ab7de9..de548812 100644 --- a/src/ghci/parse/eval.rs +++ b/src/ghci/parse/eval.rs @@ -141,7 +141,8 @@ fn eval_commands(input: &mut Located<&str>) -> PResult fn line_eval_command(input: &mut Located<&str>) -> PResult { let _ = space0.parse_next(input)?; // TODO: Perhaps these eval markers should be customizable? - let _ = "-- $> ".parse_next(input)?; + let _ = "-- $>".parse_next(input)?; + let _ = space0.parse_next(input)?; let (command, span) = until_newline.with_span().parse_next(input)?; let command: GhciCommand = command.to_owned().into(); @@ -203,6 +204,15 @@ mod tests { } ); + assert_eq!( + line_eval_command.parse(Located::new("-- $>foo\n")).unwrap(), + ByteSpanCommand { + command: "foo".to_owned().into(), + display_command: "foo".into(), + span: 5..9, + } + ); + // Leading whitespace. assert_eq!( line_eval_command