• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

tidy tool for Template Toolkit


Commit MetaInfo

修订版47360444b4ebdeb4ddbe985807e6ef2b55d8f356 (tree)
时间2015-07-08 20:27:01
作者hylom <hylom@user...>
Commiterhylom

Log Message

add more indenting rules

更改概述

差异

--- a/tttidy.py
+++ b/tttidy.py
@@ -59,12 +59,30 @@ class Indenter(object):
5959 def _calc_indent_level(self, line):
6060 count_if = len(re.findall(u'^(IF|FOREACH)\s', line))
6161 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))
6368 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
6578
6679 counter_current = 0
6780 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
6886 if count_if > count_end:
6987 count_if -= count_end
7088 count_end = 0
@@ -74,9 +92,9 @@ class Indenter(object):
7492
7593 if count_if > 0:
7694 counter_next += 1
77- if count_end > 0:
95+ elif count_end > 0:
7896 counter_current -= 1
79- if count_elsif > 0 and count_if == 0:
97+ elif count_elsif > 0 and count_if == 0:
8098 counter_current -= 1
8199 counter_next += 1
82100