]> thyrsus.com Git - comparator.git/commitdiff
We reduce shell scripts effectively.
authorEric S. Raymond <esr@thyrsus.com>
Wed, 10 Sep 2003 19:40:02 +0000 (19:40 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Wed, 10 Sep 2003 19:40:02 +0000 (19:40 +0000)
filterator

index 994520db47c71ea7ed6aa544c8c65c6fe0594b6b..d7dff5bd1240156336718f9198afb636938fcb6e 100755 (executable)
@@ -31,19 +31,21 @@ junk = {
         r'\s*#include.*',r'#\s*line.*',
         # Common error macros.
         r'\bEFAULT\b', r'\bEINVAL\b', r'\bENOSYS\b',
-        # Punctuation
+        # Punctuation and whitespace
         r'\{', r'\}', r'\(', r'\)', r'\<', r'\>', r'\[', r'\]',
         r'\^', '&', r'\|', r'\*', r'\?', r'\.', r'\+', 
         '\\\n', ';', ':', '%', ',', '-', '/', '=', '!', '\n','\t', '\v'
         )),
     "shell": map(re.compile, (
         # Idioms that don't convey any meaning in isolation
-        r"exit *\([01]\);",
+        r"exit *[01];?",
         # Bare shell keywords
-        "\bcase\b", "\bdone\b", "\bdo\b", "\belse\b", "\besac\b",
-        "\bfi\b", "\bif\b", "\bwhile\b", 
+        r"\bcase\b", r"\bdone\b", r"\bdo\b", r"\belse\b", r"\besac\b",
+        r"\bfi\b", r"\bif\b", r"\bwhile\b", 
         # Blank comment
         "^#\n",
+        # Ounctuation and whitespace
+        ':', '\n','\t', '\v'
         )),
     }
 
@@ -65,7 +67,6 @@ def nontrivial(text, filetype):
             if savecopy == text:
                 break
             else:
-                text = text.strip()
                 if debug:
                     print "Reduced:", `text`
                 continue