Exemplo n.º 1
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 )
Exemplo n.º 2
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 )
Exemplo n.º 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 )
Exemplo n.º 4
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 )
Exemplo n.º 5
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 )
Exemplo n.º 6
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 )
Exemplo n.º 7
0
	def importStmt(self, state, node, *xs):
		xViews = mapViewEval( xs, None, python25ViewState( Parser.moduleImport ) )
		xWidgets = []
		if len( xs ) > 0:
			for xv in xViews[:-1]:
				xWidgets.append( ahbox( [ xv, label( ',', punctuationStyle ) ] ) )
			xWidgets.append( xViews[-1] )
		return nodeEditor( node,
				   flow( [ keywordLabel( importKeyword ) ]  +  xWidgets, spacing=10.0 ),
				   UnparsedText( importKeyword  +  ' '  +  UnparsedText( ', ' ).join( [ xv.text   for xv in xViews ] ), PRECEDENCE_STMT ),
				   state )
Exemplo n.º 8
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 )
Exemplo n.º 9
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 )
Exemplo n.º 10
0
def tupleView(state, node, xs, parser=None):
	def tupleWidget(x):
		if x.text.state == PRECEDENCE_TUPLE:
			return ahbox( [ label( '(', punctuationStyle ), x, label( ')', punctuationStyle ) ] )
		else:
			return x
	def tupleText(x):
		if x.state == PRECEDENCE_TUPLE:
			return '(' + x + ')'
		else:
			return x
	if parser is not None:
		xViews = mapViewEval( xs, None, python25ViewState( parser ) )
	else:
		xViews = mapViewEval( xs )
	xWidgets = [ tupleWidget( x )   for x in xViews ]
	xTexts = [ tupleText( x.text )   for x in xViews ]
	return nodeEditor( node,
			   listView( ParagraphListViewLayout( 5.0, 0.0 ), None, None, ',', xWidgets ),
			   UnparsedText( UnparsedText( ', ' ).join( [ x   for x in xTexts ] ), PRECEDENCE_TUPLE ),
			   state )
Exemplo n.º 11
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 )
Exemplo n.º 12
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 )
Exemplo n.º 13
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 )
Exemplo n.º 14
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 )
Exemplo n.º 15
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 )
Exemplo n.º 16
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 )
Exemplo n.º 17
0
	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 )
Exemplo n.º 18
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 )
Exemplo n.º 19
0
	def raiseStmt(self, state, node, *xs):
		xs = [ x   for x in xs   if x != '<nil>' ]
		xViews = mapViewEval( xs )
		xWidgets = []
		if len( xs ) > 0:
			for x in xViews[:-1]:
				xWidgets.append( ahbox( [ x, label( ',', punctuationStyle ) ] ) )
			xWidgets.append( xViews[-1] )
		xText = UnparsedText( ', ' ).join( [ x.text   for x in xViews ] )
		if len( xs ) > 0:
			xText = ' ' + xText
		return nodeEditor( node,
				   flow( [ keywordLabel( raiseKeyword ) ] + xWidgets, spacing=10.0 ),
				   UnparsedText( UnparsedText( raiseKeyword )  +  xText,  PRECEDENCE_STMT ),
				   state )
Exemplo n.º 20
0
	def lambdaExpr(self, 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( expr, None, python25ViewState( exprParser ) )
		paramViews = mapViewEval( params, None, python25ViewState( Parser.param ) )
		paramWidgets = []
		if len( params ) > 0:
			for p in paramViews[:-1]:
				paramWidgets.append( ahbox( [ p, label( ',', punctuationStyle ) ] ) )
			paramWidgets.append( paramViews[-1] )
		return nodeEditor( node,
				flow( [ keywordLabel( lambdaKeyword ) ]  +  paramWidgets  +  [ label( ':', punctuationStyle ), exprView ], spacing=5.0 ),
				UnparsedText( lambdaKeyword  +  ' ' + UnparsedText( ', ' ).join( [ p.text   for p in paramViews ] ) + ': '  +  exprView.text,  PRECEDENCE_LAMBDAEXPR ),
				state )
Exemplo n.º 21
0
	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 )
Exemplo n.º 22
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 )
Exemplo n.º 23
0
	def dictLiteral(self, ctx, state, node, *xs):
		xViews = mapViewEval( ctx, xs, None, python25ViewState( Parser.keyValuePair ) )
		return nodeEditor( ctx, node,
				   listView( ctx, dict_listViewLayout, lambda: text( ctx, punctuation_textStyle, '{' ), lambda: text( ctx, punctuation_textStyle, '}' ), lambda: text( ctx, punctuation_textStyle, ',' ), xViews ),
				   PRECEDENCE_DICTLITERAL,
				   state )
Exemplo n.º 24
0
	def subscriptTuple(self, ctx, state, node, *xs):
		xViews = mapViewEval( ctx, xs, None, python25ViewState( Parser.subscriptItem ) )
		return nodeEditor( ctx, node,
				   listView( ctx, tuple_listViewLayout, None, None, lambda: text( ctx, punctuation_textStyle, ',' ), xViews ),
				   PRECEDENCE_TUPLE,
				   state )
Exemplo n.º 25
0
	def subscriptTuple(self, state, node, *xs):
		xViews = mapViewEval( xs, None, python25ViewState( Parser.subscriptItem ) )
		return nodeEditor( node,
				   listView( ParagraphListViewLayout( 5.0, 0.0 ), None, None, ',', xViews ),
				   UnparsedText( '( '  +  UnparsedText( ', ' ).join( [ x.text   for x in xViews ] )  +  ' )', PRECEDENCE_TUPLE ),
				   state )
Exemplo n.º 26
0
	def dictLiteral(self, state, node, *xs):
		xViews = mapViewEval( xs, None, python25ViewState( Parser.keyValuePair ) )
		return nodeEditor( node,
				   listView( ParagraphListViewLayout( 10.0, 5.0 ), '{', '}', ',', xViews ),
				   UnparsedText( '{ '  +  UnparsedText( ', ' ).join( [ x.text   for x in xViews ] )  +  ' }', PRECEDENCE_DICTLITERAL ),
				   state )
Exemplo n.º 27
0
def suiteView(suite):
	lineViews = mapViewEval( suite, None, python25ViewState( Parser.statement, MODE_STATEMENT ) )
	return listView( VerticalListViewLayout( 0.0, 0.0, 0.0 ), None, None, None, lineViews )
Exemplo n.º 28
0
	def listLiteral(self, state, node, *xs):
		xViews = mapViewEval( xs )
		return nodeEditor( node,
				   listView( ParagraphListViewLayout( 5.0, 0.0 ), '[', ']', ',', xViews ),
				   UnparsedText( '[ '  +  UnparsedText( ', ' ).join( [ x.text   for x in xViews ] )  +  ' ]', PRECEDENCE_LISTLITERAL ),
				   state )
Exemplo n.º 29
0
	def listTarget(self, state, node, *xs):
		xViews = mapViewEval( xs, None, python25ViewState( Parser.targetItem ) )
		return nodeEditor( node,
				   listView( ParagraphListViewLayout( 5.0, 0.0 ), '[', ']', ',', xViews ),
				   UnparsedText( '[ '  +  UnparsedText( ', ' ).join( [ x.text   for x in xViews ] )  +  ' ]', PRECEDENCE_LISTLITERAL ),
				   state )
Exemplo n.º 30
0
	def python25Module(self, state, node, *content):
		lineViews = mapViewEval( content, None, python25ViewState( Parser.statement, MODE_STATEMENT ) )
		return listView( VerticalListViewLayout( 0.0, 0.0, 0.0 ), None, None, None, lineViews ), ''