def intLiteral(self, state, node, format, numType, value): boxContents = [] if numType == 'int': if format == 'decimal': unparsed = '%d' % int( value ) elif format == 'hex': unparsed = '%x' % int( value ) valueLabel = label( unparsed, numericLiteralStyle ) boxContents.append( valueLabel ) elif numType == 'long': if format == 'decimal': unparsed = '%dL' % long( value ) elif format == 'hex': unparsed = '%xL' % long( value ) valueLabel = label( unparsed[:-1], numericLiteralStyle ) boxContents.append( valueLabel ) boxContents.append( label( 'L', literalFormatStyle ) ) valueUnparsed = UnparsedText( unparsed ) valueUnparsed.associateWith( valueLabel ) return nodeEditor( node, ahbox( boxContents ), valueUnparsed, state )
def classStmt(self, state, node, name, inheritance, suite): classLabel = keywordLabel( classKeyword ) classUnparsed = UnparsedText( classKeyword ) classUnparsed.associateWith( classLabel ) nameLabel = label( name ) nameUnparsed = UnparsedText( name ) nameUnparsed.associateWith( nameLabel ) if inheritance != '<nil>': inheritanceView = viewEval( inheritance, None, python25ViewState( Parser.tupleOrExpression ) ) inhWidget = ahbox( [ label( '(', punctuationStyle ), inheritanceView, label( ')', punctuationStyle ) ] ) inhUnparsed = UnparsedText( '(' ) + inheritanceView.text + ')' classLine = flow( [ classLabel, nameLabel, inhWidget, label( ':', punctuationStyle ) ], spacing=10.0 ) classLineUnparsed = classUnparsed + ' ' + nameUnparsed + inhUnparsed + ':' else: inhWidgets = [] classLine = flow( [ classLabel, nameLabel, label( ':', punctuationStyle ) ], spacing=10.0 ) classLineUnparsed = classUnparsed + ' ' + nameUnparsed + ':' return compoundStatementEditor( node, classLine, UnparsedText( classLineUnparsed, PRECEDENCE_STMT ), suite, state )
def decoStmt(self, state, node, name, args): atLabel = label( '@' ) atUnparsed = UnparsedText( '@' ) atUnparsed.associateWith( atLabel ) nameLabel = label( name ) nameUnparsed = UnparsedText( name ) nameUnparsed.associateWith( nameLabel ) if args != '<nil>': argViews = mapViewEval( args, None, python25ViewState( Parser.callArg ) ) argWidgets = [ label( '(', punctuationStyle ) ] if len( args ) > 0: for a in argViews[:-1]: argWidgets.append( ahbox( [ a, label( ',', punctuationStyle ) ] ) ) argWidgets.append( argViews[-1] ) argWidgets.append( label( ')', punctuationStyle ) ) argsUnparsed = '( ' + UnparsedText( ', ' ).join( [ a.text for a in argViews ] ) + ' )' else: argWidgets = [] argsUnparsed = '' return nodeEditor( node, ahbox( [ atLabel, nameLabel ] + argWidgets ), UnparsedText( atUnparsed + nameUnparsed + argsUnparsed, PRECEDENCE_STMT ), state )
def ellipsis(self, state, node): ellipsisLabel = label( '...', punctuationStyle ) ellipsisUnparsed = UnparsedText( '...' ) ellipsisUnparsed.associateWith( ellipsisLabel ) return nodeEditor( node, label( '...', punctuationStyle ), UnparsedText( ellipsisUnparsed, PRECEDENCE_SUBSCRIPTSLICE ), state )
def kwParamList(self, state, node, name): nameLabel = label( name ) nameUnparsed = UnparsedText( name ) nameUnparsed.associateWith( nameLabel ) return nodeEditor( node, ahbox( [ label( '**', punctuationStyle ), nameLabel ] ), UnparsedText( '**' + nameUnparsed, PRECEDENCE_PARAM ), state )
def defaultValueParam(self, state, node, name, value): nameLabel = label( name ) nameUnparsed = UnparsedText( name ) nameUnparsed.associateWith( nameLabel ) valueView = viewEval( value ) return nodeEditor( node, ahbox( [ nameLabel, label( '=', punctuationStyle ), valueView ] ), UnparsedText( nameUnparsed + '=' + valueView.text, PRECEDENCE_PARAM ), state )
def attributeRef(self, state, node, target, name): targetView = viewEval( target ) nameUnparsed = UnparsedText( name ) nameLabel = label( name ) nameUnparsed.associateWith( nameLabel ) return nodeEditor( node, flow( [ viewEval( target ), label( '.' ), nameLabel ] ), UnparsedText( _unparsePrecedenceGT( targetView.text, PRECEDENCE_ATTR ) + '.' + nameUnparsed, PRECEDENCE_ATTR ), state )
def subscript(self, state, node, target, index): targetView = viewEval( target ) indexView = viewEval( index, None, python25ViewState( Parser.subscriptIndex ) ) #return nodeEditor( node, #scriptRSub( targetView, ahbox( [ label( '[', punctuationStyle ), indexView, label( ']', punctuationStyle ) ] ) ), #UnparsedText( _unparsePrecedenceGT( targetView.text, PRECEDENCE_SUBSCRIPT ) + '[' + indexView.text + ']', PRECEDENCE_SUBSCRIPT ), #state ) return nodeEditor( node, ahbox( [ targetView, label( '[', punctuationStyle ), indexView, label( ']', punctuationStyle ) ] ), UnparsedText( _unparsePrecedenceGT( targetView.text, PRECEDENCE_SUBSCRIPT ) + '[' + indexView.text + ']', PRECEDENCE_SUBSCRIPT ), state )
def moduleContentImportAs(self, state, node, name, asName): nameLabel = label( name ) nameUnparsed = UnparsedText( name ) nameUnparsed.associateWith( nameLabel ) asNameLabel = label( asName ) asNameUnparsed = UnparsedText( asName ) asNameUnparsed.associateWith( asNameLabel ) return nodeEditor( node, ahbox( [ nameLabel, keywordLabel( asKeyword ), asNameLabel ] ), UnparsedText( nameUnparsed + ' ' + asKeyword + ' ' + asNameUnparsed, PRECEDENCE_IMPORTCONTENT ), state )
def call(self, state, node, target, *args): targetView = viewEval( target ) argViews = mapViewEval( args, None, python25ViewState( Parser.callArg ) ) argWidgets = [] if len( args ) > 0: for a in argViews[:-1]: argWidgets.append( ahbox( [ a, label( ',', punctuationStyle ) ] ) ) argWidgets.append( argViews[-1] ) return nodeEditor( node, flow( [ viewEval( target ), label( '(', punctuationStyle ) ] + argWidgets + [ label( ')', punctuationStyle ) ] ), UnparsedText( _unparsePrecedenceGT( targetView.text, PRECEDENCE_CALL ) + '( ' + UnparsedText( ', ' ).join( [ a.text for a in argViews ] ) + ' )', PRECEDENCE_CALL ), state )
def stringLiteral(self, state, node, format, quotation, value): valueUnparsed = UnparsedText( repr( value ) ) valueLabel = label( value ) valueUnparsed.associateWith( valueLabel ) boxContents = [] if format == 'ascii': pass elif format == 'unicode': boxContents.append( label( 'u', literalFormatStyle ) ) elif format == 'ascii-regex': boxContents.append( label( 'r', literalFormatStyle ) ) elif format == 'unicode-regex': boxContents.append( label( 'ur', literalFormatStyle ) ) else: raise ValueError, 'invalid string literal format' if quotation == 'single': boxContents.append( label( "'", punctuationStyle ) ) boxContents.append( None ) boxContents.append( label( "'", punctuationStyle ) ) else: boxContents.append( label( '"', punctuationStyle ) ) boxContents.append( None ) boxContents.append( label( '"', punctuationStyle ) ) boxContents[-2] = valueLabel return nodeEditor( node, ahbox( boxContents ), valueUnparsed, state )
def horizontalPrefixOpView(state, node, x, op, precedence): xView = viewEval( x ) unparsed = _unparsePrefixOpView( xView.text, op, precedence ) return nodeEditor( node, ahbox( [ label( op, operatorStyle ), xView ] ), unparsed, state )
def generatorExpression(self, state, node, expr, *xs): exprView = viewEval( expr ) xViews = mapViewEval( xs, None, python25ViewState( Parser.generatorExpressionItem ) ) return nodeEditor( node, flow( [ label( '(', punctuationStyle ), flow( [ exprView ] + xViews, spacing=15.0 ), label( ')', punctuationStyle ) ] ), UnparsedText( '( ' + exprView.text + ' ' + UnparsedText( ' ' ).join( [ x.text for x in xViews ] ) + ' ]', PRECEDENCE_GENERATOREXPRESSION ), state )
def keyValuePair(self, state, node, key, value): keyView = viewEval( key ) valueView = viewEval( value ) return nodeEditor( node, ahbox( [ keyView, label( ':', punctuationStyle ), valueView ] ), UnparsedText( keyView.text + ':' + valueView.text, PRECEDENCE_DICTLITERAL ), state )
def listComprehension(self, state, node, expr, *xs): exprView = viewEval( expr ) xViews = mapViewEval( xs, None, python25ViewState( Parser.listComprehensionItem ) ) return nodeEditor( node, flow( [ label( '[', punctuationStyle ), flow( [ exprView ] + xViews, spacing=15.0 ), label( ']', punctuationStyle ) ] ), UnparsedText( '[ ' + exprView.text + ' ' + UnparsedText( ' ' ).join( [ x.text for x in xViews ] ) + ' ]', PRECEDENCE_LISTCOMPREHENSION ), state )
def augAssignStmt(self, state, node, op, target, value): targetView = viewEval( target, None, python25ViewState( Parser.targetItem ) ) valueView = viewEval( value, None, python25ViewState( Parser.tupleOrExpressionOrYieldExpression ) ) return nodeEditor( node, flow( [ targetView, label( op, punctuationStyle ), valueView ] ), UnparsedText( targetView.text + op + valueView.text, PRECEDENCE_STMT ), state )
def relativeModule(self, state, node, name): nameLabel = label( name ) nameUnparsed = UnparsedText( name ) nameUnparsed.associateWith( nameLabel ) return nodeEditor( node, nameLabel, UnparsedText( nameUnparsed, PRECEDENCE_IMPORTCONTENT ), state )
def simpleParam(self, state, node, name): nameLabel = label( name ) nameUnparsed = UnparsedText( name ) nameUnparsed.associateWith( nameLabel ) return nodeEditor( node, nameLabel, UnparsedText( nameUnparsed, PRECEDENCE_PARAM ), state )
def horizontalBinOpView(state, node, x, y, op, precedence): xView = viewEval( x ) yView = viewEval( y ) unparsed = _unparseBinOpView( xView.text, yView.text, op, precedence ) return nodeEditor( node, ahbox( [ xView, label( op, operatorStyle ), yView ] ), unparsed, state )
def UNPARSED(self, state, node, value): valueUnparsed = UnparsedText( value ) valueLabel = label( '<' + value + '>', unparsedStyle ) valueUnparsed.associateWith( valueLabel ) return nodeEditor( node, valueLabel, valueUnparsed, state )
def imaginaryLiteral(self, state, node, value): valueUnparsed = UnparsedText( value ) valueLabel = label( value, numericLiteralStyle ) valueUnparsed.associateWith( valueLabel ) return nodeEditor( node, valueLabel, valueUnparsed, state )
def moduleContentImport(self, state, node, name): nameLabel = label( name ) nameUnparsed = UnparsedText( name ) nameUnparsed.associateWith( nameLabel ) return nodeEditor( node, nameLabel, UnparsedText( nameUnparsed, PRECEDENCE_IMPORTCONTENT ), state )
def var(self, state, node, name): nameUnparsed = UnparsedText( name ) nameLabel = label( name ) nameUnparsed.associateWith( nameLabel ) return nodeEditor( node, nameLabel, nameUnparsed, state )
def finallyStmt(self, state, node, suite): finallyLabel = keywordLabel( finallyKeyword ) finallyUnparsed = UnparsedText( finallyKeyword ) finallyUnparsed.associateWith( finallyLabel ) return compoundStatementEditor( node, ahbox( [ finallyLabel, label( ':', punctuationStyle ) ] ), UnparsedText( finallyUnparsed + ':', PRECEDENCE_STMT ), suite, state )
def subscriptLongSlice(self, state, node, x, y, z): widgets = [] def _v(n): if n != '<nil>': nView = viewEval( n ) widgets.append( nView ) return nView, nView.text else: return None, '' xView, xText = _v( x ) widgets.append( label( ':', punctuationStyle ) ) yView, yText = _v( y ) widgets.append( label( ':', punctuationStyle ) ) zView, zText = _v( z ) return nodeEditor( node, ahbox( widgets ), UnparsedText( xText + ':' + yText + ':' + zText, PRECEDENCE_SUBSCRIPTSLICE ), state )
def elseStmt(self, state, node, suite): elseLabel = keywordLabel( elseKeyword ) elseUnparsed = UnparsedText( elseKeyword ) elseUnparsed.associateWith( elseLabel ) return compoundStatementEditor( node, ahbox( [ elseLabel, label( ':', punctuationStyle ) ] ), UnparsedText( elseUnparsed + ':', PRECEDENCE_STMT ), suite, state )
def commentStmt(self, state, node, comment): commentLabel = label( comment, commentStyle ) commentUnparsed = UnparsedText( comment ) commentUnparsed.associateWith( commentLabel ) return nodeEditor( node, commentLabel, UnparsedText( '#' + commentUnparsed, PRECEDENCE_STMT ), state )
def whileStmt(self, state, node, condition, suite): whileLabel = keywordLabel( whileKeyword ) whileUnparsed = UnparsedText( whileKeyword ) whileUnparsed.associateWith( whileLabel ) conditionView = viewEval( condition ) return compoundStatementEditor( node, flow( [ whileLabel, ahbox( [ conditionView, label( ':', punctuationStyle ) ] ) ] ), UnparsedText( whileUnparsed + ' ' + conditionView.text + ':', PRECEDENCE_STMT ), suite, state )
def assignmentStmt(self, state, node, targets, value): targetViews = mapViewEval( targets, None, python25ViewState( Parser.targetList ) ) valueView = viewEval( value, None, python25ViewState( Parser.tupleOrExpressionOrYieldExpression ) ) targetWidgets = [] for t in targetViews: targetWidgets.append( ahbox( [ t, label( '=', punctuationStyle ) ] ) ) return nodeEditor( node, flow( targetWidgets + [ valueView ] ), UnparsedText( UnparsedText( ' = ' ).join( [ t.text for t in targetViews ] ) + ' = ' + valueView.text, PRECEDENCE_STMT ), state )
def forStmt(self, state, node, target, source, suite): forLabel = keywordLabel( forKeyword ) forUnparsed = UnparsedText( forKeyword ) forUnparsed.associateWith( forLabel ) targetView = viewEval( target, None, python25ViewState( Parser.targetList ) ) sourceView = viewEval( source, None, python25ViewState( Parser.tupleOrExpression ) ) return compoundStatementEditor( node, flow( [ forLabel, targetView, keywordLabel( inKeyword ), ahbox( [ sourceView, label( ':', punctuationStyle ) ] ) ] ), UnparsedText( forUnparsed + ' ' + targetView.text + ' ' + inKeyword + sourceView.text + ':', PRECEDENCE_LISTCOMPREHENSION ), suite, state )