Skip to content

Commit

Permalink
Simplified comment matching regex
Browse files Browse the repository at this point in the history
  • Loading branch information
WGUNDERWOOD committed May 2, 2024
1 parent ae55af8 commit 8376f40
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/regexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ lazy_static! {
pub static ref RE_NEWLINES: Regex = Regex::new(r"\n\n\n+").unwrap();
pub static ref RE_TABS: Regex = Regex::new(r"\t").unwrap();
pub static ref RE_TRAIL: Regex = Regex::new(r" +\n").unwrap();
pub static ref RE_PERCENT: Regex = Regex::new(r"\\\%").unwrap();
pub static ref RE_COMMENT: Regex = Regex::new(r"\%.*").unwrap();
pub static ref RE_COMMENT: Regex = Regex::new(r"(?P<text>.*^|[^\\])(?P<comm>\%.*$)").unwrap();
pub static ref RE_ITEM: Regex = Regex::new(r".*\\item.*").unwrap();
pub static ref RE_DOCUMENT_BEGIN: Regex =
Regex::new(r".*\\begin\{document\}.*").unwrap();
Expand Down
3 changes: 1 addition & 2 deletions src/subs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,5 @@ pub fn remove_trailing_spaces(file: &str) -> String {
//}

pub fn remove_comment(line: &str) -> String {
let new_line = RE_PERCENT.replace_all(line, "").to_string();
RE_COMMENT.replace_all(&new_line, "").to_string()
RE_COMMENT.replace_all(line, "$text").to_string()
}
4 changes: 4 additions & 0 deletions tests/comments_in.tex
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@
% Similarly they might contain \begin{align}
% unmatched environment tags.

This is a percent sign \% and not a comment

Some lines might have both \% percents % and comments \end{align}

\end{document}
4 changes: 4 additions & 0 deletions tests/comments_out.tex
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@
% Similarly they might contain \begin{align}
% unmatched environment tags.

This is a percent sign \% and not a comment

Some lines might have both \% percents % and comments \end{align}

\end{document}

0 comments on commit 8376f40

Please sign in to comment.