
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: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
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;
[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