junoser 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -1
- data/Rakefile +9 -0
- data/example/vsrx-12.1.x47.rb +610 -492
- data/exe/junoser +4 -3
- data/junoser.gemspec +2 -1
- data/lib/junoser/cli.rb +5 -8
- data/lib/junoser/display/set.rb +10 -4
- data/lib/junoser/display/structure.rb +4 -5
- data/lib/junoser/input.rb +34 -0
- data/lib/junoser/parser.rb +625 -513
- data/lib/junoser/ruler.rb +17 -4
- data/lib/junoser/transformer.rb +15 -1
- data/lib/junoser/version.rb +1 -1
- data/lib/junoser/xsd/base.rb +1 -1
- metadata +18 -4
- data/lib/junoser/display/base.rb +0 -40
data/lib/junoser/ruler.rb
CHANGED
@@ -39,6 +39,7 @@ module Junoser
|
|
39
39
|
def process_reserved_element(str)
|
40
40
|
str.gsub! /"\$\S+"/, 'arg'
|
41
41
|
str.gsub! '"as-number" arg', 'arg'
|
42
|
+
str.gsub! '"confederation-as" arg', 'arg'
|
42
43
|
str.gsub! '"equal-literal"', '"="'
|
43
44
|
str.gsub! '"plus-literal"', '"+"'
|
44
45
|
str.gsub! '"minus-literal"', '"-"'
|
@@ -79,6 +80,14 @@ module Junoser
|
|
79
80
|
' )'], $1)
|
80
81
|
end
|
81
82
|
|
83
|
+
str.gsub!(/^rule\(:regular_expression\) do\s*((?!end).)*\s*end/) do
|
84
|
+
"rule(:regular_expression) do
|
85
|
+
(quote | arg).as(:arg)
|
86
|
+
end"
|
87
|
+
end
|
88
|
+
|
89
|
+
str.gsub!(/("next-hop" \(\s*sc\(\s*c\(\s*[^)]*)"address" \(\s*ipaddr\s*\)/) { "#{$1}ipaddr" }
|
90
|
+
|
82
91
|
%w[metric metric2 metric3 metric4 tag tag2 preference preference2 color color2 local-preference].each do |key|
|
83
92
|
str.gsub!(/^(\s*"#{key}" \(\s*sc\(\s*c\(\s*)"#{key}" arg/) { "#{$1}arg" }
|
84
93
|
end
|
@@ -151,13 +160,17 @@ module Junoser
|
|
151
160
|
rule(:space) { match('\\s').repeat(1) }
|
152
161
|
rule(:any) { match('.').repeat(1) }
|
153
162
|
rule(:eos) { match('$') }
|
154
|
-
rule(:dotted) { match('[^. \\t\\n\\r\\f]').repeat(1) >>
|
155
|
-
rule(:quote) {
|
163
|
+
rule(:dotted) { match('[^. \\t\\n\\r\\f]').repeat(1) >> str('.') >> match('[^. \\t\\n\\r\\f]').repeat(1) }
|
164
|
+
rule(:quote) { str('"') >> match('[^"]').repeat(1) >> str('"') }
|
156
165
|
rule(:address) { match('[0-9a-fA-F:\.]').repeat(1) }
|
157
|
-
rule(:prefix ) { address >> (
|
166
|
+
rule(:prefix ) { address >> (str('/') >> match('[0-9]').repeat(1)).maybe }
|
158
167
|
|
159
168
|
root(:set)
|
160
|
-
rule(:set) { (str('set') | str('deactivate')) >> space >> configuration.as(:config) }
|
169
|
+
rule(:set) { (str('set') | str('deactivate')) >> space >> configuration.as(:config) >> comment.maybe }
|
170
|
+
|
171
|
+
rule(:comment) { space.maybe >> (hash_comment | slash_asterisk) }
|
172
|
+
rule(:hash_comment) { str('#') >> any.maybe }
|
173
|
+
rule(:slash_asterisk) { str('/*') >> match('(?!\\*\\/).').repeat(0) >> str('*/') }
|
161
174
|
|
162
175
|
EOS
|
163
176
|
end
|
data/lib/junoser/transformer.rb
CHANGED
@@ -23,6 +23,7 @@ module Junoser
|
|
23
23
|
end
|
24
24
|
|
25
25
|
rule(label: simple(:label), child: sequence(:children)) do
|
26
|
+
Junoser::Transformer.remove_slash_asterisk children
|
26
27
|
%[#{label}\n#{children.join("\n")}]
|
27
28
|
end
|
28
29
|
|
@@ -31,11 +32,24 @@ module Junoser
|
|
31
32
|
end
|
32
33
|
|
33
34
|
rule(statement: simple(:statement), argument: sequence(:arguments)) do
|
35
|
+
Junoser::Transformer.remove_slash_asterisk arguments
|
34
36
|
%[#{statement}\n#{arguments.join("\n")}]
|
35
37
|
end
|
36
38
|
|
37
39
|
rule(oneline: simple(:str)) do
|
38
|
-
str.gsub
|
40
|
+
str.to_s.gsub("\n", ' ')
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def self.remove_slash_asterisk(array)
|
45
|
+
open = array.index("arg(/*)\n")
|
46
|
+
close = array.index("arg(*/)")
|
47
|
+
|
48
|
+
if open && close
|
49
|
+
(open..close).reverse_each do |i|
|
50
|
+
array.delete_at i
|
51
|
+
end
|
52
|
+
end
|
39
53
|
end
|
40
54
|
end
|
41
55
|
end
|
data/lib/junoser/version.rb
CHANGED
data/lib/junoser/xsd/base.rb
CHANGED
@@ -36,7 +36,7 @@ module Junoser
|
|
36
36
|
private
|
37
37
|
|
38
38
|
def oneliner?
|
39
|
-
@oneliner ||= !xml.xpath('./xsd:annotation/xsd:appinfo/flag[
|
39
|
+
@oneliner ||= !xml.xpath('./xsd:annotation/xsd:appinfo/flag[text()="oneliner"]').empty?
|
40
40
|
end
|
41
41
|
|
42
42
|
def has_single_child_of?(klass)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: junoser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shintaro Kojima
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parslet
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: test-unit
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: PEG parser to vefiry and translate into different formats for JUNOS configuration.
|
84
98
|
email:
|
85
99
|
- goodies@codeout.net
|
@@ -102,10 +116,10 @@ files:
|
|
102
116
|
- lib/junoser/cli.rb
|
103
117
|
- lib/junoser/development.rb
|
104
118
|
- lib/junoser/display.rb
|
105
|
-
- lib/junoser/display/base.rb
|
106
119
|
- lib/junoser/display/config_store.rb
|
107
120
|
- lib/junoser/display/set.rb
|
108
121
|
- lib/junoser/display/structure.rb
|
122
|
+
- lib/junoser/input.rb
|
109
123
|
- lib/junoser/parser.rb
|
110
124
|
- lib/junoser/ruler.rb
|
111
125
|
- lib/junoser/transformer.rb
|
@@ -119,7 +133,7 @@ files:
|
|
119
133
|
- lib/junoser/xsd/restriction.rb
|
120
134
|
- lib/junoser/xsd/sequence.rb
|
121
135
|
- lib/junoser/xsd/simple_content.rb
|
122
|
-
homepage: https://github.com/codeout/
|
136
|
+
homepage: https://github.com/codeout/junoser
|
123
137
|
licenses: []
|
124
138
|
metadata: {}
|
125
139
|
post_install_message:
|
data/lib/junoser/display/base.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
module Junoser
|
2
|
-
module Display
|
3
|
-
module Base
|
4
|
-
attr_accessor :output
|
5
|
-
|
6
|
-
def initialize(io_or_string)
|
7
|
-
@input = io_or_string
|
8
|
-
@output = $stdout
|
9
|
-
end
|
10
|
-
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def read_io_or_string
|
15
|
-
return @read_io_or_string if @read_io_or_string
|
16
|
-
|
17
|
-
config = if @input.respond_to?(:read)
|
18
|
-
@input.read
|
19
|
-
else
|
20
|
-
@input.to_s
|
21
|
-
end
|
22
|
-
|
23
|
-
@read_io_or_string = remove_blank_and_comment(config)
|
24
|
-
@read_io_or_string = unify_carriage_return(@read_io_or_string)
|
25
|
-
end
|
26
|
-
|
27
|
-
def remove_blank_and_comment(str)
|
28
|
-
str.gsub! /#.*/, ''
|
29
|
-
str.gsub! /\/\*((?!\*\/).)*\*\//m, ''
|
30
|
-
str.gsub! /\n\s*/, "\n"
|
31
|
-
str.strip
|
32
|
-
end
|
33
|
-
|
34
|
-
def unify_carriage_return(str)
|
35
|
-
str.gsub! /\r\n?/, "\n"
|
36
|
-
str
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|