コード例 #1
0
	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 )
コード例 #2
0
	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 )
コード例 #3
0
	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 )
コード例 #4
0
	def ellipsis(self, state, node):
		ellipsisLabel = label( '...', punctuationStyle )
		ellipsisUnparsed = UnparsedText( '...' )
		ellipsisUnparsed.associateWith( ellipsisLabel )
		return nodeEditor( node,
				label( '...', punctuationStyle ),
				UnparsedText( ellipsisUnparsed,  PRECEDENCE_SUBSCRIPTSLICE ),
				state )
コード例 #5
0
	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 )
コード例 #6
0
	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 )
コード例 #7
0
	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 )
コード例 #8
0
	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 )
コード例 #9
0
	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 )
コード例 #10
0
	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 )
コード例 #11
0
	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 )
コード例 #12
0
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 )
コード例 #13
0
	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 )
コード例 #14
0
	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 )
コード例 #15
0
	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 )
コード例 #16
0
	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 )
コード例 #17
0
	def relativeModule(self, state, node, name):
		nameLabel = label( name )
		nameUnparsed = UnparsedText( name )
		nameUnparsed.associateWith( nameLabel )
		return nodeEditor( node,
				   nameLabel,
				   UnparsedText( nameUnparsed, PRECEDENCE_IMPORTCONTENT ),
				   state )
コード例 #18
0
	def simpleParam(self, state, node, name):
		nameLabel = label( name )
		nameUnparsed = UnparsedText( name )
		nameUnparsed.associateWith( nameLabel )
		return nodeEditor( node,
				nameLabel,
				UnparsedText( nameUnparsed,  PRECEDENCE_PARAM ),
				state )
コード例 #19
0
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 )
コード例 #20
0
	def UNPARSED(self, state, node, value):
		valueUnparsed = UnparsedText( value )
		valueLabel = label( '<' + value + '>', unparsedStyle )
		valueUnparsed.associateWith( valueLabel )
		return nodeEditor( node,
				valueLabel,
				valueUnparsed,
				state )
コード例 #21
0
	def imaginaryLiteral(self, state, node, value):
		valueUnparsed = UnparsedText( value )
		valueLabel = label( value, numericLiteralStyle )
		valueUnparsed.associateWith( valueLabel )
		return nodeEditor( node,
				valueLabel,
				valueUnparsed,
				state )
コード例 #22
0
	def moduleContentImport(self, state, node, name):
		nameLabel = label( name )
		nameUnparsed = UnparsedText( name )
		nameUnparsed.associateWith( nameLabel )
		return nodeEditor( node,
				   nameLabel,
				   UnparsedText( nameUnparsed, PRECEDENCE_IMPORTCONTENT ),
				   state )
コード例 #23
0
	def var(self, state, node, name):
		nameUnparsed = UnparsedText( name )
		nameLabel = label( name )
		nameUnparsed.associateWith( nameLabel )
		return nodeEditor( node,
				nameLabel,
				nameUnparsed,
				state )
コード例 #24
0
	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 )
コード例 #25
0
	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 )
コード例 #26
0
	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 )
コード例 #27
0
	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 )
コード例 #28
0
	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  )
コード例 #29
0
	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 )
コード例 #30
0
	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 )