[gnome-builder] python: add more generic blocks to to the rankings



commit 09145feb64fd5aaab82f13f5190d8061a882f355
Author: Christian Hergert <christian hergert me>
Date:   Sat Oct 3 14:05:59 2015 -0700

    python: add more generic blocks to to the rankings
    
    Maybe after a little more exploration we can look at joining all the
    blocks including if/elif/else to the same ranking. I especially since
    a lot of them can be composed together. It's not that bad if we unindent
    after the wrong syntax is used.

 plugins/python-pack/python_indenter.py |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
---
diff --git a/plugins/python-pack/python_indenter.py b/plugins/python-pack/python_indenter.py
index e4d592c..1ca0e48 100644
--- a/plugins/python-pack/python_indenter.py
+++ b/plugins/python-pack/python_indenter.py
@@ -46,6 +46,7 @@ class Rank:
     RETURN   = 1 << 11
     BREAK    = 1 << 12
     CONTINUE = 1 << 13
+    BLOCK    = 1 << 14
 
 _RANK_NAMES = {
     Rank.FUNCTION: 'FUNCTION',
@@ -62,6 +63,7 @@ _RANK_NAMES = {
     Rank.RETURN: 'RETURN',
     Rank.BREAK: 'BREAK',
     Rank.CONTINUE: 'CONTINUE',
+    Rank.BLOCK: 'BLOCK',
 }
 
 class Discovery:
@@ -185,6 +187,7 @@ class Discoveries:
         stop = self.buffer.get_iter_at_offset(self.stop)
 
         self._discover_break(iter, stop)
+        self._discover_blocks(iter, stop)
         self._discover_continue(iter, stop)
         self._discover_class(iter, stop)
         self._discover_comment(iter, stop)
@@ -233,6 +236,14 @@ class Discoveries:
     def _discover_pass(self, iter, stop, *, word="pass", rank=Rank.PASS):
         self._discover_simple(iter, stop, word, rank)
 
+    def _discover_blocks(self, iter, stop):
+        self._discover_simple(iter, stop, word='except', rank=Rank.BLOCK)
+        self._discover_simple(iter, stop, word='finally', rank=Rank.BLOCK)
+        self._discover_simple(iter, stop, word='for', rank=Rank.BLOCK)
+        self._discover_simple(iter, stop, word='try', rank=Rank.BLOCK)
+        self._discover_simple(iter, stop, word='while', rank=Rank.BLOCK)
+        self._discover_simple(iter, stop, word='with', rank=Rank.BLOCK)
+
     def _discover_break(self, iter, stop, *, word="break", rank=Rank.PASS):
         self._discover_simple(iter, stop, word, rank)
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]