rubyang 0.1.2.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/rubyang/model.rb CHANGED
@@ -1,932 +1,1148 @@
1
1
  # coding: utf-8
2
+ # vim: et ts=2 sw=2
2
3
 
3
- require_relative 'model/parser'
4
+ require 'rubyang/model/logger'
5
+ require 'rubyang/model/parser'
4
6
 
5
7
  module Rubyang
6
- module Model
7
- DataDefStmtList ||= %w( container leaf leaf-list list choice case augment uses anyxml )
8
- DataNodeList ||= %w( container leaf leaf-list list anyxml )
9
- SchemaNodeList ||= %w( container leaf leaf-list list choice case rpc input output notification anyxml )
10
- TypeBodyStmtList ||= %w( range fraction-digits length pattern default enum leafref path require-instance identityref union bit position )
11
-
12
- def schema_nodeid
13
- "(?:#{absolute_schema_nodeid}|#{descendant_schema_nodeid})"
14
- end
15
- def absolute_schema_nodeid
16
- "(?:(?:/#{node_identifier})+)"
17
- end
18
- def descendant_schema_nodeid
19
- "(?:#{node_identifier}#{absolute_schema_nodeid})"
20
- end
21
- def node_identifier
22
- "(?:(?:#{prefix}:)?#{identifier})"
23
- end
24
- def instance_identifier
25
- "(?:(?:/#{node_identifier}(?:#{predicate})*)+)"
26
- end
27
- def predicate
28
- "(?:\[#{wsp}*(?:#{predicate_expr}|#{pos})#{wsp}*\])"
29
- end
30
- def predicate_expr
31
- "(?:(?:#{node_identifier}|[.])#{wsp}*=#{wsp}*(?:(?:#{dquote}[^#{dquote}]*#{dquote})|(?:#{squote}[^#{squote}]*#{squote})))"
32
- end
33
- def pos
34
- '(?:[0-9]+)'
35
- end
36
- def prefix
37
- "(?:#{identifier})"
38
- end
39
- def identifier
40
- '(?:[a-zA-Z][a-zA-Z0-9._-]*)'
41
- end
42
- def dquote
43
- '"'
44
- end
45
- def squote
46
- "'"
47
- end
48
- def wsp
49
- '(?:[ \t])'
50
- end
51
-
52
- class BaseStmt
53
- def substatements
54
- {}
55
- end
56
- def initialize substmts=[]
57
- # raise if received susstatements has invalid substatement
58
- substmts.each{ |s|
59
- unless self.substatements.include? StmtMap.find( s.class ).intern
60
- raise ArgumentError, "#{StmtMap.find( s.class )} is not #{self.class}'s substatement"
61
- end
62
- }
63
- # raise if received susstatements does not satisfy defined substatements' cardinality
64
- self.substatements.each{ |k, v|
65
- unless v.include? substmts.count{ |s| StmtMap.find( s ).intern == k }
66
- raise ArgumentError, "substatement #{StmtMap.find( k )} is not in #{self.class} #{k}'s cardinality"
67
- end
68
- }
69
- # raise if received susstatements has invalid substatement class
70
- substmts.each{ |s|
71
- unless BaseStmt === s
72
- raise ArgumentError, "#{s.class} is not Rubyang::Model's class"
73
- end
74
- }
75
- @substmts = substmts
76
- end
77
- def to_s parent=true
78
- head, vars, tail = "#<#{self.class.to_s}:0x#{(self.object_id << 1).to_s(16).rjust(14,'0')} ", Array.new, ">"
79
- if parent
80
- vars.push "@substmts=#{@substmts.map{|s| s.to_s(false)}}"
81
- end
82
- head + vars.join(', ') + tail
83
- end
84
- def substmt substmt, strict: false
85
- raise TypeError unless String === substmt
86
- if strict
87
- unless self.substatements[substmt.intern]
88
- raise ArgumentError, "#{StmtMap.find( s ).class} is not #{self.class}'s substatement"
89
- end
90
- end
91
- @substmts.select{ |_s| StmtMap.find( substmt ) === _s }
92
- end
93
- def substmts substmts, strict: false
94
- raise TypeError unless Array === substmts
95
- if strict
96
- substmts.each{ |s|
97
- unless self.substatements[s.intern]
98
- raise ArgumentError, "#{StmtMap.find( s ).class} is not #{self.class}'s substatement"
99
- end
100
- }
101
- end
102
- @substmts.select{ |_s| substmts.find{ |s| StmtMap.find( s ) === _s } }
103
- end
104
- def has_substmt? substmt
105
- unless self.substatements[substmt.intern]
106
- raise ArgumentError, "#{StmtMap.find( substmt ).class} is not #{self.class}'s substatement"
107
- end
108
- if @substmts.find{ |s| StmtMap.find( substmt ) === s }
109
- true
110
- else
111
- false
112
- end
113
- end
114
- def schema_node_substmts
115
- @substmts.select{ |s| SchemaNodeList.include? StmtMap.find( s ) }
116
- end
117
- def not_schema_node_substmts
118
- @substmts.select{ |s| not SchemaNodeList.include? StmtMap.find( s ) }
119
- end
120
- def without_not_schema_node_substmts
121
- self.class.new( self.arg, self.not_schema_node_substmts )
122
- end
123
- def to_yang level=0, pretty: false, indent: 2
124
- str = ""
125
- str += " " * indent * level if pretty
126
- str += "#{StmtMap.find( self )} #{self.arg}"
127
- if @substmts.size > 0
128
- str += " {\n"
129
- @substmts.each{ |s|
130
- str += s.to_yang level+1, pretty: pretty, indent: indent
131
- }
132
- str += " " * indent * level if pretty
133
- str += "}\n"
134
- else
135
- str += ";\n"
136
- end
137
- end
138
- end
139
-
140
- class NoArgStmt < BaseStmt
141
- end
142
-
143
- class ArgStmt < BaseStmt
144
- def initialize arg, substmts=[]
145
- super substmts
146
- @arg = arg
147
- unless valid_arg? arg
148
- raise ArgumentError, "Invalid Argument: '#{arg}'"
149
- end
150
- end
151
- def to_s parent=true
152
- head, vars, tail = "#<#{self.class.to_s}:0x#{(self.object_id << 1).to_s(16).rjust(14,'0')} ", Array.new, ">"
153
- if parent
154
- vars.push "@arg=#{@arg.to_s}"
155
- vars.push "@substmts=#{@substmts.map{|s| s.to_s(false)}}"
156
- end
157
- head + vars.join(', ') + tail
158
- end
159
- def arg
160
- @arg
161
- end
162
- def arg_regexp
163
- '(?:.*)'
164
- end
165
- def valid_arg? arg
166
- re = Regexp.new( "^#{arg_regexp}$" )
167
- re === arg
168
- end
169
- end
170
-
171
- class Module < ArgStmt
172
- def substatements
173
- {
174
- :'anyxml' => 0..Float::INFINITY,
175
- :'augment' => 0..Float::INFINITY,
176
- :'choice' => 0..Float::INFINITY,
177
- :'contact' => 0..1,
178
- :'container' => 0..Float::INFINITY,
179
- :'description' => 0..1,
180
- :'deviation' => 0..Float::INFINITY,
181
- :'extension' => 0..Float::INFINITY,
182
- :'feature' => 0..Float::INFINITY,
183
- :'grouping' => 0..Float::INFINITY,
184
- :'identity' => 0..Float::INFINITY,
185
- :'import' => 0..Float::INFINITY,
186
- :'include' => 0..Float::INFINITY,
187
- :'leaf' => 0..Float::INFINITY,
188
- :'leaf-list' => 0..Float::INFINITY,
189
- :'list' => 0..Float::INFINITY,
190
- :'namespace' => 1..1,
191
- :'notification' => 0..Float::INFINITY,
192
- :'organization' => 0..1,
193
- :'prefix' => 1..1,
194
- :'reference' => 0..1,
195
- :'revision' => 0..Float::INFINITY,
196
- :'rpc' => 0..Float::INFINITY,
197
- :'typedef' => 0..Float::INFINITY,
198
- :'uses' => 0..Float::INFINITY,
199
- :'yang-version' => 0..1,
200
- }
201
- end
202
- end
203
-
204
- class YangVersion < ArgStmt
205
- end
206
-
207
- class Namespace < ArgStmt
208
- end
209
-
210
- class Prefix < ArgStmt
211
- end
212
-
213
- class Import < ArgStmt
214
- def substatements
215
- {
216
- :'prefix' => 1..1,
217
- :'revision-date' => 0..1,
218
- }
219
- end
220
- end
221
-
222
- class RevisionDate < ArgStmt
223
- end
224
-
225
- class Include < ArgStmt
226
- def substatements
227
- {
228
- :'revision-date' => 0..1,
229
- }
230
- end
231
- end
232
-
233
- class Organization < ArgStmt
234
- end
235
-
236
- class Contact < ArgStmt
237
- end
238
-
239
- class Revision < ArgStmt
240
- def substatements
241
- {
242
- :'description' => 0..1,
243
- :'reference' => 0..1,
244
- }
245
- end
246
- end
247
-
248
- class Submodule < ArgStmt
249
- def substatements
250
- {
251
- :'anyxml' => 0..Float::INFINITY,
252
- :'augment' => 0..Float::INFINITY,
253
- :'belongs-to' => 1..1,
254
- :'choice' => 0..Float::INFINITY,
255
- :'contact' => 0..1,
256
- :'container' => 0..Float::INFINITY,
257
- :'description' => 0..1,
258
- :'deviation' => 0..Float::INFINITY,
259
- :'extension' => 0..Float::INFINITY,
260
- :'feature' => 0..Float::INFINITY,
261
- :'grouping' => 0..Float::INFINITY,
262
- :'identity' => 0..Float::INFINITY,
263
- :'import' => 0..Float::INFINITY,
264
- :'include' => 0..Float::INFINITY,
265
- :'leaf' => 0..Float::INFINITY,
266
- :'leaf-list' => 0..Float::INFINITY,
267
- :'list' => 0..Float::INFINITY,
268
- :'notification' => 0..Float::INFINITY,
269
- :'organization' => 0..1,
270
- :'reference' => 0..1,
271
- :'revision' => 0..Float::INFINITY,
272
- :'rpc' => 0..Float::INFINITY,
273
- :'typedef' => 0..Float::INFINITY,
274
- :'uses' => 0..Float::INFINITY,
275
- :'yang-version' => 0..1,
276
- }
277
- end
278
- end
279
-
280
- class BelongsTo < ArgStmt
281
- def substatements
282
- {
283
- :'prefix' => 1..1,
284
- }
285
- end
286
- end
287
-
288
- class Typedef < ArgStmt
289
- def substatements
290
- {
291
- :'default' => 0..1,
292
- :'description' => 0..1,
293
- :'reference' => 0..1,
294
- :'status' => 0..1,
295
- :'type' => 1..1,
296
- :'units' => 0..1,
297
- }
298
- end
299
- end
300
-
301
- class Type < ArgStmt
302
- def substatements
303
- {
304
- :'bit' => 0..Float::INFINITY,
305
- :'enum' => 0..Float::INFINITY,
306
- :'length' => 0..1,
307
- :'path' => 0..1,
308
- :'pattern' => 0..Float::INFINITY,
309
- :'range' => 0..1,
310
- :'require-instance' => 0..1,
311
- :'type' => 0..Float::INFINITY,
312
- :'fraction-digits' => 0..1,
313
- :'base' => 0..1,
314
- }
315
- end
316
- end
317
-
318
- class Bit < ArgStmt
319
- def substatements
320
- {
321
- :'position' => 0..1,
322
- :'status' => 0..1,
323
- :'description' => 0..1,
324
- :'reference' => 0..1,
325
- }
326
- end
327
- end
328
-
329
- class Enum < ArgStmt
330
- def substatements
331
- {
332
- :'value' => 0..1,
333
- :'status' => 0..1,
334
- :'description' => 0..1,
335
- :'reference' => 0..1,
336
- }
337
- end
338
- end
339
-
340
- class Value < ArgStmt
341
- end
342
-
343
- class FractionDigits < ArgStmt
344
- end
345
-
346
- class Identityref < ArgStmt
347
- end
348
-
349
- class Leafref < ArgStmt
350
- end
351
-
352
- class Position < ArgStmt
353
- end
354
-
355
- class Union < ArgStmt
356
- end
357
-
358
- class Length < ArgStmt
359
- def substatements
360
- {
361
- :'error-message' => 0..1,
362
- :'error-app-tag' => 0..1,
363
- :'description' => 0..1,
364
- :'reference' => 0..1,
365
- }
366
- end
367
- end
368
-
369
- class Path < ArgStmt
370
- end
371
-
372
- class Pattern < ArgStmt
373
- def substatements
374
- {
375
- :'error-message' => 0..1,
376
- :'error-app-tag' => 0..1,
377
- :'description' => 0..1,
378
- :'reference' => 0..1,
379
- }
380
- end
381
- end
382
-
383
- class Range < ArgStmt
384
- def substatements
385
- {
386
- :'error-message' => 0..1,
387
- :'error-app-tag' => 0..1,
388
- :'description' => 0..1,
389
- :'reference' => 0..1,
390
- }
391
- end
392
- end
393
-
394
- class RequireInstance < ArgStmt
395
- end
396
-
397
- class Units < ArgStmt
398
- end
399
-
400
- class Default < ArgStmt
401
- end
402
-
403
- class Container < ArgStmt
404
- def substatements
405
- {
406
- :'anyxml' => 0..Float::INFINITY,
407
- :'choice' => 0..Float::INFINITY,
408
- :'config' => 0..1,
409
- :'container' => 0..Float::INFINITY,
410
- :'description' => 0..1,
411
- :'grouping' => 0..Float::INFINITY,
412
- :'if-feature' => 0..Float::INFINITY,
413
- :'leaf' => 0..Float::INFINITY,
414
- :'leaf-list' => 0..Float::INFINITY,
415
- :'list' => 0..Float::INFINITY,
416
- :'must' => 0..Float::INFINITY,
417
- :'presence' => 0..1,
418
- :'reference' => 0..1,
419
- :'status' => 0..1,
420
- :'typedef' => 0..Float::INFINITY,
421
- :'uses' => 0..Float::INFINITY,
422
- :'when' => 0..1,
423
- }
424
- end
425
- end
426
-
427
- class Must < ArgStmt
428
- def substatements
429
- {
430
- :'description' => 0..1,
431
- :'error-app-tag' => 0..1,
432
- :'error-message' => 0..1,
433
- :'reference' => 0..1,
434
- }
435
- end
436
- end
437
-
438
- class ErrorMessage < ArgStmt
439
- end
440
-
441
- class ErrorAppTag < ArgStmt
442
- end
443
-
444
- class Presence < ArgStmt
445
- end
446
-
447
- class Leaf < ArgStmt
448
- def substatements
449
- {
450
- :'config' => 0..1,
451
- :'default' => 0..1,
452
- :'description' => 0..1,
453
- :'if-feature' => 0..Float::INFINITY,
454
- :'mandatory' => 0..1,
455
- :'must' => 0..Float::INFINITY,
456
- :'reference' => 0..1,
457
- :'status' => 0..1,
458
- :'type' => 1..1,
459
- :'units' => 0..1,
460
- :'when' => 0..1,
461
- }
462
- end
463
- end
464
-
465
- class Mandatory < ArgStmt
466
- end
467
-
468
- class LeafList < ArgStmt
469
- def substatements
470
- {
471
- :'config' => 0..1,
472
- :'description' => 0..1,
473
- :'if-feature' => 0..Float::INFINITY,
474
- :'max-elements' => 0..1,
475
- :'min-elements' => 0..1,
476
- :'must' => 0..Float::INFINITY,
477
- :'ordered-by' => 0..1,
478
- :'reference' => 0..1,
479
- :'status' => 0..1,
480
- :'type' => 1..1,
481
- :'units' => 0..1,
482
- :'when' => 0..1,
483
- }
484
- end
485
- end
486
-
487
- class MinElements < ArgStmt
488
- end
489
-
490
- class MaxElements < ArgStmt
491
- end
492
-
493
- class OrderedBy < ArgStmt
494
- end
495
-
496
- class List < ArgStmt
497
- def substatements
498
- {
499
- :'anyxml' => 0..Float::INFINITY,
500
- :'choice' => 0..Float::INFINITY,
501
- :'config' => 0..1,
502
- :'container' => 0..Float::INFINITY,
503
- :'description' => 0..1,
504
- :'grouping' => 0..Float::INFINITY,
505
- :'if-feature' => 0..Float::INFINITY,
506
- :'key' => 0..1,
507
- :'leaf' => 0..Float::INFINITY,
508
- :'leaf-list' => 0..Float::INFINITY,
509
- :'list' => 0..Float::INFINITY,
510
- :'max-elements' => 0..1,
511
- :'min-elements' => 0..1,
512
- :'must' => 0..Float::INFINITY,
513
- :'ordered-by' => 0..1,
514
- :'reference' => 0..1,
515
- :'status' => 0..1,
516
- :'typedef' => 0..Float::INFINITY,
517
- :'unique' => 0..Float::INFINITY,
518
- :'uses' => 0..Float::INFINITY,
519
- :'when' => 0..1,
520
- }
521
- end
522
- end
523
-
524
- class Key < ArgStmt
525
- end
526
-
527
- class Unique < ArgStmt
528
- end
529
-
530
- class Choice < ArgStmt
531
- def substatements
532
- {
533
- :'anyxml' => 0..Float::INFINITY,
534
- :'case' => 0..Float::INFINITY,
535
- :'config' => 0..1,
536
- :'container' => 0..Float::INFINITY,
537
- :'default' => 0..1,
538
- :'description' => 0..1,
539
- :'if-feature' => 0..Float::INFINITY,
540
- :'leaf' => 0..Float::INFINITY,
541
- :'leaf-list' => 0..Float::INFINITY,
542
- :'list' => 0..Float::INFINITY,
543
- :'mandatory' => 0..1,
544
- :'reference' => 0..1,
545
- :'status' => 0..1,
546
- :'when' => 0..1,
547
- }
548
- end
549
- end
550
-
551
- class Case < ArgStmt
552
- def substatements
553
- {
554
- :'anyxml' => 0..Float::INFINITY,
555
- :'choice' => 0..Float::INFINITY,
556
- :'container' => 0..Float::INFINITY,
557
- :'description' => 0..1,
558
- :'if-feature' => 0..Float::INFINITY,
559
- :'leaf' => 0..Float::INFINITY,
560
- :'leaf-list' => 0..Float::INFINITY,
561
- :'list' => 0..Float::INFINITY,
562
- :'reference' => 0..1,
563
- :'status' => 0..1,
564
- :'uses' => 0..Float::INFINITY,
565
- :'when' => 0..1,
566
- }
567
- end
568
- end
569
-
570
- class Anyxml < ArgStmt
571
- def substatements
572
- {
573
- :'config' => 0..1,
574
- :'description' => 0..1,
575
- :'if-feature' => 0..Float::INFINITY,
576
- :'mandatory' => 0..1,
577
- :'must' => 0..Float::INFINITY,
578
- :'reference' => 0..1,
579
- :'status' => 0..1,
580
- :'when' => 0..1,
581
- }
582
- end
583
- end
584
-
585
- class Grouping < ArgStmt
586
- def substatements
587
- {
588
- :'anyxml' => 0..Float::INFINITY,
589
- :'choice' => 0..Float::INFINITY,
590
- :'container' => 0..Float::INFINITY,
591
- :'description' => 0..1,
592
- :'grouping' => 0..Float::INFINITY,
593
- :'leaf' => 0..Float::INFINITY,
594
- :'leaf-list' => 0..Float::INFINITY,
595
- :'list' => 0..Float::INFINITY,
596
- :'reference' => 0..1,
597
- :'status' => 0..1,
598
- :'typedef' => 0..Float::INFINITY,
599
- :'uses' => 0..Float::INFINITY,
600
- }
601
- end
602
- end
603
-
604
- class Uses < ArgStmt
605
- def substatements
606
- {
607
- :'augment' => 0..1,
608
- :'description' => 0..1,
609
- :'if-feature' => 0..Float::INFINITY,
610
- :'refine' => 0..1,
611
- :'reference' => 0..1,
612
- :'status' => 0..1,
613
- :'when' => 0..1,
614
- }
615
- end
616
- end
617
-
618
- class Refine < ArgStmt
619
- def substatements
620
- {
621
- :'config' => 0..1,
622
- :'default' => 0..1,
623
- :'description' => 0..1,
624
- :'mandatory' => 0..1,
625
- :'max-elements' => 0..1,
626
- :'min-elements' => 0..1,
627
- :'must' => 0..Float::INFINITY,
628
- :'presence' => 0..1,
629
- :'reference' => 0..1,
630
- :'status' => 0..1,
631
- :'when' => 0..1,
632
- }
633
- end
634
- end
635
-
636
- class Rpc < ArgStmt
637
- def substatements
638
- {
639
- :'description' => 0..1,
640
- :'grouping' => 0..Float::INFINITY,
641
- :'if-feature' => 0..Float::INFINITY,
642
- :'input' => 0..1,
643
- :'output' => 0..1,
644
- :'reference' => 0..1,
645
- :'status' => 0..1,
646
- :'typedef' => 0..Float::INFINITY,
647
- }
648
- end
649
- end
650
-
651
- class Input < NoArgStmt
652
- def substatements
653
- {
654
- :'anyxml' => 0..Float::INFINITY,
655
- :'choice' => 0..Float::INFINITY,
656
- :'container' => 0..Float::INFINITY,
657
- :'grouping' => 0..Float::INFINITY,
658
- :'leaf' => 0..Float::INFINITY,
659
- :'leaf-list' => 0..Float::INFINITY,
660
- :'list' => 0..Float::INFINITY,
661
- :'typedef' => 0..Float::INFINITY,
662
- :'uses' => 0..Float::INFINITY,
663
- }
664
- end
665
- end
666
-
667
- class Output < NoArgStmt
668
- def substatements
669
- {
670
- :'anyxml' => 0..Float::INFINITY,
671
- :'choice' => 0..Float::INFINITY,
672
- :'container' => 0..Float::INFINITY,
673
- :'grouping' => 0..Float::INFINITY,
674
- :'leaf' => 0..Float::INFINITY,
675
- :'leaf-list' => 0..Float::INFINITY,
676
- :'list' => 0..Float::INFINITY,
677
- :'typedef' => 0..Float::INFINITY,
678
- :'uses' => 0..Float::INFINITY,
679
- }
680
- end
681
- end
682
-
683
- class Notification < ArgStmt
684
- def substatements
685
- {
686
- :'anyxml' => 0..Float::INFINITY,
687
- :'choice' => 0..Float::INFINITY,
688
- :'container' => 0..Float::INFINITY,
689
- :'description' => 0..1,
690
- :'grouping' => 0..Float::INFINITY,
691
- :'if-feature' => 0..Float::INFINITY,
692
- :'leaf' => 0..Float::INFINITY,
693
- :'leaf-list' => 0..Float::INFINITY,
694
- :'list' => 0..Float::INFINITY,
695
- :'reference' => 0..1,
696
- :'status' => 0..1,
697
- :'typedef' => 0..Float::INFINITY,
698
- :'uses' => 0..Float::INFINITY,
699
- }
700
- end
701
- end
702
-
703
- class Augment < ArgStmt
704
- def substatements
705
- {
706
- :'anyxml' => 0..Float::INFINITY,
707
- :'case' => 0..Float::INFINITY,
708
- :'choice' => 0..Float::INFINITY,
709
- :'container' => 0..Float::INFINITY,
710
- :'description' => 0..1,
711
- :'if-feature' => 0..Float::INFINITY,
712
- :'leaf' => 0..Float::INFINITY,
713
- :'leaf-list' => 0..Float::INFINITY,
714
- :'list' => 0..Float::INFINITY,
715
- :'reference' => 0..1,
716
- :'status' => 0..1,
717
- :'uses' => 0..Float::INFINITY,
718
- :'when' => 0..1,
719
- }
720
- end
721
- end
722
-
723
- class Identity < ArgStmt
724
- def substatements
725
- {
726
- :'base' => 0..1,
727
- :'description' => 0..1,
728
- :'reference' => 0..1,
729
- :'status' => 0..1,
730
- }
731
- end
732
- end
733
-
734
- class Base < ArgStmt
735
- end
736
-
737
- class Extension < ArgStmt
738
- def substatements
739
- {
740
- :'argument' => 0..1,
741
- :'description' => 0..1,
742
- :'reference' => 0..1,
743
- :'status' => 0..1,
744
- }
745
- end
746
- end
747
-
748
- class Argument < ArgStmt
749
- def substatements
750
- {
751
- :'yin-element' => 0..1,
752
- }
753
- end
754
- end
755
-
756
- class YinElement < ArgStmt
757
- end
758
-
759
- class ConformanceRelated < ArgStmt
760
- end
761
-
762
- class Feature < ArgStmt
763
- def substatements
764
- {
765
- :'description' => 0..1,
766
- :'if-feature' => 0..Float::INFINITY,
767
- :'reference' => 0..1,
768
- :'status' => 0..1,
769
- }
770
- end
771
- end
772
-
773
- class IfFeature < ArgStmt
774
- end
775
-
776
- class Deviation < ArgStmt
777
- def substatements
778
- {
779
- :'description' => 0..1,
780
- :'deviate' => 1..Float::INFINITY,
781
- :'reference' => 0..1,
782
- }
783
- end
784
- end
785
-
786
- class Deviate < ArgStmt
787
- def substatements
788
- {
789
- :'config' => 0..1,
790
- :'default' => 0..1,
791
- :'mandatory' => 0..1,
792
- :'max-elements' => 0..1,
793
- :'min-elements' => 0..1,
794
- :'must' => 0..Float::INFINITY,
795
- :'type' => 0..1,
796
- :'unique' => 0..Float::INFINITY,
797
- :'units' => 0..1,
798
- }
799
- end
800
- end
801
-
802
- class Config < ArgStmt
803
- end
804
-
805
- class Status < ArgStmt
806
- end
807
-
808
- class Description < ArgStmt
809
- end
810
-
811
- class Reference < ArgStmt
812
- end
813
-
814
- class When < ArgStmt
815
- def substatements
816
- {
817
- :'description' => 0..1,
818
- :'reference' => 0..1,
819
- }
820
- end
821
- end
822
-
823
- class StmtMap
824
- @@stmt_map = [
825
- { :name => 'anyxml', :class => Rubyang::Model::Anyxml },
826
- { :name => 'augment', :class => Rubyang::Model::Augment },
827
- { :name => 'argument', :class => Rubyang::Model::Argument },
828
- { :name => 'base', :class => Rubyang::Model::Base },
829
- { :name => 'belongs-to', :class => Rubyang::Model::BelongsTo },
830
- { :name => 'bit', :class => Rubyang::Model::Bit },
831
- { :name => 'case', :class => Rubyang::Model::Case },
832
- { :name => 'choice', :class => Rubyang::Model::Choice },
833
- { :name => 'config', :class => Rubyang::Model::Config },
834
- { :name => 'contact', :class => Rubyang::Model::Contact },
835
- { :name => 'container', :class => Rubyang::Model::Container },
836
- { :name => 'default', :class => Rubyang::Model::Default },
837
- { :name => 'description', :class => Rubyang::Model::Description },
838
- { :name => 'deviation', :class => Rubyang::Model::Deviation },
839
- { :name => 'deviate', :class => Rubyang::Model::Deviate },
840
- { :name => 'enum', :class => Rubyang::Model::Enum },
841
- { :name => 'error-app-tag', :class => Rubyang::Model::ErrorAppTag },
842
- { :name => 'error-message', :class => Rubyang::Model::ErrorMessage },
843
- { :name => 'extension', :class => Rubyang::Model::Extension },
844
- { :name => 'feature', :class => Rubyang::Model::Feature },
845
- { :name => 'fraction-digits', :class => Rubyang::Model::FractionDigits },
846
- { :name => 'grouping', :class => Rubyang::Model::Grouping },
847
- { :name => 'identity', :class => Rubyang::Model::Identity },
848
- { :name => 'identityref', :class => Rubyang::Model::Identityref },
849
- { :name => 'if-feature', :class => Rubyang::Model::IfFeature },
850
- { :name => 'import', :class => Rubyang::Model::Import },
851
- { :name => 'include', :class => Rubyang::Model::Include },
852
- { :name => 'input', :class => Rubyang::Model::Input },
853
- { :name => 'key', :class => Rubyang::Model::Key },
854
- { :name => 'leaf', :class => Rubyang::Model::Leaf },
855
- { :name => 'leaf-list', :class => Rubyang::Model::LeafList },
856
- { :name => 'leafref', :class => Rubyang::Model::Leafref },
857
- { :name => 'length', :class => Rubyang::Model::Length },
858
- { :name => 'list', :class => Rubyang::Model::List },
859
- { :name => 'mandatory', :class => Rubyang::Model::Mandatory },
860
- { :name => 'max-elements', :class => Rubyang::Model::MaxElements },
861
- { :name => 'min-elements', :class => Rubyang::Model::MinElements },
862
- { :name => 'module', :class => Rubyang::Model::Module },
863
- { :name => 'must', :class => Rubyang::Model::Must },
864
- { :name => 'namespace', :class => Rubyang::Model::Namespace },
865
- { :name => 'notification', :class => Rubyang::Model::Notification },
866
- { :name => 'ordered-by', :class => Rubyang::Model::OrderedBy },
867
- { :name => 'organization', :class => Rubyang::Model::Organization },
868
- { :name => 'output', :class => Rubyang::Model::Output },
869
- { :name => 'path', :class => Rubyang::Model::Path },
870
- { :name => 'pattern', :class => Rubyang::Model::Pattern },
871
- { :name => 'position', :class => Rubyang::Model::Position },
872
- { :name => 'prefix', :class => Rubyang::Model::Prefix },
873
- { :name => 'presence', :class => Rubyang::Model::Presence },
874
- { :name => 'range', :class => Rubyang::Model::Range },
875
- { :name => 'reference', :class => Rubyang::Model::Reference },
876
- { :name => 'refine', :class => Rubyang::Model::Refine },
877
- { :name => 'revision', :class => Rubyang::Model::Revision },
878
- { :name => 'revision-date', :class => Rubyang::Model::RevisionDate },
879
- { :name => 'require-instance', :class => Rubyang::Model::RequireInstance },
880
- { :name => 'rpc', :class => Rubyang::Model::Rpc },
881
- { :name => 'status', :class => Rubyang::Model::Status },
882
- { :name => 'type', :class => Rubyang::Model::Type },
883
- { :name => 'typedef', :class => Rubyang::Model::Typedef },
884
- { :name => 'uses', :class => Rubyang::Model::Uses },
885
- { :name => 'union', :class => Rubyang::Model::Union },
886
- { :name => 'units', :class => Rubyang::Model::Units },
887
- { :name => 'unique', :class => Rubyang::Model::Unique },
888
- { :name => 'value', :class => Rubyang::Model::Value },
889
- { :name => 'when', :class => Rubyang::Model::When },
890
- { :name => 'yang-version', :class => Rubyang::Model::YangVersion },
891
- { :name => 'yin-element', :class => Rubyang::Model::YinElement },
892
- ]
893
- def self.find key
894
- case key
895
- when String, Symbol
896
- @@stmt_map.find{ |h| h[:name] == key.to_s }[:class]
897
- when Class
898
- @@stmt_map.find{ |h| h[:class] == key }[:name]
899
- else
900
- @@stmt_map.find{ |h| h[:class] === key }[:name]
901
- end
902
- end
903
- end
904
- end
8
+ module Model
9
+ DataDefStmtList ||= %w( container leaf leaf-list list choice case augment uses anyxml )
10
+ DataNodeList ||= %w( container leaf leaf-list list anyxml )
11
+ SchemaNodeList ||= %w( container leaf leaf-list list choice case rpc input output notification anyxml )
12
+ TypeBodyStmtList ||= %w( range fraction-digits length pattern default enum leafref path require-instance identityref union bit position )
13
+
14
+ def schema_nodeid
15
+ "(?:#{absolute_schema_nodeid}|#{descendant_schema_nodeid})"
16
+ end
17
+ def absolute_schema_nodeid
18
+ "(?:(?:/#{node_identifier})+)"
19
+ end
20
+ def descendant_schema_nodeid
21
+ "(?:#{node_identifier}#{absolute_schema_nodeid})"
22
+ end
23
+ def node_identifier
24
+ "(?:(?:#{prefix}:)?#{identifier})"
25
+ end
26
+ def instance_identifier
27
+ "(?:(?:/#{node_identifier}(?:#{predicate})*)+)"
28
+ end
29
+ def predicate
30
+ "(?:\[#{wsp}*(?:#{predicate_expr}|#{pos})#{wsp}*\])"
31
+ end
32
+ def predicate_expr
33
+ "(?:(?:#{node_identifier}|[.])#{wsp}*=#{wsp}*(?:(?:#{dquote}[^#{dquote}]*#{dquote})|(?:#{squote}[^#{squote}]*#{squote})))"
34
+ end
35
+ def pos
36
+ '(?:[0-9]+)'
37
+ end
38
+ def prefix
39
+ "(?:#{identifier})"
40
+ end
41
+ def identifier
42
+ '(?:[a-zA-Z][a-zA-Z0-9._-]*)'
43
+ end
44
+ def dquote
45
+ '"'
46
+ end
47
+ def squote
48
+ "'"
49
+ end
50
+ def wsp
51
+ '(?:[ \t])'
52
+ end
53
+
54
+ class BaseStmt
55
+ def substatements
56
+ {}
57
+ end
58
+ def initialize substmts=[]
59
+ # raise if received susstatements has invalid substatement
60
+ substmts.each{ |s|
61
+ unless self.substatements.include? StmtMap.find( s.class ).intern
62
+ raise ArgumentError, "#{StmtMap.find( s.class )} is not #{self.class}'s substatement"
63
+ end
64
+ }
65
+ # raise if received susstatements does not satisfy defined substatements' cardinality
66
+ self.substatements.each{ |k, v|
67
+ unless v.include? substmts.count{ |s| StmtMap.find( s ).intern == k }
68
+ raise ArgumentError, "substatement #{StmtMap.find( k )} is not in #{self.class} #{k}'s cardinality"
69
+ end
70
+ }
71
+ # raise if received susstatements has invalid substatement class
72
+ substmts.each{ |s|
73
+ unless BaseStmt === s
74
+ raise ArgumentError, "#{s.class} is not Rubyang::Model's class"
75
+ end
76
+ }
77
+ @substmts = substmts
78
+ end
79
+ def to_s parent=true
80
+ head, vars, tail = "#<#{self.class.to_s}:0x#{(self.object_id << 1).to_s(16).rjust(14,'0')} ", Array.new, ">"
81
+ if parent
82
+ vars.push "@substmts=#{@substmts.map{|s| s.to_s(false)}}"
83
+ end
84
+ head + vars.join(', ') + tail
85
+ end
86
+ def substmt substmt, strict: false
87
+ raise TypeError unless String === substmt
88
+ if strict
89
+ unless self.substatements[substmt.intern]
90
+ raise ArgumentError, "#{StmtMap.find( s ).class} is not #{self.class}'s substatement"
91
+ end
92
+ end
93
+ @substmts.select{ |_s| StmtMap.find( substmt ) === _s }
94
+ end
95
+ def substmts substmts, strict: false
96
+ raise TypeError unless Array === substmts
97
+ if strict
98
+ substmts.each{ |s|
99
+ unless self.substatements[s.intern]
100
+ raise ArgumentError, "#{StmtMap.find( s ).class} is not #{self.class}'s substatement"
101
+ end
102
+ }
103
+ end
104
+ @substmts.select{ |_s| substmts.find{ |s| StmtMap.find( s ) === _s } }
105
+ end
106
+ def has_substmt? substmt
107
+ unless self.substatements[substmt.intern]
108
+ raise ArgumentError, "#{StmtMap.find( substmt ).class} is not #{self.class}'s substatement"
109
+ end
110
+ if @substmts.find{ |s| StmtMap.find( substmt ) === s }
111
+ true
112
+ else
113
+ false
114
+ end
115
+ end
116
+ def schema_node_substmts
117
+ @substmts.select{ |s| SchemaNodeList.include? StmtMap.find( s ) }
118
+ end
119
+ def not_schema_node_substmts
120
+ @substmts.select{ |s| not SchemaNodeList.include? StmtMap.find( s ) }
121
+ end
122
+ def without_not_schema_node_substmts
123
+ self.class.new( self.arg, self.not_schema_node_substmts )
124
+ end
125
+ def to_yang level=0, pretty: false, indent: 2
126
+ str = ""
127
+ str += " " * indent * level if pretty
128
+ str += "#{StmtMap.find( self )} #{self.arg}"
129
+ if @substmts.size > 0
130
+ str += " {\n"
131
+ @substmts.each{ |s|
132
+ str += s.to_yang level+1, pretty: pretty, indent: indent
133
+ }
134
+ str += " " * indent * level if pretty
135
+ str += "}\n"
136
+ else
137
+ str += ";\n"
138
+ end
139
+ end
140
+ end
141
+
142
+ class NoArgStmt < BaseStmt
143
+ end
144
+
145
+ class ArgStmt < BaseStmt
146
+ def initialize arg, substmts=[]
147
+ super substmts
148
+ @arg = arg
149
+ unless valid_arg? arg
150
+ raise ArgumentError, "Invalid Argument: '#{arg}'"
151
+ end
152
+ end
153
+ def to_s parent=true
154
+ head, vars, tail = "#<#{self.class.to_s}:0x#{(self.object_id << 1).to_s(16).rjust(14,'0')} ", Array.new, ">"
155
+ if parent
156
+ vars.push "@arg=#{@arg.to_s}"
157
+ vars.push "@substmts=#{@substmts.map{|s| s.to_s(false)}}"
158
+ end
159
+ head + vars.join(', ') + tail
160
+ end
161
+ def arg
162
+ @arg
163
+ end
164
+ def arg_regexp
165
+ '(?:.*)'
166
+ end
167
+ def valid_arg? arg
168
+ re = Regexp.new( "^#{arg_regexp}$" )
169
+ re === arg
170
+ end
171
+ end
172
+
173
+ class Module < ArgStmt
174
+ def substatements
175
+ {
176
+ :'anyxml' => 0..Float::INFINITY,
177
+ :'augment' => 0..Float::INFINITY,
178
+ :'choice' => 0..Float::INFINITY,
179
+ :'contact' => 0..1,
180
+ :'container' => 0..Float::INFINITY,
181
+ :'description' => 0..1,
182
+ :'deviation' => 0..Float::INFINITY,
183
+ :'extension' => 0..Float::INFINITY,
184
+ :'feature' => 0..Float::INFINITY,
185
+ :'grouping' => 0..Float::INFINITY,
186
+ :'identity' => 0..Float::INFINITY,
187
+ :'import' => 0..Float::INFINITY,
188
+ :'include' => 0..Float::INFINITY,
189
+ :'leaf' => 0..Float::INFINITY,
190
+ :'leaf-list' => 0..Float::INFINITY,
191
+ :'list' => 0..Float::INFINITY,
192
+ :'namespace' => 1..1,
193
+ :'notification' => 0..Float::INFINITY,
194
+ :'organization' => 0..1,
195
+ :'prefix' => 1..1,
196
+ :'reference' => 0..1,
197
+ :'revision' => 0..Float::INFINITY,
198
+ :'rpc' => 0..Float::INFINITY,
199
+ :'typedef' => 0..Float::INFINITY,
200
+ :'uses' => 0..Float::INFINITY,
201
+ :'yang-version' => 0..1,
202
+ :'unknown' => 0..Float::INFINITY,
203
+ }
204
+ end
205
+ end
206
+
207
+ class YangVersion < ArgStmt
208
+ def substatements
209
+ {
210
+ :'unknown' => 0..Float::INFINITY,
211
+ }
212
+ end
213
+ end
214
+
215
+ class Namespace < ArgStmt
216
+ def substatements
217
+ {
218
+ :'unknown' => 0..Float::INFINITY,
219
+ }
220
+ end
221
+ end
222
+
223
+ class Prefix < ArgStmt
224
+ def substatements
225
+ {
226
+ :'unknown' => 0..Float::INFINITY,
227
+ }
228
+ end
229
+ end
230
+
231
+ class Import < ArgStmt
232
+ def substatements
233
+ {
234
+ :'prefix' => 1..1,
235
+ :'revision-date' => 0..1,
236
+ :'unknown' => 0..Float::INFINITY,
237
+ }
238
+ end
239
+ end
240
+
241
+ class RevisionDate < ArgStmt
242
+ def substatements
243
+ {
244
+ :'unknown' => 0..Float::INFINITY,
245
+ }
246
+ end
247
+ end
248
+
249
+ class Include < ArgStmt
250
+ def substatements
251
+ {
252
+ :'revision-date' => 0..1,
253
+ :'unknown' => 0..Float::INFINITY,
254
+ }
255
+ end
256
+ end
257
+
258
+ class Organization < ArgStmt
259
+ def substatements
260
+ {
261
+ :'unknown' => 0..Float::INFINITY,
262
+ }
263
+ end
264
+ end
265
+
266
+ class Contact < ArgStmt
267
+ def substatements
268
+ {
269
+ :'unknown' => 0..Float::INFINITY,
270
+ }
271
+ end
272
+ end
273
+
274
+ class Revision < ArgStmt
275
+ def substatements
276
+ {
277
+ :'description' => 0..1,
278
+ :'reference' => 0..1,
279
+ :'unknown' => 0..Float::INFINITY,
280
+ }
281
+ end
282
+ end
283
+
284
+ class Submodule < ArgStmt
285
+ def substatements
286
+ {
287
+ :'anyxml' => 0..Float::INFINITY,
288
+ :'augment' => 0..Float::INFINITY,
289
+ :'belongs-to' => 1..1,
290
+ :'choice' => 0..Float::INFINITY,
291
+ :'contact' => 0..1,
292
+ :'container' => 0..Float::INFINITY,
293
+ :'description' => 0..1,
294
+ :'deviation' => 0..Float::INFINITY,
295
+ :'extension' => 0..Float::INFINITY,
296
+ :'feature' => 0..Float::INFINITY,
297
+ :'grouping' => 0..Float::INFINITY,
298
+ :'identity' => 0..Float::INFINITY,
299
+ :'import' => 0..Float::INFINITY,
300
+ :'include' => 0..Float::INFINITY,
301
+ :'leaf' => 0..Float::INFINITY,
302
+ :'leaf-list' => 0..Float::INFINITY,
303
+ :'list' => 0..Float::INFINITY,
304
+ :'notification' => 0..Float::INFINITY,
305
+ :'organization' => 0..1,
306
+ :'reference' => 0..1,
307
+ :'revision' => 0..Float::INFINITY,
308
+ :'rpc' => 0..Float::INFINITY,
309
+ :'typedef' => 0..Float::INFINITY,
310
+ :'uses' => 0..Float::INFINITY,
311
+ :'yang-version' => 0..1,
312
+ :'unknown' => 0..Float::INFINITY,
313
+ }
314
+ end
315
+ end
316
+
317
+ class BelongsTo < ArgStmt
318
+ def substatements
319
+ {
320
+ :'prefix' => 1..1,
321
+ :'unknown' => 0..Float::INFINITY,
322
+ }
323
+ end
324
+ end
325
+
326
+ class Typedef < ArgStmt
327
+ def substatements
328
+ {
329
+ :'default' => 0..1,
330
+ :'description' => 0..1,
331
+ :'reference' => 0..1,
332
+ :'status' => 0..1,
333
+ :'type' => 1..1,
334
+ :'units' => 0..1,
335
+ :'unknown' => 0..Float::INFINITY,
336
+ }
337
+ end
338
+ end
339
+
340
+ class Type < ArgStmt
341
+ def substatements
342
+ {
343
+ :'bit' => 0..Float::INFINITY,
344
+ :'enum' => 0..Float::INFINITY,
345
+ :'length' => 0..1,
346
+ :'path' => 0..1,
347
+ :'pattern' => 0..Float::INFINITY,
348
+ :'range' => 0..1,
349
+ :'require-instance' => 0..1,
350
+ :'type' => 0..Float::INFINITY,
351
+ :'fraction-digits' => 0..1,
352
+ :'base' => 0..1,
353
+ :'unknown' => 0..Float::INFINITY,
354
+ }
355
+ end
356
+ end
357
+
358
+ class Bit < ArgStmt
359
+ def substatements
360
+ {
361
+ :'position' => 0..1,
362
+ :'status' => 0..1,
363
+ :'description' => 0..1,
364
+ :'reference' => 0..1,
365
+ :'unknown' => 0..Float::INFINITY,
366
+ }
367
+ end
368
+ end
369
+
370
+ class Enum < ArgStmt
371
+ def substatements
372
+ {
373
+ :'value' => 0..1,
374
+ :'status' => 0..1,
375
+ :'description' => 0..1,
376
+ :'reference' => 0..1,
377
+ :'unknown' => 0..Float::INFINITY,
378
+ }
379
+ end
380
+ end
381
+
382
+ class Value < ArgStmt
383
+ def substatements
384
+ {
385
+ :'unknown' => 0..Float::INFINITY,
386
+ }
387
+ end
388
+ end
389
+
390
+ class FractionDigits < ArgStmt
391
+ def substatements
392
+ {
393
+ :'unknown' => 0..Float::INFINITY,
394
+ }
395
+ end
396
+ end
397
+
398
+ class Identityref < ArgStmt
399
+ def substatements
400
+ {
401
+ :'unknown' => 0..Float::INFINITY,
402
+ }
403
+ end
404
+ end
405
+
406
+ class Leafref < ArgStmt
407
+ def substatements
408
+ {
409
+ :'unknown' => 0..Float::INFINITY,
410
+ }
411
+ end
412
+ end
413
+
414
+ class Position < ArgStmt
415
+ def substatements
416
+ {
417
+ :'unknown' => 0..Float::INFINITY,
418
+ }
419
+ end
420
+ end
421
+
422
+ class Union < ArgStmt
423
+ def substatements
424
+ {
425
+ :'unknown' => 0..Float::INFINITY,
426
+ }
427
+ end
428
+ end
429
+
430
+ class Length < ArgStmt
431
+ def substatements
432
+ {
433
+ :'error-message' => 0..1,
434
+ :'error-app-tag' => 0..1,
435
+ :'description' => 0..1,
436
+ :'reference' => 0..1,
437
+ :'unknown' => 0..Float::INFINITY,
438
+ }
439
+ end
440
+ end
441
+
442
+ class Path < ArgStmt
443
+ def substatements
444
+ {
445
+ :'unknown' => 0..Float::INFINITY,
446
+ }
447
+ end
448
+ end
449
+
450
+ class Pattern < ArgStmt
451
+ def substatements
452
+ {
453
+ :'error-message' => 0..1,
454
+ :'error-app-tag' => 0..1,
455
+ :'description' => 0..1,
456
+ :'reference' => 0..1,
457
+ :'unknown' => 0..Float::INFINITY,
458
+ }
459
+ end
460
+ end
461
+
462
+ class Range < ArgStmt
463
+ def substatements
464
+ {
465
+ :'error-message' => 0..1,
466
+ :'error-app-tag' => 0..1,
467
+ :'description' => 0..1,
468
+ :'reference' => 0..1,
469
+ :'unknown' => 0..Float::INFINITY,
470
+ }
471
+ end
472
+ end
473
+
474
+ class RequireInstance < ArgStmt
475
+ def substatements
476
+ {
477
+ :'unknown' => 0..Float::INFINITY,
478
+ }
479
+ end
480
+ end
481
+
482
+ class Units < ArgStmt
483
+ def substatements
484
+ {
485
+ :'unknown' => 0..Float::INFINITY,
486
+ }
487
+ end
488
+ end
489
+
490
+ class Default < ArgStmt
491
+ def substatements
492
+ {
493
+ :'unknown' => 0..Float::INFINITY,
494
+ }
495
+ end
496
+ end
497
+
498
+ class Container < ArgStmt
499
+ def substatements
500
+ {
501
+ :'anyxml' => 0..Float::INFINITY,
502
+ :'choice' => 0..Float::INFINITY,
503
+ :'config' => 0..1,
504
+ :'container' => 0..Float::INFINITY,
505
+ :'description' => 0..1,
506
+ :'grouping' => 0..Float::INFINITY,
507
+ :'if-feature' => 0..Float::INFINITY,
508
+ :'leaf' => 0..Float::INFINITY,
509
+ :'leaf-list' => 0..Float::INFINITY,
510
+ :'list' => 0..Float::INFINITY,
511
+ :'must' => 0..Float::INFINITY,
512
+ :'presence' => 0..1,
513
+ :'reference' => 0..1,
514
+ :'status' => 0..1,
515
+ :'typedef' => 0..Float::INFINITY,
516
+ :'uses' => 0..Float::INFINITY,
517
+ :'when' => 0..1,
518
+ :'unknown' => 0..Float::INFINITY,
519
+ }
520
+ end
521
+ end
522
+
523
+ class Must < ArgStmt
524
+ def substatements
525
+ {
526
+ :'description' => 0..1,
527
+ :'error-app-tag' => 0..1,
528
+ :'error-message' => 0..1,
529
+ :'reference' => 0..1,
530
+ :'unknown' => 0..Float::INFINITY,
531
+ }
532
+ end
533
+ end
534
+
535
+ class ErrorMessage < ArgStmt
536
+ def substatements
537
+ {
538
+ :'unknown' => 0..Float::INFINITY,
539
+ }
540
+ end
541
+ end
542
+
543
+ class ErrorAppTag < ArgStmt
544
+ def substatements
545
+ {
546
+ :'unknown' => 0..Float::INFINITY,
547
+ }
548
+ end
549
+ end
550
+
551
+ class Presence < ArgStmt
552
+ def substatements
553
+ {
554
+ :'unknown' => 0..Float::INFINITY,
555
+ }
556
+ end
557
+ end
558
+
559
+ class Leaf < ArgStmt
560
+ def substatements
561
+ {
562
+ :'config' => 0..1,
563
+ :'default' => 0..1,
564
+ :'description' => 0..1,
565
+ :'if-feature' => 0..Float::INFINITY,
566
+ :'mandatory' => 0..1,
567
+ :'must' => 0..Float::INFINITY,
568
+ :'reference' => 0..1,
569
+ :'status' => 0..1,
570
+ :'type' => 1..1,
571
+ :'units' => 0..1,
572
+ :'when' => 0..1,
573
+ :'unknown' => 0..Float::INFINITY,
574
+ }
575
+ end
576
+ end
577
+
578
+ class Mandatory < ArgStmt
579
+ def substatements
580
+ {
581
+ :'unknown' => 0..Float::INFINITY,
582
+ }
583
+ end
584
+ end
585
+
586
+ class LeafList < ArgStmt
587
+ def substatements
588
+ {
589
+ :'config' => 0..1,
590
+ :'description' => 0..1,
591
+ :'if-feature' => 0..Float::INFINITY,
592
+ :'max-elements' => 0..1,
593
+ :'min-elements' => 0..1,
594
+ :'must' => 0..Float::INFINITY,
595
+ :'ordered-by' => 0..1,
596
+ :'reference' => 0..1,
597
+ :'status' => 0..1,
598
+ :'type' => 1..1,
599
+ :'units' => 0..1,
600
+ :'when' => 0..1,
601
+ :'unknown' => 0..Float::INFINITY,
602
+ }
603
+ end
604
+ end
605
+
606
+ class MinElements < ArgStmt
607
+ def substatements
608
+ {
609
+ :'unknown' => 0..Float::INFINITY,
610
+ }
611
+ end
612
+ end
613
+
614
+ class MaxElements < ArgStmt
615
+ def substatements
616
+ {
617
+ :'unknown' => 0..Float::INFINITY,
618
+ }
619
+ end
620
+ end
621
+
622
+ class OrderedBy < ArgStmt
623
+ def substatements
624
+ {
625
+ :'unknown' => 0..Float::INFINITY,
626
+ }
627
+ end
628
+ end
629
+
630
+ class List < ArgStmt
631
+ def substatements
632
+ {
633
+ :'anyxml' => 0..Float::INFINITY,
634
+ :'choice' => 0..Float::INFINITY,
635
+ :'config' => 0..1,
636
+ :'container' => 0..Float::INFINITY,
637
+ :'description' => 0..1,
638
+ :'grouping' => 0..Float::INFINITY,
639
+ :'if-feature' => 0..Float::INFINITY,
640
+ :'key' => 0..1,
641
+ :'leaf' => 0..Float::INFINITY,
642
+ :'leaf-list' => 0..Float::INFINITY,
643
+ :'list' => 0..Float::INFINITY,
644
+ :'max-elements' => 0..1,
645
+ :'min-elements' => 0..1,
646
+ :'must' => 0..Float::INFINITY,
647
+ :'ordered-by' => 0..1,
648
+ :'reference' => 0..1,
649
+ :'status' => 0..1,
650
+ :'typedef' => 0..Float::INFINITY,
651
+ :'unique' => 0..Float::INFINITY,
652
+ :'uses' => 0..Float::INFINITY,
653
+ :'when' => 0..1,
654
+ :'unknown' => 0..Float::INFINITY,
655
+ }
656
+ end
657
+ end
658
+
659
+ class Key < ArgStmt
660
+ def substatements
661
+ {
662
+ :'unknown' => 0..Float::INFINITY,
663
+ }
664
+ end
665
+ end
666
+
667
+ class Unique < ArgStmt
668
+ def substatements
669
+ {
670
+ :'unknown' => 0..Float::INFINITY,
671
+ }
672
+ end
673
+ end
674
+
675
+ class Choice < ArgStmt
676
+ def substatements
677
+ {
678
+ :'anyxml' => 0..Float::INFINITY,
679
+ :'case' => 0..Float::INFINITY,
680
+ :'config' => 0..1,
681
+ :'container' => 0..Float::INFINITY,
682
+ :'default' => 0..1,
683
+ :'description' => 0..1,
684
+ :'if-feature' => 0..Float::INFINITY,
685
+ :'leaf' => 0..Float::INFINITY,
686
+ :'leaf-list' => 0..Float::INFINITY,
687
+ :'list' => 0..Float::INFINITY,
688
+ :'mandatory' => 0..1,
689
+ :'reference' => 0..1,
690
+ :'status' => 0..1,
691
+ :'when' => 0..1,
692
+ :'unknown' => 0..Float::INFINITY,
693
+ }
694
+ end
695
+ end
696
+
697
+ class Case < ArgStmt
698
+ def substatements
699
+ {
700
+ :'anyxml' => 0..Float::INFINITY,
701
+ :'choice' => 0..Float::INFINITY,
702
+ :'container' => 0..Float::INFINITY,
703
+ :'description' => 0..1,
704
+ :'if-feature' => 0..Float::INFINITY,
705
+ :'leaf' => 0..Float::INFINITY,
706
+ :'leaf-list' => 0..Float::INFINITY,
707
+ :'list' => 0..Float::INFINITY,
708
+ :'reference' => 0..1,
709
+ :'status' => 0..1,
710
+ :'uses' => 0..Float::INFINITY,
711
+ :'when' => 0..1,
712
+ :'unknown' => 0..Float::INFINITY,
713
+ }
714
+ end
715
+ end
716
+
717
+ class Anyxml < ArgStmt
718
+ def substatements
719
+ {
720
+ :'config' => 0..1,
721
+ :'description' => 0..1,
722
+ :'if-feature' => 0..Float::INFINITY,
723
+ :'mandatory' => 0..1,
724
+ :'must' => 0..Float::INFINITY,
725
+ :'reference' => 0..1,
726
+ :'status' => 0..1,
727
+ :'when' => 0..1,
728
+ :'unknown' => 0..Float::INFINITY,
729
+ }
730
+ end
731
+ end
732
+
733
+ class Grouping < ArgStmt
734
+ def substatements
735
+ {
736
+ :'anyxml' => 0..Float::INFINITY,
737
+ :'choice' => 0..Float::INFINITY,
738
+ :'container' => 0..Float::INFINITY,
739
+ :'description' => 0..1,
740
+ :'grouping' => 0..Float::INFINITY,
741
+ :'leaf' => 0..Float::INFINITY,
742
+ :'leaf-list' => 0..Float::INFINITY,
743
+ :'list' => 0..Float::INFINITY,
744
+ :'reference' => 0..1,
745
+ :'status' => 0..1,
746
+ :'typedef' => 0..Float::INFINITY,
747
+ :'uses' => 0..Float::INFINITY,
748
+ :'unknown' => 0..Float::INFINITY,
749
+ }
750
+ end
751
+ end
752
+
753
+ class Uses < ArgStmt
754
+ def substatements
755
+ {
756
+ :'augment' => 0..1,
757
+ :'description' => 0..1,
758
+ :'if-feature' => 0..Float::INFINITY,
759
+ :'refine' => 0..1,
760
+ :'reference' => 0..1,
761
+ :'status' => 0..1,
762
+ :'when' => 0..1,
763
+ :'unknown' => 0..Float::INFINITY,
764
+ }
765
+ end
766
+ end
767
+
768
+ class Refine < ArgStmt
769
+ def substatements
770
+ {
771
+ :'config' => 0..1,
772
+ :'default' => 0..1,
773
+ :'description' => 0..1,
774
+ :'mandatory' => 0..1,
775
+ :'max-elements' => 0..1,
776
+ :'min-elements' => 0..1,
777
+ :'must' => 0..Float::INFINITY,
778
+ :'presence' => 0..1,
779
+ :'reference' => 0..1,
780
+ :'status' => 0..1,
781
+ :'when' => 0..1,
782
+ :'unknown' => 0..Float::INFINITY,
783
+ }
784
+ end
785
+ end
786
+
787
+ class Rpc < ArgStmt
788
+ def substatements
789
+ {
790
+ :'description' => 0..1,
791
+ :'grouping' => 0..Float::INFINITY,
792
+ :'if-feature' => 0..Float::INFINITY,
793
+ :'input' => 0..1,
794
+ :'output' => 0..1,
795
+ :'reference' => 0..1,
796
+ :'status' => 0..1,
797
+ :'typedef' => 0..Float::INFINITY,
798
+ :'unknown' => 0..Float::INFINITY,
799
+ }
800
+ end
801
+ end
802
+
803
+ class Input < NoArgStmt
804
+ def substatements
805
+ {
806
+ :'anyxml' => 0..Float::INFINITY,
807
+ :'choice' => 0..Float::INFINITY,
808
+ :'container' => 0..Float::INFINITY,
809
+ :'grouping' => 0..Float::INFINITY,
810
+ :'leaf' => 0..Float::INFINITY,
811
+ :'leaf-list' => 0..Float::INFINITY,
812
+ :'list' => 0..Float::INFINITY,
813
+ :'typedef' => 0..Float::INFINITY,
814
+ :'uses' => 0..Float::INFINITY,
815
+ :'unknown' => 0..Float::INFINITY,
816
+ }
817
+ end
818
+ end
819
+
820
+ class Output < NoArgStmt
821
+ def substatements
822
+ {
823
+ :'anyxml' => 0..Float::INFINITY,
824
+ :'choice' => 0..Float::INFINITY,
825
+ :'container' => 0..Float::INFINITY,
826
+ :'grouping' => 0..Float::INFINITY,
827
+ :'leaf' => 0..Float::INFINITY,
828
+ :'leaf-list' => 0..Float::INFINITY,
829
+ :'list' => 0..Float::INFINITY,
830
+ :'typedef' => 0..Float::INFINITY,
831
+ :'uses' => 0..Float::INFINITY,
832
+ :'unknown' => 0..Float::INFINITY,
833
+ }
834
+ end
835
+ end
836
+
837
+ class Notification < ArgStmt
838
+ def substatements
839
+ {
840
+ :'anyxml' => 0..Float::INFINITY,
841
+ :'choice' => 0..Float::INFINITY,
842
+ :'container' => 0..Float::INFINITY,
843
+ :'description' => 0..1,
844
+ :'grouping' => 0..Float::INFINITY,
845
+ :'if-feature' => 0..Float::INFINITY,
846
+ :'leaf' => 0..Float::INFINITY,
847
+ :'leaf-list' => 0..Float::INFINITY,
848
+ :'list' => 0..Float::INFINITY,
849
+ :'reference' => 0..1,
850
+ :'status' => 0..1,
851
+ :'typedef' => 0..Float::INFINITY,
852
+ :'uses' => 0..Float::INFINITY,
853
+ :'unknown' => 0..Float::INFINITY,
854
+ }
855
+ end
856
+ end
857
+
858
+ class Augment < ArgStmt
859
+ def substatements
860
+ {
861
+ :'anyxml' => 0..Float::INFINITY,
862
+ :'case' => 0..Float::INFINITY,
863
+ :'choice' => 0..Float::INFINITY,
864
+ :'container' => 0..Float::INFINITY,
865
+ :'description' => 0..1,
866
+ :'if-feature' => 0..Float::INFINITY,
867
+ :'leaf' => 0..Float::INFINITY,
868
+ :'leaf-list' => 0..Float::INFINITY,
869
+ :'list' => 0..Float::INFINITY,
870
+ :'reference' => 0..1,
871
+ :'status' => 0..1,
872
+ :'uses' => 0..Float::INFINITY,
873
+ :'when' => 0..1,
874
+ :'unknown' => 0..Float::INFINITY,
875
+ }
876
+ end
877
+ end
878
+
879
+ class Identity < ArgStmt
880
+ def substatements
881
+ {
882
+ :'base' => 0..1,
883
+ :'description' => 0..1,
884
+ :'reference' => 0..1,
885
+ :'status' => 0..1,
886
+ :'unknown' => 0..Float::INFINITY,
887
+ }
888
+ end
889
+ end
890
+
891
+ class Base < ArgStmt
892
+ end
893
+
894
+ class Extension < ArgStmt
895
+ def substatements
896
+ {
897
+ :'argument' => 0..1,
898
+ :'description' => 0..1,
899
+ :'reference' => 0..1,
900
+ :'status' => 0..1,
901
+ :'unknown' => 0..Float::INFINITY,
902
+ }
903
+ end
904
+ end
905
+
906
+ class Argument < ArgStmt
907
+ def substatements
908
+ {
909
+ :'yin-element' => 0..1,
910
+ :'unknown' => 0..Float::INFINITY,
911
+ }
912
+ end
913
+ end
914
+
915
+ class YinElement < ArgStmt
916
+ def substatements
917
+ {
918
+ :'unknown' => 0..Float::INFINITY,
919
+ }
920
+ end
921
+ end
922
+
923
+ class ConformanceRelated < ArgStmt
924
+ def substatements
925
+ {
926
+ :'unknown' => 0..Float::INFINITY,
927
+ }
928
+ end
929
+ end
930
+
931
+ class Feature < ArgStmt
932
+ def substatements
933
+ {
934
+ :'description' => 0..1,
935
+ :'if-feature' => 0..Float::INFINITY,
936
+ :'reference' => 0..1,
937
+ :'status' => 0..1,
938
+ :'unknown' => 0..Float::INFINITY,
939
+ }
940
+ end
941
+ end
942
+
943
+ class IfFeature < ArgStmt
944
+ def substatements
945
+ {
946
+ :'unknown' => 0..Float::INFINITY,
947
+ }
948
+ end
949
+ end
950
+
951
+ class Deviation < ArgStmt
952
+ def substatements
953
+ {
954
+ :'description' => 0..1,
955
+ :'deviate' => 1..Float::INFINITY,
956
+ :'reference' => 0..1,
957
+ :'unknown' => 0..Float::INFINITY,
958
+ }
959
+ end
960
+ end
961
+
962
+ class Deviate < ArgStmt
963
+ def substatements
964
+ {
965
+ :'config' => 0..1,
966
+ :'default' => 0..1,
967
+ :'mandatory' => 0..1,
968
+ :'max-elements' => 0..1,
969
+ :'min-elements' => 0..1,
970
+ :'must' => 0..Float::INFINITY,
971
+ :'type' => 0..1,
972
+ :'unique' => 0..Float::INFINITY,
973
+ :'units' => 0..1,
974
+ :'unknown' => 0..Float::INFINITY,
975
+ }
976
+ end
977
+ end
978
+
979
+ class Config < ArgStmt
980
+ def substatements
981
+ {
982
+ :'unknown' => 0..Float::INFINITY,
983
+ }
984
+ end
985
+ def valid_arg? arg
986
+ ['true', 'false'].include? arg
987
+ end
988
+ end
989
+
990
+ class Status < ArgStmt
991
+ def substatements
992
+ {
993
+ :'unknown' => 0..Float::INFINITY,
994
+ }
995
+ end
996
+ end
997
+
998
+ class Description < ArgStmt
999
+ def substatements
1000
+ {
1001
+ :'unknown' => 0..Float::INFINITY,
1002
+ }
1003
+ end
1004
+ end
1005
+
1006
+ class Reference < ArgStmt
1007
+ def substatements
1008
+ {
1009
+ :'unknown' => 0..Float::INFINITY,
1010
+ }
1011
+ end
1012
+ end
1013
+
1014
+ class When < ArgStmt
1015
+ def substatements
1016
+ {
1017
+ :'description' => 0..1,
1018
+ :'reference' => 0..1,
1019
+ }
1020
+ end
1021
+ end
1022
+
1023
+ class Unknown < ArgStmt
1024
+ def substatements
1025
+ {
1026
+ :'unknown' => 0..Float::INFINITY,
1027
+ }
1028
+ end
1029
+ def initialize name, arg='', substmts=[]
1030
+ super arg, substmts
1031
+ @name = name
1032
+ end
1033
+ def name
1034
+ @name
1035
+ end
1036
+ end
1037
+
1038
+ class StmtMap
1039
+ @@stmt_map = [
1040
+ { :name => 'anyxml', :class => Rubyang::Model::Anyxml },
1041
+ { :name => 'augment', :class => Rubyang::Model::Augment },
1042
+ { :name => 'argument', :class => Rubyang::Model::Argument },
1043
+ { :name => 'base', :class => Rubyang::Model::Base },
1044
+ { :name => 'belongs-to', :class => Rubyang::Model::BelongsTo },
1045
+ { :name => 'bit', :class => Rubyang::Model::Bit },
1046
+ { :name => 'case', :class => Rubyang::Model::Case },
1047
+ { :name => 'choice', :class => Rubyang::Model::Choice },
1048
+ { :name => 'config', :class => Rubyang::Model::Config },
1049
+ { :name => 'contact', :class => Rubyang::Model::Contact },
1050
+ { :name => 'container', :class => Rubyang::Model::Container },
1051
+ { :name => 'default', :class => Rubyang::Model::Default },
1052
+ { :name => 'description', :class => Rubyang::Model::Description },
1053
+ { :name => 'deviation', :class => Rubyang::Model::Deviation },
1054
+ { :name => 'deviate', :class => Rubyang::Model::Deviate },
1055
+ { :name => 'enum', :class => Rubyang::Model::Enum },
1056
+ { :name => 'error-app-tag', :class => Rubyang::Model::ErrorAppTag },
1057
+ { :name => 'error-message', :class => Rubyang::Model::ErrorMessage },
1058
+ { :name => 'extension', :class => Rubyang::Model::Extension },
1059
+ { :name => 'feature', :class => Rubyang::Model::Feature },
1060
+ { :name => 'fraction-digits', :class => Rubyang::Model::FractionDigits },
1061
+ { :name => 'grouping', :class => Rubyang::Model::Grouping },
1062
+ { :name => 'identity', :class => Rubyang::Model::Identity },
1063
+ { :name => 'identityref', :class => Rubyang::Model::Identityref },
1064
+ { :name => 'if-feature', :class => Rubyang::Model::IfFeature },
1065
+ { :name => 'import', :class => Rubyang::Model::Import },
1066
+ { :name => 'include', :class => Rubyang::Model::Include },
1067
+ { :name => 'input', :class => Rubyang::Model::Input },
1068
+ { :name => 'key', :class => Rubyang::Model::Key },
1069
+ { :name => 'leaf', :class => Rubyang::Model::Leaf },
1070
+ { :name => 'leaf-list', :class => Rubyang::Model::LeafList },
1071
+ { :name => 'leafref', :class => Rubyang::Model::Leafref },
1072
+ { :name => 'length', :class => Rubyang::Model::Length },
1073
+ { :name => 'list', :class => Rubyang::Model::List },
1074
+ { :name => 'mandatory', :class => Rubyang::Model::Mandatory },
1075
+ { :name => 'max-elements', :class => Rubyang::Model::MaxElements },
1076
+ { :name => 'min-elements', :class => Rubyang::Model::MinElements },
1077
+ { :name => 'module', :class => Rubyang::Model::Module },
1078
+ { :name => 'must', :class => Rubyang::Model::Must },
1079
+ { :name => 'namespace', :class => Rubyang::Model::Namespace },
1080
+ { :name => 'notification', :class => Rubyang::Model::Notification },
1081
+ { :name => 'ordered-by', :class => Rubyang::Model::OrderedBy },
1082
+ { :name => 'organization', :class => Rubyang::Model::Organization },
1083
+ { :name => 'output', :class => Rubyang::Model::Output },
1084
+ { :name => 'path', :class => Rubyang::Model::Path },
1085
+ { :name => 'pattern', :class => Rubyang::Model::Pattern },
1086
+ { :name => 'position', :class => Rubyang::Model::Position },
1087
+ { :name => 'prefix', :class => Rubyang::Model::Prefix },
1088
+ { :name => 'presence', :class => Rubyang::Model::Presence },
1089
+ { :name => 'range', :class => Rubyang::Model::Range },
1090
+ { :name => 'reference', :class => Rubyang::Model::Reference },
1091
+ { :name => 'refine', :class => Rubyang::Model::Refine },
1092
+ { :name => 'revision', :class => Rubyang::Model::Revision },
1093
+ { :name => 'revision-date', :class => Rubyang::Model::RevisionDate },
1094
+ { :name => 'require-instance', :class => Rubyang::Model::RequireInstance },
1095
+ { :name => 'rpc', :class => Rubyang::Model::Rpc },
1096
+ { :name => 'status', :class => Rubyang::Model::Status },
1097
+ { :name => 'type', :class => Rubyang::Model::Type },
1098
+ { :name => 'typedef', :class => Rubyang::Model::Typedef },
1099
+ { :name => 'uses', :class => Rubyang::Model::Uses },
1100
+ { :name => 'union', :class => Rubyang::Model::Union },
1101
+ { :name => 'units', :class => Rubyang::Model::Units },
1102
+ { :name => 'unique', :class => Rubyang::Model::Unique },
1103
+ { :name => 'value', :class => Rubyang::Model::Value },
1104
+ { :name => 'when', :class => Rubyang::Model::When },
1105
+ { :name => 'yang-version', :class => Rubyang::Model::YangVersion },
1106
+ { :name => 'yin-element', :class => Rubyang::Model::YinElement },
1107
+ { :name => 'unknown', :class => Rubyang::Model::Unknown },
1108
+ ]
1109
+ def self.find key
1110
+ case key
1111
+ when String, Symbol
1112
+ @@stmt_map.find{ |h| h[:name] == key.to_s }[:class]
1113
+ when Class
1114
+ @@stmt_map.find{ |h| h[:class] == key }[:name]
1115
+ else
1116
+ @@stmt_map.find{ |h| h[:class] === key }[:name]
1117
+ end
1118
+ end
1119
+ end
1120
+ end
905
1121
  end
906
1122
 
907
1123
  if __FILE__ == $0
908
- model_yang_version = Rubyang::Model::YangVersion.new( '1' )
909
- model_namespace = Rubyang::Model::Namespace.new( 'testnamespace' )
910
- model_prefix = Rubyang::Model::Prefix.new( 'testprefix' )
911
- model_type = Rubyang::Model::Type.new( 'string' )
912
- model_leaf = Rubyang::Model::Leaf.new( 'testleaf', [model_type] )
913
- model_module_substmts = [
914
- model_yang_version,
915
- model_namespace,
916
- model_prefix,
917
- model_leaf,
918
- ]
919
- model_module = Rubyang::Model::Module.new( 'testmodule', model_module_substmts )
920
- p model_module
921
- p model_module.has_substmt?( 'yang-version' )
922
- p model_module.has_substmt?( 'namespace' )
923
- p model_module.has_substmt?( 'prefix' )
924
- p model_module.substmt( 'yang-version' )
925
- p model_module.substmt( 'namespace' )
926
- p model_module.substmt( 'prefix' )
927
-
928
- print model_module.to_yang pretty: true
929
- p model_module.schema_node_substmts
930
- p model_module.not_schema_node_substmts
1124
+ model_yang_version = Rubyang::Model::YangVersion.new( '1' )
1125
+ model_namespace = Rubyang::Model::Namespace.new( 'testnamespace' )
1126
+ model_prefix = Rubyang::Model::Prefix.new( 'testprefix' )
1127
+ model_type = Rubyang::Model::Type.new( 'string' )
1128
+ model_leaf = Rubyang::Model::Leaf.new( 'testleaf', [model_type] )
1129
+ model_module_substmts = [
1130
+ model_yang_version,
1131
+ model_namespace,
1132
+ model_prefix,
1133
+ model_leaf,
1134
+ ]
1135
+ model_module = Rubyang::Model::Module.new( 'testmodule', model_module_substmts )
1136
+ p model_module
1137
+ p model_module.has_substmt?( 'yang-version' )
1138
+ p model_module.has_substmt?( 'namespace' )
1139
+ p model_module.has_substmt?( 'prefix' )
1140
+ p model_module.substmt( 'yang-version' )
1141
+ p model_module.substmt( 'namespace' )
1142
+ p model_module.substmt( 'prefix' )
1143
+
1144
+ print model_module.to_yang pretty: true
1145
+ p model_module.schema_node_substmts
1146
+ p model_module.not_schema_node_substmts
931
1147
  end
932
1148