Posted 9 years ago by Yaroslav - Principal Engineer, Ipreo
Version: 4.0.0283
Avatar
Hello,
I need to create AST for LINQ expression written in both C# and VB.NET.
C# code. I tested following code:

class Program
{
static void Main(string[] args)
{
var q = from c in new Query<Company>() select c;
}
}

AST for this code comes out like this (negative offsets for the code in document.HeaderText). As you can see, it is parsed correctly.

[-227-122] CompilationUnit
[-227-122] ClassDeclaration: Program
[-221--214] QualifiedIdentifier: Program
[-130-82] MethodDeclaration: Name=Main
[-118--114] QualifiedIdentifier: Main
[-123--119] TypeReference: System.Void
[-113--100] ParameterDeclaration
[-113--107] TypeReference: System.String[]
[-8-42] LocalVariableDeclaration
[-4-39] VariableDeclarator
[0-39] TypeReference: System.Object
[-4--3] QualifiedIdentifier: q
[0-39] QueryExpression
[0-30] FromQueryOperator
[5-30] CollectionRangeVariableDeclaration
[5-6] VariableDeclarator
[5-5] TypeReference: _Anonymous
[5-6] QualifiedIdentifier: c
[10-30] ObjectCreationExpression
[14-19] TypeReference: Query`1
[20-27] TypeReference: Company
[31-39] SelectQueryOperator
[38-38] VariableDeclarator
[38-38] TypeReference: _Anonymous
[38-39] SimpleName: c

When I parse an equivalent code in VB.NET:

Imports System.Collections
Imports System.Linq
Module Module1
Public Class TestClass
Sub TestSub()
Dim q = From c In New Query(Of Company) Select c
End Sub
End Class
End Module

the resulting AST does not have any LINQ-related nodes in it:

[-297-187] CompilationUnit
[-297--212] UsingDirectiveSection
[-297--271] UsingDirective
[-289--271] QualifiedIdentifier: System.Collections
[-231--212] UsingDirective
[-223--212] QualifiedIdentifier: System.Linq
[-170-187] StandardModuleDeclaration: Module1
[-163--156] QualifiedIdentifier: Module1
[-115-137] ClassDeclaration: Module1+TestClass
[-102--93] QualifiedIdentifier: TestClass
[-53-88] MethodDeclaration: Name=TestSub
[-49--42] QualifiedIdentifier: TestSub
[0-43] BlockStatement

How can I get correct AST for VB.NET code? Any suggestions are appreciated.

Comments (1)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Yaroslav,

Thanks for reporting this. It appears to be a bug that was introduced when we added support for VB 10 implicit line terminators. We've fixed it for the next maintenance release.


Actipro Software Support

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

Add Comment

Please log in to a validated account to post comments.