Exemplo n.º 1
0
    def layout(self, editor, obj, context):
        parent = context[-1][0] if len(context) > 0 else None
        ys = lambda i, plac="*": editor.layout_star(obj, i, context, plac)
        y = lambda i: editor.layout_dot(obj, i, context)

        if isstring(obj):
            if parent.name == 'int':
                return string(editor.font(obj).mul(blue))
            if parent.name == 'string':
                return string(editor.font(obj).mul(purple))
            return None

        if obj.name in ('variable', 'int', 'string'):
            return group(ys(0))

#        if name == 'int' and len(obj) > 0:
#            return group(delimit(y(), xglue, 8, 0))
        if obj.name in operator:
            label = editor.font(operator_symbol[obj.name]).mul(orange)
            return group(delimit(
                self.wrap(parent.name, obj.name,
                    [ y(0), string(label), y(1) ]
                ),
                xglue, 8, 0
            ))
#                )
#            )

#        if name == 'program':
#            language = obj.get('language') or '<unknown>'
#            header = group([
#                string(editor.font("program").mul(dark)),
#                xglue(8,0),
#                string(editor.font(language).mul(dark).mul(blue)),
#            ])

        if obj.name == 'call':
            return group([ y(0), xglue(8,0), 
                group(
                    delimit(self.wrap('call', 'call', ys(1)), xglue, 8, 0)
                )
            ])

        if obj.name == 'function':
            return group([
                group(delimit(ys(0, 'argument*'), xglue, 8, 0)),
                yglue(3, 0),
                group(delimit(ys(1, 'exp*'), yglue, 3, 0)),
            ])

        if obj.name == 'if':
            return group([
                group([
                    string(editor.font('if').mul(gray)),
                    xglue(8, 0),
                    y(0),
                ]),
                yglue(3, 0),
                group([
                    string(editor.font('else').mul(gray)),
                    xglue(8, 0),
                    group(delimit(ys(1, 'exp*'), yglue, 3, 0)),
                ]),
                yglue(3, 0),
                group([
                    string(editor.font('otherwise').mul(gray)),
                    xglue(8, 0),
                    group(delimit(ys(2, 'exp*'), yglue, 3, 0)),
                ]),
            ])
Exemplo n.º 2
0
 def wrap(self, parent, this, data):
     lparen, rparen = self.parens
     if operator.get(parent, 0) >= operator.get(this):
         return [string(lparen)] + data + [string(rparen)]
     return data