1 |
#Region "Microsoft.VisualBasic::8529e2191b687be474795150f6385cff, Microsoft.VisualBasic.Core\Scripting\TokenIcer\LangModels\Func.vb"
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
#End Region
|
59 |
|
60 |
Imports Microsoft.VisualBasic.Linq
|
61 |
Imports Microsoft.VisualBasic.Language
|
62 |
|
63 |
Namespace Scripting.TokenIcer
|
64 |
|
65 |
Public MustInherit Class ExprToken(Of Tokens As IComparable)
|
66 |
|
67 |
Public MustOverride Function ToArray(stackT As StackTokens(Of Tokens)) As Token(Of Tokens)()
|
68 |
|
69 |
End Class
|
70 |
|
71 |
Public Class Func(Of Tokens As IComparable) : Inherits ExprToken(Of Tokens)
|
72 |
|
73 |
Public Property Caller As List(Of InnerToken(Of Tokens))
|
74 |
Public Property Args As Func(Of Tokens)()
|
75 |
|
76 |
Public ReadOnly Property IsFuncCalls As Boolean
|
77 |
Get
|
78 |
Return Not Args.IsNullOrEmpty
|
79 |
End Get
|
80 |
End Property
|
81 |
|
82 |
Sub New()
|
83 |
End Sub
|
84 |
|
85 |
Sub New(currStack As InnerToken(Of Tokens))
|
86 |
Caller = New List(Of InnerToken(Of Tokens)) From {currStack}
|
87 |
End Sub
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
Public Overrides Function ToArray(stackT As StackTokens(Of Tokens)) As Token(Of Tokens)()
|
94 |
Dim list As New List(Of Token(Of Tokens))
|
95 |
Call __expand(list, stackT)
|
96 |
Return list.ToArray
|
97 |
End Function
|
98 |
|
99 |
Private Sub __expand(ByRef list As List(Of Token(Of Tokens)), stackT As StackTokens(Of Tokens))
|
100 |
For Each x In Caller
|
101 |
Call list.AddRange(x.ToArray(stackT))
|
102 |
Next
|
103 |
If Not Args.IsNullOrEmpty Then
|
104 |
For Each x In Args
|
105 |
Call x.__expand(list, stackT)
|
106 |
Next
|
107 |
End If
|
108 |
End Sub
|
109 |
|
110 |
Public Overrides Function ToString() As String
|
111 |
If Args.IsNullOrEmpty Then
|
112 |
Return String.Join(" ", Caller.Select(Function(x) x.ToString).ToArray)
|
113 |
Else
|
114 |
Dim caller As String = String.Join(" ", Me.Caller.Select(Function(x) x.ToString).ToArray)
|
115 |
Dim params As String() = Me.Args.Select(Function(x) x.ToString).ToArray
|
116 |
Dim args As String = String.Join(", ", params)
|
117 |
Return $"{caller}({args})"
|
118 |
End If
|
119 |
End Function
|
120 |
End Class
|
121 |
|
122 |
Public Class InnerToken(Of Tokens As IComparable) : Inherits ExprToken(Of Tokens)
|
123 |
|
124 |
Public Property obj As Token(Of Tokens)
|
125 |
Public Property InnerStack As Func(Of Tokens)()
|
126 |
|
127 |
Sub New(x As Token(Of Tokens), stack As IEnumerable(Of Func(Of Tokens)))
|
128 |
obj = x
|
129 |
InnerStack = stack.ToArray
|
130 |
End Sub
|
131 |
|
132 |
Sub New(x As Token(Of Tokens))
|
133 |
obj = x
|
134 |
End Sub
|
135 |
|
136 |
Sub New(pretend As Tokens, funcCall As Func(Of Tokens))
|
137 |
obj = New Token(Of Tokens)(pretend, "FuncCalls")
|
138 |
InnerStack = {funcCall}
|
139 |
End Sub
|
140 |
|
141 |
Public Overrides Function ToString() As String
|
142 |
If InnerStack.IsNullOrEmpty Then
|
143 |
Return obj.Value
|
144 |
Else
|
145 |
Dim inner As String() = InnerStack.Select(Function(x) x.ToString).ToArray
|
146 |
Dim s As String = String.Join(" ", inner)
|
147 |
Return $"({s})"
|
148 |
End If
|
149 |
End Function
|
150 |
|
151 |
Public Overrides Function ToArray(stackT As StackTokens(Of Tokens)) As Token(Of Tokens)()
|
152 |
If stackT.Equals(obj.name, stackT.Pretend) Then
|
153 |
Dim list As New List(Of Token(Of Tokens))
|
154 |
For Each x In InnerStack
|
155 |
Call list.AddRange(x.ToArray(stackT))
|
156 |
Next
|
157 |
|
158 |
Return list.ToArray
|
159 |
Else
|
160 |
Return {obj}
|
161 |
End If
|
162 |
End Function
|
163 |
End Class
|
164 |
End Namespace
|