Ejemplo n.º 1
0
	def fromImportAllStmt(self, ctx, state, node, moduleName):
		moduleNameView = viewEval( ctx, moduleName, None, python25ViewState( Parser.moduleContentImport ) )
		return nodeEditor( ctx, node,
				   paragraph( ctx, python_paragraphStyle, [ keywordText( ctx, fromKeyword ), text( ctx, default_textStyle, ' ' ), moduleNameView, text( ctx, default_textStyle, ' ' ),
									     keywordText( ctx, importKeyword ), text( ctx, default_textStyle, ' ' ),  text( ctx, punctuation_textStyle, '*' ) ] ),
				   PRECEDENCE_STMT,
				   state )
Ejemplo n.º 2
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.º 3
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.º 4
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.º 5
0
	def globalStmt(self, ctx, state, node, *xs):
		xViews = mapViewEval( ctx, xs, None, python25ViewState( Parser.globalVar ) )
		xElements = []
		if len( xs ) > 0:
			for xv in xViews[:-1]:
				xElements.extend( [ xv,  text( ctx, punctuation_textStyle, ', ' ) ] )
			xElements.append( xViews[-1] )
		return nodeEditor( ctx, node,
				   paragraph( ctx, python_paragraphStyle, [ keywordText( ctx, globalKeyword ),  text( ctx, default_textStyle, ' ' ) ]  +  xElements ),
				   PRECEDENCE_STMT,
				   state )
Ejemplo n.º 6
0
	def raiseStmt(self, ctx, state, node, *xs):
		xs = [ x   for x in xs   if x != '<nil>' ]
		xViews = mapViewEval( ctx, xs )
		xElements = []
		if len( xs ) > 0:
			for x in xViews[:-1]:
				xElements.extend( [ x,  text( ctx, punctuation_textStyle, ', ' ) ] )
			xElements.append( xViews[-1] )
		return nodeEditor( ctx, node,
				   paragraph( ctx, python_paragraphStyle, [ keywordText( ctx, raiseKeyword ),  text( ctx, default_textStyle, ' ' ) ] + xElements ),
				   PRECEDENCE_STMT,
				   state )
Ejemplo n.º 7
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.º 8
0
	def classStmt(self, ctx, state, node, name, inheritance, suite):
		if inheritance != '<nil>':
			inheritanceView = viewEval( ctx, inheritance, None, python25ViewState( Parser.tupleOrExpression ) )
			inhElements = [ text( ctx, punctuation_textStyle, '(' ),  inheritanceView,  text( ctx, punctuation_textStyle, ')' ) ]
		else:
			inhElements = []
			
		return compoundStatementEditor( ctx, node,
						paragraph( ctx, python_paragraphStyle, [ keywordText( ctx, classKeyword ),  text( ctx, default_textStyle, ' ' ),  text( ctx, default_textStyle, name ) ]  +  \
							   inhElements  +  [ text( ctx, punctuation_textStyle, ':' ) ] ),
						PRECEDENCE_STMT,
						suite,
						state )
Ejemplo n.º 9
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.º 10
0
	def fromImportStmt(self, ctx, state, node, moduleName, *xs):
		moduleNameView = viewEval( ctx, moduleName, None, python25ViewState( Parser.moduleContentImport ) )
		xViews = mapViewEval( ctx, xs, None, python25ViewState( Parser.moduleImport ) )
		xElements = []
		if len( xs ) > 0:
			for xv in xViews[:-1]:
				xElements.extend( [ xv,  text( ctx, punctuation_textStyle, ', ' ) ] )
			xElements.append( xViews[-1] )
		return nodeEditor( ctx, node,
				   paragraph( ctx, python_paragraphStyle, [ keywordText( ctx, fromKeyword ), text( ctx, default_textStyle, ' ' ), moduleNameView, text( ctx, default_textStyle, ' ' ),
									    keywordText( ctx, importKeyword ), text( ctx, default_textStyle, ' ' ) ]  +  xElements ),
				   PRECEDENCE_STMT,
				   state )
Ejemplo n.º 11
0
	def call(self, ctx, state, node, target, *args):
		targetView = viewEval( ctx, target )
		argViews = mapViewEval( ctx, args, None, python25ViewState( Parser.callArg ) )
		argElements = []
		if len( args ) > 0:
			for a in argViews[:-1]:
				argElements.append( a )
				argElements.append( text( ctx, punctuation_textStyle, ', ' ) )
			argElements.append( argViews[-1] )
		return nodeEditor( ctx, node,
				   paragraph( ctx, python_paragraphStyle, [ targetView, text( ctx, punctuation_textStyle, '(' ) ]  +  argElements  +  [ text( ctx, punctuation_textStyle, ')' ) ] ),
				   PRECEDENCE_CALL,
				   state )
Ejemplo n.º 12
0
	def defStmt(self, ctx, state, node, name, params, suite):
		paramViews = mapViewEval( ctx, params, None, python25ViewState( Parser.param ) )
		paramElements = [ text( ctx, punctuation_textStyle, '(' ) ]
		if len( params ) > 0:
			for p in paramViews[:-1]:
				paramElements.extend( [ p,  text( ctx, punctuation_textStyle, ', ' ) ] )
			paramElements.append( paramViews[-1] )
		paramElements.append( text( ctx, punctuation_textStyle, ')' ) )
		return compoundStatementEditor( ctx, node,
						paragraph( ctx, python_paragraphStyle, [ keywordText( ctx, defKeyword ),  text( ctx, default_textStyle, ' ' ),  text( ctx, default_textStyle, name ) ]  +  \
							   paramElements  +  [ text( ctx, punctuation_textStyle, ':' ) ] ),
						PRECEDENCE_STMT,
						suite,
						state )
Ejemplo n.º 13
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.º 14
0
	def stringLiteral(self, ctx, state, node, format, quotation, value):
		boxContents = []

		if format == 'ascii':
			pass
		elif format == 'unicode':
			boxContents.append( text( ctx, literalFormat_textStyle, 'u' ) )
		elif format == 'ascii-regex':
			boxContents.append( text( ctx, literalFormat_textStyle, 'r' ) )
		elif format == 'unicode-regex':
			boxContents.append( text( ctx, literalFormat_textStyle, 'ur' ) )
		else:
			raise ValueError, 'invalid string literal format'

		if quotation == 'single':
			boxContents.append( text( ctx, punctuation_textStyle, "'" ) )
			boxContents.append( None )
			boxContents.append( text( ctx, punctuation_textStyle, "'" ) )
		else:
			boxContents.append( text( ctx, punctuation_textStyle, '"' ) )
			boxContents.append( None )
			boxContents.append( text( ctx, punctuation_textStyle, '"' ) )

		boxContents[-2] = text( ctx, default_textStyle, value )

		return nodeEditor( ctx, node,
				   paragraph( ctx, python_paragraphStyle, boxContents ),
				   PRECEDENCE_LITERALVALUE,
				   state )
Ejemplo n.º 15
0
	def decoStmt(self, ctx, state, node, name, args):
		if args != '<nil>':
			argViews = mapViewEval( ctx, args, None, python25ViewState( Parser.callArg ) )
			argElements = [ text( ctx, punctuation_textStyle, '(' ) ]
			if len( args ) > 0:
				for a in argViews[:-1]:
					argElements.extend( [ a, text( ctx, punctuation_textStyle, ', ' ) ] )
				argElements.append( argViews[-1] )
			argElements.append( text( ctx, punctuation_textStyle, ')' ) )
		else:
			argElements = []
		return nodeEditor( ctx, node,
				   paragraph( ctx, python_paragraphStyle, [ text( ctx, punctuation_textStyle, '@' ),  text( ctx, default_textStyle, name ) ]  +  argElements ),
				   PRECEDENCE_STMT,
				   state )
Ejemplo n.º 16
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.º 17
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.º 18
0
	def whileStmt(self, ctx, state, node, condition, suite):
		conditionView = viewEval( ctx, condition )
		return compoundStatementEditor( ctx, node,
						paragraph( ctx, python_paragraphStyle, [ keywordText( ctx, whileKeyword ),  text( ctx, default_textStyle, ' ' ),  conditionView,  text( ctx, punctuation_textStyle, ':' ) ] ),
						PRECEDENCE_STMT,
						suite,
						state  )
Ejemplo n.º 19
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.º 20
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.º 21
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.º 22
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.º 23
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.º 24
0
def paragraphBinOpElement(ctx, x, y, op, precedence, bRightAssociative=False):
	if bRightAssociative:
		x = _precedenceGTE( ctx, x, precedence )
		y = _precedenceGT( ctx, y, precedence )
	else:
		x = _precedenceGT( ctx, x, precedence )
		y = _precedenceGTE( ctx, y, precedence )
	return paragraph( ctx, python_paragraphStyle, [ x, text( ctx, default_textStyle, ' ' ), op, text( ctx, default_textStyle, ' ' ), y ] )
Ejemplo n.º 25
0
	def assignmentStmt(self, ctx, state, node, targets, value):
		targetViews = mapViewEval( ctx, targets, None, python25ViewState( Parser.targetList ) )
		valueView = viewEval( ctx, value, None, python25ViewState( Parser.tupleOrExpressionOrYieldExpression ) )
		targetElements = []
		for t in targetViews:
			targetElements.extend( [ t,  text( ctx, punctuation_textStyle, ' = ' ) ] )
		return nodeEditor( ctx, node,
				   paragraph( ctx, python_paragraphStyle, targetElements  +  [ valueView ] ),
				   PRECEDENCE_STMT,
				   state )
Ejemplo n.º 26
0
	def intLiteral(self, ctx, state, node, format, numType, value):
		boxContents = []

		if numType == 'int':
			if format == 'decimal':
				valueString = '%d'  %  int( value )
			elif format == 'hex':
				valueString = '%x'  %  int( value, 16 )
			boxContents.append( text( ctx, numericLiteral_textStyle, valueString ) )
		elif numType == 'long':
			if format == 'decimal':
				valueString = '%d'  %  long( value )
			elif format == 'hex':
				valueString = '%x'  %  long( value, 16 )
			boxContents.append( text( ctx, numericLiteral_textStyle, valueString ) )
			boxContents.append( text( ctx, literalFormat_textStyle, 'L' ) )

		return nodeEditor( ctx, node,
				   paragraph( ctx, python_paragraphStyle, boxContents ),
				   PRECEDENCE_LITERALVALUE,
				   state )
Ejemplo n.º 27
0
	def listComprehension(self, ctx, state, node, expr, *xs):
		exprView = viewEval( ctx, expr )
		xViews = mapViewEval( ctx, xs, None, python25ViewState( Parser.listComprehensionItem ) )
		xViewsSpaced = []
		if len( xViews ) > 0:
			for x in xViews[:-1]:
				xViewsSpaced.append( x )
				xViewsSpaced.append( whitespace( ctx, ' ', 15.0 ) )
			xViewsSpaced.append( xViews[-1] )
		return nodeEditor( ctx, node,
				   paragraph( ctx, python_paragraphStyle, [ text( ctx, punctuation_textStyle, '[' ),  exprView,  whitespace( ctx, ' ', 15.0 ) ] + xViewsSpaced + [ text( ctx, punctuation_textStyle, ']' ) ] ),
				   PRECEDENCE_LISTCOMPREHENSION,
				   state )
Ejemplo n.º 28
0
	def generatorExpression(self, ctx, state, node, expr, *xs):
		exprView = viewEval( ctx, expr )
		xViews = mapViewEval( ctx, xs, None, python25ViewState( Parser.generatorExpressionItem ) )
		xViewsSpaced = []
		if len( xViews ) > 0:
			for x in xViews[:-1]:
				xViewsSpaced.append( x )
				xViewsSpaced.append( whitespace( ctx, ' ', 15.0 ) )
			xViewsSpaced.append( xViews[-1] )
		return nodeEditor( ctx, node,
				   paragraph( ctx, python_paragraphStyle, [ text( ctx, punctuation_textStyle, '(' ),  exprView,  whitespace( ctx, ' ', 15.0 ) ] + xViewsSpaced + [ text( ctx, punctuation_textStyle, ')' ) ] ),
				   PRECEDENCE_GENERATOREXPRESSION,
				   state )
Ejemplo n.º 29
0
	def lambdaExpr(self, ctx, state, node, params, expr):
		# The Python 2.5 grammar has two versions of the lambda expression grammar; one what reckognises the full lambda expression, and one that
		# reckognises a lambda expression that cannot wrap conditional expression.
		# Ensure that we use the correct parser for @expr
		exprParser = Parser.expression
		if state is not None:
			parser, mode = state
			if parser is Parser.oldExpression   or  parser is Parser.oldLambdaExpr  or  parser is Parser.oldTupleOrExpression:
				exprParser = Parser.oldExpression

		exprView = viewEval( ctx, expr, None, python25ViewState( exprParser ) )
		paramViews = mapViewEval( ctx, params, None, python25ViewState( Parser.param ) )
		paramElements = []
		if len( params ) > 0:
			for p in paramViews[:-1]:
				paramElements.append( p )
				paramElements.append( text( ctx, punctuation_textStyle, ', ' ) )
			paramElements.append( paramViews[-1] )
		return nodeEditor( ctx, node,
				   paragraph( ctx, python_paragraphStyle, [ keywordText( ctx, lambdaKeyword ),  text( ctx, default_textStyle, ' ' ) ]  +  paramElements  +  [ text( ctx, punctuation_textStyle, ': ' ), exprView ] ),
				   PRECEDENCE_LAMBDAEXPR,
				   state )
Ejemplo n.º 30
0
def tupleView(ctx, state, node, xs, parser=None):
	def tupleElement(x):
		if x.metadata == PRECEDENCE_TUPLE:
			return paragraph( ctx, python_paragraphStyle, [ text( ctx, punctuation_textStyle, '(' ), x, text( ctx, punctuation_textStyle, ')' ) ] )
		else:
			return x
	if parser is not None:
		xViews = mapViewEval( ctx, xs, None, python25ViewState( parser ) )
	else:
		xViews = mapViewEval( ctx, xs )
	xElements = [ tupleElement( x )   for x in xViews ]
	return nodeEditor( ctx, node,
			   listView( ctx, tuple_listViewLayout, None, None, lambda: text( ctx, punctuation_textStyle, ',' ), xElements ),
			   PRECEDENCE_TUPLE,
			   state )