View unanswered posts | View active topics



Reply to topic  [ 11 posts ] 
Delegate params in comment 
Author Message
Member

Joined: Fri Jul 30, 2010 2:28 am
Posts: 118
Reply with quote
Hi,

It would be very nice to have describing of function signature similar to typifying of Array in comment:
Code:
var myArr:Array/*String*/ = [];

To have like that:
Code:
var myCallback:Function/*f( x:Number, y:Number ):Number*/ = Math.max;
myCallback( | <- here highlight of expecting params


If are you very busy so could you point me in source code where an Array typifying is implemented?
Thanks.


Wed Mar 09, 2011 7:46 am
Profile
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 12172
Location: London
Reply with quote
Very interesting suggestion.

First the parser extracts the Array's "IndexType" around line 1540 of ASFileParser - a similar extraction could be done for Function members.

Then if a function declaration was found, the curMember should be modified to become a function declaration instead of a var of type Function declaration.

This syntax would be better I think:
Quote:
var callback:Function/*(x:Number, y:Numer):void*/

I won't implement this right now so you can give it a try if you want ;)


Wed Mar 09, 2011 10:24 am
Profile WWW
Member

Joined: Fri Jul 30, 2010 2:28 am
Posts: 118
Reply with quote
Hi Philippe, I've implemented that :)

Little presentation:
Image

To patch FD - please use this:
Code:
Index: External/Plugins/ASCompletion/Model/ASFileParser.cs
===================================================================
--- External/Plugins/ASCompletion/Model/ASFileParser.cs   (revision 1773)
+++ External/Plugins/ASCompletion/Model/ASFileParser.cs   (working copy)
@@ -55,6 +55,8 @@
       static public Regex re_balancedBraces = new Regex("{[^{}]*(((?<Open>{)[^{}]*)+((?<Close-Open>})[^{}]*)+)*(?(Open)(?!))}", ro_cs);
         static public Regex re_import = new Regex("^[\\s]*import[\\s]+(?<package>[\\w.]+)", ro_cm);
       static private Regex re_spaces = new Regex("\\s+", RegexOptions.Compiled);
+      static private Regex re_param = new Regex( "[\\(,]\\s*((?<pName>(\\.\\.\\.)?[\\w\\$]+)\\s*(\\:\\s*(?<pType>[\\w\\$\\*\\.\\<\\>]+))?)", RegexOptions.Compiled );
+      static private Regex re_functType = new Regex( "\\s*\\:\\s*(?<fType>[\\w\\$\\.\\<\\>]+)", RegexOptions.Compiled );
         static private Regex re_validTypeName = new Regex("^(\\s*of\\s*)?(?<type>[\\w.\\$]*)$", RegexOptions.Compiled);
         static private Regex re_region = new Regex(@"^(#|{)[ ]?region[:\\s]*(?<name>[^\r\n]*)", RegexOptions.Compiled);
       #endregion
@@ -1546,6 +1548,19 @@
                         lastComment = null;
                     }
             }
+            else if( curMember.Type == "Function" && lastComment != null )
+            {
+               MemberModel fnModel = ParseDelegateDeclaration( lastComment );
+
+               if( fnModel != null )
+               {
+                  curMember.Type = fnModel.Type;
+                  curMember.Flags = fnModel.Flags;
+                  curMember.Parameters = fnModel.Parameters;
+
+                  lastComment = null;
+               }
+            }
          }
             else if (hadContext && (hadKeyword || inParams || inEnum || inTypedef))
          {
@@ -1857,6 +1872,57 @@
          int p = token.LastIndexOf(separator);
          return (p >= 0) ? token.Substring(p+1) : token;
       }
+
+      /// <summary>
+      /// Added by [i.o.] 11.03.2011
+      /// Delegate comment declaration parsing
+      /// </summary>
+      /// <param name="decl"></param>
+      /// <returns></returns>
+      private MemberModel ParseDelegateDeclaration( string decl )
+      {
+         // Testing for correct declaration
+         if( decl == null || decl.Length == 0 )
+            return null;
+
+         int idxBraceOp = decl.IndexOf( "(" );
+         int idxBraceCl = decl.IndexOf( ")" );
+
+         if( idxBraceOp < 0 || idxBraceCl < 0 )
+            return null;
+
+         Regex re_braceOp = new Regex( "\\(", RegexOptions.Compiled );
+         Regex re_braceCl = new Regex( "\\)", RegexOptions.Compiled );
+
+         if( re_braceOp.Matches( decl ).Count > 1 ||
+            re_braceCl.Matches( decl ).Count > 1 )
+            return null;
+
+         // Tests: OK
+
+         // Setting default values
+         MemberModel fm = new MemberModel( "unknown", "*", FlagType.Function, Visibility.Default );
+         fm.Parameters = new List<MemberModel>();
+
+         // Getting a type of function
+         Match m = re_functType.Match( decl.Substring( idxBraceCl ) );
+         if( m.Success )
+            fm.Type = m.Groups["fType"].Value;
+
+         // Getting params matches
+         String pBody = decl.Substring( idxBraceOp, 1 + idxBraceCl - idxBraceOp );
+         MatchCollection pMatches = re_param.Matches( pBody );
+         int i, l = pMatches.Count;
+         for( i=0; i<l; i++ )
+         {
+            fm.Parameters.Add( new MemberModel( pMatches[i].Groups["pName"].Value,
+                                       pMatches[i].Groups["pType"].Value,
+                                       FlagType.ParameterVar,
+                                       Visibility.Default ) );
+         }
+
+         return fm;
+      }
       #endregion
    }
 }


Fri Mar 11, 2011 5:49 pm
Profile
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 12172
Location: London
Reply with quote
Looks good :) can you provide a patch file? (hard to get clean from a forum post)


Fri Mar 11, 2011 7:05 pm
Profile WWW
Member

Joined: Fri Jul 30, 2010 2:28 am
Posts: 118
Reply with quote
I've sent you PM.
Actually I have some doubts:
I guess I'm starting to understand why in all yours regexes added "^" at start and "$" at end. Is it for defining that current comment is "special", not usual (It should begin immediately at comment starting and ends at comment ending)? If I'm right please modify my regexes... (re_param & re_functType)


Fri Mar 11, 2011 7:45 pm
Profile
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 12172
Location: London
Reply with quote
I think it's ok.

One thing however wasn't: do use "compiled" regexes inside functions - only for static, reused ones.


Fri Mar 11, 2011 8:10 pm
Profile WWW
Member

Joined: Thu Apr 03, 2008 11:15 pm
Posts: 55
Location: Los Angeles
Reply with quote
Nice new feature. :)

Two small problems I've noticed...

Code:
/**
 *
 */
public function loadXML(url:String, callback:Function/*(url:String, data:XML):void*/):void {
   
}
...typing /** here didn't trigger the usual ASDOC parameter list to be automatically generated.

Also, the callback params end up appearing in the code hint tooltip for loadXML, like so:
Quote:
loadXML (url:String, callback:Function/*(url:String, data:XML):void*/) : void …


I was hoping that the the code generator would then auto-generate a function with the specified parameters... :idea:

_________________
EasyAGAL by David Barlia
https://github.com/Barliesque/EasyAGAL
Open source ActionScript library that facilitates coding assembly language shaders for Stage3D.
Advantages include: Code completion and hinting, easier-to-read code, macro libraries and more.


Tue Aug 02, 2011 7:53 pm
Profile WWW
Member

Joined: Fri Jul 30, 2010 2:28 am
Posts: 118
Reply with quote
Thanks for bugreport.
I'm afraid I don't know where it can be fixed and where it can be linked with code generation.
Waiting Philippe and ir73 :)


Fri Aug 05, 2011 5:29 pm
Profile
Member

Joined: Thu Mar 29, 2007 9:32 am
Posts: 244
Reply with quote
barliesque wrote:
I was hoping that the the code generator would then auto-generate a function with the specified parameters... :idea:

Sorry, don't get what to generate from what?


Fri Aug 05, 2011 6:11 pm
Profile
Member

Joined: Fri Jul 30, 2010 2:28 am
Posts: 118
Reply with quote
Quote:
Sorry, don't get what to generate from what?

I guess from commented signature
Code:
callback:Function/*(url:String, data:XML):void*/

To like that:
Code:
someObject.loadXML("lalala", myCallback|->Ctrl+Shift+1->GenerateTypedCallbackAsPrivateMethodOrLikeThat);
....
// result:
private function myCallback( url:String, data:XML ):void
{
    // TODO
}

Hint: to know the MemberModel is TypedCallback - just check if MemberModel.Flags has current kind (FlagType.ParameterVar or FlagType.Variable or FlagType.Getter) plus FlagType.Function
TypedCallback creation - 1962 line : ASFileParser.cs

About ASDoc generator bug - line 131-133 ASDocumentation.cs


Sat Aug 06, 2011 3:25 am
Profile
Member

Joined: Thu Apr 03, 2008 11:15 pm
Posts: 55
Location: Los Angeles
Reply with quote
Hi i.o,
Yes, that was the idea.
:)

_________________
EasyAGAL by David Barlia
https://github.com/Barliesque/EasyAGAL
Open source ActionScript library that facilitates coding assembly language shaders for Stage3D.
Advantages include: Code completion and hinting, easier-to-read code, macro libraries and more.


Sat Aug 06, 2011 6:56 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 11 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.