Changeset 4439:0e1deb54e881 in livinglogic.python.xist

Show
Ignore:
Timestamp:
04/04/11 13:20:22 (8 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Let UL4 pis (and others) fiddle with the indentation in pretty printing.

Files:
5 modified

Legend:

Unmodified
Added
Removed
  • NEWS.rst

    r4436 r4439  
    4646*   :class:`ll.orasql.Table` has a new method :meth:`organization` that returns 
    4747    ``"heap"`` or normal tables and ``"index"`` for index organized tables. 
     48 
     49*   Pretty printing of XIST trees can now be customized with the class attributes 
     50    :var:`prettyindentbefore` and :var:`prettyindentafter`. The values will be 
     51    added to the current indentation level before and after the node in question. 
    4852 
    4953 
  • src/ll/xist/ns/jsp.py

    r4422 r4439  
    7272class If(scriptlet): 
    7373    xmlname = "if" 
     74    prettyindentbefore = 0 
     75    prettyindentafter = 1 
    7476 
    7577    def convert(self, converter): 
     
    7981class Else(scriptlet): 
    8082    xmlname = "else" 
     83    prettyindentbefore = -1 
     84    prettyindentafter = 1 
    8185 
    8286    def convert(self, converter): 
     
    8690class ElIf(scriptlet): 
    8791    xmlname = "elif" 
     92    prettyindentbefore = -1 
     93    prettyindentafter = 1 
    8894 
    8995    def convert(self, converter): 
     
    9399class End(scriptlet): 
    94100    xmlname = "end" 
     101    prettyindentbefore = -1 
     102    prettyindentafter = 0 
    95103 
    96104    def convert(self, converter): 
  • src/ll/xist/ns/php.py

    r4422 r4439  
    3737class If(php): 
    3838    xmlname = "if" 
     39    prettyindentbefore = 0 
     40    prettyindentafter = 1 
    3941 
    4042    def convert(self, converter): 
     
    4446class Else(php): 
    4547    xmlname = "else" 
     48    prettyindentbefore = -1 
     49    prettyindentafter = 1 
    4650 
    4751    def convert(self, converter): 
     
    5155class ElIf(php): 
    5256    xmlname = "elif" 
     57    prettyindentbefore = -1 
     58    prettyindentafter = 1 
    5359 
    5460    def convert(self, converter): 
     
    5864class End(php): 
    5965    xmlname = "end" 
     66    prettyindentbefore = -1 
     67    prettyindentafter = 0 
    6068 
    6169    def convert(self, converter): 
  • src/ll/xist/ns/ul4.py

    r4422 r4439  
    106106class if_(xsc.ProcInst): 
    107107    xmlname = "if" 
     108    prettyindentbefore = 0 
     109    prettyindentafter = 1 
     110 
    108111 
    109112 
    110113class elif_(xsc.ProcInst): 
    111114    xmlname = "elif" 
     115    prettyindentbefore = -1 
     116    prettyindentafter = 1 
    112117 
    113118 
    114119class else_(xsc.ProcInst): 
    115120    xmlname = "else" 
     121    prettyindentbefore = -1 
     122    prettyindentafter = 1 
    116123 
    117124 
     
    119126    """ 
    120127    Ends an :class:`if_` or :class:`for_`. The PI value may be the type of the 
    121     block (either ``"if"`` or ``"for"``). If the value is empty the innermost 
    122     block will be closed without any checks for the type of block. 
     128    block (either ``"if"``, ``"for"`` or ``"def"``). If the value is empty the 
     129    innermost block will be closed without any checks for the type of block. 
    123130    """ 
     131    prettyindentbefore = -1 
     132    prettyindentafter = 0 
    124133 
    125134 
    126135class for_(xsc.ProcInst): 
    127136    xmlname = "for" 
     137    prettyindentbefore = 0 
     138    prettyindentafter = 1 
    128139 
    129140 
     
    138149class def_(xsc.ProcInst): 
    139150    xmlname = "def" 
     151    prettyindentbefore = 0 
     152    prettyindentafter = 1 
  • src/ll/xist/xsc.py

    r4422 r4439  
    982982    Context = Context 
    983983 
     984    prettyindentbefore = 0 
     985    prettyindentafter = 0 
     986 
    984987    def __repr__(self): 
    985988        return "<{0.__module__}:{0.__fullname__} object at {1:#x}>".format(self, id(self)) 
     
    19901993            if i: 
    19911994                node.append("\n") 
     1995            level += child.prettyindentbefore 
    19921996            node.append(child.pretty(level, indent)) 
     1997            level += child.prettyindentafter 
    19931998        return node 
    19941999 
     
    34593464 
    34603465    def pretty(self, level=0, indent="\t"): 
     3466        orglevel = level # Remember the original indent level, so that any misconfiguration inside the element doesn't mess with the indentation 
    34613467        node = self.__class__(self.attrs) 
    34623468        if len(self): 
     
    34683474                    break 
    34693475            else: 
     3476                level += 1 
    34703477                for child in self: 
    3471                     node.append("\n", child.pretty(level+1, indent)) 
    3472                 node.append("\n", indent*level) 
    3473         if level>0: 
    3474             node = Frag(indent*level, node) 
     3478                    level += child.prettyindentbefore 
     3479                    node.append("\n", child.pretty(level, indent)) 
     3480                    level += child.prettyindentafter 
     3481                node.append("\n", indent*orglevel) 
     3482        if orglevel>0: 
     3483            node = Frag(indent*orglevel, node) 
    34753484        return node 
    34763485