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 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 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 moduleContentImport(self, state, node, name): nameLabel = label( name ) nameUnparsed = UnparsedText( name ) nameUnparsed.associateWith( nameLabel ) return nodeEditor( node, nameLabel, UnparsedText( nameUnparsed, PRECEDENCE_IMPORTCONTENT ), 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 imaginaryLiteral(self, state, node, value): valueUnparsed = UnparsedText( value ) valueLabel = label( value, numericLiteralStyle ) valueUnparsed.associateWith( valueLabel ) return nodeEditor( node, valueLabel, valueUnparsed, state )
def var(self, state, node, name): nameUnparsed = UnparsedText( name ) nameLabel = label( name ) nameUnparsed.associateWith( nameLabel ) return nodeEditor( node, nameLabel, nameUnparsed, 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 UNPARSED(self, state, node, value): valueUnparsed = UnparsedText( value ) valueLabel = label( '<' + value + '>', unparsedStyle ) valueUnparsed.associateWith( valueLabel ) return nodeEditor( node, valueLabel, valueUnparsed, 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 relativeModule(self, state, node, name): nameLabel = label( name ) nameUnparsed = UnparsedText( name ) nameUnparsed.associateWith( nameLabel ) return nodeEditor( node, nameLabel, UnparsedText( nameUnparsed, PRECEDENCE_IMPORTCONTENT ), 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 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 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 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 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 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 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 )
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 globalStmt(self, state, node, *xs): globalLabel = keywordLabel( globalKeyword ) globalUnparsed = UnparsedText( globalKeyword ) globalUnparsed.associateWith( globalLabel ) xViews = mapViewEval( xs, None, python25ViewState( Parser.globalVar ) ) xWidgets = [] if len( xs ) > 0: for xv in xViews[:-1]: xWidgets.append( ahbox( [ xv, label( ',', punctuationStyle ) ] ) ) xWidgets.append( xViews[-1] ) return nodeEditor( node, flow( [ globalLabel ] + xWidgets, spacing=10.0 ), UnparsedText( globalUnparsed + ' ' + UnparsedText( ', ' ).join( [ xv.text for xv in xViews ] ), PRECEDENCE_STMT ), state )
def assertStmt(self, state, node, condition, fail): assertLabel = keywordLabel( assertKeyword ) assertUnparsed = UnparsedText( assertKeyword ) assertUnparsed.associateWith( assertLabel ) conditionView = viewEval( condition ) widgets = [ assertLabel ] if fail != '<nil>': failView = viewEval( fail ) widgets.append( ahbox( [ conditionView, label( ',', punctuationStyle ) ] ) ) widgets.append( viewEval( fail ) ) else: failView = None widgets.append( conditionView ) return nodeEditor( node, flow( widgets, spacing=10.0 ), UnparsedText( assertUnparsed + ' ' + conditionView.text + ( ', ' + failView.text ) if failView is not None else '', PRECEDENCE_STMT ), state )
def withStmt(self, state, node, expr, target, suite): withLabel = keywordLabel( withKeyword ) withUnparsed = UnparsedText( withKeyword ) withUnparsed.associateWith( withLabel ) exprView = viewEval( expr ) widgets = [ exprView ] txt = withUnparsed + ' ' + exprView.text if target != '<nil>': targetView = viewEval( target ) widgets.append( keywordLabel( asKeyword ) ) widgets.append( targetView ) txt += ' as ' + targetView.text widgets.append( label( ':', punctuationStyle ) ) return compoundStatementEditor( node, flow( [ withLabel ] + widgets, spacing=10.0 ), UnparsedText( txt + ':', PRECEDENCE_STMT ), suite, state )
def defStmt(self, state, node, name, params, suite): defLabel = keywordLabel( defKeyword ) defUnparsed = UnparsedText( defKeyword ) defUnparsed.associateWith( defLabel ) nameLabel = label( name ) nameUnparsed = UnparsedText( name ) nameUnparsed.associateWith( nameLabel ) paramViews = mapViewEval( params, None, python25ViewState( Parser.param ) ) paramWidgets = [ label( '(', punctuationStyle ) ] if len( params ) > 0: for p in paramViews[:-1]: paramWidgets.append( ahbox( [ p, label( ',', punctuationStyle ) ] ) ) paramWidgets.append( paramViews[-1] ) paramWidgets.append( label( ')', punctuationStyle ) ) return compoundStatementEditor( node, flow( [ defLabel, nameLabel ] + paramWidgets + [ label( ':', punctuationStyle ) ], spacing=10.0 ), UnparsedText( defUnparsed + ' ' + nameUnparsed + '(' + UnparsedText( ', ' ).join( [ p.text for p in paramViews ] ) + '):', PRECEDENCE_STMT ), suite, state )
def exceptStmt(self, state, node, exc, target, suite): exceptLabel = keywordLabel( exceptKeyword ) exceptUnparsed = UnparsedText( exceptKeyword ) exceptUnparsed.associateWith( exceptLabel ) widgets = [] txt = exceptUnparsed if exc != '<nil>': excView = viewEval( exc ) if target != '<nil>': widgets.append( ahbox( [ excView, label( ',', punctuationStyle ) ] ) ) else: widgets.append( excView ) txt += ' ' + excView.text if target != '<nil>': targetView = viewEval( target ) widgets.append( targetView ) txt += ', ' + targetView.text widgets.append( label( ':', punctuationStyle ) ) return compoundStatementEditor( node, flow( [ exceptLabel ] + widgets, spacing=10.0 ), UnparsedText( txt + ':', PRECEDENCE_STMT ), suite, state )
def execStmt(self, state, node, src, loc, glob): execLabel = keywordLabel( execKeyword ) execUnparsed = UnparsedText( execKeyword ) execUnparsed.associateWith( execLabel ) srcView = viewEval( src, None, python25ViewState( Parser.orOp ) ) widgets = [ srcView ] txt = execUnparsed + ' ' + srcView.text if loc != '<nil>': locView = viewEval( loc ) widgets.append( keywordLabel( inKeyword ) ) if glob != '<nil>': widgets.append( ahbox( [ locView, label( ',', punctuationStyle ) ] ) ) else: widgets.append( locView ) txt += ' ' + inKeyword + ' ' + locView.text if glob != '<nil>': globView = viewEval( glob ) widgets.append( globView ) txt += ', ' + globView.text return nodeEditor( node, flow( [ execLabel ] + widgets, spacing=10.0 ), UnparsedText( txt , PRECEDENCE_STMT ), state )