From 9ef12624c327f5b30c5a161884cdfbf7a6146c49 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Thu, 26 Sep 2024 22:23:22 -0400 Subject: [PATCH] feat(cli): add a `no-ranges` flag to the parse command --- cli/src/main.rs | 3 +++ cli/src/parse.rs | 18 +++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index afd9b8c1..2be442c5 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -191,6 +191,8 @@ struct Parse { pub test_number: Option, #[arg(short, long, help = "Force rebuild the parser")] pub rebuild: bool, + #[arg(long, help = "Omit ranges in the output")] + pub no_ranges: bool, } #[derive(Args)] @@ -605,6 +607,7 @@ impl Parse { cancellation_flag: Some(&cancellation_flag), encoding, open_log: self.open_log, + no_ranges: self.no_ranges, }; let parse_result = parse::parse_file_at_path(&mut parser, &opts)?; diff --git a/cli/src/parse.rs b/cli/src/parse.rs index 7c1dfc90..31a477e4 100644 --- a/cli/src/parse.rs +++ b/cli/src/parse.rs @@ -60,6 +60,7 @@ pub struct ParseFileOptions<'a> { pub cancellation_flag: Option<&'a AtomicUsize>, pub encoding: Option, pub open_log: bool, + pub no_ranges: bool, } #[derive(Copy, Clone)] @@ -178,15 +179,14 @@ pub fn parse_file_at_path(parser: &mut Parser, opts: &ParseFileOptions) -> Resul if let Some(field_name) = cursor.field_name() { write!(&mut stdout, "{field_name}: ")?; } - write!( - &mut stdout, - "({} [{}, {}] - [{}, {}]", - node.kind(), - start.row, - start.column, - end.row, - end.column - )?; + write!(&mut stdout, "({}", node.kind())?; + if !opts.no_ranges { + write!( + &mut stdout, + " [{}, {}] - [{}, {}]", + start.row, start.column, end.row, end.column + )?; + } needs_newline = true; } if cursor.goto_first_child() {