Posted 13 years ago by Nik Verkhovtseff
Version: 4.0.0233
Avatar
Hi,

I try to merge a DynamicSyntaxLanguage and CSharpSyntaxLanguage (from .Net Add-on) using a Direct Lexical State Transition. I load a DynamicSyntaxLanguage from XML file, then chain it to a CSharpSyntaxLanguage when ASP-style <% and %> directives are matched. But I see no IntelliPromt for C#, i.e. semantic parsing for C# is not performed. Could you please tell how to initialize a semantic parsing in such case?

Thanks,
Nik

Comments (14)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Nik,

We still need to work on the ability for IntelliPrompt to work correctly when in a merged language scenario.


Actipro Software Support

Posted 13 years ago by Nik Verkhovtseff
Avatar
Hi,

Thanks for response.
Another question about merging. I tried to merge DynamicSyntaxLanguage (as root language) and CSharpSyntaxLanguage using Direct Lexical State Transition.

I have a C# class:

class MyClass
{

    void Method1()
    {
        // ...
    }

    void Method2()
    {
        // ...
    }
}
and html text:

<html>
<body>

<script>
// body of Method1
</script>

<script>
// body of Method2
</script>

</body>
</html>
Is it possible to create a AST manually for MyClass, and then *talk* to C# semantic parser to parse a text inside script tags as Method1 and Method2 bodies?

Thanks,

Nik
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes, you can always make manual requests to the semantic parser service. Check out the Document Outline QuickStart since that shows this. You can get the AST results back and do whatever you need with them.


Actipro Software Support

Posted 13 years ago by Nik Verkhovtseff
Avatar
Hi,

As well as I understand CSharpSyntaxLanguage parses a text as a CompilationUnit.
In my case (merging DynamicSyntaxLnguage and CSharpSyntaxLanguage) I build a root part of AST manually, i.e. without source text, just by calling ctor of CompilationUnit(), etc.),
and then I need to parse a fragment of code and add result to some AST node of my tree.

Is it possible to add a method like this:

AstNode Parse(AstNode parent, TextRange textRange);

to parse a fragment of code (not only CompilationUnit) and provide IntelliPromp features ?

Thanks,
Nik
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Eventually (probably like in a v4.5) we hope to add processing capabilities for supporting merged languages like that and combining AST trees in various fashions.

I'm not quite clear from your code example on how you would like things parsed. Could you maybe show a "hello world" type simple example of what you are trying to accomplish and what the language is designed to be used for? That would help us in our future planning for these types of features and would maybe enable us to give you some advice in the meantime if there is anything that will work for you now.


Actipro Software Support

Posted 13 years ago by Nik Verkhovtseff
Avatar
Hi,

I got a some base of C#(VB) class:

class MyClass
{

    void Method1()
    {
        // ...
    }

    void Method2()
    {
        // ...
    }
}
and I want to allow end-user to edit a parts (fragments) of code only. For instance, I load a DynamicSyntaxLanguage from XML file and merge it with CSharpSyntaxLanguage using a Direct Lexical State Transition. I define some tokens to distinguish what part of class (method body, class members, etc.) is edited by user. Then I assign this language to document and show in SyntaxEditor. User enters some text:

<html>
<body>

<metod1_body>
 // body of Method1
</metod1_body>

<class_members>
 // additional class members is defined here
</class_members>

</body>
</html>
As well as I know the structure of class, I can build a base (root) of AST manually (i.e. without parsing the text of class). To provide IntelliPrompt I should semantically parse the text between my custom tokens. Unfortunately CSharpSyntaxLanguage parses a text as CompilationUnit only. It would be a nice feature in SyntaxLanguage if I could parse a fragment of code using a some method like this:

AstNode Parse(AstNode parent, TextRange textRange);

where parent is AST node (parsing context) from manually builded AST (for instance, ClassDeclaration or MethodDeclaration).

make sense?

Thanks,
Nik
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Ok I think I understand better now.

It seems like you need another couple methods like ParseTypeDeclaration or ParseMemberDeclaration. That way you could call those methods on the CSharpSemanticParser class instead of Parse. And they would return an AstNodeList or AstNode depending on their implementation. After you have those, you could add them to a collection or do whatever else with them.

Is that correct? If so, please indicate the parse methods you'd like to see.


Actipro Software Support

Posted 13 years ago by Nik Verkhovtseff
Avatar
Yes. But I suppose the more general (flexible) way is to implement a more general method, something like this:

Parse(AstNode parent, TextRange textRange);

or

Parse(CSharpContext context, TextRange textRange);

since I need to parse a method parameters also, and someone needs to parse in other context.
Could you imlpement this?

Thanks,
Nik
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
There's no way to have things be that generic. You have to define a starting point for parsing to begin. It has to know whether we are at a compilation unit level, namespace level, type level, member level, or method body level, etc.

Also, passing in a parent node probably is not a good idea. The Parse method should return the result of the parse if anything. That way you can do whatever you want with the result. Even if we did allow passing in of a parent, it wouldn't know how to add it to that parent properly since adding of child nodes is done with a certain context ID and that sort of functionality is generally wrapped by an IAstNodeList property on the parent node.


Actipro Software Support

Posted 13 years ago by Nik Verkhovtseff
Avatar
Hi,

I supposed that's possible to define a starting point (context) for parsing from parent node (passed as parameter of method). The Parse method signature I gave as example.

Anyway, if you could add ParseTypeDeclaration and ParseMemberDeclaration methods, it would be great.

Thanks,
Nik
Posted 13 years ago by Nik Verkhovtseff
Avatar
Hi,

Do you plan to add the *special* parsing methods (such as ParseTypeDeclaration, ParseMemberDeclaration, ParseMethodParametersDeclaration) to C# (VB.NET) SyntaxLanguage?

Thanks,
Nik
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes that is on the TODO list.


Actipro Software Support

Posted 13 years ago by Nik Verkhovtseff
Avatar
Hi,

It's a good news.
When will you plan to release a new version (with *special* parsing methods)?

Thanks,
Nik
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
It's going to take some reorganization of code within the C# grammar file to accomplish this so it's not as easy of a change as we had hoped. It's on the TODO list so we'll try and get to it soon.


Actipro Software Support

The latest build of this product (v2018.1 build 0341) was released 6 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.