Skip to content

Commit

Permalink
Formatting: Fixed comment handling before %start
Browse files Browse the repository at this point in the history
  • Loading branch information
jsinger67 committed Jul 12, 2023
1 parent 84c0d08 commit 7ae1a15
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
BC1
*/
%start OptionalAlternatives

%%

OptionalAlternatives
: [ "x" | "y" | "z" ]
;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// LC1
// LC2
%start OptionalAlternatives

%%

OptionalAlternatives
: [ "x" | "y" | "z" ]
;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
BC1
*/
%start OptionalAlternatives

%%

OptionalAlternatives
: [ "x" | "y" | "z" ];
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// LC1
// LC2
%start OptionalAlternatives

%%

OptionalAlternatives
: [ "x" | "y" | "z" ];
6 changes: 6 additions & 0 deletions crates/parol-ls/data/input/block_comments_before_start.par
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
BC1
*/
%start OptionalAlternatives
%%
OptionalAlternatives: [ "x" | "y" | "z" ];
5 changes: 5 additions & 0 deletions crates/parol-ls/data/input/line_comments_before_start.par
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// LC1
// LC2
%start OptionalAlternatives
%%
OptionalAlternatives: [ "x" | "y" | "z" ];
17 changes: 13 additions & 4 deletions crates/parol-ls/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,14 +672,23 @@ impl Fmt for SimpleTokenOpt {
}
impl Fmt for StartDeclaration {
fn txt(&self, options: &FmtOptions) -> String {
let comment_options_left = options.clone().with_padding(Padding::Left);
let comment_options_right = options.clone().with_padding(Padding::Right);
let comment_options_top = if let Some(last_comment) = self.comments.comments_list.last() {
match &*last_comment.comment {
Comment::BlockComment(_) => {
options.clone().with_line_end(LineEnd::ForceSingleNewline)
}
Comment::LineComment(_) => options.clone(),
}
} else {
options.clone()
};
let comment_options_bottom = options.clone().with_padding(Padding::Left);
format!(
"{}{} {}{}\n",
handle_comments(&self.comments, &comment_options_right),
handle_comments(&self.comments, &comment_options_top),
self.percent_start,
self.identifier.txt(options),
handle_comments(&self.comments0, &comment_options_left),
handle_comments(&self.comments0, &comment_options_bottom),
)
}
}
Expand Down

0 comments on commit 7ae1a15

Please sign in to comment.