-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathDebugger.prg
196 lines (175 loc) · 6.74 KB
/
Debugger.prg
1
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#include "protheus.ch"
#define TOKEN ""
#xtranslate @Token { <name> <value> } => Eval( T_<name>, <value> )
#xtranslate @Instance <name> <value> => T_<name> := <value>
#xtranslate @Next => Context++
#xtranslate @Previous => Context--
Function Debugger( xVar, aParser )
Local cExprResult
Static Context := 0
@Instance KEYWORD aParser[ 1 ]
@Instance NUMBER aParser[ 2 ]
@Instance STRING aParser[ 3 ]
@Instance INDENT aParser[ 4 ]
@Instance SYMBOL aParser[ 5 ]
@Instance NEWLINE aParser[ 6 ]
@Instance DATE aParser[ 7 ]
@Instance TRUE aParser[ 8 ]
@Instance FALSE aParser[ 9 ]
@Instance NIL aParser[ 10 ]
@Instance BLOCK aParser[ 11 ]
@Instance PROPERTY aParser[ 12 ]
@Instance OBJECT aParser[ 13 ]
@Instance UNKNOWN aParser[ 14 ]
@Instance NAME aParser[ 15 ]
@Instance DEDENT aParser[ 16 ]
@Instance FOLDER aParser[ 17 ]
@Instance BEGIN_CLOS aParser[ 18 ]
@Instance END_CLOS aParser[ 19 ]
cExprResult := ParseExpr( xVar )
ConOut( cExprResult )
Return cExprResult
Static Function ParseExpr( xVar )
Local cType := ValType( xVar )
Do Case
Case cType == "C" // String
Return ParseString( xVar )
Case cType == "N" // Number
Return ParseNumber( xVar )
Case cType == "A" // Array
Return ParseArray( xVar )
Case cType == "U" // Nil
Return ParseNil( xVar )
Case cType == "D" // Date
Return ParseDate( xVar )
Case cType == "B" // Block
Return ParseBlock( xVar )
Case cType == "O" // Object
Return ParseObject( xVar )
Case cType == "L" // Logic
If xVar
Return ParseTrue()
Else
Return ParseFalse()
EndIf
Otherwise
Return ParseUnknown( xVar )
EndCase
Return
Static Function ParseString( cData )
Return @Token { KEYWORD "string" } ;
+ @Token { SYMBOL "<" } ;
+ @Token { NUMBER AllTrim( Str( Len( cData ) ) ) } ;
+ @Token { SYMBOL ">" } ;
+ @Token { SYMBOL "(" } ;
+ @Token { STRING cData } ;
+ @Token { SYMBOL ")" } ;
+ @Token { NEWLINE TOKEN }
Static Function ParseNumber( nData )
Return @Token { KEYWORD "number" } ;
+ @Token { SYMBOL "(" } ;
+ @Token { NUMBER AllTrim( Str( nData ) ) } ;
+ @Token { SYMBOL ")" } ;
+ @Token { NEWLINE TOKEN }
Static Function ParseTrue
Return @Token { KEYWORD "logic" } ;
+ @Token { SYMBOL "(" } ;
+ @Token { TRUE ".T." } ;
+ @Token { SYMBOL ")" } ;
+ @Token { NEWLINE TOKEN }
Static Function ParseFalse
Return @Token { KEYWORD "logic" } ;
+ @Token { SYMBOL "(" } ;
+ @Token { FALSE ".F." } ;
+ @Token { SYMBOL ")" } ;
+ @Token { NEWLINE TOKEN }
Static Function ParseUnknown( xData )
Return @Token { KEYWORD "unknown" } ;
+ @Token { SYMBOL "(" } ;
+ @Token { UNKNOWN ValType( xData ) } ;
+ @Token { SYMBOL ")" } ;
+ @Token { NEWLINE TOKEN }
Static Function ParseNil
Return @Token { NIL "nil" } ;
+ @Token { NEWLINE TOKEN }
Static Function ParseBlock( bData )
Return @Token { KEYWORD "block" } ;
+ @Token { SYMBOL "(" } ;
+ @Token { BLOCK GetCBSource( bData ) } ;
+ @Token { SYMBOL ")" } ;
+ @Token { NEWLINE TOKEN }
Static Function ParseDate( dData )
Return @Token { KEYWORD "date" } ;
+ @Token { SYMBOL "(" } ;
+ @Token { DATE DtoC( dData ) } ;
+ @Token { SYMBOL ")" } ;
+ @Token { NEWLINE TOKEN }
Static Function ParseObject( oData )
Local cTemplate := ""
Local aChildren := ClassDataArr( oData )
Local nContext := 0
@Next
nContext := Context
cTemplate += @Token { KEYWORD "object" } ;
+ @Token { SYMBOL "<" } ;
+ @Token { NAME GetClassName( oData ) } ;
+ @Token { SYMBOL ">" } ;
+ @Token { SYMBOL "(" }
If Len( aChildren ) > 0
cTemplate += @Token { FOLDER TOKEN } ;
+ @Token { BEGIN_CLOS TOKEN } ;
+ @Token { NEWLINE TOKEN }
Else
cTemplate += @Token { SYMBOL ")" } ;
+ @Token { NEWLINE TOKEN }
@Previous
Return cTemplate
EndIf
cTemplate += ParseProperty( aChildren ) ;
+ @Token { DEDENT nContext } ;
+ @Token { SYMBOL ")" } ;
+ @Token { END_CLOS TOKEN } ;
+ @Token { NEWLINE TOKEN }
@Previous
Return cTemplate
Static Function ParseProperty( aProp )
Local nI
Local cTemplate := ""
For nI := 1 To Len( aProp )
cTemplate += @Token { INDENT Context } ;
+ @Token { KEYWORD "Property" } ;
+ @Token { SYMBOL "<" } ;
+ @Token { PROPERTY aProp[ nI ][ 1 ] } ;
+ @Token { SYMBOL ">" } ;
+ @Token { SYMBOL ": " } ;
+ ParseExpr( aProp[ nI ][ 2 ] )
Next nI
Return cTemplate
Static Function ParseArray( aData )
Local nI
Local cTemplate := ""
Local nContext
@Next
nContext := Context
cTemplate += @Token { KEYWORD "array" } ;
+ @Token { SYMBOL "<" } ;
+ @Token { NUMBER AllTrim( Str( Len( aData ) ) ) } ;
+ @Token { SYMBOL ">" } ;
+ @Token { SYMBOL "(" } ;
+ @Token { FOLDER TOKEN } ;
+ @Token { BEGIN_CLOS TOKEN } ;
+ @Token { NEWLINE TOKEN }
For nI := 1 To Len( aData )
cTemplate += @Token { INDENT Context } ;
+ @Token { SYMBOL "[" } ;
+ @Token { NUMBER AllTrim( Str( nI ) ) } ;
+ @Token { SYMBOL "]" } ;
+ @Token { SYMBOL " => " } ;
+ ParseExpr( aData[ nI ] )
Next nI
cTemplate += @Token { DEDENT nContext } ;
+ @Token { SYMBOL ")" } ;
+ @Token { END_CLOS TOKEN } ;
+ @Token { NEWLINE TOKEN }
@Previous
Return cTemplate