locked
Easy Way to Create Language Service for Hybrid Languages? RRS feed

  • Question

  • A hybrid language is a language that consists of multiple sub-languages.

    My question has to do with 2 kinds of hybrid language:

    1. Sub-languages are nicely isolated and don't interact with each other

    Like MarkDown, other languages are encapsulated in code blocks and have absolutely nothing to do with other stuffs in the code.

    # Title
    
    One day I was writing a document with MarkDown happily. But suddenly:
    
    ```cs
    // I have to insert a C# code block
    var codeBlock = new CodeBlock();
    ```

    2. Opposite to case 1 

    Let's say one of the language's assignment syntax takes another language's expression/code block as valid right-hand-side value. Like:

    VARIABLE_IN_LANGUAGE_FOO = new ConstructorCallInCSharp(args);
    
    VARIABLE_IN_LANGUAGE_FOO = Expression + In / C * Sharp;

    So in both cases, if possible, how do I do the following task(to simplify the question, we have a DSL Foo that hybrid with C#):

    1. Syntax coloring for C# code fragments

    2. Syntax error checking for C# code fragments

    3. Intelligence sense for C# code fragments (In case 1, without constraint. In case 2, the expression's return type is constraint)

    Is it possible to just make use of C#'s language service somehow, without writing my own scanner/parser for C#?

    (Take Emacs for example, you can actually combine multiple existing language modes with a small amount of code to provide language service for a hybrid language. Something like that.)  

    Thanks.


    Code for fun, not for food.





    • Edited by CatOoXx Tuesday, February 25, 2014 5:56 AM
    Monday, February 24, 2014 10:12 AM

Answers

  • Well, it turns out that I was barking up the wrong tree. What I should do is to extend the editor with projection. Haven't actually done it yet. But msdn says that ASP.net pages use projection to handle embedded scripts: http://msdn.microsoft.com/en-us/library/dd885240.aspx#projection

    Code for fun, not for food.

    • Marked as answer by CatOoXx Saturday, March 8, 2014 12:21 AM
    Saturday, March 8, 2014 12:21 AM

All replies

  • Thanks for your reply.

    I know about how to create language service for one single language. 

    What I am wondering it that if there's a mechanism in place that allow me to to handle C# code blocks in my language with default C# language service.

    (Take Emacs for example, you can actually combine multiple existing language modes with a small amount of code to provide language service for a hybrid language. )  

    Anyway I am looking at Roslyn for now. Might give me what I need for C#. But how about other languages (that have VS language services installed)?


    Code for fun, not for food.

    Tuesday, February 25, 2014 5:52 AM
  • Well, it turns out that I was barking up the wrong tree. What I should do is to extend the editor with projection. Haven't actually done it yet. But msdn says that ASP.net pages use projection to handle embedded scripts: http://msdn.microsoft.com/en-us/library/dd885240.aspx#projection

    Code for fun, not for food.

    • Marked as answer by CatOoXx Saturday, March 8, 2014 12:21 AM
    Saturday, March 8, 2014 12:21 AM
  • Hi,

    I'm glad to hear that you got it working.

    Thank you for sharing your solutions & experience here. It will be very beneficial for other community members who have similar questions.

    Best regards,

    Sunny

    Sunday, March 9, 2014 9:08 AM