Ejemplo n.º 1
0
	def augAssignStmt(self, ctx, state, node, op, target, value):
		targetView = viewEval( ctx, target, None, python25ViewState( Parser.targetItem ) )
		valueView = viewEval( ctx, value, None, python25ViewState( Parser.tupleOrExpressionOrYieldExpression ) )
		return nodeEditor( ctx, node,
				   paragraph( ctx, python_paragraphStyle, [ targetView,  text( ctx, punctuation_textStyle, ' ' + op + ' ' ),  valueView ] ),
				   PRECEDENCE_STMT,
				   state )
Ejemplo n.º 2
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 )
Ejemplo n.º 3
0
	def subscriptSlice(self, ctx, state, node, x, y):
		xView = viewEval( ctx, x )
		yView = viewEval( ctx, y )
		return nodeEditor( ctx, node,
				   paragraph( ctx, python_paragraphStyle, [ xView, text( ctx, punctuation_textStyle, ':' ), yView ] ),
				   PRECEDENCE_SUBSCRIPTSLICE,
				   state )
Ejemplo n.º 4
0
	def subscript(self, ctx, state, node, target, index):
		targetView = viewEval( ctx, target )
		indexView = viewEval( ctx, index, None, python25ViewState( Parser.subscriptIndex ) )
		return nodeEditor( ctx, node,
				   paragraph( ctx, python_paragraphStyle, [ targetView,  text( ctx, punctuation_textStyle, '[' ),  indexView,  text( ctx, punctuation_textStyle, ']' ) ] ),
				   PRECEDENCE_SUBSCRIPT,
				   state )
Ejemplo n.º 5
0
	def genFor(self, ctx, state, node, target, source):
		targetView = viewEval( ctx, target, None, python25ViewState( Parser.targetList ) )
		sourceView = viewEval( ctx, source, None, python25ViewState( Parser.orTest ) )
		return nodeEditor( ctx, node,
				   paragraph( ctx, python_paragraphStyle, [ keywordText( ctx, forKeyword ), text( ctx, default_textStyle, ' ' ), targetView, text( ctx, default_textStyle, ' ' ), keywordText( ctx, inKeyword ), text( ctx, default_textStyle, ' ' ), sourceView ] ),
				   PRECEDENCE_GENERATOREXPRESSION,
				   state )
Ejemplo n.º 6
0
	def keyValuePair(self, ctx, state, node, key, value):
		keyView = viewEval( ctx, key )
		valueView = viewEval( ctx, value )
		return nodeEditor( ctx, node,
				   paragraph( ctx, python_paragraphStyle, [ keyView, text( ctx, punctuation_textStyle, ' : ' ), valueView ] ),
				   None,
				   state )
Ejemplo n.º 7
0
def paragraphBinOpView(ctx, state, node, x, y, op, precedence, bRightAssociative):
	xView = viewEval( ctx, x )
	yView = viewEval( ctx, y )
	return nodeEditor( ctx, node,
			   paragraphBinOpElement( ctx, xView, yView, text( ctx, operator_textStyle, op ), precedence, bRightAssociative ),
			   precedence,
			   state )
Ejemplo n.º 8
0
	def listFor(self, ctx, state, node, target, source):
		targetView = viewEval( ctx, target, None, python25ViewState( Parser.targetList ) )
		sourceView = viewEval( ctx, source, None, python25ViewState( Parser.oldTupleOrExpression ) )
		return nodeEditor( ctx, node,
				   paragraph( ctx, python_paragraphStyle, [ keywordText( ctx, forKeyword ), text( ctx, default_textStyle, ' ' ), targetView, text( ctx, default_textStyle, ' ' ), keywordText( ctx, inKeyword ), text( ctx, default_textStyle, ' ' ), sourceView ] ),
				   PRECEDENCE_LISTCOMPREHENSION,
				   state )
Ejemplo n.º 9
0
	def listFor(self, state, node, target, source):
		targetView = viewEval( target, None, python25ViewState( Parser.targetList ) )
		sourceView = viewEval( source, None, python25ViewState( Parser.oldTupleOrExpression ) )
		return nodeEditor( node,
				   flow( [ keywordLabel( forKeyword ), targetView, keywordLabel( inKeyword ), sourceView ] ),
				   UnparsedText( forKeyword  +  ' '  +  targetView.text  +  ' '  +  inKeyword  +  sourceView.text, PRECEDENCE_LISTCOMPREHENSION ),
				   state )
Ejemplo n.º 10
0
	def genFor(self, state, node, target, source):
		targetView = viewEval( target, None, python25ViewState( Parser.targetList ) )
		sourceView = viewEval( source, None, python25ViewState( Parser.orTest ) )
		return nodeEditor( node,
				   flow( [ keywordLabel( forKeyword ), targetView, keywordLabel( inKeyword ), sourceView ] ),
				   UnparsedText( forKeyword  +  ' '  +  targetView.text  +  ' '  +  inKeyword  +  sourceView.text, PRECEDENCE_GENERATOREXPRESSION ),
				   state )
Ejemplo n.º 11
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 )
Ejemplo n.º 12
0
def binOpView(state, node, x, y, unparsedOp, widgetFactory, precedence):
	xView = viewEval( x )
	yView = viewEval( y )
	unparsed = _unparseBinOpView( xView.text, yView.text, unparsedOp, precedence )
	return nodeEditor( node,
			widgetFactory( state, node, x, y, xView, yView ),
			unparsed,
			state )
Ejemplo n.º 13
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 )
Ejemplo n.º 14
0
	def conditionalExpr(self, state, node, condition, expr, elseExpr):
		conditionView = viewEval( condition, None, python25ViewState( Parser.orTest ) )
		exprView = viewEval( expr, None, python25ViewState( Parser.orTest ) )
		elseExprView = viewEval( elseExpr, None, python25ViewState( Parser.expression ) )
		return nodeEditor( node,
				   ahbox( [ exprView,   ahbox( [ keywordLabel( ifKeyword ), conditionView ] ), ahbox( [ keywordLabel( elseKeyword ), elseExprView ] )   ], spacing=15.0 ),
				   UnparsedText( exprView.text  +  '   '  +  ifKeyword  +  ' '  +  conditionView.text  +  ' '  +  elseKeyword  +  '   '   +  elseExprView.text, PRECEDENCE_CONDITIONALEXPRESSION ),
				   state )
Ejemplo n.º 15
0
	def forStmt(self, ctx, state, node, target, source, suite):
		targetView = viewEval( ctx, target, None, python25ViewState( Parser.targetList ) )
		sourceView = viewEval( ctx, source, None, python25ViewState( Parser.tupleOrExpression ) )
		return compoundStatementEditor( ctx, node,
						paragraph( ctx, python_paragraphStyle, [ keywordText( ctx, forKeyword ),  text( ctx, default_textStyle, ' ' ),  targetView,  text( ctx, default_textStyle, ' ' ),
											 keywordText( ctx, inKeyword ),  text( ctx, default_textStyle, ' ' ),  sourceView,  text( ctx, punctuation_textStyle, ':' ) ] ),
						PRECEDENCE_STMT,
						suite,
						state  )
Ejemplo n.º 16
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 )
Ejemplo n.º 17
0
	def assertStmt(self, ctx, state, node, condition, fail):
		conditionView = viewEval( ctx, condition )
		elements = [ keywordText( ctx, assertKeyword ), text( ctx, default_textStyle, ' ' ), conditionView ]
		if fail != '<nil>':
			failView = viewEval( ctx, fail )
			elements.extend( [ text( ctx, punctuation_textStyle, ', ' ),  failView ] )
		return nodeEditor( ctx, node,
				   paragraph( ctx, python_paragraphStyle, elements ),
				   PRECEDENCE_STMT,
				   state )
Ejemplo n.º 18
0
	def conditionalExpr(self, ctx, state, node, condition, expr, elseExpr):
		conditionView = viewEval( ctx, condition, None, python25ViewState( Parser.orTest ) )
		exprView = viewEval( ctx, expr, None, python25ViewState( Parser.orTest ) )
		elseExprView = viewEval( ctx, elseExpr, None, python25ViewState( Parser.expression ) )
		return nodeEditor( ctx, node,
				   paragraph( ctx, python_paragraphStyle, [ exprView,   whitespace( ctx, '  ', 15.0 ),
									    keywordText( ctx, ifKeyword ), text( ctx, default_textStyle, ' ' ), conditionView,   whitespace( ctx, '  ', 15.0 ),
									    keywordText( ctx, elseKeyword ), text( ctx, default_textStyle, ' ' ), elseExprView ] ),
				   PRECEDENCE_CONDITIONALEXPRESSION,
				   state )
Ejemplo n.º 19
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 )
Ejemplo n.º 20
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 )
Ejemplo n.º 21
0
	def withStmt(self, ctx, state, node, expr, target, suite):
		exprView = viewEval( ctx, expr )
		elements = [ exprView ]
		if target != '<nil>':
			targetView = viewEval( ctx, target )
			elements.extend( [ text( ctx, default_textStyle, ' ' ),  keywordText( ctx, asKeyword ),  text( ctx, default_textStyle, ' ' ),  targetView ] )
		elements.append( text( ctx, punctuation_textStyle, ':' ) )
		return compoundStatementEditor( ctx, node,
						paragraph( ctx, python_paragraphStyle, [ keywordText( ctx, withKeyword ),  text( ctx, default_textStyle, ' ' ) ]  +  elements ),
						PRECEDENCE_STMT,
						suite,
						state )
Ejemplo n.º 22
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 )
Ejemplo n.º 23
0
def binOpView(ctx, state, node, x, y, precedence, bRightAssociative, elementFactory):
	xView = viewEval( ctx, x )
	yView = viewEval( ctx, y )
	if bRightAssociative:
		xView = _precedenceGTE( ctx, xView, precedence )
		yView = _precedenceGT( ctx, yView, precedence )
	else:
		xView = _precedenceGT( ctx, xView, precedence )
		yView = _precedenceGTE( ctx, yView, precedence )
	return nodeEditor( ctx, node,
			   elementFactory( ctx, state, node, x, y, xView, yView ),
			   precedence,
			   state )
Ejemplo n.º 24
0
	def execStmt(self, ctx, state, node, src, loc, glob):
		srcView = viewEval( ctx, src, None, python25ViewState( Parser.orOp ) )
		elements = [ srcView ]
		if loc != '<nil>':
			locView = viewEval( ctx, loc )
			elements.extend( [ text( ctx, default_textStyle, ' ' ),  keywordText( ctx, inKeyword ),  text( ctx, default_textStyle, ' ' ),  locView ] )
		if glob != '<nil>':
			globView = viewEval( ctx, glob )
			elements.extend( [ text( ctx, default_textStyle, ', ' ),  globView ] )
		return nodeEditor( ctx, node,
				   paragraph( ctx, python_paragraphStyle, [ keywordText( ctx, execKeyword ),  text( ctx, default_textStyle, ' ' ) ]  +  elements ),
				   PRECEDENCE_STMT,
				   state )
Ejemplo n.º 25
0
	def exceptStmt(self, ctx, state, node, exc, target, suite):
		elements = []
		if exc != '<nil>':
			excView = viewEval( ctx, exc )
			elements.extend( [ text( ctx, default_textStyle, ' ' ),  excView ] )
		if target != '<nil>':
			targetView = viewEval( ctx, target )
			elements.extend( [ text( ctx, default_textStyle, ', ' ),  targetView ] )
		elements.append( text( ctx, punctuation_textStyle, ':' ) )
		return compoundStatementEditor( ctx, node,
						paragraph( ctx, python_paragraphStyle, [ keywordText( ctx, exceptKeyword ) ]  +  elements ),
						PRECEDENCE_STMT,
						suite,
						state )
Ejemplo n.º 26
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 )
Ejemplo n.º 27
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 )
Ejemplo n.º 28
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 )
Ejemplo n.º 29
0
		def _v(n):
			if n != '<nil>':
				nView = viewEval( n )
				widgets.append( nView )
				return nView, nView.text
			else:
				return None, ''
Ejemplo n.º 30
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 )