ic_agent 0.1.4 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,15 +3,19 @@ require 'treetop'
3
3
  module IcAgent
4
4
  module Ast
5
5
  module Nodes
6
+ # Represents a named node in the abstract syntax tree.
6
7
  class NamedNode < Treetop::Runtime::SyntaxNode
8
+ # The title of the named node.
7
9
  def title
8
10
  :named_node
9
11
  end
10
12
 
13
+ # Converts the node and its children to an array representation.
11
14
  def to_array
12
15
  [title] + elements.map(&:to_array)
13
16
  end
14
17
 
18
+ # Converts the node and its children to a string representation.
15
19
  def to_s
16
20
  "#{title.to_s.upcase} #{elements_to_s}"
17
21
  end
@@ -25,53 +29,68 @@ module IcAgent
25
29
  end
26
30
  end
27
31
 
32
+ # Represents an instruction node in the abstract syntax tree, a subclass of NamedNode.
28
33
  class Instruction < NamedNode
34
+ # The title of the instruction node.
29
35
  def title
30
36
  :instruction
31
37
  end
32
38
 
39
+ # Converts the instruction node to a string representation.
33
40
  def to_s
34
41
  elements_to_s
35
42
  end
36
43
  end
37
44
 
45
+ # Represents a comment node in the abstract syntax tree, a subclass of NamedNode.
38
46
  class Comment < NamedNode
47
+ # The title of the comment node.
39
48
  def title
40
49
  :comment
41
50
  end
42
51
 
52
+ # Converts the comment node to a string representation with '#' prefix.
43
53
  def to_s
44
54
  "# #{elements[0].to_s}"
45
55
  end
46
56
  end
47
57
 
58
+ # Represents a DID file node in the abstract syntax tree, a subclass of NamedNode.
48
59
  class DIDFile < NamedNode
60
+ # The title of the DID file node.
49
61
  def title
50
62
  :did_file
51
63
  end
52
64
 
65
+ # Converts the DID file node to a string representation.
53
66
  def to_s
54
67
  elements_to_s
55
68
  end
56
69
  end
57
70
 
71
+ # Represents a type declaration node in the abstract syntax tree, a subclass of NamedNode.
58
72
  class TypeDeclaration < NamedNode
73
+ # The title of the type declaration node.
59
74
  def title
60
75
  :type_declaration
61
76
  end
62
77
 
78
+ # Returns the name of the type parameter.
63
79
  def type_param_name
64
80
  elements[0].source_content
65
81
  end
66
82
 
83
+ # Returns the content of the type parameter without newlines and trailing ';}' replaced with '}'.
67
84
  def type_param_content
68
85
  elements[1].source_content.gsub("\n", '').gsub(';}', '}')
69
86
  end
70
87
 
88
+ # Returns the opt code of the root type element.
71
89
  def type_root_opt_code
72
90
  elements[1].opt_code
73
91
  end
74
92
 
93
+ # Returns an array of type child items.
75
94
  def type_child_items
76
95
  if elements && elements[1] && elements[1].elements && elements[1].elements[0]
77
96
  elements[1].elements[0].elements
@@ -80,6 +99,7 @@ module IcAgent
80
99
  end
81
100
  end
82
101
 
102
+ # Returns an array of keys of type child items.
83
103
  def type_child_item_keys
84
104
  names = []
85
105
  type_child_items.each do |ele|
@@ -88,6 +108,7 @@ module IcAgent
88
108
  names
89
109
  end
90
110
 
111
+ # Returns an array of referenced types in the type parameter content.
91
112
  def type_refer_items
92
113
  source_string = self.type_param_content
93
114
  parser = IcAgent::Ast::StatementParser.new
@@ -96,10 +117,12 @@ module IcAgent
96
117
  refer_type
97
118
  end
98
119
 
120
+ # Converts the type declaration node to a string representation.
99
121
  def to_s
100
122
  text_value
101
123
  end
102
124
 
125
+ # Converts the type declaration node to a hash representation.
103
126
  def to_obj
104
127
  {
105
128
  'type_param_name' => type_param_name,
@@ -110,199 +133,257 @@ module IcAgent
110
133
  end
111
134
  end
112
135
 
136
+ # Represents a base type node in the abstract syntax tree, a subclass of NamedNode.
113
137
  class BaseType < NamedNode
138
+ # The title of the base type node.
114
139
  def title
115
140
  :base_type
116
141
  end
117
142
 
143
+ # Converts the base type node to a string representation.
118
144
  def to_s
119
145
  elements_to_s
120
146
  end
121
147
  end
122
148
 
149
+ # Represents a single base type node in the abstract syntax tree, a subclass of BaseType.
123
150
  class BaseTypeSingle < NamedNode
151
+ # The title of the single base type node.
124
152
  def title
125
153
  :base_type_single
126
154
  end
127
155
 
156
+ # Converts the single base type node to a string representation.
128
157
  def to_s
129
158
  elements_to_s
130
159
  end
131
160
 
161
+ # Returns the opt code for the single base type.
132
162
  def opt_code
133
163
  'single'
134
164
  end
135
165
  end
136
166
 
167
+ # Represents a record base type node in the abstract syntax tree, a subclass of BaseType.
137
168
  class BaseTypeRecord < NamedNode
169
+ # The title of the record base type node.
138
170
  def title
139
171
  :base_type_record
140
172
  end
141
173
 
174
+ # Converts the record base type node to a string representation.
142
175
  def to_s
143
176
  elements_to_s
144
177
  end
145
178
 
179
+ # Returns the opt code for the record base type.
146
180
  def opt_code
147
181
  'record'
148
182
  end
149
183
  end
150
184
 
185
+ # Represents a key base type node in the abstract syntax tree, a subclass of BaseType.
151
186
  class BaseTypeKey < NamedNode
187
+ # The title of the key base type node.
152
188
  def title
153
189
  :base_type_key
154
190
  end
155
191
 
192
+ # Converts the key base type node to a string representation.
156
193
  def to_s
157
194
  elements_to_s
158
195
  end
159
196
  end
160
197
 
198
+ # Represents a variant base type node in the abstract syntax tree, a subclass of BaseType.
161
199
  class BaseTypeVariant < NamedNode
200
+ # The title of the variant base type node.
162
201
  def title
163
202
  :base_type_variant
164
203
  end
165
204
 
205
+ # Converts the variant base type node to a string representation.
166
206
  def to_s
167
207
  elements_to_s
168
208
  end
169
209
 
210
+ # Returns the opt code for the variant base type.
170
211
  def opt_code
171
212
  'variant'
172
213
  end
173
214
  end
174
215
 
216
+ # Represents a function base type node in the abstract syntax tree, a subclass of BaseType.
175
217
  class BaseTypeFunc < NamedNode
218
+ # The title of the function base type node.
176
219
  def title
177
220
  :base_type_func
178
221
  end
179
222
 
223
+ # Converts the function base type node to a string representation.
180
224
  def to_s
181
225
  elements_to_s
182
226
  end
183
227
 
228
+ # Returns the opt code for the function base type.
184
229
  def opt_code
185
230
  'func'
186
231
  end
187
232
  end
188
233
 
234
+ # Represents an optional base type node in the abstract syntax tree, a subclass of BaseType.
189
235
  class BaseTypeOpt < NamedNode
236
+ # The title of the optional base type node.
190
237
  def title
191
238
  :base_type_opt
192
239
  end
193
240
 
241
+ # Converts the optional base type node to a string representation.
194
242
  def to_s
195
243
  elements_to_s
196
244
  end
197
245
 
246
+ # Returns the opt code for the optional base type.
198
247
  def opt_code
199
248
  'opt'
200
249
  end
201
250
  end
202
251
 
252
+ # Represents a vector base type node in the abstract syntax tree, a subclass of BaseType.
203
253
  class BaseTypeVec < NamedNode
254
+ # The title of the vector base type node.
204
255
  def title
205
256
  :base_type_vec
206
257
  end
207
258
 
259
+ # Converts the vector base type node to a string representation.
208
260
  def to_s
209
261
  elements_to_s
210
262
  end
211
263
 
264
+ # Returns the opt code for the vector base type.
212
265
  def opt_code
213
266
  'vec'
214
267
  end
215
268
  end
216
269
 
270
+ # Represents an other base type node in the abstract syntax tree, a subclass of BaseType.
217
271
  class BaseTypeOther < NamedNode
272
+ # The title of the other base type node.
218
273
  def title
219
274
  :base_type_other
220
275
  end
221
276
 
277
+ # Converts the other base type node to a string representation.
222
278
  def to_s
223
279
  elements_to_s
224
280
  end
225
281
 
282
+ # Returns the opt code for the other base type.
226
283
  def opt_code
227
284
  text_value
228
285
  end
229
286
  end
230
287
 
288
+ # Represents the content of a base type node in the abstract syntax tree, a subclass of NamedNode.
231
289
  class BaseTypeContent < NamedNode
290
+ # The title of the base type content node.
232
291
  def title
233
292
  :base_type_content
234
293
  end
235
294
 
295
+ # Converts the base type content node to a string representation.
236
296
  def to_s
237
297
  elements_to_s
238
298
  end
239
299
  end
240
300
 
301
+ # Represents a child of a base type node in the abstract syntax tree, a subclass of NamedNode.
241
302
  class BaseTypeChild < NamedNode
303
+ # The title of the base type child node.
242
304
  def title
243
305
  :base_type_child
244
306
  end
245
307
 
308
+ # Converts the base type child node to a string representation.
246
309
  def to_s
247
310
  elements_to_s
248
311
  end
249
312
  end
250
313
 
314
+ # Represents a type name node in the abstract syntax tree, a subclass of NamedNode.
251
315
  class TypeName < NamedNode
316
+ # The title of the type name node.
252
317
  def title
253
318
  :type_name
254
319
  end
255
320
 
321
+ # Converts the type name node to a string representation.
256
322
  def to_s
257
323
  elements_to_s
258
324
  end
259
325
  end
260
326
 
327
+ # Represents an IC service node in the abstract syntax tree, a subclass of NamedNode.
261
328
  class Service < NamedNode
329
+ # The title of the IC service node.
262
330
  def title
263
331
  :ic_service
264
332
  end
265
333
 
334
+ # Converts the IC service node to a string representation.
266
335
  def to_s
267
336
  elements_to_s
268
337
  end
269
338
  end
270
339
 
340
+ # Represents an IC service name node in the abstract syntax tree, a subclass of NamedNode.
271
341
  class IcServiceName < NamedNode
342
+ # The title of the IC service name node.
272
343
  def title
273
344
  :ic_service_name
274
345
  end
275
346
 
347
+ # Converts the IC service name node to a string representation with '#' prefix.
276
348
  def to_s
277
349
  "# #{elements[0].to_s}"
278
350
  end
279
351
  end
280
352
 
353
+ # Represents IC service methods node in the abstract syntax tree, a subclass of NamedNode.
281
354
  class IcServiceMethods < NamedNode
355
+ # The title of the IC service methods node.
282
356
  def title
283
357
  :ic_service_methods
284
358
  end
285
359
 
360
+ # Returns an array of IC service method nodes.
286
361
  def value
287
362
  elements.map { |update| update.value }
288
363
  end
289
364
  end
290
365
 
366
+ # Represents an IC service method name node in the abstract syntax tree, a subclass of NamedNode.
291
367
  class IcServiceMethodName < NamedNode
368
+ # The title of the IC service method name node.
292
369
  def title
293
370
  :ic_service_method_name
294
371
  end
295
372
  end
296
373
 
374
+ # Represents an IC service item node in the abstract syntax tree, a subclass of NamedNode.
297
375
  class IcServiceItem < NamedNode
376
+ # The title of the IC service item node.
298
377
  def title
299
378
  :ic_service_item
300
379
  end
301
380
 
381
+ # Converts the IC service item node to a string representation.
302
382
  def to_s
303
383
  elements_to_s
304
384
  end
305
385
 
386
+ # Converts the IC service item node to a hash representation.
306
387
  def to_obj
307
388
  obj = {}
308
389
  elements.each do |element|
@@ -312,61 +393,79 @@ module IcAgent
312
393
  end
313
394
  end
314
395
 
396
+ # Represents an IC service param node in the abstract syntax tree, a subclass of NamedNode.
315
397
  class IcServiceParam < NamedNode
398
+ # The title of the IC service param node.
316
399
  def title
317
400
  :ic_service_param
318
401
  end
319
402
 
403
+ # Converts the IC service param node to a string representation with '#' prefix.
320
404
  def to_s
321
405
  "# #{elements[0].to_s}"
322
406
  end
323
407
  end
324
408
 
409
+ # Represents an IC service name node in the abstract syntax tree, a subclass of NamedNode.
325
410
  class IcServiceName < NamedNode
411
+ # The title of the IC service name node.
326
412
  def title
327
413
  :ic_service_name
328
414
  end
329
415
 
416
+ # Converts the IC service name node to a string representation with '#' prefix.
330
417
  def to_s
331
418
  "# #{elements[0].to_s}"
332
419
  end
333
420
  end
334
421
 
422
+ # Represents an IC service method params node in the abstract syntax tree, a subclass of NamedNode.
335
423
  class IcServiceMethodParams < NamedNode
424
+ # The title of the IC service method params node.
336
425
  def title
337
426
  :ic_service_method_params
338
427
  end
339
428
 
429
+ # Converts the IC service method params node to a string representation.
340
430
  def to_s
341
431
  elements_to_s
342
432
  end
343
433
  end
344
434
 
435
+ # Represents an IC service method return node in the abstract syntax tree, a subclass of NamedNode.
345
436
  class IcServiceMethodReturn < NamedNode
437
+ # The title of the IC service method return node.
346
438
  def title
347
439
  :ic_service_method_return
348
440
  end
349
441
 
442
+ # Converts the IC service method return node to a string representation.
350
443
  def to_s
351
444
  elements_to_s
352
445
  end
353
446
  end
354
447
 
448
+ # Represents an IC service method query node in the abstract syntax tree, a subclass of NamedNode.
355
449
  class IcServiceMethodQuery < NamedNode
450
+ # The title of the IC service method query node.
356
451
  def title
357
452
  :ic_service_method_query
358
453
  end
359
454
 
455
+ # Converts the IC service method query node to a string representation.
360
456
  def to_s
361
457
  elements_to_s
362
458
  end
363
459
  end
364
460
 
461
+ # Represents the content of a base type node in the abstract syntax tree, a subclass of NamedNode.
365
462
  class BaseTypeContent < NamedNode
463
+ # The title of the IC service method query node.
366
464
  def title
367
465
  :ic_service_method_query
368
466
  end
369
467
 
468
+ # Converts the IC service method query node to a string representation.
370
469
  def to_s
371
470
  elements_to_s
372
471
  end
@@ -374,4 +473,3 @@ module IcAgent
374
473
  end
375
474
  end
376
475
  end
377
-