junoser 0.7.2 → 0.7.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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/Gemfile +10 -0
  4. data/Gemfile.lock +36 -6
  5. data/Rakefile +6 -3
  6. data/bin/console +4 -3
  7. data/exe/junoser +6 -5
  8. data/exe/junoser-squash +9 -6
  9. data/junoser.gemspec +15 -17
  10. data/lib/junoser/cli.rb +2 -2
  11. data/lib/junoser/development.rb +2 -0
  12. data/lib/junoser/display/config_store.rb +12 -12
  13. data/lib/junoser/display/enumerable.rb +6 -4
  14. data/lib/junoser/display/set.rb +15 -17
  15. data/lib/junoser/display/structure.rb +7 -7
  16. data/lib/junoser/display.rb +2 -0
  17. data/lib/junoser/input.rb +11 -10
  18. data/lib/junoser/js_ruler.rb +74 -66
  19. data/lib/junoser/parser.rb +156 -0
  20. data/lib/junoser/rule_tree/node.rb +3 -1
  21. data/lib/junoser/rule_tree/parser.rb +11 -8
  22. data/lib/junoser/rule_tree.rb +2 -0
  23. data/lib/junoser/ruler.rb +190 -170
  24. data/lib/junoser/squash.rb +16 -14
  25. data/lib/junoser/transformer.rb +9 -8
  26. data/lib/junoser/version.rb +3 -1
  27. data/lib/junoser/xsd/base.rb +15 -14
  28. data/lib/junoser/xsd/choice.rb +10 -9
  29. data/lib/junoser/xsd/complex_type.rb +13 -11
  30. data/lib/junoser/xsd/element.rb +34 -36
  31. data/lib/junoser/xsd/enumeration.rb +9 -8
  32. data/lib/junoser/xsd/parsable.rb +2 -0
  33. data/lib/junoser/xsd/restriction.rb +15 -13
  34. data/lib/junoser/xsd/sequence.rb +11 -8
  35. data/lib/junoser/xsd/simple_content.rb +6 -4
  36. data/lib/junoser/xsd/simple_type.rb +7 -5
  37. data/lib/junoser/xsd/union.rb +6 -4
  38. data/lib/junoser.rb +2 -0
  39. data/lib/underscorable.rb +10 -5
  40. metadata +5 -65
  41. data/.github/dependabot.yml +0 -6
  42. data/.github/workflows/test-linux.yaml +0 -30
  43. data/.gitignore +0 -11
  44. data/.pre-commit-config.yaml +0 -7
  45. data/commitlint.config.js +0 -6
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Style/PerlBackrefs -- to simplify
4
+
1
5
  module Junoser
2
6
  class JsRuler
3
-
4
7
  def initialize(input)
5
8
  @rule = input
6
9
  @sequence = 0
@@ -11,15 +14,15 @@ module Junoser
11
14
  end
12
15
 
13
16
  def to_rule
14
- rule_header << rule.gsub(/^/, ' ') << rule_footer
17
+ +rule_header << rule.gsub(/^/, ' ') << rule_footer
15
18
  end
16
19
 
17
20
  def rule
18
21
  str = @rule.read
19
22
  str = process_lines(str)
20
- str = str.split(/\n/).map { |l|
23
+ str = str.split("\n").map do |l|
21
24
  process_line(l) unless l =~ /^ *#/ # Skip additional comment lines
22
- }.compact.join("\n")
25
+ end.compact.join("\n")
23
26
  finalize(str)
24
27
  end
25
28
 
@@ -27,7 +30,7 @@ module Junoser
27
30
 
28
31
  def process_lines(str)
29
32
  # set groups
30
- str.gsub! /"groups" \(.*\s*s\(\s*any\s*\)\s*\)/, <<-EOS.strip
33
+ str.gsub!(/"groups" \(.*\s*s\(\s*any\s*\)\s*\)/, <<-REPLACE.strip)
31
34
  "groups" arg ( /* Configuration groups */
32
35
  c(
33
36
  this.configuration({ groups: false }),
@@ -47,7 +50,7 @@ module Junoser
47
50
  )
48
51
  )
49
52
  )
50
- EOS
53
+ REPLACE
51
54
 
52
55
  # set protocols mpls path
53
56
  str.gsub!(/("path" arg \(.*Route of a label-switched path.*)(\s*)c\(/) do
@@ -56,7 +59,7 @@ module Junoser
56
59
 
57
60
  # set protocols iccp peer xxx liveness-detection single-hop
58
61
  str.gsub!(/(^rule\(:peer_group\) do.*?\n(\s*)"detection-time" \(.*?c\(\s*"threshold" arg .*?\)\s*\))/m) do
59
- "#{$1},\n#{format('"single-hop"', $2)}"
62
+ %(#{$1},\n#{$2}"single-hop")
60
63
  end
61
64
 
62
65
  # set forwarding-options dhcp-relay server-group
@@ -66,7 +69,7 @@ module Junoser
66
69
 
67
70
  # set interfaces xxx enable
68
71
  str.gsub!(/^(rule\(:interfaces_type\) do\s*[^\n]*\s*c\()(\s*)/m) do
69
- %[#{$1}#{$2}"enable",#{$2}]
72
+ %(#{$1}#{$2}"enable",#{$2})
70
73
  end
71
74
 
72
75
  str
@@ -79,30 +82,28 @@ module Junoser
79
82
  str = process_structural_syntax(str)
80
83
  str = process_word(str)
81
84
  str = process_reserved_word(str)
82
- str = process_comment(str)
83
-
84
- str
85
+ process_comment(str)
85
86
  end
86
87
 
87
88
  def remove_undefined_variables(str)
88
89
  str.gsub! '.as(:oneline)', ''
89
90
 
90
91
  # "$junos-interface-unit" |
91
- str.gsub! /"\$[\w-]+" \| /, ''
92
+ str.gsub!(/"\$[\w-]+" \| /, '')
92
93
 
93
94
  str
94
95
  end
95
96
 
96
97
  def process_common_syntax(str)
97
98
  # rule(:foo) do -> foo(opts) {
98
- str.gsub!(/^rule\(:(\S+)\) do/) { "#$1(opts) { return_next_line" }
99
+ str.gsub!(/^rule\(:(\S+)\) do/) { "#{$1}(opts) { return_next_line" }
99
100
  # end -> }
100
- str.gsub!(/^(\s*)end$/) { "#$1}" }
101
+ str.gsub!(/^(\s*)end$/) { "#{$1}}" }
101
102
 
102
103
  # arg.as(:arg) ( -> {"arg":
103
- str.gsub! /arg\.as\(:arg\) \(/, '{"arg":'
104
+ str.gsub!('arg.as(:arg) (', '{"arg":')
104
105
  # arg.as(:arg) -> {"arg": null}
105
- str.gsub! /arg.as\(:arg\)/, '{"arg": null}'
106
+ str.gsub!(/arg.as\(:arg\)/, '{"arg": null}')
106
107
  # ("foo" | "bar").as(:arg) ( -> {"(bar|baz)":
107
108
  str.gsub!(/\(([^)]+)\)\.as\(:arg\) \(/) { "{\"(#{$1.gsub('"', '').split(' | ').join('|')})\":" }
108
109
  # enum(("foo" | "bar")).as(:arg) ( -> {"(bar|baz)": # TODO: support "enum" in the middle of line
@@ -111,15 +112,15 @@ module Junoser
111
112
  str.gsub! '.as(:arg)', ''
112
113
 
113
114
  # c( -> {
114
- str.gsub!(/^(\s*)c\(/) { "#$1{" }
115
+ str.gsub!(/^(\s*)c\(/) { "#{$1}{" }
115
116
 
116
117
  # foo /* doc */, -> foo() /* doc */,
117
- str.gsub!(%r|^(\s*)(?!arg)(\w+)( /\* (.*) \*/,?)$|) { "#$1this.#$2()#$3" }
118
+ str.gsub!(%r{^(\s*)(?!arg)(\w+)( /\* (.*) \*/,?)$}) { "#{$1}this.#{$2}()#{$3}" }
118
119
  # foo, -> foo(),
119
- str.gsub!(%r|^(\s*)(?!arg)(\w+)(,?)$|) { "#$1this.#$2()#$3" }
120
+ str.gsub!(/^(\s*)(?!arg)(\w+)(,?)$/) { "#{$1}this.#{$2}()#{$3}" }
120
121
 
121
122
  # ) -> }
122
- str.gsub!(/^(\s+)\)/) { "#$1}" }
123
+ str.gsub!(/^(\s+)\)/) { "#{$1}}" }
123
124
 
124
125
  str
125
126
  end
@@ -127,56 +128,62 @@ module Junoser
127
128
  def process_argument_syntax(str)
128
129
  # "foo" (("bar" | "baz")) ( -> "foo(bar|baz)": {
129
130
  # "foo" enum(("bar" | "baz")) ( -> "foo(bar|baz)": { # TODO: support "enum" in the middle of line
130
- str.gsub!(/^(\s*)"(\S+)" (?:enum)?\(\((.*)\)\) \(/) { "#$1\"#$2(#{$3.gsub('"', '').split(' | ').join('|')})\": {" }
131
+ str.gsub!(/^(\s*)"(\S+)" (?:enum)?\(\((.*)\)\) \(/) do
132
+ "#{$1}\"#{$2}(#{$3.gsub('"', '').split(' | ').join('|')})\": {"
133
+ end
131
134
  # "foo" arg ( -> "foo(arg)": {
132
- str.gsub!(/^(\s*)"(\S+)" arg \(/) { "#$1\"#$2(arg)\": {" }
135
+ str.gsub!(/^(\s*)"(\S+)" arg \(/) { "#{$1}\"#{$2}(arg)\": {" }
133
136
 
134
137
  # "foo" (... | arg) /* doc */ -> "foo": "arg"
135
- str.gsub!(%r|^(\s*)"(\S+)" \(.* \| arg ?.*\) /\* (.*) \*/(,?)$|) { "#$1\"#$2 | #$3\": arg#$4" }
138
+ str.gsub!(%r{^(\s*)"(\S+)" \(.* \| arg ?.*\) /\* (.*) \*/(,?)$}) { "#{$1}\"#{$2} | #{$3}\": arg#{$4}" }
136
139
 
137
140
  # "foo" (... | arg) ( /* doc */ -> "foo(arg)": {
138
- str.gsub!(%r|^(\s*)"(\S+)" \(.* \| arg ?.*\) \( /\* (.*) \*/$|) { "#$1\"#$2(arg) | #$3\": {" }
141
+ str.gsub!(%r{^(\s*)"(\S+)" \(.* \| arg ?.*\) \( /\* (.*) \*/$}) { "#{$1}\"#{$2}(arg) | #{$3}\": {" }
139
142
  # "foo" (... | arg) ( -> "foo(arg)": {
140
- str.gsub!(%r|^(\s*)"(\S+)" \(.* \| arg ?.*\) \($|) { "#$1\"#$2(arg)\": {" }
143
+ str.gsub!(/^(\s*)"(\S+)" \(.* \| arg ?.*\) \($/) { "#{$1}\"#{$2}(arg)\": {" }
141
144
 
142
145
  # "foo" (arg | ...) /* doc */ -> "foo": "arg"
143
- str.gsub!(%r|^(\s*)"(\S+)" \(arg ?.*\) /\* (.*) \*/(,?)$|) { "#$1\"#$2 | #$3\": arg#$4" }
146
+ str.gsub!(%r{^(\s*)"(\S+)" \(arg ?.*\) /\* (.*) \*/(,?)$}) { "#{$1}\"#{$2} | #{$3}\": arg#{$4}" }
144
147
 
145
148
  # "foo" (arg | ...) ( /* doc */ -> "foo(arg)": {
146
- str.gsub!(%r|^(\s*)"(\S+)" \(arg ?.*\) \( /\* (.*) \*/(,?)$|) { "#$1\"#$2(arg) | #$3\": {#$4" }
149
+ str.gsub!(%r{^(\s*)"(\S+)" \(arg ?.*\) \( /\* (.*) \*/(,?)$}) { "#{$1}\"#{$2}(arg) | #{$3}\": {#{$4}" }
147
150
 
148
151
  # "foo" ("bar" | "baz") ( /* doc */ -> "foo(bar|baz)": {
149
- str.gsub!(%r|^(\s*)"(\S+)" \("([^)]+)"\) \( /\* (.*) \*/$|) { "#$1\"#$2(#{$3.split('" | "').join('|')}) | #$4\": {" }
152
+ str.gsub!(%r{^(\s*)"(\S+)" \("([^)]+)"\) \( /\* (.*) \*/$}) do
153
+ "#{$1}\"#{$2}(#{$3.split('" | "').join('|')}) | #{$4}\": {"
154
+ end
150
155
  # "foo" ("bar" | "baz") ( -> "foo(bar|baz)": {
151
- str.gsub!(%r|^(\s*)"(\S+)" \("([^)]+)"\) \($|) { "#$1\"#$2(#{$3.split('" | "').join('|')})\": {" }
156
+ str.gsub!(/^(\s*)"(\S+)" \("([^)]+)"\) \($/) { "#{$1}\"#{$2}(#{$3.split('" | "').join('|')})\": {" }
152
157
 
153
158
  # "foo" ("bar" | "baz") /* doc */, -> "foo": ["bar", "baz"],
154
- str.gsub!(%r|^(\s*)"(\S+)" \(([^)]+)\) /\* (.*) \*/(,?)$|) { "#$1\"#$2 | #$4\": [#{$3.split(' | ').join(', ')}]#$5" }
159
+ str.gsub!(%r{^(\s*)"(\S+)" \(([^)]+)\) /\* (.*) \*/(,?)$}) do
160
+ "#{$1}\"#{$2} | #{$4}\": [#{$3.split(' | ').join(', ')}]#{$5}"
161
+ end
155
162
  # "foo" ("bar" | "baz"), -> "foo": ["bar", "baz"],
156
- str.gsub!(%r|^(\s*)"(\S+)" \(([^)]+)\)(,?)$|) { "#$1\"#$2\": [#{$3.split(' | ').join(', ')}]#$4" }
163
+ str.gsub!(/^(\s*)"(\S+)" \(([^)]+)\)(,?)$/) { "#{$1}\"#{$2}\": [#{$3.split(' | ').join(', ')}]#{$4}" }
157
164
 
158
165
  # "foo" enum(("bar" | "baz")) -> "foo": new Enumeration(["bar", "baz"])
159
- str.gsub!(/^(\s*)("\S+") enum\(\((.*)\)\)/) { "#$1#$2: new Enumeration(#{$3.gsub('"', '').split(' | ')})" }
166
+ str.gsub!(/^(\s*)("\S+") enum\(\((.*)\)\)/) { "#{$1}#{$2}: new Enumeration(#{$3.gsub('"', '').split(' | ')})" }
160
167
 
161
168
  # "foo" arg /* doc */, -> "foo | doc": "arg",
162
- str.gsub!(%r|^(\s*)"([^"]+)" arg /\* (.*) \*/(,?)$|) { "#$1\"#$2 | #$3\": \"arg\"#$4" }
169
+ str.gsub!(%r{^(\s*)"([^"]+)" arg /\* (.*) \*/(,?)$}) { "#{$1}\"#{$2} | #{$3}\": \"arg\"#{$4}" }
163
170
  # "foo" arg, -> "foo": "arg",
164
- str.gsub!(%r|(\s*)"([^"]+)" arg(,?)$|) { "#$1\"#$2\": \"arg\"#$3" }
171
+ str.gsub!(/(\s*)"([^"]+)" arg(,?)$/) { "#{$1}\"#{$2}\": \"arg\"#{$3}" }
165
172
 
166
173
  # "foo" ipaddr, -> "foo": this.ipaddr(),
167
- str.gsub!(%r|(\s*)"([^"]+)" ipaddr(,?)$|) { "#$1\"#$2\": this.ipaddr()#$3" }
174
+ str.gsub!(/(\s*)"([^"]+)" ipaddr(,?)$/) { "#{$1}\"#{$2}\": this.ipaddr()#{$3}" }
168
175
 
169
176
  str
170
177
  end
171
178
 
172
179
  def process_structural_syntax(str)
173
180
  # "foo" ( /* doc */ -> "foo | doc": (opts) => {
174
- str.gsub!(%r|^(\s*)"(\S+)" \( /\* (.*) \*/|) { "#$1\"#$2 | #$3\": {" }
181
+ str.gsub!(%r{^(\s*)"(\S+)" \( /\* (.*) \*/}) { "#{$1}\"#{$2} | #{$3}\": {" }
175
182
  # "foo" ( -> "foo": (opts) => {
176
- str.gsub!(%r|^(\s*)"(\S+)" \($|) { "#$1\"#$2\": {" }
183
+ str.gsub!(/^(\s*)"(\S+)" \($/) { "#{$1}\"#{$2}\": {" }
177
184
 
178
185
  # "foo" arg ( /* doc */ -> "foo | doc": (opts) => {
179
- str.gsub!(%r|^(\s*)"(\S+)" arg \( /\* (.*) \*/|) { "#$1\"#$2 | #$3\": {" }
186
+ str.gsub!(%r{^(\s*)"(\S+)" arg \( /\* (.*) \*/}) { "#{$1}\"#{$2} | #{$3}\": {" }
180
187
 
181
188
  str
182
189
  end
@@ -188,21 +195,21 @@ module Junoser
188
195
  str.gsub!(/ ((?!arg\w)(arg)|(enum)?\(arg\))/, ' "arg"')
189
196
 
190
197
  # "foo" /* doc */, -> "foo | doc": null,
191
- str.gsub!(%r|^(\s*)"([^"]+)" /\* (.*) \*/(,?)$|) { "#$1\"#$2 | #$3\": null#$4" }
198
+ str.gsub!(%r{^(\s*)"([^"]+)" /\* (.*) \*/(,?)$}) { "#{$1}\"#{$2} | #{$3}\": null#{$4}" }
192
199
  # "foo", -> "foo": null,
193
- str.gsub!(%r|^(\s*)"([^"]+)"(,?)$|) { "#$1\"#$2\": null#$3" }
200
+ str.gsub!(/^(\s*)"([^"]+)"(,?)$/) { "#{$1}\"#{$2}\": null#{$3}" }
194
201
 
195
202
  # ("foo" | "bar") -> ["foo", "bar"]
196
203
  str.gsub!(/^(\s*) \(+("[^"]+(?:" \| "[^"]+)*")\)+(,?)$/) do
197
204
  comma = $3
198
- "#$1#{$2.gsub('"', '').split(' | ')}#{comma}"
205
+ "#{$1}#{$2.gsub('"', '').split(' | ')}#{comma}"
199
206
  end
200
207
 
201
208
  # enum(("bar" | "baz")) -> "foo": new Enumeration(["bar", "baz"])
202
- str.gsub!(/^(\s*)enum\(\((.*)\)\)/) { "#$1new Enumeration(#{$2.gsub('"', '').split(' | ')})" }
209
+ str.gsub!(/^(\s*)enum\(\((.*)\)\)/) { "#{$1}new Enumeration(#{$2.gsub('"', '').split(' | ')})" }
203
210
 
204
211
  # (arg | "foo") -> ["arg", "foo"]
205
- str.gsub!(/^(\s*) \(arg( \| "[^"]+")+\)/) { "#$1[\"arg\"#{$2.split(' | ').join(', ')}]" }
212
+ str.gsub!(/^(\s*) \(arg( \| "[^"]+")+\)/) { "#{$1}[\"arg\"#{$2.split(' | ').join(', ')}]" }
206
213
 
207
214
  str
208
215
  end
@@ -242,17 +249,14 @@ module Junoser
242
249
  end
243
250
 
244
251
  def fix_route_filter(str)
245
- str.gsub!(/("exact \| [^"]*"): "arg"/) { "#$1: null" }
246
- str.gsub!(/("longer \| [^"]*"): "arg"/) { "#$1: null" }
247
- str.gsub!(/("orlonger \| [^"]*"): "arg"/) { "#$1: null" }
252
+ str.gsub!(/("exact \| [^"]*"): "arg"/) { "#{$1}: null" }
253
+ str.gsub!(/("longer \| [^"]*"): "arg"/) { "#{$1}: null" }
254
+ str.gsub!(/("orlonger \| [^"]*"): "arg"/) { "#{$1}: null" }
248
255
  end
249
256
 
250
257
  def process_comment(str)
251
- # % -> %%
252
- str.gsub! '%', '' % %''
253
-
254
258
  # "foo": ... /* doc */, -> "foo | doc": ...,
255
- str.gsub!(%r|^(\s*)"([^"]+)": (.*) /\* (.*) \*/(,?)$|) { "#$1\"#$2 | #$4\": #$3#$5" }
259
+ str.gsub!(%r{^(\s*)"([^"]+)": (.*) /\* (.*) \*/(,?)$}) { "#{$1}\"#{$2} | #{$4}\": #{$3}#{$5}" }
256
260
 
257
261
  str
258
262
  end
@@ -267,7 +271,7 @@ module Junoser
267
271
  # ->
268
272
  #
269
273
  # return ...
270
- lines.gsub!(/return_next_line\n(\s*)/m) { "\n#$1return " }
274
+ lines.gsub!(/return_next_line\n(\s*)/m) { "\n#{$1}return " }
271
275
 
272
276
  # {
273
277
  # {
@@ -276,7 +280,7 @@ module Junoser
276
280
  #
277
281
  # {
278
282
  # "null_1": {
279
- lines.gsub!(/([{,]\n\s*){/m) { "#$1\"null_#{sequence}\": {" }
283
+ lines.gsub!(/([{,]\n\s*){/m) { "#{$1}\"null_#{sequence}\": {" }
280
284
 
281
285
  # {
282
286
  # foo()
@@ -285,10 +289,10 @@ module Junoser
285
289
  #
286
290
  # {
287
291
  # "null_1": foo()
288
- lines.gsub!(/([{,]\n\s*)([^ "(]+)/m) { "#$1\"null_#{sequence}\": #$2" }
292
+ lines.gsub!(/([{,]\n\s*)([^ "(]+)/m) { "#{$1}\"null_#{sequence}\": #{$2}" }
289
293
 
290
294
  # "arg" -> "arg_1"
291
- lines.gsub('"arg":') { %["arg_#{sequence}":] }
295
+ lines.gsub('"arg":') { %("arg_#{sequence}":) }
292
296
 
293
297
  conditional_groups(lines)
294
298
  end
@@ -298,13 +302,15 @@ module Junoser
298
302
  # Fixes
299
303
  lines.gsub! 'Timeslots (1..24;', 'Timeslots (1..24);'
300
304
  lines.gsub! '(such that the VLAN range is x <= range <= y.', '(such that the VLAN range is x <= range <= y).'
301
- lines.gsub! '(intended primarily for use with a peer or group"', '(intended primarily for use with a peer or group)"'
305
+ lines.gsub! '(intended primarily for use with a peer or group"',
306
+ '(intended primarily for use with a peer or group)"'
302
307
  lines.gsub! '(e.g. QSFP28 and QSFP+,', '(e.g. QSFP28 and QSFP+),'
303
- lines.gsub! '(see the description of policy evaluation at the top of this module."', '(see the description of policy evaluation at the top of this module)."'
308
+ lines.gsub! '(see the description of policy evaluation at the top of this module."',
309
+ '(see the description of policy evaluation at the top of this module)."'
304
310
 
305
311
  count = 0
306
312
  target = nil
307
- buf = ''
313
+ buf = +''
308
314
  stack = []
309
315
 
310
316
  lines.each_char do |c|
@@ -344,12 +350,12 @@ module Junoser
344
350
 
345
351
  def objectize_arg_of_s(lines)
346
352
  # s( -> s({
347
- lines.gsub!(/^( *(?:return|\S+:)? +)s\($/m) { "#$1this.s({" }
353
+ lines.gsub!(/^( *(?:return|\S+:)? +)s\($/m) { "#{$1}this.s({" }
348
354
  # sc( -> sc({
349
- lines.gsub!(/^( *(?:return|\S+:)? +)sc\($/m) { "#$1this.sc({" }
355
+ lines.gsub!(/^( *(?:return|\S+:)? +)sc\($/m) { "#{$1}this.sc({" }
350
356
 
351
357
  # ) -> })
352
- lines.gsub!(/^( *)\)(,?)$/m) { "#$1})#$2" }
358
+ lines.gsub!(/^( *)\)(,?)$/m) { "#{$1}})#{$2}" }
353
359
 
354
360
  lines
355
361
  end
@@ -360,13 +366,13 @@ module Junoser
360
366
  # (opts === undefined || opts?.configuration !== false) && { "null_13264": this.configuration(false) },
361
367
  #
362
368
  # ref: process_lines()
363
- lines.gsub(/("groups\(arg\) \| .*":) {/) {
369
+ lines.gsub(/("groups\(arg\) \| .*":) {/) do
364
370
  "#{$1} opts?.groups !== false && {"
365
- }
371
+ end
366
372
  end
367
373
 
368
374
  def rule_header
369
- <<~EOS
375
+ <<~HEADER
370
376
  /* eslint-disable semi */
371
377
 
372
378
  class Enumeration {
@@ -405,17 +411,19 @@ module Junoser
405
411
  return new Repeatable(obj);
406
412
  }
407
413
 
408
- EOS
414
+ HEADER
409
415
  end
410
416
 
411
417
  def rule_footer
412
- <<~EOS
418
+ <<~FOOTER
413
419
 
414
420
  }
415
421
 
416
422
  // eslint-disable-next-line no-undef
417
423
  module.exports = {JunosSchema, Enumeration, Repeatable, Sequence};
418
- EOS
424
+ FOOTER
419
425
  end
420
426
  end
421
427
  end
428
+
429
+ # rubocop:enable Style/PerlBackrefs
@@ -23779,6 +23779,162 @@ module Junoser
23779
23779
  str("use-actual-mac-on-physical-interfaces"),
23780
23780
  str("use-active-child-mac-on-reth")
23781
23781
  )
23782
+ ),
23783
+ b(str("high-availability"),
23784
+ c(
23785
+ str("hardware-upgrade"),
23786
+ b(str("local-id"),
23787
+ sc(
23788
+ arg,
23789
+ b(str("local-ip"),
23790
+ ipaddr
23791
+ )
23792
+ )
23793
+ ).as(:oneline),
23794
+ b(a(str("peer-id"), arg),
23795
+ c(
23796
+ a(str("desc"), arg),
23797
+ b(str("peer-ip"),
23798
+ ipaddr
23799
+ ),
23800
+ b(str("interface"),
23801
+ interface_name
23802
+ ),
23803
+ a(str("routing-instance"), arg),
23804
+ a(str("vpn-profile"), arg),
23805
+ b(str("liveness-detection"),
23806
+ c(
23807
+ b(str("version"),
23808
+ (str("0") | str("1") | str("automatic"))
23809
+ ),
23810
+ a(str("minimum-interval"), arg),
23811
+ a(str("minimum-transmit-interval"), arg),
23812
+ a(str("minimum-receive-interval"), arg),
23813
+ a(str("multiplier"), arg),
23814
+ c(
23815
+ str("no-adaptation")
23816
+ ),
23817
+ b(str("transmit-interval"),
23818
+ c(
23819
+ a(str("minimum-interval"), arg),
23820
+ a(str("threshold"), arg)
23821
+ )
23822
+ ),
23823
+ b(str("detection-time"),
23824
+ c(
23825
+ a(str("threshold"), arg)
23826
+ )
23827
+ )
23828
+ )
23829
+ )
23830
+ )
23831
+ ),
23832
+ b(str("traceoptions"),
23833
+ c(
23834
+ str("no-remote-trace"),
23835
+ b(str("file"),
23836
+ sc(
23837
+ arg,
23838
+ a(str("size"), arg),
23839
+ a(str("files"), arg),
23840
+ str("world-readable"),
23841
+ str("no-world-readable"),
23842
+ b(str("match"),
23843
+ regular_expression
23844
+ )
23845
+ )
23846
+ ).as(:oneline),
23847
+ a(str("flag"), enum(str("cli") | str("configuration") | str("eventlib") | str("fsm") | str("heartbeat") | str("interface") | str("routing-socket") | str("uspipc") | str("init") | str("socket") | str("snmp") | str("ip-monitoring") | str("hw-monitoring") | str("fabric-monitoring") | str("health-monitoring") | str("schedule-monitoring") | str("heartbeat-tlv") | str("ha-peer") | str("srg") | str("all"))).as(:oneline),
23848
+ b(str("level"),
23849
+ (str("emergency") | str("alert") | str("critical") | str("error") | str("warning") | str("notice") | str("info") | str("debug") | str("all"))
23850
+ )
23851
+ )
23852
+ ),
23853
+ b(a(str("services-redundancy-group"), arg),
23854
+ c(
23855
+ a(str("shutdown-on-failure"), arg),
23856
+ b(str("deployment-type"),
23857
+ (str("cloud") | str("hybrid") | str("routing") | str("switching"))
23858
+ ),
23859
+ b(str("peer-id"),
23860
+ c(
23861
+ arg
23862
+ )
23863
+ ),
23864
+ b(str("activeness-probe"),
23865
+ c(
23866
+ b(str("dest-ip"),
23867
+ c(
23868
+ b(str("src-ip"),
23869
+ ipaddr
23870
+ ),
23871
+ a(str("routing-instance"), arg),
23872
+ ipaddr
23873
+ )
23874
+ ),
23875
+ a(str("minimum-interval"), arg),
23876
+ a(str("multiplier"), arg)
23877
+ )
23878
+ ),
23879
+ b(a(str("virtual-ip"), arg),
23880
+ c(
23881
+ b(str("ip"),
23882
+ ipprefix_mandatory
23883
+ ),
23884
+ b(str("interface"),
23885
+ interface_name
23886
+ ),
23887
+ str("use-virtual-mac")
23888
+ )
23889
+ ),
23890
+ b(str("monitor"),
23891
+ c(
23892
+ b(a(str("ip"), arg),
23893
+ c(
23894
+ a(str("routing-instance"), arg)
23895
+ )
23896
+ ),
23897
+ b(a(str("bfd-liveliness"), arg),
23898
+ c(
23899
+ b(str("src-ip"),
23900
+ ipv4addr
23901
+ ),
23902
+ a(str("routing-instance"), arg),
23903
+ b(str("session-type"),
23904
+ (str("singlehop") | str("multihop"))
23905
+ ),
23906
+ b(str("interface"),
23907
+ interface_name
23908
+ )
23909
+ )
23910
+ ),
23911
+ a(str("interface"), arg)
23912
+ )
23913
+ ),
23914
+ b(str("active-signal-route"),
23915
+ c(
23916
+ ipv4addr,
23917
+ a(str("routing-instance"), arg)
23918
+ )
23919
+ ),
23920
+ b(str("backup-signal-route"),
23921
+ c(
23922
+ ipv4addr,
23923
+ a(str("routing-instance"), arg)
23924
+ )
23925
+ ),
23926
+ b(a(str("prefix-list"), arg),
23927
+ c(
23928
+ a(str("routing-instance"), arg)
23929
+ )
23930
+ ),
23931
+ a(str("managed-services"), enum(str("ipsec"))).as(:oneline),
23932
+ str("preemption"),
23933
+ str("process-packet-on-backup"),
23934
+ a(str("activeness-priority"), arg)
23935
+ )
23936
+ )
23937
+ )
23782
23938
  )
23783
23939
  # End of vSRX 22.4R1.10
23784
23940
  )
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Junoser
2
4
  module RuleTree
3
5
  class Node
@@ -14,7 +16,7 @@ module Junoser
14
16
  end
15
17
 
16
18
  def print(level = 0)
17
- puts INDENT * level + "- #{@name}"
19
+ puts (INDENT * level) + "- #{@name}"
18
20
  @children.each do |child|
19
21
  child.print level + 1
20
22
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Junoser
2
4
  module RuleTree
3
5
  class Parser
@@ -20,7 +22,7 @@ module Junoser
20
22
 
21
23
  validate_uniq rules[root_index..].map(&:first)
22
24
 
23
- @nodes = Hash[rules[root_index..].map { |name, _| [name, Node.new(name)] }]
25
+ @nodes = rules[root_index..].to_h { |name, _| [name, Node.new(name)] }
24
26
  used = Set.new
25
27
 
26
28
  rules[root_index..].map do |name, refs|
@@ -30,6 +32,7 @@ module Junoser
30
32
  used += children
31
33
  children.each do |child|
32
34
  raise %(Unknown rule: #{child}) unless @nodes[child]
35
+
33
36
  @nodes[name] << @nodes[child]
34
37
  end
35
38
  end
@@ -40,11 +43,11 @@ module Junoser
40
43
  private
41
44
 
42
45
  def content
43
- @_content ||= @content
44
- .gsub(%r| */\*.*\*/|, '')
45
- .gsub(/\.as\(:oneline\)/, '')
46
- .gsub(/^(?!rule.*).*["#()].*\n/, '')
47
- .gsub(/ *arg,?\n/, '')
46
+ @content ||= @content
47
+ .gsub(%r{ */\*.*\*/}, '')
48
+ .gsub('.as(:oneline)', '')
49
+ .gsub(/^(?!rule.*).*["#()].*\n/, '')
50
+ .gsub(/ *arg,?\n/, '')
48
51
  end
49
52
 
50
53
  def validate_uniq(rules)
@@ -58,8 +61,8 @@ module Junoser
58
61
  unused = all - used - %w[configuration]
59
62
  return if unused.empty?
60
63
 
61
- $stderr.puts 'Warning: Unused rules:'
62
- unused.each { |r| $stderr.puts " - #{r}" }
64
+ warn 'Warning: Unused rules:'
65
+ unused.each { |r| warn " - #{r}" }
63
66
  end
64
67
  end
65
68
  end
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'junoser/rule_tree/node'
2
4
  require 'junoser/rule_tree/parser'