SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Extending the SharpDevelop with a support for an other language for .NET

Last post 06-02-2006 3:05 PM by DanielGrunwald. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 06-01-2006 7:45 PM

    Extending the SharpDevelop with a support for an other language for .NET

    Hello all,

     

    I just want ask how should I proceed if I want to add a support for my own language for .NET. My idea is to have a envirnoment for my own custom language (for example subset of C or a script language). How big is the effort of providing suhc functionality - let's say I juet want to have a project template for my language and I want to debug its source code.

     

    Greetings,

     

    Dominik

  • 06-01-2006 7:52 PM In reply to

    Re: Extending the SharpDevelop with a support for an other language for .NET

    First you need to have a compiler (with support for emitting .pdb debug symbols) for your language before you should think about integration in SharpDevelop. Adding a project template is easy, and debugging will automatically work if your compiler emits correct .NET debug information.
    Daniel Grunwald
  • 06-01-2006 11:29 PM In reply to

    Re: Extending the SharpDevelop with a support for an other language for .NET

    Let's say that I have such a compiler - what should I do to add such a template ?

    Thx for answer :)

     

    Dominik

  • 06-02-2006 10:19 AM In reply to

    Re: Extending the SharpDevelop with a support for an other language for .NET

    The project templates are XML files which you can open in any text editor. Just pick one close to what you need and see what is needed for your compiler.


  • 06-02-2006 3:05 PM In reply to

    Re: Extending the SharpDevelop with a support for an other language for .NET

    Someone recently asked me by mail about adding IronPython support. This should help everyone until we have "real" documentation for writing backend bindings.

    The first step is creating a project type and the compiler binding. For the compiler, you need to write a MSBuild task for the compiler. Then you'll need a targets file that can be included by MSBuild and calls that task.
    In the SharpDevelop source code, take a look at SharpDevelop\src\Libraries\ICSharpCode.Build.Tasks\Project\ILAsm.cs and SharpDevelop.Build.MSIL.targets
    However it is possible that the Visual Studio IronPython integration already comes with the MSBuild task and targets file; then you can just use that.

    Now the real start: Create a new SharpDevelop AddIn project.
    The video at http://laputa.sharpdevelop.net/WritingASharpDevelopAddInTutorialVideo.aspx should help you understand the basics. Don't forget to look at the SharpDevelop\doc\technotes directory (in the SharpDevelop source code download).
    Then you should look at the ILAsmBinding source code (it's the simplest backend binding possible). When you look at ILAsmBinding.addin, you'll see the most important things to provide:
    1. FileFilter entry. Just copy it from ILAsmBinding and adjust to your needs.
    2. Templates: The XML entry tells SharpDevelop to look for a "Templates" directory inside the directory containing your AddIn assembly. Just create such a directory in the project browser and add a .xpt file to it, then set "Copy to output directory" for the .xpt file to "Always".
    For writing the .xpt project template, just use the one from ILAsmBinding and adjust it to your needs. The important part is the <LanguageName> property: this must match the language name used in the next step.
    3. Language Binding. Use the <LanguageBinding> codon to register your language binding with SharpDevelop. Try to use the file extension and GUID from the Visual Studio IronPython AddIn; or create your own GUID (Tools > Insert New GUID) and use a new file extension.
    For writing the LanguageBinding class: just adapt the ILAsmLanguageBinding to your needs. The "single file compilation" is not supported by SharpDevelop 2.0, it'll always use MSBuild. The important methods left are LoadProject and CreateProject. Both have to return a new instance of your project class. The project class can be really simple (again, look at ILAsmProject) if you inherit from MSBuildProject. Just set the language name; don't forget to call base.Create(info) in the new project constructor / SetupProject(fileName) in the load project constructor. In the constructor creating a new project, you have to use "imports.Add()" to add a reference to your MSBuild target file. If you put your targets file in your AddIn's directory, you can create your own MSBuild property like this:
           static bool initialized = false;
           static void Init()
           {
               if (!initialized) {
                   initialized = true;
                   MSBuildEngine.CompileTaskNames.Add("nameOfMyMSBuildCompilerTask"); // makes SharpDevelop show the "Compiling ProjectName..."-line when compiling your projects
                   MSBuildEngine.MSBuildProperties.Add("MyLanguageBinPath", Path.GetDirectoryName(typeof(MyProject).Assembly.Location));
               }
           }
    Make sure you call Init() in both constructors of your project class.

    4. ILAsmBinding.addin also contains the project options section. The dialog panels reference panels in the main SharpDevelop code that can be used for all (.NET) languages. If you use them, you need a "<Import assembly = ":ICSharpCode.SharpDevelop"/>" entry in your <Runtime> section.

    5. Syntax mode for the text editor should be compiled as embedded resource and can be loaded using the <SyntaxMode> codon. You don't need this at the beginning.

    This is everything you need for very simple integration of a language.
    The next step after this is providing a parser for the language. That is a bit complicated (especially if you cannot use the parser from the IronPython compiler and have to write your own), but it will enable folding and the class browser (both the "Classes" pad and the combo boxes above the code editor).
    Daniel Grunwald
Page 1 of 1 (5 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.