rubyang 0.1.1 → 0.1.2
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.
- checksums.yaml +5 -5
- data/.travis.yml +13 -2
- data/README.md +2 -3
- data/lib/rubyang/database/data_tree.rb +494 -130
- data/lib/rubyang/database/schema_tree.rb +541 -293
- data/lib/rubyang/database.rb +10 -0
- data/lib/rubyang/logger.rb +19 -0
- data/lib/rubyang/model/parser/parser.tab.rb +919 -901
- data/lib/rubyang/model/parser/parser.y +9 -1
- data/lib/rubyang/model/parser.rb +48 -18
- data/lib/rubyang/model.rb +16 -1
- data/lib/rubyang/version.rb +1 -1
- data/lib/rubyang/xpath/parser/parser.tab.rb +561 -548
- data/lib/rubyang/xpath/parser/parser.y +74 -78
- data/lib/rubyang/xpath/parser.rb +12 -2
- data/lib/rubyang/xpath.rb +342 -105
- data/lib/rubyang.rb +1 -0
- data/rubyang.gemspec +2 -2
- metadata +8 -7
@@ -9,6 +9,59 @@ require_relative '../xpath'
|
|
9
9
|
module Rubyang
|
10
10
|
class Database
|
11
11
|
class SchemaTree
|
12
|
+
# when start
|
13
|
+
class When
|
14
|
+
attr_reader :arg, :xpath
|
15
|
+
def initialize schema_node, schema
|
16
|
+
@schema_node = schema_node
|
17
|
+
@schema = schema
|
18
|
+
@arg = schema.arg
|
19
|
+
@xpath = Rubyang::Xpath::Parser.parse @arg
|
20
|
+
require 'yaml'
|
21
|
+
puts ''
|
22
|
+
puts 'when xpath:'
|
23
|
+
puts @xpath.to_yaml
|
24
|
+
puts
|
25
|
+
@schema_node.evaluate_xpath @xpath
|
26
|
+
end
|
27
|
+
end
|
28
|
+
# end
|
29
|
+
|
30
|
+
# must start
|
31
|
+
class Must
|
32
|
+
attr_reader :arg, :xpath
|
33
|
+
def initialize schema_node, schema
|
34
|
+
@schema_node = schema_node
|
35
|
+
@schema = schema
|
36
|
+
@arg = schema.arg
|
37
|
+
@xpath = Rubyang::Xpath::Parser.parse @arg
|
38
|
+
@logger = Rubyang::Logger.instance
|
39
|
+
@logger.debug @xpath
|
40
|
+
@schema_node.evaluate_xpath @xpath
|
41
|
+
end
|
42
|
+
end
|
43
|
+
# end
|
44
|
+
|
45
|
+
# min-elements start
|
46
|
+
class MinElements
|
47
|
+
attr_reader :arg
|
48
|
+
def initialize schema_node
|
49
|
+
@schema_node = schema_node
|
50
|
+
@arg = schema_node.arg
|
51
|
+
end
|
52
|
+
end
|
53
|
+
# end
|
54
|
+
|
55
|
+
# max-elements start
|
56
|
+
class MaxElements
|
57
|
+
attr_reader :arg
|
58
|
+
def initialize schema_node
|
59
|
+
@schema_node = schema_node
|
60
|
+
@arg = schema_node.arg
|
61
|
+
end
|
62
|
+
end
|
63
|
+
# end
|
64
|
+
|
12
65
|
class Type
|
13
66
|
attr_reader :arg
|
14
67
|
end
|
@@ -36,6 +89,15 @@ module Rubyang
|
|
36
89
|
result
|
37
90
|
end
|
38
91
|
end
|
92
|
+
class Decimal64Type < Type
|
93
|
+
def initialize arg
|
94
|
+
@arg = arg
|
95
|
+
end
|
96
|
+
def valid? value
|
97
|
+
result = true
|
98
|
+
result
|
99
|
+
end
|
100
|
+
end
|
39
101
|
class StringType < Type
|
40
102
|
attr_reader :length, :pattern
|
41
103
|
def initialize
|
@@ -113,14 +175,13 @@ module Rubyang
|
|
113
175
|
end
|
114
176
|
end
|
115
177
|
class LeafrefType < Type
|
116
|
-
def initialize
|
178
|
+
def initialize schema_node, path_arg
|
117
179
|
@arg = 'leafref'
|
118
180
|
@path_arg = path_arg
|
119
|
-
@path = Path.new
|
181
|
+
@path = Path.new schema_node, path_arg
|
120
182
|
end
|
121
183
|
def path
|
122
|
-
@
|
123
|
-
@path.path
|
184
|
+
@path.xpath
|
124
185
|
end
|
125
186
|
def valid? data_tree, value
|
126
187
|
result = true
|
@@ -151,17 +212,39 @@ module Rubyang
|
|
151
212
|
result
|
152
213
|
end
|
153
214
|
end
|
215
|
+
class Identityref < Type
|
216
|
+
def initialize identity_list, type_stmt
|
217
|
+
@arg = 'identityref'
|
218
|
+
@base_arg = type_stmt.substmt( 'base' ).first.arg
|
219
|
+
@identity_list = identity_list
|
220
|
+
end
|
221
|
+
def valid? value
|
222
|
+
@identity_list.select{ |identity| (identity.substmt( 'base' ).first.arg rescue nil) == @base_arg }.any?{ |identity| identity.arg == value }
|
223
|
+
end
|
224
|
+
end
|
154
225
|
|
155
226
|
class Path
|
156
|
-
attr_reader :
|
227
|
+
attr_reader :xpath
|
157
228
|
|
158
|
-
def initialize
|
159
|
-
@
|
160
|
-
if !(@
|
161
|
-
raise "unsupported path: #{@
|
229
|
+
def initialize schema_node, arg
|
230
|
+
@xpath = Rubyang::Xpath::Parser.parse arg
|
231
|
+
#if !(@xpath[0].axis.name == Rubyang::Xpath::Axis::PARENT && @xpath[0].node_test.node_test == Rubyang::Xpath::NodeTest::NodeType::NODE)
|
232
|
+
#raise "unsupported path: #{@xpath}"
|
233
|
+
#end
|
234
|
+
if Rubyang::Xpath::Parser::DEBUG
|
235
|
+
require 'yaml'
|
236
|
+
puts
|
237
|
+
puts 'in Path:'
|
238
|
+
puts
|
239
|
+
puts 'schema_node:'
|
240
|
+
puts schema_node.to_yaml
|
241
|
+
puts
|
242
|
+
puts '@xpath:'
|
243
|
+
puts @xpath.to_yaml
|
244
|
+
puts
|
162
245
|
end
|
163
|
-
target =
|
164
|
-
if target.size == 0
|
246
|
+
target = schema_node.evaluate_xpath( @xpath )
|
247
|
+
if target.class != Array || target.size == 0
|
165
248
|
raise ArgumentError, "#{arg} is not valid"
|
166
249
|
end
|
167
250
|
@target = target
|
@@ -184,7 +267,7 @@ module Rubyang
|
|
184
267
|
end
|
185
268
|
def update arg
|
186
269
|
new_range = Array.new
|
187
|
-
arg.
|
270
|
+
arg.delete( ' ' ).split( '|' ).each{ |range_part|
|
188
271
|
case range_part
|
189
272
|
when /[^\.]+\.\.[^\.]+/
|
190
273
|
min, max = range_part.split('..')
|
@@ -227,7 +310,7 @@ module Rubyang
|
|
227
310
|
end
|
228
311
|
def update arg
|
229
312
|
new_length = Array.new
|
230
|
-
arg.
|
313
|
+
arg.delete( ' ' ).split( '|' ).each{ |length_part|
|
231
314
|
case length_part
|
232
315
|
when /[^\.]+\.\.[^\.]+/
|
233
316
|
min, max = length_part.split('..')
|
@@ -322,6 +405,18 @@ module Rubyang
|
|
322
405
|
@yang = yang
|
323
406
|
@parent = parent
|
324
407
|
@module = _module
|
408
|
+
@logger = Rubyang::Logger.instance
|
409
|
+
end
|
410
|
+
def to_s parent=true
|
411
|
+
head, vars, tail = "#<#{self.class.to_s}:0x#{(self.object_id << 1).to_s(16).rjust(14,'0')} ", Array.new, ">"
|
412
|
+
if parent
|
413
|
+
vars.push "@yangs=#{@yangs.to_s}"
|
414
|
+
vars.push "@arg=#{@arg.to_s}"
|
415
|
+
vars.push "@yang=#{@yang.to_s(false) rescue @yang.to_s}"
|
416
|
+
vars.push "@parent=#{@parent.to_s(false) rescue @parent.to_s}"
|
417
|
+
vars.push "@module=#{@module.to_s(false) rescue @module.to_s}"
|
418
|
+
end
|
419
|
+
head + vars.join(', ') + tail
|
325
420
|
end
|
326
421
|
def model
|
327
422
|
@yang
|
@@ -344,19 +439,95 @@ module Rubyang
|
|
344
439
|
self.to_json_recursive( h )
|
345
440
|
h.to_json
|
346
441
|
end
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
442
|
+
|
443
|
+
def evaluate_xpath xpath, current=self
|
444
|
+
if Rubyang::Xpath::Parser::DEBUG
|
445
|
+
require 'yaml'
|
446
|
+
puts
|
447
|
+
puts 'in evaluate_xpath:'
|
448
|
+
puts
|
449
|
+
puts 'xpath:'
|
450
|
+
puts xpath.to_yaml
|
451
|
+
puts
|
452
|
+
puts 'current:'
|
453
|
+
puts current.class
|
454
|
+
puts
|
455
|
+
end
|
456
|
+
evaluate_xpath_expr xpath, current
|
457
|
+
end
|
458
|
+
|
459
|
+
def evaluate_xpath_path location_path, current
|
460
|
+
if Rubyang::Xpath::Parser::DEBUG
|
461
|
+
require 'yaml'
|
462
|
+
puts
|
463
|
+
puts 'in evaluate_xpath_path:'
|
464
|
+
puts
|
465
|
+
puts 'location_path:'
|
466
|
+
puts location_path.to_yaml
|
467
|
+
puts
|
468
|
+
puts 'current:'
|
469
|
+
puts current.class
|
470
|
+
end
|
471
|
+
first_location_step = location_path.location_step_sequence.first
|
472
|
+
if Rubyang::Xpath::Parser::DEBUG
|
473
|
+
require 'yaml'
|
474
|
+
puts
|
475
|
+
puts 'first_location_step:'
|
476
|
+
puts first_location_step.to_yaml
|
477
|
+
end
|
478
|
+
candidates_by_axis = self.evaluate_xpath_axis( first_location_step, current )
|
479
|
+
if Rubyang::Xpath::Parser::DEBUG
|
480
|
+
require 'yaml'
|
481
|
+
puts
|
482
|
+
puts 'candidates_by_axis:'
|
483
|
+
puts candidates_by_axis.to_yaml
|
484
|
+
end
|
485
|
+
candidates_by_node_test = candidates_by_axis.inject([]){ |cs, c| cs + c.evaluate_xpath_node_test( first_location_step, current ) }
|
486
|
+
if Rubyang::Xpath::Parser::DEBUG
|
487
|
+
require 'yaml'
|
488
|
+
puts
|
489
|
+
puts 'candidates_by_node_test:'
|
490
|
+
puts candidates_by_node_test.to_yaml
|
491
|
+
end
|
492
|
+
candidates_by_predicates = candidates_by_node_test.inject([]){ |cs, c| cs + c.evaluate_xpath_predicates( first_location_step, current ) }
|
493
|
+
if Rubyang::Xpath::Parser::DEBUG
|
494
|
+
require 'yaml'
|
495
|
+
puts
|
496
|
+
puts 'candidates_by_predicates:'
|
497
|
+
puts candidates_by_predicates.to_yaml
|
498
|
+
end
|
499
|
+
if location_path.location_step_sequence[1..-1].size == 0
|
353
500
|
candidates_by_predicates
|
354
501
|
else
|
355
|
-
candidates_by_predicates.inject([]){ |cs, c|
|
502
|
+
candidates_by_predicates.inject([]){ |cs, c|
|
503
|
+
following_location_path = Rubyang::Xpath::LocationPath.new *(location_path.location_step_sequence[1..-1])
|
504
|
+
if Rubyang::Xpath::Parser::DEBUG
|
505
|
+
puts
|
506
|
+
puts 'following_location_path:'
|
507
|
+
puts following_location_path.to_yaml
|
508
|
+
puts
|
509
|
+
end
|
510
|
+
c.evaluate_xpath_path( following_location_path, current )
|
511
|
+
}
|
356
512
|
end
|
357
513
|
end
|
514
|
+
|
358
515
|
def evaluate_xpath_axis location_step, current
|
516
|
+
if Rubyang::Xpath::Parser::DEBUG
|
517
|
+
require 'yaml'
|
518
|
+
puts
|
519
|
+
puts 'in evaluate_xpath_axis:'
|
520
|
+
puts
|
521
|
+
puts 'location_step:'
|
522
|
+
puts location_step.to_yaml
|
523
|
+
puts
|
524
|
+
puts 'current:'
|
525
|
+
puts current.class
|
526
|
+
puts
|
527
|
+
end
|
359
528
|
case location_step.axis.name
|
529
|
+
when Rubyang::Xpath::Axis::SELF
|
530
|
+
[self]
|
360
531
|
when Rubyang::Xpath::Axis::PARENT
|
361
532
|
[@parent]
|
362
533
|
when Rubyang::Xpath::Axis::CHILD
|
@@ -365,6 +536,7 @@ module Rubyang
|
|
365
536
|
raise "location_step.axis.name: #{location_step.axis.name} NOT implemented"
|
366
537
|
end
|
367
538
|
end
|
539
|
+
|
368
540
|
def evaluate_xpath_node_test location_step, current
|
369
541
|
case location_step.node_test.node_test_type
|
370
542
|
when Rubyang::Xpath::NodeTest::NodeTestType::NAME_TEST
|
@@ -390,19 +562,31 @@ module Rubyang
|
|
390
562
|
raise ""
|
391
563
|
end
|
392
564
|
end
|
565
|
+
|
393
566
|
def evaluate_xpath_predicates location_step, current
|
394
567
|
case location_step.predicates.size
|
395
568
|
when 0
|
396
569
|
[self]
|
397
570
|
else
|
398
|
-
location_step.predicates.
|
399
|
-
self.
|
571
|
+
location_step.predicates.each{ |predicate|
|
572
|
+
self.evaluate_xpath_expr predicate.expr, current
|
400
573
|
}
|
574
|
+
[self]
|
401
575
|
end
|
402
576
|
end
|
403
|
-
|
577
|
+
|
578
|
+
def evaluate_xpath_expr expr, current
|
404
579
|
case expr
|
405
|
-
when Rubyang::Xpath::
|
580
|
+
when Rubyang::Xpath::Expr
|
581
|
+
if Rubyang::Xpath::Parser::DEBUG
|
582
|
+
puts
|
583
|
+
puts "in Expr"
|
584
|
+
puts "op: #{expr.op}"
|
585
|
+
puts
|
586
|
+
end
|
587
|
+
op = expr.op
|
588
|
+
op_result = self.evaluate_xpath_expr( op, current )
|
589
|
+
when Rubyang::Xpath::OrExpr
|
406
590
|
if Rubyang::Xpath::Parser::DEBUG
|
407
591
|
puts
|
408
592
|
puts "in OrExpr"
|
@@ -412,14 +596,14 @@ module Rubyang
|
|
412
596
|
end
|
413
597
|
op1 = expr.op1
|
414
598
|
op2 = expr.op2
|
415
|
-
op1_result = self.
|
599
|
+
op1_result = self.evaluate_xpath_expr( op1, current )
|
416
600
|
if op2 == nil
|
417
601
|
op1_result
|
418
602
|
else
|
419
|
-
op2_result = self.
|
420
|
-
|
603
|
+
op2_result = self.evaluate_xpath_expr( op2, current )
|
604
|
+
Rubyang::Xpath::BasicType::Boolean
|
421
605
|
end
|
422
|
-
when Rubyang::Xpath::
|
606
|
+
when Rubyang::Xpath::AndExpr
|
423
607
|
if Rubyang::Xpath::Parser::DEBUG
|
424
608
|
puts
|
425
609
|
puts "in AndExpr"
|
@@ -429,14 +613,14 @@ module Rubyang
|
|
429
613
|
end
|
430
614
|
op1 = expr.op1
|
431
615
|
op2 = expr.op2
|
432
|
-
op1_result = self.
|
616
|
+
op1_result = self.evaluate_xpath_expr( op1, current )
|
433
617
|
if op2 == nil
|
434
618
|
op1_result
|
435
619
|
else
|
436
|
-
op2_result = self.
|
437
|
-
|
620
|
+
op2_result = self.evaluate_xpath_expr( op2, current )
|
621
|
+
Rubyang::Xpath::BasicType::Boolean
|
438
622
|
end
|
439
|
-
when Rubyang::Xpath::
|
623
|
+
when Rubyang::Xpath::EqualityExpr
|
440
624
|
if Rubyang::Xpath::Parser::DEBUG
|
441
625
|
puts
|
442
626
|
puts "in EqualityExpr"
|
@@ -448,26 +632,14 @@ module Rubyang
|
|
448
632
|
op1 = expr.op1
|
449
633
|
op2 = expr.op2
|
450
634
|
operator = expr.operator
|
451
|
-
op1_result = self.
|
635
|
+
op1_result = self.evaluate_xpath_expr( op1, current )
|
452
636
|
if op2 == nil
|
453
637
|
op1_result
|
454
638
|
else
|
455
|
-
|
456
|
-
|
457
|
-
op2_result = self.evaluate_xpath_predicate_expr( op2, current )
|
458
|
-
if op1_result.size > 0 and op2_result.size >0
|
459
|
-
[self]
|
460
|
-
else
|
461
|
-
[]
|
462
|
-
end
|
463
|
-
#op1_result.select{ |a| op2_result.map{ |b| b.value }.include? a }
|
464
|
-
when /^\!\=$/
|
465
|
-
raise "Equality Expr: '!=' not implemented"
|
466
|
-
else
|
467
|
-
raise "Equality Expr: other than '=' and '!=' not implemented"
|
468
|
-
end
|
639
|
+
op2_result = self.evaluate_xpath_expr( op2, current )
|
640
|
+
Rubyang::Xpath::BasicType::Boolean
|
469
641
|
end
|
470
|
-
when Rubyang::Xpath::
|
642
|
+
when Rubyang::Xpath::RelationalExpr
|
471
643
|
if Rubyang::Xpath::Parser::DEBUG
|
472
644
|
puts
|
473
645
|
puts "in RelationalExpr"
|
@@ -479,24 +651,14 @@ module Rubyang
|
|
479
651
|
op1 = expr.op1
|
480
652
|
op2 = expr.op2
|
481
653
|
operator = expr.operator
|
482
|
-
op1_result = self.
|
654
|
+
op1_result = self.evaluate_xpath_expr( op1, current )
|
483
655
|
if op2 == nil
|
484
656
|
op1_result
|
485
657
|
else
|
486
|
-
|
487
|
-
|
488
|
-
raise "Relational Expr: '>' not implemented"
|
489
|
-
when /^\<$/
|
490
|
-
raise "Relational Expr: '<' not implemented"
|
491
|
-
when /^\>\=$/
|
492
|
-
raise "Relational Expr: '>=' not implemented"
|
493
|
-
when /^\<\=$/
|
494
|
-
raise "Relational Expr: '<=' not implemented"
|
495
|
-
else
|
496
|
-
raise "Relational Expr: other than '>', '<', '>=' and '<=' not implemented"
|
497
|
-
end
|
658
|
+
op2_result = self.evaluate_xpath_expr( op2, current )
|
659
|
+
Rubyang::Xpath::BasicType::Boolean
|
498
660
|
end
|
499
|
-
when Rubyang::Xpath::
|
661
|
+
when Rubyang::Xpath::AdditiveExpr
|
500
662
|
if Rubyang::Xpath::Parser::DEBUG
|
501
663
|
puts
|
502
664
|
puts "in AdditiveExpr"
|
@@ -508,20 +670,14 @@ module Rubyang
|
|
508
670
|
op1 = expr.op1
|
509
671
|
op2 = expr.op2
|
510
672
|
operator = expr.operator
|
511
|
-
op1_result = self.
|
673
|
+
op1_result = self.evaluate_xpath_expr( op1, current )
|
512
674
|
if op2 == nil
|
513
675
|
op1_result
|
514
676
|
else
|
515
|
-
|
516
|
-
|
517
|
-
raise "Additive Expr: '+' not implemented"
|
518
|
-
when /^\-$/
|
519
|
-
raise "Additive Expr: '-' not implemented"
|
520
|
-
else
|
521
|
-
raise "Additive Expr: other than '+' and '-' not implemented"
|
522
|
-
end
|
677
|
+
op2_result = self.evaluate_xpath_expr( op2, current )
|
678
|
+
Rubyang::Xpath::BasicType::Number
|
523
679
|
end
|
524
|
-
when Rubyang::Xpath::
|
680
|
+
when Rubyang::Xpath::MultiplicativeExpr
|
525
681
|
if Rubyang::Xpath::Parser::DEBUG
|
526
682
|
puts
|
527
683
|
puts "in MultiplicativeExpr"
|
@@ -533,20 +689,14 @@ module Rubyang
|
|
533
689
|
op1 = expr.op1
|
534
690
|
op2 = expr.op2
|
535
691
|
operator = expr.operator
|
536
|
-
op1_result = self.
|
692
|
+
op1_result = self.evaluate_xpath_expr( op1, current )
|
537
693
|
if op2 == nil
|
538
694
|
op1_result
|
539
695
|
else
|
540
|
-
|
541
|
-
|
542
|
-
raise "Multiplicative Expr: '*' not implemented"
|
543
|
-
when /^\/$/
|
544
|
-
raise "Multiplicative Expr: '/' not implemented"
|
545
|
-
else
|
546
|
-
raise "Multiplicative Expr: other than '*' and '/' not implemented"
|
547
|
-
end
|
696
|
+
op2_result = self.evaluate_xpath_expr( op2, current )
|
697
|
+
Rubyang::Xpath::BasicType::Number
|
548
698
|
end
|
549
|
-
when Rubyang::Xpath::
|
699
|
+
when Rubyang::Xpath::UnaryExpr
|
550
700
|
if Rubyang::Xpath::Parser::DEBUG
|
551
701
|
puts
|
552
702
|
puts "in UnaryExpr"
|
@@ -556,16 +706,13 @@ module Rubyang
|
|
556
706
|
end
|
557
707
|
op1 = expr.op1
|
558
708
|
operator = expr.operator
|
559
|
-
op1_result = self.
|
560
|
-
|
561
|
-
when nil
|
709
|
+
op1_result = self.evaluate_xpath_expr( op1, current )
|
710
|
+
if operator == nil
|
562
711
|
op1_result
|
563
|
-
when /^\-$/
|
564
|
-
raise "Unary Expr: '-' not implemented"
|
565
712
|
else
|
566
|
-
|
713
|
+
Rubyang::Xpath::BasicType::Number
|
567
714
|
end
|
568
|
-
when Rubyang::Xpath::
|
715
|
+
when Rubyang::Xpath::UnionExpr
|
569
716
|
if Rubyang::Xpath::Parser::DEBUG
|
570
717
|
puts
|
571
718
|
puts "in UnionExpr"
|
@@ -577,18 +724,14 @@ module Rubyang
|
|
577
724
|
op1 = expr.op1
|
578
725
|
op2 = expr.op2
|
579
726
|
operator = expr.operator
|
580
|
-
op1_result = self.
|
727
|
+
op1_result = self.evaluate_xpath_expr( op1, current )
|
581
728
|
if op2 == nil
|
582
729
|
op1_result
|
583
730
|
else
|
584
|
-
|
585
|
-
|
586
|
-
raise "Union Expr: '|' not implemented"
|
587
|
-
else
|
588
|
-
raise "Union Expr: other than '|' not implemented"
|
589
|
-
end
|
731
|
+
op2_result = self.evaluate_xpath_expr( op2, current )
|
732
|
+
Rubyang::Xpath::BasicType::NodeSet
|
590
733
|
end
|
591
|
-
when Rubyang::Xpath::
|
734
|
+
when Rubyang::Xpath::PathExpr
|
592
735
|
if Rubyang::Xpath::Parser::DEBUG
|
593
736
|
puts
|
594
737
|
puts "in PathExpr"
|
@@ -600,36 +743,21 @@ module Rubyang
|
|
600
743
|
op1 = expr.op1
|
601
744
|
op2 = expr.op2
|
602
745
|
operator = expr.operator
|
603
|
-
case op1
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
case op2
|
614
|
-
when Rubyang::Xpath::LocationSteps
|
615
|
-
if !(op2[0].axis.name == Rubyang::Xpath::Axis::PARENT &&
|
616
|
-
op2[0].node_test.node_test == Rubyang::Xpath::NodeTest::NodeType::NODE)
|
617
|
-
raise "unsupported path: #{op2}"
|
618
|
-
end
|
619
|
-
current.evaluate_xpath (op1_result + op2[1..-1]), current
|
620
|
-
else
|
621
|
-
raise "Path Expr: op1 is not LocationSteps"
|
622
|
-
end
|
623
|
-
when /^\/\/$/
|
624
|
-
raise "Path Expr: '//' not implemented"
|
625
|
-
else
|
626
|
-
raise "Path Expr: other than '/' and '//' not implemented"
|
627
|
-
end
|
628
|
-
end
|
746
|
+
op1_result = case op1
|
747
|
+
when Rubyang::Xpath::LocationPath
|
748
|
+
self.evaluate_xpath_path( op1, current )
|
749
|
+
when Rubyang::Xpath::FilterExpr
|
750
|
+
self.evaluate_xpath_expr( op1, current )
|
751
|
+
else
|
752
|
+
raise "PathExpr: #{op1} not supported"
|
753
|
+
end
|
754
|
+
if op2 == nil
|
755
|
+
op1_result
|
629
756
|
else
|
630
|
-
|
757
|
+
op2_result = self.evaluate_xpath_path( op2, current )
|
758
|
+
Rubyang::Xpath::BasicType::NodeSet
|
631
759
|
end
|
632
|
-
when Rubyang::Xpath::
|
760
|
+
when Rubyang::Xpath::FilterExpr
|
633
761
|
if Rubyang::Xpath::Parser::DEBUG
|
634
762
|
puts
|
635
763
|
puts "in FilterExpr"
|
@@ -639,14 +767,14 @@ module Rubyang
|
|
639
767
|
end
|
640
768
|
op1 = expr.op1
|
641
769
|
op2 = expr.op2
|
642
|
-
op1_result = self.
|
770
|
+
op1_result = self.evaluate_xpath_expr( op1, current )
|
643
771
|
if op2 == nil
|
644
772
|
op1_result
|
645
773
|
else
|
646
|
-
op2_result = self.
|
647
|
-
|
774
|
+
op2_result = self.evaluate_xpath_expr( op2.expr, current )
|
775
|
+
Rubyang::Xpath::BasicType::NodeSet
|
648
776
|
end
|
649
|
-
when Rubyang::Xpath::
|
777
|
+
when Rubyang::Xpath::PrimaryExpr
|
650
778
|
if Rubyang::Xpath::Parser::DEBUG
|
651
779
|
puts
|
652
780
|
puts "in PrimaryExpr"
|
@@ -655,16 +783,20 @@ module Rubyang
|
|
655
783
|
end
|
656
784
|
op1 = expr.op1
|
657
785
|
case op1
|
658
|
-
when Rubyang::Xpath::
|
659
|
-
|
660
|
-
when Rubyang::Xpath::
|
661
|
-
op1_result = self.
|
662
|
-
when
|
663
|
-
|
786
|
+
when Rubyang::Xpath::VariableReference
|
787
|
+
Rubyang::Xpath::BasicType::String
|
788
|
+
when Rubyang::Xpath::Expr
|
789
|
+
op1_result = self.evaluate_xpath_expr( op1, current )
|
790
|
+
when Rubyang::Xpath::Literal
|
791
|
+
Rubyang::Xpath::BasicType::String
|
792
|
+
when Rubyang::Xpath::Number
|
793
|
+
Rubyang::Xpath::BasicType::Boolean
|
794
|
+
when Rubyang::Xpath::FunctionCall
|
795
|
+
op1_result = self.evaluate_xpath_expr( op1, current )
|
664
796
|
else
|
665
|
-
raise "Primary Expr: '
|
797
|
+
raise "Primary Expr: '#{op1}' not implemented"
|
666
798
|
end
|
667
|
-
when Rubyang::Xpath::
|
799
|
+
when Rubyang::Xpath::FunctionCall
|
668
800
|
if Rubyang::Xpath::Parser::DEBUG
|
669
801
|
puts
|
670
802
|
puts "in FunctionCall"
|
@@ -674,145 +806,17 @@ module Rubyang
|
|
674
806
|
end
|
675
807
|
name = expr.name
|
676
808
|
case name
|
677
|
-
when Rubyang::Xpath::
|
678
|
-
Rubyang::Xpath::
|
809
|
+
when Rubyang::Xpath::FunctionCall::CURRENT
|
810
|
+
Rubyang::Xpath::BasicType::NodeSet
|
679
811
|
else
|
680
812
|
raise "FunctionCall: #{name} not implemented"
|
681
813
|
end
|
682
814
|
else
|
683
|
-
raise "Unrecognized
|
684
|
-
end
|
685
|
-
end
|
686
|
-
end
|
687
|
-
|
688
|
-
class InteriorSchemaNode < SchemaNode
|
689
|
-
attr_accessor :yangs, :arg, :yang, :parent, :children
|
690
|
-
|
691
|
-
def initialize yangs, arg, yang, parent, _module
|
692
|
-
super yangs, arg, yang, parent, _module
|
693
|
-
@children = []
|
694
|
-
end
|
695
|
-
|
696
|
-
def resolve_type type_stmt, yangs, current_module, typedef_list
|
697
|
-
case type_stmt.arg
|
698
|
-
when 'int8', 'int16', 'int32', 'int64', 'uint8', 'uint16', 'uint32', 'uint64'
|
699
|
-
type = IntegerType.new type_stmt.arg
|
700
|
-
type_stmt.substmts( Rubyang::Model::TypeBodyStmtList ).each{ |s|
|
701
|
-
case s
|
702
|
-
when Rubyang::Model::Range
|
703
|
-
type.update_range s.arg
|
704
|
-
else
|
705
|
-
raise ArgumentError, "#{s} is not valid"
|
706
|
-
end
|
707
|
-
}
|
708
|
-
when 'string'
|
709
|
-
type = StringType.new
|
710
|
-
type_stmt.substmts( Rubyang::Model::TypeBodyStmtList ).each{ |s|
|
711
|
-
case s
|
712
|
-
when Rubyang::Model::Length
|
713
|
-
type.update_length s.arg
|
714
|
-
when Rubyang::Model::Pattern
|
715
|
-
type.update_pattern s.arg
|
716
|
-
else
|
717
|
-
raise ArgumentError, "#{s} is not valid"
|
718
|
-
end
|
719
|
-
}
|
720
|
-
when 'boolean'
|
721
|
-
type = BooleanType.new
|
722
|
-
type_stmt.substmts( Rubyang::Model::TypeBodyStmtList ).each{ |s|
|
723
|
-
raise ArgumentError, "#{s} is not valid"
|
724
|
-
}
|
725
|
-
when 'enumeration'
|
726
|
-
type = EnumerationType.new
|
727
|
-
type_stmt.substmts( Rubyang::Model::TypeBodyStmtList ).each{ |s|
|
728
|
-
case s
|
729
|
-
when Rubyang::Model::Enum
|
730
|
-
type.update_enum s.arg
|
731
|
-
else
|
732
|
-
raise ArgumentError, "#{s} is not valid"
|
733
|
-
end
|
734
|
-
}
|
735
|
-
when 'bits'
|
736
|
-
type = BitsType.new
|
737
|
-
type_stmt.substmts( Rubyang::Model::TypeBodyStmtList ).each{ |s|
|
738
|
-
case s
|
739
|
-
when Rubyang::Model::Bit
|
740
|
-
type.update_bit s.arg
|
741
|
-
else
|
742
|
-
raise ArgumentError, "#{s} is not valid"
|
743
|
-
end
|
744
|
-
}
|
745
|
-
when 'binary'
|
746
|
-
type = BinaryType.new
|
747
|
-
type_stmt.substmts( Rubyang::Model::TypeBodyStmtList ).each{ |s|
|
748
|
-
case s
|
749
|
-
when Rubyang::Model::Length
|
750
|
-
type.update_length s.arg
|
751
|
-
else
|
752
|
-
raise ArgumentError, "#{s} is not valid"
|
753
|
-
end
|
754
|
-
}
|
755
|
-
when 'leafref'
|
756
|
-
type = LeafrefType.new self, type_stmt.substmt( 'path' )[0].arg
|
757
|
-
when 'empty'
|
758
|
-
type = EmptyType.new
|
759
|
-
when 'union'
|
760
|
-
type = UnionType.new
|
761
|
-
type_stmt.substmt( "type" ).each{ |s|
|
762
|
-
type.add_type( resolve_type s, yangs, current_module, typedef_list )
|
763
|
-
}
|
764
|
-
else
|
765
|
-
case type_stmt.arg
|
766
|
-
when /^[^:]+$/
|
767
|
-
arg = type_stmt.arg
|
768
|
-
if typedef_list.find{ |s| s.arg == arg }
|
769
|
-
typedef_stmt = typedef_list.find{ |s| s.arg == arg }
|
770
|
-
type = resolve_type typedef_stmt.substmt( 'type' )[0], yangs, current_module, typedef_list
|
771
|
-
else
|
772
|
-
include_submodule = current_module.substmt( 'include' ).map{ |s|
|
773
|
-
yangs.find{ |y| y.arg == s.arg }
|
774
|
-
}.find{ |s|
|
775
|
-
s.substmt( 'typedef' ).find{ |t| t.arg == arg }
|
776
|
-
}
|
777
|
-
typedef_stmt = include_submodule.substmt( 'typedef' ).find{ |s| s.arg == arg }
|
778
|
-
type = resolve_type typedef_stmt.substmt( 'type' )[0], yangs, include_submodule, include_submodule.substmt( 'typedef' )
|
779
|
-
end
|
780
|
-
when /^[^:]+:[^:]+$/
|
781
|
-
prefix, arg = type_stmt.arg.split(':')
|
782
|
-
case current_module
|
783
|
-
when Rubyang::Model::Module
|
784
|
-
case prefix
|
785
|
-
when current_module.substmt( 'prefix' )[0].arg
|
786
|
-
typedef_stmt = typedef_list.find{ |s| s.arg == arg }
|
787
|
-
type = resolve_type typedef_stmt.substmt( 'type' )[0], yangs, current_module, typedef_list
|
788
|
-
else
|
789
|
-
import_module = yangs.find{ |y|
|
790
|
-
y.arg == current_module.substmt( 'import' ).find{ |s| s.substmt( 'prefix' )[0].arg == prefix }.arg
|
791
|
-
}
|
792
|
-
typedef_stmt = import_module.substmt( 'typedef' ).find{ |s| s.arg == arg }
|
793
|
-
type = resolve_type typedef_stmt.substmt( 'type' )[0], yangs, import_module, import_module.substmt( 'typedef' )
|
794
|
-
end
|
795
|
-
when Rubyang::Model::Submodule
|
796
|
-
case prefix
|
797
|
-
when current_module.substmt( 'belongs-to' )[0].substmt( 'prefix' )[0].arg
|
798
|
-
typedef_stmt = typedef_list.find{ |s| s.arg == arg }
|
799
|
-
type = resolve_type typedef_stmt.substmt( 'type' )[0], yangs, current_module, typedef_list
|
800
|
-
else
|
801
|
-
import_module = yangs.find{ |y|
|
802
|
-
y.arg == current_module.substmt( 'import' ).find{ |s| s.substmt( 'prefix' )[0].arg == prefix }.arg
|
803
|
-
}
|
804
|
-
typedef_stmt = import_module.substmt( 'typedef' ).find{ |s| s.arg == arg }
|
805
|
-
type = resolve_type typedef_stmt.substmt( 'type' )[0], yangs, import_module, import_module.substmt( 'typedef' )
|
806
|
-
end
|
807
|
-
else
|
808
|
-
raise
|
809
|
-
end
|
810
|
-
end
|
815
|
+
raise "Unrecognized Expr: #{expr}"
|
811
816
|
end
|
812
|
-
type
|
813
817
|
end
|
814
818
|
|
815
|
-
def load_yang yang, yangs=@yangs, parent_module=yang, current_module=yang, grouping_list=[], typedef_list=[]
|
819
|
+
def load_yang yang, yangs=@yangs, parent_module=yang, current_module=yang, grouping_list=[], typedef_list=[], identity_list=[]
|
816
820
|
case yang
|
817
821
|
when Rubyang::Model::Module
|
818
822
|
yangs.push yang
|
@@ -821,47 +825,82 @@ module Rubyang
|
|
821
825
|
prefix_arg = yang.substmt( 'prefix' )[0].arg
|
822
826
|
grouping_list += yang.substmt( 'grouping' )
|
823
827
|
typedef_list += yang.substmt( 'typedef' )
|
828
|
+
identity_list += yang.substmt( 'identity' )
|
824
829
|
yang.substmt( 'include' ).each{ |i|
|
825
830
|
i.substmts( Rubyang::Model::DataDefStmtList ).each{ |s|
|
826
|
-
self.load_yang s, yangs, parent_module, i, i.substmt( 'grouping' ), i.substmt( 'typedef' )
|
831
|
+
self.load_yang s, yangs, parent_module, i, i.substmt( 'grouping' ), i.substmt( 'typedef' ), i.substmt( 'identity' )
|
827
832
|
}
|
828
833
|
}
|
829
834
|
yang.substmts( Rubyang::Model::DataDefStmtList ).each{ |s|
|
830
|
-
self.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list
|
835
|
+
self.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
831
836
|
}
|
832
837
|
when Rubyang::Model::Submodule
|
833
838
|
yangs.push yang
|
839
|
+
when Rubyang::Model::Anyxml
|
840
|
+
arg = yang.arg
|
841
|
+
self.children.push Anyxml.new( yangs, arg, yang, self, parent_module )
|
834
842
|
when Rubyang::Model::Container
|
835
843
|
container_arg = yang.arg
|
836
844
|
grouping_list += yang.substmt( 'grouping' )
|
837
845
|
typedef_list += yang.substmt( 'typedef' )
|
846
|
+
identity_list += yang.substmt( 'identity' )
|
838
847
|
self.children.push Container.new( yangs, container_arg, yang, self, parent_module )
|
848
|
+
# when start
|
849
|
+
yang.substmt( "when" ).each{ |s|
|
850
|
+
self.children.last.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
851
|
+
}
|
852
|
+
# end
|
853
|
+
# must start
|
854
|
+
yang.substmt( "must" ).each{ |s|
|
855
|
+
self.children.last.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
856
|
+
}
|
857
|
+
# end
|
839
858
|
yang.substmts( Rubyang::Model::DataDefStmtList ).each{ |s|
|
840
|
-
self.children.last.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list
|
859
|
+
self.children.last.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
841
860
|
}
|
842
861
|
when Rubyang::Model::Leaf
|
843
862
|
leaf_arg = yang.arg
|
844
|
-
|
845
|
-
self.children.push Leaf.new( yangs, leaf_arg, yang, self, parent_module, type )
|
863
|
+
self.children.push Leaf.new( yangs, leaf_arg, yang, self, parent_module, current_module, typedef_list, identity_list )
|
846
864
|
when Rubyang::Model::LeafList
|
847
865
|
leaf_arg = yang.arg
|
848
|
-
|
849
|
-
|
866
|
+
self.children.push LeafList.new( yangs, leaf_arg, yang, self, parent_module, current_module, typedef_list, identity_list )
|
867
|
+
# min-elements start
|
868
|
+
yang.substmt( "min-elements" ).each{ |s|
|
869
|
+
self.children.last.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
870
|
+
}
|
871
|
+
# end
|
872
|
+
# max-elements start
|
873
|
+
yang.substmt( "max-elements" ).each{ |s|
|
874
|
+
self.children.last.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
875
|
+
}
|
876
|
+
# end
|
850
877
|
when Rubyang::Model::List
|
851
878
|
list_arg = yang.arg
|
852
879
|
grouping_list += yang.substmt( 'grouping' )
|
853
880
|
typedef_list += yang.substmt( 'typedef' )
|
881
|
+
identity_list += yang.substmt( 'identity' )
|
854
882
|
self.children.push List.new( yangs, list_arg, yang, self, parent_module )
|
855
883
|
yang.substmts( Rubyang::Model::DataDefStmtList ).each{ |s|
|
856
|
-
self.children.last.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list
|
884
|
+
self.children.last.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
885
|
+
}
|
886
|
+
# min-elements start
|
887
|
+
yang.substmt( "min-elements" ).each{ |s|
|
888
|
+
self.children.last.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
857
889
|
}
|
890
|
+
# end
|
891
|
+
# max-elements start
|
892
|
+
yang.substmt( "max-elements" ).each{ |s|
|
893
|
+
self.children.last.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
894
|
+
}
|
895
|
+
# end
|
858
896
|
when Rubyang::Model::Choice
|
859
897
|
choice_arg = yang.arg
|
860
898
|
grouping_list += yang.substmt( 'grouping' )
|
861
899
|
typedef_list += yang.substmt( 'typedef' )
|
900
|
+
identity_list += yang.substmt( 'identity' )
|
862
901
|
self.children.push Choice.new( yangs, choice_arg, yang, self, parent_module )
|
863
902
|
yang.substmts( Rubyang::Model::DataDefStmtList ).each{ |s|
|
864
|
-
self.children.last.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list
|
903
|
+
self.children.last.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
865
904
|
}
|
866
905
|
when Rubyang::Model::Case
|
867
906
|
case_arg = yang.arg
|
@@ -869,19 +908,56 @@ module Rubyang
|
|
869
908
|
typedef_list += yang.substmt( 'typedef' )
|
870
909
|
self.children.push Case.new( yangs, case_arg, yang, self, parent_module )
|
871
910
|
yang.substmts( Rubyang::Model::DataDefStmtList ).each{ |s|
|
872
|
-
self.children.last.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list
|
911
|
+
self.children.last.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
873
912
|
}
|
874
913
|
when Rubyang::Model::Augment
|
875
914
|
target_node = self.resolve_node( yang.arg )
|
876
915
|
yang.substmts( Rubyang::Model::DataDefStmtList ).each{ |s|
|
877
|
-
target_node.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list
|
916
|
+
target_node.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
878
917
|
}
|
879
918
|
when Rubyang::Model::Uses
|
880
|
-
self.resolve_uses( yang, yangs, parent_module, current_module, grouping_list, typedef_list )
|
919
|
+
self.resolve_uses( yang, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list )
|
920
|
+
# when start
|
921
|
+
when Rubyang::Model::When
|
922
|
+
require 'yaml'
|
923
|
+
puts ''
|
924
|
+
puts 'when statement'
|
925
|
+
puts ''
|
926
|
+
puts 'yang'
|
927
|
+
puts yang.to_yaml
|
928
|
+
self.whens.push When.new( self, yang )
|
929
|
+
# end
|
930
|
+
# must start
|
931
|
+
when Rubyang::Model::Must
|
932
|
+
@logger.debug yang
|
933
|
+
self.musts.push Must.new( self, yang )
|
934
|
+
# end
|
935
|
+
# min-elements start
|
936
|
+
when Rubyang::Model::MinElements
|
937
|
+
@logger.debug yang
|
938
|
+
self.min_elements.push MinElements.new( yang )
|
939
|
+
# end
|
940
|
+
# max-elements start
|
941
|
+
when Rubyang::Model::MaxElements
|
942
|
+
@logger.debug yang
|
943
|
+
self.max_elements.push MaxElements.new( yang )
|
944
|
+
# end
|
945
|
+
else
|
946
|
+
raise "#{yang.class} is not impletented yet"
|
881
947
|
end
|
882
948
|
end
|
949
|
+
end
|
883
950
|
|
884
|
-
|
951
|
+
class InteriorSchemaNode < SchemaNode
|
952
|
+
attr_accessor :yangs, :arg, :yang, :parent, :children
|
953
|
+
|
954
|
+
def initialize yangs, arg, yang, parent, _module
|
955
|
+
super yangs, arg, yang, parent, _module
|
956
|
+
@children = []
|
957
|
+
@logger = Rubyang::Logger.instance
|
958
|
+
end
|
959
|
+
|
960
|
+
def resolve_uses uses_stmt, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
885
961
|
case uses_stmt.arg
|
886
962
|
when /^[^:]+$/
|
887
963
|
arg = uses_stmt.arg
|
@@ -889,8 +965,9 @@ module Rubyang
|
|
889
965
|
grouping_stmt = grouping_list.find{ |s| s.arg == arg }
|
890
966
|
grouping_list += grouping_stmt.substmt( 'grouping' )
|
891
967
|
typedef_list += grouping_stmt.substmt( 'typedef' )
|
968
|
+
identity_list += grouping_stmt.substmt( 'identity' )
|
892
969
|
grouping_stmt.substmts( Rubyang::Model::DataDefStmtList ).each{ |s|
|
893
|
-
self.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list
|
970
|
+
self.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
894
971
|
}
|
895
972
|
else
|
896
973
|
include_submodule = current_module.substmt( 'include' ).map{ |s|
|
@@ -901,8 +978,9 @@ module Rubyang
|
|
901
978
|
grouping_stmt = include_submodule.substmt( 'grouping' ).find{ |s| s.arg == arg }
|
902
979
|
grouping_list = include_submodule.substmt( 'grouping' ) + grouping_stmt.substmt( 'grouping' )
|
903
980
|
typedef_list = include_submodule.substmt( 'typedef' ) + grouping_stmt.substmt( 'typedef' )
|
981
|
+
identity_list = include_submodule.substmt( 'identity' ) + grouping_stmt.substmt( 'identity' )
|
904
982
|
grouping_stmt.substmt( Rubyang::Model::DataDefStmtList ).each{ |s|
|
905
|
-
self.load_yang s, yangs, parent_module, include_submodule, grouping_list, typedef_list
|
983
|
+
self.load_yang s, yangs, parent_module, include_submodule, grouping_list, typedef_list, identity_list
|
906
984
|
}
|
907
985
|
end
|
908
986
|
when /^[^:]+:[^:]+$/
|
@@ -914,8 +992,9 @@ module Rubyang
|
|
914
992
|
grouping_stmt = grouping_list.find{ |s| s.arg == arg }
|
915
993
|
grouping_list += grouping_stmt.substmt( 'grouping' )
|
916
994
|
typedef_list += grouping_stmt.substmt( 'typedef' )
|
995
|
+
identity_list += grouping_stmt.substmt( 'identity' )
|
917
996
|
grouping_stmt.substmts( Rubyang::Model::DataDefStmtList ).each{ |s|
|
918
|
-
self.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list
|
997
|
+
self.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
919
998
|
}
|
920
999
|
else
|
921
1000
|
import_module = yangs.find{ |y|
|
@@ -924,8 +1003,9 @@ module Rubyang
|
|
924
1003
|
grouping_stmt = import_module.substmt( 'grouping' ).find{ |s| s.arg == arg }
|
925
1004
|
grouping_list = import_module.substmt( 'grouping' ) + grouping_stmt.substmt( 'grouping' )
|
926
1005
|
typedef_list = import_module.substmt( 'typedef' ) + grouping_stmt.substmt( 'typedef' )
|
1006
|
+
identity_list = import_module.substmt( 'identity' ) + grouping_stmt.substmt( 'identity' )
|
927
1007
|
grouping_stmt.substmts( Rubyang::Model::DataDefStmtList ).each{ |s|
|
928
|
-
self.load_yang s, yangs, parent_module, import_module, grouping_list, typedef_list
|
1008
|
+
self.load_yang s, yangs, parent_module, import_module, grouping_list, typedef_list, identity_list
|
929
1009
|
}
|
930
1010
|
end
|
931
1011
|
when Rubyang::Model::Submodule
|
@@ -934,8 +1014,9 @@ module Rubyang
|
|
934
1014
|
grouping_stmt = grouping_list.find{ |s| s.arg == arg }
|
935
1015
|
grouping_list += grouping_stmt.substmt( 'grouping' )
|
936
1016
|
typedef_list += grouping_stmt.substmt( 'typedef' )
|
1017
|
+
identity_list += grouping_stmt.substmt( 'identity' )
|
937
1018
|
grouping_stmt.substmts( Rubyang::Model::DataDefStmtList ).each{ |s|
|
938
|
-
self.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list
|
1019
|
+
self.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
939
1020
|
}
|
940
1021
|
else
|
941
1022
|
import_module = yangs.find{ |y|
|
@@ -944,8 +1025,9 @@ module Rubyang
|
|
944
1025
|
grouping_stmt = import_module.substmt( 'grouping' ).find{ |s| s.arg == arg }
|
945
1026
|
grouping_list = import_module.substmt( 'grouping' ) + grouping_stmt.substmt( 'grouping' )
|
946
1027
|
typedef_list = import_module.substmt( 'typedef' ) + grouping_stmt.substmt( 'typedef' )
|
1028
|
+
identity_list = import_module.substmt( 'identity' ) + grouping_stmt.substmt( 'identity' )
|
947
1029
|
grouping_stmt.substmts( Rubyang::Model::DataDefStmtList ).each{ |s|
|
948
|
-
self.load_yang s, yangs, parent_module, import_module, grouping_list, typedef_list
|
1030
|
+
self.load_yang s, yangs, parent_module, import_module, grouping_list, typedef_list, identity_list
|
949
1031
|
}
|
950
1032
|
end
|
951
1033
|
else
|
@@ -960,6 +1042,8 @@ module Rubyang
|
|
960
1042
|
self
|
961
1043
|
when '..'
|
962
1044
|
self
|
1045
|
+
when /[^:]+:[^:]+/
|
1046
|
+
@children.find{ |c| [c.prefix, c.model.arg].join(':') == path_splitted.first }
|
963
1047
|
else
|
964
1048
|
@children.find{ |c| c.model.arg == path_splitted.first }
|
965
1049
|
end
|
@@ -972,14 +1056,138 @@ module Rubyang
|
|
972
1056
|
end
|
973
1057
|
|
974
1058
|
class LeafSchemaNode < SchemaNode
|
975
|
-
attr_reader :yangs, :arg, :yang, :parent, :module, :
|
976
|
-
def initialize yangs, arg, yang, parent, _module,
|
1059
|
+
attr_reader :yangs, :arg, :yang, :parent, :module, :current_module, :typedef_list, :identity_list
|
1060
|
+
def initialize yangs, arg, yang, parent, _module, current_module, typedef_list, identity_list
|
977
1061
|
super yangs, arg, yang, parent, _module
|
978
|
-
@type = type
|
1062
|
+
@type = self.resolve_type yang.substmt( 'type' )[0], yangs, current_module, typedef_list, identity_list
|
979
1063
|
end
|
1064
|
+
|
980
1065
|
def type
|
981
1066
|
@type
|
982
1067
|
end
|
1068
|
+
|
1069
|
+
def resolve_type type_stmt, yangs, current_module, typedef_list, identity_list
|
1070
|
+
case type_stmt.arg
|
1071
|
+
when 'int8', 'int16', 'int32', 'int64', 'uint8', 'uint16', 'uint32', 'uint64'
|
1072
|
+
type = IntegerType.new type_stmt.arg
|
1073
|
+
type_stmt.substmts( Rubyang::Model::TypeBodyStmtList ).each{ |s|
|
1074
|
+
case s
|
1075
|
+
when Rubyang::Model::Range
|
1076
|
+
type.update_range s.arg
|
1077
|
+
else
|
1078
|
+
raise ArgumentError, "#{s} is not valid"
|
1079
|
+
end
|
1080
|
+
}
|
1081
|
+
when 'decimal64'
|
1082
|
+
type = Decimal64Type.new type_stmt.arg
|
1083
|
+
when 'string'
|
1084
|
+
type = StringType.new
|
1085
|
+
type_stmt.substmts( Rubyang::Model::TypeBodyStmtList ).each{ |s|
|
1086
|
+
case s
|
1087
|
+
when Rubyang::Model::Length
|
1088
|
+
type.update_length s.arg
|
1089
|
+
when Rubyang::Model::Pattern
|
1090
|
+
type.update_pattern s.arg
|
1091
|
+
else
|
1092
|
+
raise ArgumentError, "#{s} is not valid"
|
1093
|
+
end
|
1094
|
+
}
|
1095
|
+
when 'boolean'
|
1096
|
+
type = BooleanType.new
|
1097
|
+
type_stmt.substmts( Rubyang::Model::TypeBodyStmtList ).each{ |s|
|
1098
|
+
raise ArgumentError, "#{s} is not valid"
|
1099
|
+
}
|
1100
|
+
when 'enumeration'
|
1101
|
+
type = EnumerationType.new
|
1102
|
+
type_stmt.substmts( Rubyang::Model::TypeBodyStmtList ).each{ |s|
|
1103
|
+
case s
|
1104
|
+
when Rubyang::Model::Enum
|
1105
|
+
type.update_enum s.arg
|
1106
|
+
else
|
1107
|
+
raise ArgumentError, "#{s} is not valid"
|
1108
|
+
end
|
1109
|
+
}
|
1110
|
+
when 'bits'
|
1111
|
+
type = BitsType.new
|
1112
|
+
type_stmt.substmts( Rubyang::Model::TypeBodyStmtList ).each{ |s|
|
1113
|
+
case s
|
1114
|
+
when Rubyang::Model::Bit
|
1115
|
+
type.update_bit s.arg
|
1116
|
+
else
|
1117
|
+
raise ArgumentError, "#{s} is not valid"
|
1118
|
+
end
|
1119
|
+
}
|
1120
|
+
when 'binary'
|
1121
|
+
type = BinaryType.new
|
1122
|
+
type_stmt.substmts( Rubyang::Model::TypeBodyStmtList ).each{ |s|
|
1123
|
+
case s
|
1124
|
+
when Rubyang::Model::Length
|
1125
|
+
type.update_length s.arg
|
1126
|
+
else
|
1127
|
+
raise ArgumentError, "#{s} is not valid"
|
1128
|
+
end
|
1129
|
+
}
|
1130
|
+
when 'leafref'
|
1131
|
+
type = LeafrefType.new self, type_stmt.substmt( 'path' )[0].arg
|
1132
|
+
when 'empty'
|
1133
|
+
type = EmptyType.new
|
1134
|
+
when 'union'
|
1135
|
+
type = UnionType.new
|
1136
|
+
type_stmt.substmt( "type" ).each{ |s|
|
1137
|
+
type.add_type( resolve_type s, yangs, current_module, typedef_list, identity_list )
|
1138
|
+
}
|
1139
|
+
when 'identityref'
|
1140
|
+
type = Identityref.new identity_list, type_stmt
|
1141
|
+
else
|
1142
|
+
case type_stmt.arg
|
1143
|
+
when /^[^:]+$/
|
1144
|
+
arg = type_stmt.arg
|
1145
|
+
if typedef_list.find{ |s| s.arg == arg }
|
1146
|
+
typedef_stmt = typedef_list.find{ |s| s.arg == arg }
|
1147
|
+
type = resolve_type typedef_stmt.substmt( 'type' )[0], yangs, current_module, typedef_list, identity_list
|
1148
|
+
else
|
1149
|
+
include_submodule = current_module.substmt( 'include' ).map{ |s|
|
1150
|
+
yangs.find{ |y| y.arg == s.arg }
|
1151
|
+
}.find{ |s|
|
1152
|
+
s.substmt( 'typedef' ).find{ |t| t.arg == arg }
|
1153
|
+
}
|
1154
|
+
typedef_stmt = include_submodule.substmt( 'typedef' ).find{ |s| s.arg == arg }
|
1155
|
+
type = resolve_type typedef_stmt.substmt( 'type' )[0], yangs, include_submodule, include_submodule.substmt( 'typedef' ), include_submodule.substmt( 'identity' )
|
1156
|
+
end
|
1157
|
+
when /^[^:]+:[^:]+$/
|
1158
|
+
prefix, arg = type_stmt.arg.split(':')
|
1159
|
+
case current_module
|
1160
|
+
when Rubyang::Model::Module
|
1161
|
+
case prefix
|
1162
|
+
when current_module.substmt( 'prefix' )[0].arg
|
1163
|
+
typedef_stmt = typedef_list.find{ |s| s.arg == arg }
|
1164
|
+
type = resolve_type typedef_stmt.substmt( 'type' )[0], yangs, current_module, typedef_list, identity_list
|
1165
|
+
else
|
1166
|
+
import_module = yangs.find{ |y|
|
1167
|
+
y.arg == current_module.substmt( 'import' ).find{ |s| s.substmt( 'prefix' )[0].arg == prefix }.arg
|
1168
|
+
}
|
1169
|
+
typedef_stmt = import_module.substmt( 'typedef' ).find{ |s| s.arg == arg }
|
1170
|
+
type = resolve_type typedef_stmt.substmt( 'type' )[0], yangs, import_module, import_module.substmt( 'typedef' ), import_module.substmt( 'identity' )
|
1171
|
+
end
|
1172
|
+
when Rubyang::Model::Submodule
|
1173
|
+
case prefix
|
1174
|
+
when current_module.substmt( 'belongs-to' )[0].substmt( 'prefix' )[0].arg
|
1175
|
+
typedef_stmt = typedef_list.find{ |s| s.arg == arg }
|
1176
|
+
type = resolve_type typedef_stmt.substmt( 'type' )[0], yangs, current_module, typedef_list, identity_list
|
1177
|
+
else
|
1178
|
+
import_module = yangs.find{ |y|
|
1179
|
+
y.arg == current_module.substmt( 'import' ).find{ |s| s.substmt( 'prefix' )[0].arg == prefix }.arg
|
1180
|
+
}
|
1181
|
+
typedef_stmt = import_module.substmt( 'typedef' ).find{ |s| s.arg == arg }
|
1182
|
+
type = resolve_type typedef_stmt.substmt( 'type' )[0], yangs, import_module, import_module.substmt( 'typedef' ), import_module.substmt( 'identity' )
|
1183
|
+
end
|
1184
|
+
else
|
1185
|
+
raise
|
1186
|
+
end
|
1187
|
+
end
|
1188
|
+
end
|
1189
|
+
type
|
1190
|
+
end
|
983
1191
|
end
|
984
1192
|
|
985
1193
|
class Root < InteriorSchemaNode
|
@@ -1000,7 +1208,20 @@ module Rubyang
|
|
1000
1208
|
end
|
1001
1209
|
end
|
1002
1210
|
|
1211
|
+
class Anyxml < SchemaNode
|
1212
|
+
def initialize *args
|
1213
|
+
super
|
1214
|
+
@logger = Rubyang::Logger.instance
|
1215
|
+
end
|
1216
|
+
end
|
1217
|
+
|
1003
1218
|
class Container < InteriorSchemaNode
|
1219
|
+
attr_accessor :whens, :musts
|
1220
|
+
def initialize *args
|
1221
|
+
super
|
1222
|
+
@whens = []
|
1223
|
+
@musts = []
|
1224
|
+
end
|
1004
1225
|
def to_json_recursive h
|
1005
1226
|
h['type'] = 'container'
|
1006
1227
|
h['arg'] = @arg
|
@@ -1030,12 +1251,33 @@ module Rubyang
|
|
1030
1251
|
end
|
1031
1252
|
|
1032
1253
|
class List < InteriorSchemaNode
|
1254
|
+
# min-elements start
|
1255
|
+
# max-elements start
|
1256
|
+
attr_reader :min_elements, :max_elements
|
1257
|
+
def initialize *args
|
1258
|
+
super
|
1259
|
+
@min_elements = []
|
1260
|
+
@max_elements = []
|
1261
|
+
end
|
1262
|
+
# end
|
1263
|
+
# end
|
1264
|
+
|
1033
1265
|
def keys
|
1034
1266
|
@yang.substmt( 'key' )[0].arg.split( /[ \t]+/ )
|
1035
1267
|
end
|
1036
1268
|
end
|
1037
1269
|
|
1038
1270
|
class LeafList < LeafSchemaNode
|
1271
|
+
# min-elements start
|
1272
|
+
# max-elements start
|
1273
|
+
attr_reader :min_elements, :max_elements
|
1274
|
+
def initialize *args
|
1275
|
+
super
|
1276
|
+
@min_elements = []
|
1277
|
+
@max_elements = []
|
1278
|
+
end
|
1279
|
+
# end
|
1280
|
+
# end
|
1039
1281
|
end
|
1040
1282
|
|
1041
1283
|
class Choice < InteriorSchemaNode
|
@@ -1052,13 +1294,19 @@ module Rubyang
|
|
1052
1294
|
end
|
1053
1295
|
class Notification < SchemaNode
|
1054
1296
|
end
|
1055
|
-
class Anyxml < SchemaNode
|
1056
|
-
end
|
1057
1297
|
|
1058
1298
|
def initialize yangs
|
1059
1299
|
@yangs = yangs
|
1060
1300
|
@root = Root.new @yangs
|
1061
1301
|
end
|
1302
|
+
def to_s parent=true
|
1303
|
+
head, vars, tail = "#<#{self.class.to_s}:0x#{(self.object_id << 1).to_s(16).rjust(14,'0')} ", Array.new, ">"
|
1304
|
+
if parent
|
1305
|
+
vars.push "@yangs=#{@yangs.to_s}"
|
1306
|
+
vars.push "@root=#{@root.to_s( false )}"
|
1307
|
+
end
|
1308
|
+
head + vars.join(', ') + tail
|
1309
|
+
end
|
1062
1310
|
def root
|
1063
1311
|
@root
|
1064
1312
|
end
|