tidy tool for Template Toolkit
Revision | 47360444b4ebdeb4ddbe985807e6ef2b55d8f356 (tree) |
---|---|
Time | 2015-07-08 20:27:01 |
Author | hylom <hylom@user...> |
Commiter | hylom |
add more indenting rules
@@ -59,12 +59,30 @@ class Indenter(object): | ||
59 | 59 | def _calc_indent_level(self, line): |
60 | 60 | count_if = len(re.findall(u'^(IF|FOREACH)\s', line)) |
61 | 61 | count_if += len(re.findall(u'\s(IF|FOREACH)\s', line)) |
62 | - count_end = len(re.findall(u'END(\s|;)', line)) | |
62 | + count_if += len(re.findall(u'^BLOCK(\s|;)', line)) | |
63 | + count_if += len(re.findall(u'\sBLOCK(\s|;)', line)) | |
64 | + count_end = len(re.findall(u'^END(\s|;)', line)) | |
65 | + count_end += len(re.findall(u'(\s|;)END(\s|;)', line)) | |
66 | + count_end += len(re.findall(u'^END$', line)) | |
67 | + count_end += len(re.findall(u'(\s|;)END$', line)) | |
63 | 68 | count_elsif = len(re.findall(u'^ELSIF\s', line)) |
64 | - count_elsif += len(re.findall(u'\sELSIF\s', line)) | |
69 | + count_elsif += len(re.findall(u'(\s|;)ELSIF\s', line)) | |
70 | + count_elsif += len(re.findall(u'^ELSE(\s|;)', line)) | |
71 | + count_elsif += len(re.findall(u'(\s|;)ELSE(\s|;)', line)) | |
72 | + count_elsif += len(re.findall(u'^ELSE$', line)) | |
73 | + count_elsif += len(re.findall(u'(|;)\sELSE$', line)) | |
74 | + | |
75 | + # support for "PROCESS xxx IF" style | |
76 | + if re.search(r'PROCESS\s+[^;]+\s+IF', line): | |
77 | + count_if -= 1 | |
65 | 78 | |
66 | 79 | counter_current = 0 |
67 | 80 | counter_next = 0 |
81 | + # case: IF - ELSIF - ELSE - END directives all exists in one line | |
82 | + if count_if == count_end and count_if > 0 and count_elsif > 0: | |
83 | + return (counter_current, counter_next) | |
84 | + | |
85 | + # else | |
68 | 86 | if count_if > count_end: |
69 | 87 | count_if -= count_end |
70 | 88 | count_end = 0 |
@@ -74,9 +92,9 @@ class Indenter(object): | ||
74 | 92 | |
75 | 93 | if count_if > 0: |
76 | 94 | counter_next += 1 |
77 | - if count_end > 0: | |
95 | + elif count_end > 0: | |
78 | 96 | counter_current -= 1 |
79 | - if count_elsif > 0 and count_if == 0: | |
97 | + elif count_elsif > 0 and count_if == 0: | |
80 | 98 | counter_current -= 1 |
81 | 99 | counter_next += 1 |
82 | 100 |