junoser 0.7.6 → 0.8.0

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/junoser/ruler.rb CHANGED
@@ -166,7 +166,7 @@ module Junoser
166
166
 
167
167
  str.gsub! '"any" | "any-ipv4" | "any-ipv6"', '"any-ipv4" | "any-ipv6" | "any"'
168
168
 
169
- # Fix overkill
169
+ # Fix overkill
170
170
  str.gsub!(/^(\s*)"priority" \(\s*ca\(\s*arg\s*\)/) do
171
171
  fmt(['"priority" (',
172
172
  ' a(arg, arg)', $1])
@@ -219,8 +219,8 @@ module Junoser
219
219
  # Fix .xsd: Elements without "nokeyword" flag
220
220
  #
221
221
  str.gsub!(/\((.*) \| "name"\)/) { "(#{$1} | arg)" }
222
+ str.gsub!(/\("name" \| (.*?)\)/) { "(#{$1} | arg)" }
222
223
  str.gsub! '"vlan" ("all" | "vlan-name")', '"vlan" ("all" | arg)'
223
- str.gsub!(/\((.*) \| "vlan-id"\)/) { "(#{$1} | arg)" }
224
224
 
225
225
  %w[filename].each do |key|
226
226
  str.gsub! %("#{key}" arg), 'arg'
@@ -297,6 +297,12 @@ module Junoser
297
297
  str.gsub!(/^(\s*)\)(,\s*"fpc" enum\(\("all" \| "fpc-slot-number"\)\) \(\s*)c\((.*"lldp-priority"\s*\)\s*\))/m) do
298
298
  "#{$1}).as(:oneline)#{$2}sc(#{$3}.as(:oneline)"
299
299
  end
300
+ str.gsub! '"fpc" enum(("all" | "fpc-slot-number"))', '"fpc" ("all" | arg)'
301
+
302
+ # Fix .xsd: slot numbers in "set chassis alarm fru-absence ignore fpc xxx pem xxx"
303
+ # these must come after the "poe" section above, which matches "fpc" enum(("all" | "fpc-slot-number"))
304
+ str.gsub! '("all" | "fpc-slot-number")', '("all" | arg)'
305
+ str.gsub! '("all" | "psu-slot-number")', '("all" | arg)'
300
306
 
301
307
  # Fix .xsd: support "set protocols iccp peer xxx liveness-detection single-hop"
302
308
  str.gsub!(/(^rule\(:peer_group\) do.*?\n(\s*)"detection-time" \(\s*c\(\s*"threshold" arg\s*\)\s*\))/m) do
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Junoser
4
- VERSION = '0.7.6'
4
+ VERSION = '0.8.0'
5
5
  end
@@ -40,13 +40,13 @@ module Junoser
40
40
  @oneliner ||= !xml.xpath('./xsd:annotation/xsd:appinfo/*[local-name()="flag" and text()="oneliner"]').empty?
41
41
  end
42
42
 
43
- private
44
-
45
43
  def nokeyword?
46
44
  # don't use "/flag" as xsd manipulation automatically add "xsd:" prefix
47
45
  @nokeyword ||= !xml.xpath('./xsd:annotation/xsd:appinfo/*[local-name()="flag" and text()="nokeyword"]').empty?
48
46
  end
49
47
 
48
+ private
49
+
50
50
  def has_single_child_of?(klass) # rubocop:disable Naming/PredicatePrefix
51
51
  config.size == 1 && config.first.is_a?(klass)
52
52
  end
@@ -25,15 +25,38 @@ module Junoser
25
25
  if config.empty?
26
26
  ''
27
27
  elsif has_single_child_of?(Junoser::Xsd::Choice)
28
- fmt('c(', config.first.config.map(&:to_s).join(",\n"), ')')
28
+ child = config.first
29
+ str = join(child.config)
30
+ return '' if str.empty?
31
+
32
+ child.sequential_arguments? ? fmt('s(', str, ')') : fmt('c(', str, ')')
33
+ elsif sequential_arguments?
34
+ fmt('s(', join(config), ')')
29
35
  else
30
- fmt('c(', config.map(&:to_s).join(",\n"), ')')
36
+ fmt('c(', join(config), ')')
31
37
  end
32
38
  end
33
39
 
34
40
  def unbounded?
35
41
  xml['maxOccurs'] == 'unbounded'
36
42
  end
43
+
44
+ # xsd describes a sequence of positional arguments as an unbounded choice of
45
+ # "nokeyword" elements, eg. "priority <setup-priority> <reservation-priority>".
46
+ def sequential_arguments?
47
+ # a bounded choice means one of the arguments, which is a single argument
48
+ unbounded? && config.size > 1 &&
49
+ # Strictly, a sequence should cover the arguments only, eg. c("foo", s(arg, arg)).
50
+ # In .xsd, however, such a choice always has arguments only, so all? is enough.
51
+ config.all? { |c| c.is_a?(Junoser::Xsd::Element) && c.nokeyword? }
52
+ end
53
+
54
+ private
55
+
56
+ # drop a child that renders as an empty string, because an empty operand breaks the generated parser
57
+ def join(children)
58
+ children.map(&:to_s).reject(&:empty?).join(",\n")
59
+ end
37
60
  end
38
61
  end
39
62
  end
@@ -35,7 +35,9 @@ module Junoser
35
35
  return if str.empty?
36
36
 
37
37
  # Assuming that <xsd:sequence> always has <xsd:complexType> as the parent
38
- if parent.parent&.oneliner? && config.first.unbounded?
38
+ if child.sequential_arguments?
39
+ fmt('s(', str, ')')
40
+ elsif parent.parent&.oneliner? && child.unbounded?
39
41
  fmt('sc(', str, ')')
40
42
  else
41
43
  fmt('c(', str, ')')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: junoser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.6
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shintaro Kojima