parse projection oputput test success

master
xieguigang 5 years ago
parent f2783e0aa5
commit 121a109600

@ -4,9 +4,19 @@ Namespace Interpreter.Expressions
Public Class BinaryExpression : Inherits Expression
Dim left, right As Expression
Friend ReadOnly left, right As Expression
Dim op As String
Public ReadOnly Property LikeValueAssign As Boolean
Get
If op <> "=" Then
Return False
Else
Return TypeOf left Is SymbolReference
End If
End Get
End Property
Sub New(left As Expression, right As Expression, op As String)
Me.left = left
Me.right = right

@ -4,7 +4,7 @@ Namespace Interpreter.Expressions
Public Class SymbolReference : Inherits Expression
Dim symbolName As String
Friend ReadOnly symbolName As String
Sub New(name As String)
Me.symbolName = name

@ -78,14 +78,26 @@ Namespace Script
Dim values As Expression() = tokenList.GetParameters.ToArray
Dim fields As New List(Of NamedValue(Of Expression))
For Each item As Expression In values
If TypeOf item Is BinaryExpression Then
With DirectCast(item, BinaryExpression)
If .LikeValueAssign Then
fields.Add(New NamedValue(Of Expression)(DirectCast(.left, SymbolReference).symbolName, .right))
Else
fields.Add(New NamedValue(Of Expression)(item.ToString, item))
End If
End With
Else
fields.Add(New NamedValue(Of Expression)(item.ToString, item))
End If
Next
Return New OutputProjection(fields)
End Function
<Extension>
Public Function ParseExpression(tokenList As Token()) As Expression
If tokenList.Length = 1 Then
Return tokenList(Scan0).ParseToken
ElseIf tokenList(Scan0).isKeywordFrom OrElse tokenList(Scan0).isKeywordAggregate OrElse tokenList(Scan0).isKeyword("let") Then
Private Function ParseKeywordExpression(tokenList As Token()) As Expression
If tokenList(Scan0).isKeywordFrom OrElse tokenList(Scan0).isKeywordAggregate OrElse tokenList(Scan0).isKeyword("let") Then
' declare new symbol
Dim name As String = tokenList(1).text
Dim type As String = "any"
@ -101,6 +113,17 @@ Namespace Script
Return ParseExpression(tokenList.Skip(1).ToArray)
ElseIf tokenList(Scan0).isKeyword("select") Then
Return tokenList.Skip(1).GetProjection
Else
Throw New SyntaxErrorException
End If
End Function
<Extension>
Public Function ParseExpression(tokenList As Token()) As Expression
If tokenList.Length = 1 Then
Return tokenList(Scan0).ParseToken
ElseIf tokenList(Scan0).name = Tokens.keyword Then
Return tokenList.ParseKeywordExpression
End If
Dim blocks = tokenList.SplitByTopLevelStack.ToArray

@ -10,7 +10,7 @@ Public Module Program
Dim script = "
from x as double in [(1+y)*8,2,3,4,5,6,7,8,9] # this is comment text
where x^3 > (5 *x)
select x ^ 2+99
select x ^ 2+99 , y = x*2
"
Dim tokens = LINQ.Language.GetTokens(script).ToArray
Dim query = tokens.PopulateQueryExpression

Loading…
Cancel
Save