Forums

Generating .NET API list - a crude attempt

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Generating .NET API list - a crude attempt

Postby ObtuseAngle » Thu Jun 09, 2011 7:51 pm

While I suspect that this will mostly be superseded by @help (particularly if we can access it is a standalone call from a text editor), I wanted to generate an API list for pop-up help (and possible autocompletion) in SciTE (my favourite editor).

Below is my rather crude first attempt (warning: generates a huge list).
Below the if true line are some sample alternatives for testing, if you don't want the whole list.

Any improvements (extracting further documentation from the assemblies, getting member argument names, etc) would be most welcome.

Obtusely yours, OA.

Code: Select all
"""
Get classes, methods/members, valueTypes in .NET framework

Significantly based on Andrew Hare's C# code in a thread on StackOverflow
Thread: http://stackoverflow.com/questions/2137444/exactly-how-large-is-the-net-3-5-framework-class-library
Andrew Hare: http://stackoverflow.com/users/34211/andrew-hare
"""

use System.Reflection
use System.Runtime.InteropServices
use System.Text.RegularExpressions

class Example

    def main
        assemblies = []
        for f in Directory.getFiles(RuntimeEnvironment.getRuntimeDirectory)
            if f.endsWith(".dll")
                assemblies.add(f)

        for name in assemblies
            # We need to catch BadImageFormatException
            # because not all DLLs in the runtime directory
            # are CLR assemblies.
            try
                filename = name.toString
                types = Assembly.loadFile(filename).getTypes

                for t in types
                    if t.isClass
                        if true
                        #~ if "FileExists" in t.toString
                        #~ if t.toString == "System.Net.WebClient"
                            ms = t.getMethods
                            invoke = false
                            for m in ms
                                s = m.toString
                                if " Invoke(" in s
                                    wordMatch = Regex.match(s, r"([\w+\.\[\]]+) Invoke(\([^\)]+\))")
                                    if wordMatch.success
                                        print '[t.toString][wordMatch.groups[2]] --> [wordMatch.groups[1]]'
                                        invoke = true
                            if not invoke
                                mms = t.getMembers
                                for mm in mms
                                    sm = mm.toString
                                    mwordMatch = Regex.match(sm, r"([\w+\.\[\]]+) (.+)")
                                    if mwordMatch.success
                                        print '[t.toString]() [mwordMatch.groups[2]] --> [mwordMatch.groups[1]]'
                    else if t.isValueType
                        pass
                        #~ print t.toString
            catch BadImageFormatException
                pass
99 programming bugs in the code, 99 bugs in the code, fix 1 bug and compile it again, 101 programming bugs in the code
ObtuseAngle
 
Posts: 42
Location: Gippsland, Australia

Re: Generating .NET API list - a crude attempt

Postby Charles » Fri Jun 10, 2011 12:36 am

Cobra has command line features for this:
Code: Select all
cd Source
cobra -doc -files:files-to-compile.text

You can also try a library like:
cobra -doc-lib:Cobra.Lang
cobra -doc-lib:System.Web


-doc works on Cobra source code and -doc-lib works on any DLL. It's been awhile since I've tested them and last time I tried -doc-lib it had some problems with some libraries. I plan on fixing those problems as I intend the @help page generator to leverage that code rather than duplicate it. There's probably much room for improvement in the formatting and HTML output.

If you want to see what Cobra is doing, look at DocGenerator.cobra in the source. Note that it's working on Cobra compiler data structures.

If you want to see how Cobra reads DLLs, look at ScanClrType.cobra in BackEndClr in Source.

But there's nothing wrong with building your own solution if it works well for you.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Generating .NET API list - a crude attempt

Postby RIGHT_THEN » Fri Jun 10, 2011 12:06 pm

Sorry Removing content wrote answer to wrong post
Good attempt thou.


Thanking_You
RIGHT_THEN
RIGHT_THEN
 
Posts: 99

Re: Generating .NET API list - a crude attempt

Postby Charles » Fri Jun 10, 2011 8:49 pm

I fixed the major bugs in -doc-lib and it now runs successfully on the following:

Code: Select all
cobra -doc-lib:Cobra.Lang
cobra -doc-lib:System
cobra -doc-lib:System.Core
cobra -doc-lib:System.Web
cobra -doc-lib:mscorlib

It needs a lot of improvements (which are listed in DocGenerator.cobra), but at least it's usable now.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Generating .NET API list - a crude attempt

Postby ObtuseAngle » Mon Jun 13, 2011 4:58 pm

Charles wrote:Cobra has command line features for this:
Code: Select all
cd Source
cobra -doc -files:files-to-compile.text

You can also try a library like:
cobra -doc-lib:Cobra.Lang
cobra -doc-lib:System.Web


-doc works on Cobra source code and -doc-lib works on any DLL.
[...]
If you want to see what Cobra is doing, look at DocGenerator.cobra in the source. Note that it's working on Cobra compiler data structures.

If you want to see how Cobra reads DLLs, look at ScanClrType.cobra in BackEndClr in Source.


Thanks!

I'll need to wrangle either the code or the output files to give me SciTE API format, but that's a lot further along than I would have been on my own.

Cheers, Obtuse.
99 programming bugs in the code, 99 bugs in the code, fix 1 bug and compile it again, 101 programming bugs in the code
ObtuseAngle
 
Posts: 42
Location: Gippsland, Australia

Re: Generating .NET API list - a crude attempt

Postby Charles » Tue Jun 14, 2011 11:01 am

Is the SciTE API format simply something that you prefer, or is it something technical that allows for integration with SciTE?
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Generating .NET API list - a crude attempt

Postby ObtuseAngle » Tue Jun 14, 2011 4:46 pm

It's a simple text file of API information that allows SciTE to provide calltips for both autocompletion, e.g. (Python example)

Image

and for API parameter information, e.g.:

Image

The API parameter calltip above is the line in the .api file that gives both the above options, plus a few lines of configuration in my SciTEUser.properties file.
Basically it's just one API call per line in a text file.

Cheers, Obtuse.
99 programming bugs in the code, 99 bugs in the code, fix 1 bug and compile it again, 101 programming bugs in the code
ObtuseAngle
 
Posts: 42
Location: Gippsland, Australia


Return to Discussion

Who is online

Users browsing this forum: No registered users and 16 guests