junoser 0.8.0 → 0.9.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +58 -0
- data/Gemfile.lock +1 -1
- data/Rakefile +1 -1
- data/lib/junoser/parser.rb +77161 -69828
- data/lib/junoser/ruler.rb +38 -41
- data/lib/junoser/version.rb +1 -1
- data/lib/junoser/xsd/parsable.rb +2 -1
- metadata +1 -1
data/lib/junoser/ruler.rb
CHANGED
|
@@ -30,25 +30,25 @@ module Junoser
|
|
|
30
30
|
def process_line(str)
|
|
31
31
|
return str if str =~ /^(.* do|end)$/
|
|
32
32
|
|
|
33
|
-
str.gsub!(/("[^"]+")/) { "
|
|
33
|
+
str.gsub!(/("[^"]+")/) { "k(#{$1})" } # "foo" -> k("foo")
|
|
34
34
|
|
|
35
35
|
str.gsub!(/^(\s*)arg(\.as\(:\S+\))? \($/) { "#{$1}b(arg#{$2}," } # arg ( -> b(arg,
|
|
36
|
-
#
|
|
37
|
-
str.gsub!(/^(\s*)(
|
|
36
|
+
# k("foo") bar -> a(k("foo"), bar)
|
|
37
|
+
str.gsub!(/^(\s*)(k\(\S+\)) ([^ \t\n\r\f(|,]+)(\.as\(:\S+\))?(,?)$/) do
|
|
38
38
|
"#{$1}a(#{$2}, #{$3})#{$4}#{$5}"
|
|
39
39
|
end
|
|
40
|
-
#
|
|
41
|
-
str.gsub!(/^(\s*)(
|
|
40
|
+
# k("foo") (a | b) -> a(k("foo"), a | b)
|
|
41
|
+
str.gsub!(/^(\s*)(k\(\S+\)) (enum)?\((.*)\)(,?)$/) do
|
|
42
42
|
"#{$1}a(#{$2}, #{$3}#{$4})#{$5}"
|
|
43
43
|
end
|
|
44
|
-
str.gsub!(/^(\s*)(
|
|
44
|
+
str.gsub!(/^(\s*)(k\(\S+\)) \($/) { "#{$1}b(#{$2}," } # k("foo") ( -> b(k("foo"),
|
|
45
45
|
str.gsub!(/^(\s*)(enum)?(\(.*\))(\.as\(:\S\))? \($/) { "#{$1}b(#{$2}#{$3}#{$4}," } # (a | b) ( -> b((a | b),
|
|
46
|
-
#
|
|
47
|
-
str.gsub!(/^(\s*)(
|
|
46
|
+
# k("foo") bar ( -> b(a(k("foo"), bar),
|
|
47
|
+
str.gsub!(/^(\s*)(k\(\S+\)) ([^ \t\n\r\f(|,]+) \($/) do
|
|
48
48
|
"#{$1}b(a(#{$2}, #{$3}),"
|
|
49
49
|
end
|
|
50
|
-
#
|
|
51
|
-
str.gsub!(/^(\s*)(
|
|
50
|
+
# k("foo") (a | b) ( -> a(k("foo"), a | b,
|
|
51
|
+
str.gsub!(/^(\s*)(k\(\S+\)) (enum)?\((.*)\) \($/) do
|
|
52
52
|
"#{$1}a(#{$2}, #{$3}#{$4},"
|
|
53
53
|
end
|
|
54
54
|
str
|
|
@@ -164,51 +164,31 @@ module Junoser
|
|
|
164
164
|
' a(arg, arg)'], '')
|
|
165
165
|
end
|
|
166
166
|
|
|
167
|
-
str.gsub! '"any" | "any-ipv4" | "any-ipv6"', '"any-ipv4" | "any-ipv6" | "any"'
|
|
168
|
-
|
|
169
167
|
# Fix overkill
|
|
170
168
|
str.gsub!(/^(\s*)"priority" \(\s*ca\(\s*arg\s*\)/) do
|
|
171
169
|
fmt(['"priority" (',
|
|
172
170
|
' a(arg, arg)', $1])
|
|
173
171
|
end
|
|
174
172
|
|
|
175
|
-
#
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
#
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
# "inet6"
|
|
185
|
-
str.gsub!(/"cspf"(.*\s*.*)"cspf-link"/) { %("cspf-link"#{$1}"cspf") }
|
|
186
|
-
str.gsub!(/"http"(.*\s*.*)"https"/) { %("https"#{$1}"http") }
|
|
187
|
-
str.gsub!(/"inet"(.*\s*.*)"inet6"/) { %("inet6"#{$1}"inet") }
|
|
188
|
-
str.gsub!(/"icmp"(.*\s*.*)"icmp6"/) { %("icmp6"#{$1}"icmp") }
|
|
189
|
-
str.gsub!(/"icmp"(.*\s*.*)"icmpv6"/) { %("icmpv6"#{$1}"icmp") }
|
|
190
|
-
str.gsub!(/"snmp"(.*\s*.*)"snmptrap"/) { %("snmptrap"#{$1}"snmp") }
|
|
191
|
-
str.gsub!(/"ospf"(.*\s*.*)"ospf3"/) { %("ospf3"#{$1}"ospf") }
|
|
192
|
-
str.gsub!(/"deny"(.*\s*.*)"deny-password"/) { %("deny-password"#{$1}"deny") }
|
|
193
|
-
str.gsub!(/"no-redirects"(.*\s*.*)"no-redirects-ipv6"/) { %("no-redirects-ipv6"#{$1}"no-redirects") }
|
|
194
|
-
str.gsub!(/"chassis"([^()]*)"chassis-ha-reswatch"/m) { %("chassis-ha-reswatch"#{$1}"chassis") }
|
|
195
|
-
str.gsub! '"tls1" | "tls11" | "tls12"', '"tls11" | "tls12" | "tls1"'
|
|
196
|
-
str.gsub!(/("group1" \| "group2" \| "group5") \| ([^)]+)/) { "#{$2} | #{$1}" }
|
|
197
|
-
|
|
198
|
-
%w[ccc ethernet-over-atm tcc vpls bridge].each do |encap|
|
|
199
|
-
str.gsub!(/"ethernet"(.*)"ethernet-#{encap}"/) { %("ethernet-#{encap}"#{$1}"ethernet") }
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
str.gsub!(/^(\s*)"path" arg \(\s*c\(\s*sc\(\s*"abstract",\s*c\(\s*"loose",\s*"loose-link",\s*"strict"\s*\)\s*\)\.as\(:oneline\)/) do
|
|
173
|
+
# 26.2 puts "exclude" in front of the oneline part of "path". Keep it and rewrite the oneline part only.
|
|
174
|
+
exclude = /((?:\s*"exclude" \(\s*c\(\s*arg\s*\)\s*\),)?)/
|
|
175
|
+
oneline = /sc\(\s*"abstract",\s*c\(\s*"loose",\s*"loose-link",\s*"strict"\s*\)\s*\)\.as\(:oneline\)/
|
|
176
|
+
str.gsub!(/^(\s*)"path" arg \(\s*c\(#{exclude}\s*#{oneline}/) do
|
|
177
|
+
members = if $2.empty?
|
|
178
|
+
[]
|
|
179
|
+
else
|
|
180
|
+
[' "exclude" (', ' c(', ' arg', ' )', ' ),']
|
|
181
|
+
end
|
|
203
182
|
fmt(['"path" arg (',
|
|
204
183
|
' c(',
|
|
184
|
+
*members,
|
|
205
185
|
' b(',
|
|
206
186
|
' ipaddr,',
|
|
207
187
|
' c(',
|
|
208
188
|
' "abstract",',
|
|
209
189
|
' c(',
|
|
210
|
-
' "loose-link",',
|
|
211
190
|
' "loose",',
|
|
191
|
+
' "loose-link",',
|
|
212
192
|
' "strict"',
|
|
213
193
|
' )',
|
|
214
194
|
' ).as(:oneline)',
|
|
@@ -378,6 +358,23 @@ module Junoser
|
|
|
378
358
|
end
|
|
379
359
|
end
|
|
380
360
|
|
|
361
|
+
# A keyword fails when more characters follow it. Otherwise a bare keyword in a choice also matches the
|
|
362
|
+
# head of a longer sibling ("immediate-leave" vs "immediate-leave-on-host-interface") and parslet never
|
|
363
|
+
# tries the longer one. One atom is cheaper than str(word) >> lookahead.
|
|
364
|
+
class Keyword < Parslet::Atoms::Str
|
|
365
|
+
def try(source, context, consume_all)
|
|
366
|
+
result = super
|
|
367
|
+
# fail when the keyword goes on, like "-on-host-interface" after "immediate-leave"
|
|
368
|
+
return result unless result.first && source.matches?(/[^\\s#]/)
|
|
369
|
+
|
|
370
|
+
context.err(self, source, "Keyword \#{str.inspect} is followed by more characters")
|
|
371
|
+
end
|
|
372
|
+
end
|
|
373
|
+
|
|
374
|
+
def k(word)
|
|
375
|
+
Keyword.new(word)
|
|
376
|
+
end
|
|
377
|
+
|
|
381
378
|
# block with children maybe
|
|
382
379
|
def b(object, *children)
|
|
383
380
|
children.inject(object) {|rule, child| rule.as(:label) >> (space >> child.as(:child) | eos) }
|
data/lib/junoser/version.rb
CHANGED
data/lib/junoser/xsd/parsable.rb
CHANGED
|
@@ -24,7 +24,8 @@ module Junoser
|
|
|
24
24
|
|
|
25
25
|
def remove_unused
|
|
26
26
|
xpath('/xsd:schema/*[self::xsd:import]').remove
|
|
27
|
-
|
|
27
|
+
# not "//": with a predicate libxml2 collects every node first and hits its nodeset limit on large schemas
|
|
28
|
+
xpath('descendant::xsd:element[@ref="undocumented" or @ref="junos:comment" or @name="apply-advanced"]').remove
|
|
28
29
|
self
|
|
29
30
|
end
|
|
30
31
|
end
|