#NEWLINE# def FunctionDefinition( tokenizer , staticContext , requireName , functionForm ) : #NEWLINE# #INDENT# builder = staticContext . builder #NEWLINE# functionNode = builder . FUNCTION_build ( staticContext ) #NEWLINE# if tokenizer . match ( 'identifier' ) : #NEWLINE# #INDENT# builder . FUNCTION_setName ( functionNode , tokenizer . token . value ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if requireName : #NEWLINE# #INDENT# raise SyntaxError ( 'Missing def identifier' , tokenizer ) #NEWLINE# #UNINDENT# #UNINDENT# tokenizer . mustMatch ( 'left_paren' ) #NEWLINE# if ( not tokenizer . match ( 'right_paren' ) ) : #NEWLINE# #INDENT# builder . FUNCTION_initParams ( functionNode , tokenizer ) #NEWLINE# prevParamNode = None #NEWLINE# while True : #NEWLINE# #INDENT# tokenType = tokenizer . get ( ) #NEWLINE# if ( ( tokenType == 'left_bracket' ) or ( tokenType == 'left_curly' ) ) : #NEWLINE# #INDENT# tokenizer . unget ( ) #NEWLINE# paramNode = DestructuringExpression ( tokenizer , staticContext ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( tokenType == 'identifier' ) : #NEWLINE# #INDENT# paramNode = builder . FUNCTION_wrapParam ( tokenizer ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise SyntaxError ( 'Missing formal parameter' , tokenizer ) #NEWLINE# #UNINDENT# #UNINDENT# builder . FUNCTION_addParam ( functionNode , tokenizer , paramNode ) #NEWLINE# builder . COMMENTS_add ( paramNode , prevParamNode , tokenizer . getComments ( ) ) #NEWLINE# if ( not tokenizer . match ( 'comma' ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# prevParamNode = paramNode #NEWLINE# #UNINDENT# tokenizer . mustMatch ( 'right_paren' ) #NEWLINE# #UNINDENT# tokenType = tokenizer . get ( ) #NEWLINE# if ( tokenType != 'left_curly' ) : #NEWLINE# #INDENT# builder . FUNCTION_setExpressionClosure ( functionNode , True ) #NEWLINE# tokenizer . unget ( ) #NEWLINE# #UNINDENT# childContext = StaticContext ( True , builder ) #NEWLINE# rp = tokenizer . save ( ) #NEWLINE# if staticContext . inFunction : #NEWLINE# #INDENT# childContext . blockId = staticContext . blockId #NEWLINE# #UNINDENT# if ( tokenType != 'left_curly' ) : #NEWLINE# #INDENT# builder . FUNCTION_setBody ( functionNode , AssignExpression ( tokenizer , staticContext ) ) #NEWLINE# if staticContext . isGenerator : #NEWLINE# #INDENT# raise SyntaxError ( 'Generator returns a value' , tokenizer ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# builder . FUNCTION_hoistVars ( childContext . blockId ) #NEWLINE# builder . FUNCTION_setBody ( functionNode , Script ( tokenizer , childContext ) ) #NEWLINE# #UNINDENT# if ( tokenType == 'left_curly' ) : #NEWLINE# #INDENT# tokenizer . mustMatch ( 'right_curly' ) #NEWLINE# #UNINDENT# functionNode . end = tokenizer . token . end #NEWLINE# functionNode . functionForm = functionForm #NEWLINE# builder . COMMENTS_add ( functionNode . body , functionNode . body , tokenizer . getComments ( ) ) #NEWLINE# builder . FUNCTION_finish ( functionNode , staticContext ) #NEWLINE# return functionNode