boost_info 0.1.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 +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +56 -0
- data/Rakefile +9 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/boost_info.gemspec +22 -0
- data/lib/boost_info/generator.rb +43 -0
- data/lib/boost_info/node.rb +68 -0
- data/lib/boost_info/parser.rb +138 -0
- data/lib/boost_info/version.rb +3 -0
- data/lib/boost_info.rb +20 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c098287f6a9aa1b72253d21886e450420b5b9051
|
4
|
+
data.tar.gz: 7c15191f3ef8489a95147c15d8ad06ef17834f83
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 908bd73787b1099e4c082c7bf8a2a3bce1edbac1f7d4846af5e45d2a7f55e165160faacdc612394038aabe565a55869b2dda0af3511fab146dab9323c6edd69f
|
7
|
+
data.tar.gz: ecf4cc6dc51b30c1e0a6ca4d828c12c793a725b837b5492e6fbd6f812ed23bae3462fba3b2d0ebf755ae9329aa43e5cc4be20f92289b88ea746c5000f7bcda77
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Alexander Tsygankov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# BoostInfo
|
2
|
+
|
3
|
+
Simple parser for [Boost INFO format](http://www.boost.org/doc/libs/1_42_0/doc/html/boost_propertytree/parsers.html#boost_propertytree.parsers.info_parser).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'boost_info'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install boost_info
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Parsing INFO
|
24
|
+
```ruby
|
25
|
+
BoostInfo.parse(file, options={})
|
26
|
+
```
|
27
|
+
|
28
|
+
Available options:
|
29
|
+
|
30
|
+
- **symbolize_names**: convert all keys to symbols (default: false)
|
31
|
+
|
32
|
+
### Generating INFO
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
{ x: 'y' }.to_info(options={})
|
36
|
+
```
|
37
|
+
|
38
|
+
Available options:
|
39
|
+
|
40
|
+
- **indent**: indentation level (default: 4)
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it ( https://github.com/zenbro/boost_info/fork )
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create a new Pull Request
|
49
|
+
|
50
|
+
## Credits
|
51
|
+
|
52
|
+
Originally created by Igor Vetrov.
|
53
|
+
|
54
|
+
## License
|
55
|
+
|
56
|
+
Code released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "boost_info"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/boost_info.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'boost_info/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "boost_info"
|
8
|
+
spec.version = BoostInfo::VERSION
|
9
|
+
spec.authors = ["Igor Vetrov", "Alexander Tsygankov"]
|
10
|
+
spec.email = ["capybarov@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Simple parser for Boost INFO format}
|
13
|
+
spec.homepage = "https://github.com/zenbro/boost_info"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'boost_info/node'
|
2
|
+
|
3
|
+
module BoostInfo
|
4
|
+
class Generator
|
5
|
+
def initialize(hash, opts={})
|
6
|
+
raise TypeError unless hash.is_a?(Hash)
|
7
|
+
@hash = hash
|
8
|
+
@opts = opts
|
9
|
+
@opts[:indent] ||= 4
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate
|
13
|
+
@result = ''
|
14
|
+
level = 0
|
15
|
+
iterate_hash(@hash, level)
|
16
|
+
@result
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def iterate_hash(hash, level)
|
22
|
+
hash.each do |k,v|
|
23
|
+
k = k.to_s
|
24
|
+
@result << add_indent(k, level)
|
25
|
+
if v.is_a?(Hash)
|
26
|
+
@result << " {\n"
|
27
|
+
iterate_hash(v, level + 1)
|
28
|
+
else
|
29
|
+
v = v.to_s
|
30
|
+
# Wrap "values with spaces and /"
|
31
|
+
v = %["#{ v }"] if v[/[\s\/]/]
|
32
|
+
@result << ' ' + v + "\n"
|
33
|
+
@result << add_indent("}\n", level - 1) if k == hash.keys.last
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def add_indent(string, level)
|
39
|
+
indent = @opts[:indent] * level
|
40
|
+
"#{ ' ' * indent if indent > 0}#{string}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module BoostInfo
|
4
|
+
class Node
|
5
|
+
attr_accessor :level, :name, :value, :parent, :children
|
6
|
+
|
7
|
+
def initialize(level, name, value=nil)
|
8
|
+
# Instance initializer
|
9
|
+
@level = level
|
10
|
+
@name = name
|
11
|
+
@value = value
|
12
|
+
@parent = nil
|
13
|
+
@children = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
# String representation for node
|
18
|
+
if @value
|
19
|
+
"#{'| '*@level}#{@level} #{@name} = #{@value}"
|
20
|
+
else
|
21
|
+
"#{'| '*@level}#{@level} #{@name}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_h(symbolize=false)
|
26
|
+
key = symbolize ? @name.to_sym : @name
|
27
|
+
if has_children?
|
28
|
+
result = {}
|
29
|
+
@children.each { |c| result.merge!(c.to_h(symbolize)) }
|
30
|
+
{ key => result }
|
31
|
+
else
|
32
|
+
{ key => @value }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_child(child)
|
37
|
+
# Add child node and assign parent to child node
|
38
|
+
child.parent = self
|
39
|
+
@children << child
|
40
|
+
end
|
41
|
+
|
42
|
+
def has_children?
|
43
|
+
# Check children existence
|
44
|
+
@children.size > 0
|
45
|
+
end
|
46
|
+
|
47
|
+
def has_parent?
|
48
|
+
# Check parent existence
|
49
|
+
@parent != nil
|
50
|
+
end
|
51
|
+
|
52
|
+
def find(name)
|
53
|
+
# Recursive node search by name
|
54
|
+
return self if @name == name
|
55
|
+
result_node = nil
|
56
|
+
@children.each do |node|
|
57
|
+
if node.name==name then result_node = node; break end
|
58
|
+
if node.has_children?
|
59
|
+
found_node = node.find(name)
|
60
|
+
if found_node
|
61
|
+
if found_node.name==name then result_node = found_node; break end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
result_node
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'boost_info/node'
|
2
|
+
|
3
|
+
module BoostInfo
|
4
|
+
class ParseError < StandardError; end
|
5
|
+
|
6
|
+
class Parser
|
7
|
+
attr_accessor :nodes
|
8
|
+
|
9
|
+
# Boost info tokens
|
10
|
+
@@tokens = '{}'
|
11
|
+
@@open_token = '{'
|
12
|
+
@@close_token = '}'
|
13
|
+
|
14
|
+
def initialize(source, opts={})
|
15
|
+
unless source.is_a?(String)
|
16
|
+
raise TypeError, "no implicit conversion of #{source.class} into String"
|
17
|
+
end
|
18
|
+
|
19
|
+
# Initialize instance variables
|
20
|
+
@nodes = []
|
21
|
+
@level = 0
|
22
|
+
@source = source
|
23
|
+
@tokens = []
|
24
|
+
@opts = opts
|
25
|
+
@opts[:symbolize_keys] ||= false
|
26
|
+
|
27
|
+
# without empty lines and comments
|
28
|
+
tokenize! { |token| @tokens << token }
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse
|
32
|
+
# Parse source
|
33
|
+
opens = @source.count(@@open_token)
|
34
|
+
closes = @source.count(@@close_token)
|
35
|
+
if opens != closes
|
36
|
+
raise BoostInfo::ParseError, "open [#{opens}] and close tokens [#{closes}] does not match..."
|
37
|
+
end
|
38
|
+
nodes = {}
|
39
|
+
@tokens.each do |token|
|
40
|
+
if @@open_token == token
|
41
|
+
@level += 1
|
42
|
+
elsif @@close_token == token
|
43
|
+
@level -= 1
|
44
|
+
else
|
45
|
+
list = token.split
|
46
|
+
if list.size > 2
|
47
|
+
val = list[1..-1].join(" ")
|
48
|
+
else
|
49
|
+
val = list[1]
|
50
|
+
end
|
51
|
+
val = val.gsub(/\A["]+|["]+\z/, "") if val
|
52
|
+
node = Node.new(@level, list[0], val)
|
53
|
+
nodes[@level] = node
|
54
|
+
if @level == 0
|
55
|
+
@nodes << node
|
56
|
+
else
|
57
|
+
nodes[@level] = node unless nodes.has_key?(@level)
|
58
|
+
nodes[@level-1].add_child(node)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
self
|
63
|
+
end
|
64
|
+
|
65
|
+
def find(name)
|
66
|
+
# Recursive node search by name
|
67
|
+
result_node = nil
|
68
|
+
@nodes.each do |node|
|
69
|
+
result_node = node.find(name)
|
70
|
+
break if result_node
|
71
|
+
end
|
72
|
+
result_node
|
73
|
+
end
|
74
|
+
|
75
|
+
def [](offset)
|
76
|
+
# Get elements by key
|
77
|
+
find(offset)
|
78
|
+
end
|
79
|
+
|
80
|
+
def print_node(node)
|
81
|
+
# Print node with children
|
82
|
+
puts node
|
83
|
+
node.children.each { |child| print_node(child) }
|
84
|
+
puts "#{'| '*node.level}#{node.level} #{node.name} close" if node.has_children?
|
85
|
+
end
|
86
|
+
|
87
|
+
def print_tree
|
88
|
+
# Print parsed tree
|
89
|
+
@nodes.each { |node| print_node(node) }
|
90
|
+
end
|
91
|
+
|
92
|
+
def child_source(node)
|
93
|
+
result = ' '*node.level + node.name + (node.value ? " #{ node.value }" : '')
|
94
|
+
if node.has_children?
|
95
|
+
result += " {\n"
|
96
|
+
node.children.each { |child| result += self.child_source(child) }
|
97
|
+
result += ' '*node.level + "}\n"
|
98
|
+
else
|
99
|
+
result += "\n"
|
100
|
+
end
|
101
|
+
result
|
102
|
+
end
|
103
|
+
|
104
|
+
def to_s
|
105
|
+
self.to_h.to_info
|
106
|
+
end
|
107
|
+
|
108
|
+
def to_h
|
109
|
+
result = {}
|
110
|
+
@nodes.each { |n| result.merge!(n.to_h(@opts[:symbolize_keys])) }
|
111
|
+
result
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
def tokenize!
|
117
|
+
# tokenize boost info format
|
118
|
+
lines = []
|
119
|
+
@source.split("\n").each do |line|
|
120
|
+
lines << line.split(';')[0].strip unless line.strip.empty? || line.strip[0] == ';'
|
121
|
+
end
|
122
|
+
lines.each do |line|
|
123
|
+
token = ''
|
124
|
+
line.each_char do |char|
|
125
|
+
if '{}'.include?(char)
|
126
|
+
token = token.strip
|
127
|
+
yield token unless token.empty?
|
128
|
+
yield char
|
129
|
+
token = ''
|
130
|
+
else
|
131
|
+
token += char
|
132
|
+
end
|
133
|
+
end
|
134
|
+
yield token.strip unless token.empty?
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
data/lib/boost_info.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'boost_info/version'
|
2
|
+
require 'boost_info/node'
|
3
|
+
require 'boost_info/parser'
|
4
|
+
require 'boost_info/generator'
|
5
|
+
|
6
|
+
module BoostInfo
|
7
|
+
def self.parse(source, opts={})
|
8
|
+
BoostInfo::Parser.new(source, opts).parse.to_h
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.generate(hash, opts={})
|
12
|
+
BoostInfo::Generator.new(hash, opts).generate
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Hash
|
17
|
+
def to_info(opts={})
|
18
|
+
BoostInfo.generate(self, opts)
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: boost_info
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Igor Vetrov
|
8
|
+
- Alexander Tsygankov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-05-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.8'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.8'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
description:
|
43
|
+
email:
|
44
|
+
- capybarov@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- ".travis.yml"
|
51
|
+
- CODE_OF_CONDUCT.md
|
52
|
+
- Gemfile
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- bin/console
|
57
|
+
- bin/setup
|
58
|
+
- boost_info.gemspec
|
59
|
+
- lib/boost_info.rb
|
60
|
+
- lib/boost_info/generator.rb
|
61
|
+
- lib/boost_info/node.rb
|
62
|
+
- lib/boost_info/parser.rb
|
63
|
+
- lib/boost_info/version.rb
|
64
|
+
homepage: https://github.com/zenbro/boost_info
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 2.4.5
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: Simple parser for Boost INFO format
|
88
|
+
test_files: []
|