ios_parser 0.5.1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +37 -0
- data/.rubocop.yml +39 -0
- data/.travis.yml +16 -0
- data/CHANGELOG.md +30 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +9 -0
- data/Guardfile +15 -0
- data/LICENSE.txt +675 -0
- data/README.md +90 -0
- data/Rakefile +20 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/doc/state_machine.graphviz +41 -0
- data/doc/state_machine.png +0 -0
- data/ext/ios_parser/c_lexer/extconf.rb +4 -0
- data/ext/ios_parser/c_lexer/lexer.c +507 -0
- data/fixtures/complex_banner.txt +24 -0
- data/ios_parser.gemspec +25 -0
- data/lib/ios_parser/ios/command.rb +91 -0
- data/lib/ios_parser/ios/document.rb +54 -0
- data/lib/ios_parser/ios/queryable.rb +219 -0
- data/lib/ios_parser/ios.rb +73 -0
- data/lib/ios_parser/lexer.rb +327 -0
- data/lib/ios_parser/pure.rb +2 -0
- data/lib/ios_parser/version.rb +7 -0
- data/lib/ios_parser.rb +37 -0
- data/spec/lib/ios_parser/ios/queryable_spec.rb +157 -0
- data/spec/lib/ios_parser/ios_spec.rb +337 -0
- data/spec/lib/ios_parser/lexer_spec.rb +290 -0
- data/spec/lib/ios_parser_spec.rb +96 -0
- data/spec/spec_helper.rb +19 -0
- metadata +121 -0
@@ -0,0 +1,96 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require 'ios_parser'
|
3
|
+
|
4
|
+
describe IOSParser do
|
5
|
+
describe '.parse' do
|
6
|
+
context 'indented region' do
|
7
|
+
let(:input) { <<-END.unindent }
|
8
|
+
policy-map mypolicy_in
|
9
|
+
class myservice_service
|
10
|
+
police 300000000 1000000 exceed-action policed-dscp-transmit
|
11
|
+
set dscp cs1
|
12
|
+
class other_service
|
13
|
+
police 600000000 1000000 exceed-action policed-dscp-transmit
|
14
|
+
set dscp cs2
|
15
|
+
command_with_no_args
|
16
|
+
END
|
17
|
+
|
18
|
+
let(:output) do
|
19
|
+
{
|
20
|
+
commands:
|
21
|
+
[{ args: ['policy-map', 'mypolicy_in'],
|
22
|
+
commands:
|
23
|
+
[{ args: %w[class myservice_service],
|
24
|
+
commands: [{ args: ['police', 300_000_000, 1_000_000,
|
25
|
+
'exceed-action',
|
26
|
+
'policed-dscp-transmit'],
|
27
|
+
commands: [{ args: %w[set dscp cs1],
|
28
|
+
commands: [], pos: 114 }],
|
29
|
+
pos: 50 }],
|
30
|
+
pos: 24 },
|
31
|
+
|
32
|
+
{ args: %w[class other_service],
|
33
|
+
commands: [{ args: ['police', 600_000_000, 1_000_000,
|
34
|
+
'exceed-action',
|
35
|
+
'policed-dscp-transmit'],
|
36
|
+
commands: [{ args: %w[set dscp cs2],
|
37
|
+
commands: [], pos: 214 },
|
38
|
+
{ args: ['command_with_no_args'],
|
39
|
+
commands: [], pos: 230 }],
|
40
|
+
pos: 150 }],
|
41
|
+
pos: 128 }],
|
42
|
+
pos: 0 }]
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
subject { described_class.parse(input) }
|
47
|
+
|
48
|
+
it('constructs the right AST') do
|
49
|
+
should be_a IOSParser::IOS::Document
|
50
|
+
expect(subject.to_hash).to eq output
|
51
|
+
end
|
52
|
+
end # context 'indented region'
|
53
|
+
|
54
|
+
context 'partial outdent' do
|
55
|
+
let(:input) do
|
56
|
+
<<-END.unindent
|
57
|
+
class-map match-any foobar
|
58
|
+
description blah blah blah
|
59
|
+
match access-group fred
|
60
|
+
END
|
61
|
+
end
|
62
|
+
|
63
|
+
let(:output) do
|
64
|
+
{
|
65
|
+
commands:
|
66
|
+
[
|
67
|
+
{
|
68
|
+
args: ['class-map', 'match-any', 'foobar'],
|
69
|
+
commands: [
|
70
|
+
{
|
71
|
+
args: %w[description blah blah blah],
|
72
|
+
commands: [],
|
73
|
+
pos: 29
|
74
|
+
},
|
75
|
+
{
|
76
|
+
args: ['match', 'access-group', 'fred'],
|
77
|
+
commands: [],
|
78
|
+
pos: 57
|
79
|
+
}
|
80
|
+
],
|
81
|
+
pos: 0
|
82
|
+
}
|
83
|
+
]
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
subject { described_class.parse(input) }
|
88
|
+
|
89
|
+
it 'constructs the right AST' do
|
90
|
+
should be_a IOSParser::IOS::Document
|
91
|
+
actual = subject.to_hash
|
92
|
+
expect(actual).to eq(output)
|
93
|
+
end
|
94
|
+
end # context "partial outdent" do
|
95
|
+
end # describe '.parse'
|
96
|
+
end # describe IOSParser
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
$LOAD_PATH << File.dirname(__FILE__) + '/../lib'
|
2
|
+
|
3
|
+
def klass
|
4
|
+
described_class
|
5
|
+
end
|
6
|
+
|
7
|
+
def text_fixture(name)
|
8
|
+
File.read(File.expand_path(__dir__ + "/../fixtures/#{name}.txt"))
|
9
|
+
end
|
10
|
+
|
11
|
+
class String
|
12
|
+
def unindent
|
13
|
+
indent = split("\n")
|
14
|
+
.reject { |line| line.strip.empty? }
|
15
|
+
.map { |line| line.index(/[^\s]/) }
|
16
|
+
.compact.min || 0
|
17
|
+
gsub(/^[[:blank:]]{#{indent}}/, '')
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ios_parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.1
|
5
|
+
platform: java
|
6
|
+
authors:
|
7
|
+
- Ben Miller
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0.9'
|
19
|
+
name: rake-compiler
|
20
|
+
prerelease: false
|
21
|
+
type: :development
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.2'
|
33
|
+
name: rspec
|
34
|
+
prerelease: false
|
35
|
+
type: :development
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0.54'
|
47
|
+
name: rubocop
|
48
|
+
prerelease: false
|
49
|
+
type: :development
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.54'
|
55
|
+
description:
|
56
|
+
email: bjmllr@gmail.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- ".gitignore"
|
62
|
+
- ".rubocop.yml"
|
63
|
+
- ".travis.yml"
|
64
|
+
- CHANGELOG.md
|
65
|
+
- CODE_OF_CONDUCT.md
|
66
|
+
- Gemfile
|
67
|
+
- Guardfile
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- doc/state_machine.graphviz
|
74
|
+
- doc/state_machine.png
|
75
|
+
- ext/ios_parser/c_lexer/extconf.rb
|
76
|
+
- ext/ios_parser/c_lexer/lexer.c
|
77
|
+
- fixtures/complex_banner.txt
|
78
|
+
- ios_parser.gemspec
|
79
|
+
- lib/ios_parser.rb
|
80
|
+
- lib/ios_parser/ios.rb
|
81
|
+
- lib/ios_parser/ios/command.rb
|
82
|
+
- lib/ios_parser/ios/document.rb
|
83
|
+
- lib/ios_parser/ios/queryable.rb
|
84
|
+
- lib/ios_parser/lexer.rb
|
85
|
+
- lib/ios_parser/pure.rb
|
86
|
+
- lib/ios_parser/version.rb
|
87
|
+
- spec/lib/ios_parser/ios/queryable_spec.rb
|
88
|
+
- spec/lib/ios_parser/ios_spec.rb
|
89
|
+
- spec/lib/ios_parser/lexer_spec.rb
|
90
|
+
- spec/lib/ios_parser_spec.rb
|
91
|
+
- spec/spec_helper.rb
|
92
|
+
homepage: https://github.com/bjmllr/ios_parser
|
93
|
+
licenses:
|
94
|
+
- GPL-3.0
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.7.6
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: convert network switch and router config files to structured data
|
116
|
+
test_files:
|
117
|
+
- spec/lib/ios_parser/ios/queryable_spec.rb
|
118
|
+
- spec/lib/ios_parser/ios_spec.rb
|
119
|
+
- spec/lib/ios_parser/lexer_spec.rb
|
120
|
+
- spec/lib/ios_parser_spec.rb
|
121
|
+
- spec/spec_helper.rb
|