protected override FunctionDefinition ParseFunction( TokenStream tokens, TopLevelEntity nullableOwner, FileScope fileScope, ModifierCollection modifiers, AnnotationCollection annotations) { AType returnType = this.parser.TypeParser.Parse(tokens); Token firstToken = modifiers.FirstToken ?? returnType.FirstToken; Token functionNameToken = tokens.Pop(); this.parser.VerifyIdentifier(functionNameToken); FunctionDefinition fd = new FunctionDefinition(firstToken, returnType, nullableOwner, functionNameToken, modifiers, annotations, fileScope); tokens.PopExpected("("); List <AType> argTypes = new List <AType>(); List <Token> argNames = new List <Token>(); List <Expression> defaultValues = new List <Expression>(); this.ParseArgumentListDeclaration(tokens, fd, argTypes, argNames, defaultValues); fd.ArgTypes = argTypes.ToArray(); fd.ArgNames = argNames.ToArray(); fd.DefaultValues = defaultValues.ToArray(); fd.FinalizeArguments(); IList <Executable> code = this.parser.ExecutableParser.ParseBlock(tokens, true, fd); fd.Code = code.ToArray(); return(fd); }
protected override FunctionDefinition ParseFunction( TokenStream tokens, TopLevelEntity nullableOwner, FileScope fileScope, ModifierCollection modifiers, AnnotationCollection annotations) { bool isStatic = nullableOwner != null && nullableOwner is ClassDefinition && tokens.PopIfPresent(this.parser.Keywords.STATIC); Token functionToken = tokens.PopExpected(this.parser.Keywords.FUNCTION); Token functionNameToken = tokens.Pop(); this.parser.VerifyIdentifier(functionNameToken); FunctionDefinition fd = new FunctionDefinition(functionToken, AType.Any(functionToken), nullableOwner, functionNameToken, modifiers, annotations, fileScope); tokens.PopExpected("("); List <Token> argNames = new List <Token>(); List <Expression> defaultValues = new List <Expression>(); List <AType> argTypes = new List <AType>(); this.ParseArgumentListDeclaration(tokens, fd, argTypes, argNames, defaultValues); fd.ArgTypes = argTypes.ToArray(); fd.ArgNames = argNames.ToArray(); fd.DefaultValues = defaultValues.ToArray(); fd.FinalizeArguments(); IList <Executable> code = this.parser.ExecutableParser.ParseBlock(tokens, true, fd); fd.Code = code.ToArray(); return(fd); }