Posted 17 years ago by Nik Verkhovtseff
Version: 4.0.0234
Avatar
Hi,

I need to parse a fragment of C# code. I can't use Document.HeaderText/FooterText, as I use CSharpSyntaxLanguage as child language. So I write a primitive C# semantic parser and use it in CSharpSyntaxLanguage derived class. I build a root part (ClassDeclaration+MethodDeclaration) of AST manually (i.e. without source text, just by calling ctor of CompilationUnit(), etc.).

Using my primitive C# semantic parser, I parse a fragment of code:

int a;
a = 1;
and then add a parsing result to AST. In debugger, AST looks like this:

[0-23] CompilationUnit
[0-23] NamespaceDeclaration
[-1--1] QualifiedIdentifier
[-1--1] UsingDirectiveSection
[-1--1] UsingDirective
[-1--1] QualifiedIdentifier
[0-23] ClassDeclaration: MyClass
[-1--1] QualifiedIdentifier
[-1--1] TypeReference
[3-23] MethodDeclaration
[-1--1] QualifiedIdentifier
[-1--1] TypeReference
[3-10] LocalVariableDeclaration
[3-6] TypeReference
[7-10] VariableDeclarator
[7-10] QualifiedIdentifier
[12-20] StatementExpression
[12-19] AssignmentExpression
[12-15] SimpleName
[18-19] LiteralExpression

When I try to get a CSharpContext for variable a in AssignmentExpression, TargetItemType == Unknown, but for int it works fine.

Is it possible to use CShaprContext for type resolving in my case? Or I do something wrong?

Thanks,
Nik

Comments (3)

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

It's tough to say what is going on here since you are swapping in a lot of things. Can you explain more about how you are getting the context?

It might help if you could provide us with a tiny sample project that shows this. If you keep it minimal to what is needed to show the issue, we can debug it and tell you what is wrong.

We do still have on the TODO list to add parse entry points for things like expressions or method bodies, etc. However that will take a little bit of reshuffling of our semantic parser code. But once that is done, that will help resolve this particular issue I believe since you wouldn't need to add in all this extra stuff.


Actipro Software Support

Posted 17 years ago by Nik Verkhovtseff
Avatar
Hi,

I'm getting the context using CSharpContext.GetContextAtOffset. In debugger I see that CSharpContext.ImportedNamespaces contains only namespace from NamespaceDeclaration and noone from UsingDirectiveSection.
As root of AST is not present in Document, I set TextRange for root nodes to TextRange.Deleted. Can this trick affect the type resolving?

Thanks,
Nik
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
But isn't the UsingDirectiveSection the one that you defined in the NamespaceDeclaration? At least from your AST list that's what it looks like, that they are the same thing. From your AST list there appears to be one "using" defined under the namespace node.

TextRanges are used in context determination but as to whether that is causing the problem here, I'm not sure without debugging it.


Actipro Software Support

The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.