From d1e475dc227e3bcdbef0f464b7522fd0c4be356e Mon Sep 17 00:00:00 2001 From: Otto Kohulak Date: Tue, 18 Oct 2022 14:06:45 +0200 Subject: [PATCH] Fix irpf90_indent now does not produce white space lines Fix C preprocessor macros are now never indented Fix !$omp directive are now never indeted --- src/irpf90_indent.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/irpf90_indent.py b/src/irpf90_indent.py index fe98a63..8faaf89 100755 --- a/src/irpf90_indent.py +++ b/src/irpf90_indent.py @@ -106,6 +106,14 @@ class Grep(object): def declaration(self,string): return re.match(self.re_declaration,string) is not None + re_preprocessor = re.compile(r"^\s*#.*$") + def preprocessor(self,string): + return re.match(self.re_preprocessor,string) is not None + + re_omppragma = re.compile(r"^\s*!\$omp\s.*$") + def omppragma(self,string): + return re.match(self.re_omppragma,string) is not None + grep = Grep() class indent(object): @@ -167,6 +175,19 @@ class indent(object): for i in range(len(self.text)): prevline = line line = self.text[i].strip() + + if line == "": + print("") + continue + + if grep.preprocessor(line): + print(line.lstrip()) + continue + + if grep.omppragma(line): + print(line.lstrip()) + continue + if grep.continuation(line): line = self.format_continuation(line,k)