erlang_config_parser 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 10665ef6d83199a0b4d6450350e93abea1b351a8
4
+ data.tar.gz: 98ce9d84b2e0ea7ecd2f88b28ba510094f3fc775
5
+ SHA512:
6
+ metadata.gz: 19ed64edf71da64a347c94314f0c7f4127aa82d82cf34776250c9056b3e53d0e094f5f547d7508194ebdd2f2cfa407406cb4e707b8bf7f3b7ccf62edc7998711
7
+ data.tar.gz: d1fed5337237082f034cfd80d2b7e70e05a6f21e602158581d0363bcf6fc7a8093790bcb3aa46be62fd4d4468b6b84a15fb672f3cffb436b03411a6de3689a5f
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.4
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in erlang_config_parser.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 nownabe
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,43 @@
1
+ # ErlangConfigParser
2
+
3
+ ErlangConfigParser can parse Erlang configs to Ruby objects.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'erlang_config_parser'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install erlang_config_parser
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require "erlang_config_parser"
25
+
26
+ configs = ErlangConfigParser.parse(erlang_config_string)
27
+ ```
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nownabe/erlang_config_parser.
38
+
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
43
+
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
8
+ desc "Compile parser"
9
+ task :compile do
10
+ Bundler.with_clean_env do
11
+ base_dir = File.expand_path("../lib/erlang_config_parser", __FILE__)
12
+ dst_path = File.join(base_dir, "parser.rb")
13
+ src_path = File.join(base_dir, "parser.ry")
14
+ system("bundle exec racc -g -o #{dst_path} #{src_path}")
15
+ end
16
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "erlang_config_parser"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'erlang_config_parser/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "erlang_config_parser"
8
+ spec.version = ErlangConfigParser::VERSION
9
+ spec.authors = ["nownabe"]
10
+ spec.email = ["nownabe@gmail.com"]
11
+
12
+ spec.summary = %q{ErlangConfigParser can parse Erlang configs into Ruby objects.}
13
+ spec.homepage = "https://github.com/nownabe/erlang_config_parser"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.11"
22
+ spec.add_development_dependency "racc"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "erlang_config_parser/parser"
4
+
5
+ module ErlangConfigParser
6
+ def self.parse(erlang_config_string)
7
+ Parser.new.parse(erlang_config_string)
8
+ end
9
+ end
@@ -0,0 +1,238 @@
1
+ #
2
+ # DO NOT MODIFY!!!!
3
+ # This file is automatically generated by Racc 1.4.14
4
+ # from Racc grammer file "".
5
+ #
6
+
7
+ require 'racc/parser.rb'
8
+
9
+ require "strscan"
10
+
11
+ module ErlangConfigParser
12
+ class Parser < Racc::Parser
13
+
14
+ module_eval(<<'...end parser.ry/module_eval...', 'parser.ry', 27)
15
+
16
+ def parse(str)
17
+ ss = StringScanner.new(str)
18
+ @tokens = []
19
+
20
+ until ss.eos?
21
+ ss.scan(/"(.+)"/) ? @tokens << [:STRING, ss[1]] :
22
+ ss.scan(/\d+\.\d+/) ? @tokens << [:FLOAT, ss.matched] :
23
+ ss.scan(/\d+/) ? @tokens << [:INTEGER, ss.matched] :
24
+ ss.scan(/\[/) ? @tokens << [:LIST_BEGIN, ss.matched] :
25
+ ss.scan(/\]/) ? @tokens << [:LIST_END, ss.matched] :
26
+ ss.scan(/{/) ? @tokens << [:TUPLE_BEGIN, ss.matched] :
27
+ ss.scan(/}/) ? @tokens << [:TUPLE_END, ss.matched] :
28
+ ss.scan(/'([-\w_@]+)'/) ? @tokens << [:ATOM, ss[1]] :
29
+ ss.scan(/[a-z][\w_@]+/) ? @tokens << [:ATOM, ss.matched] :
30
+ ss.scan(/,/) ? @tokens << [:COMMA, ss.matched] :
31
+ ss.scan(/\s/) ? nil :
32
+ (raise "scanner error")
33
+ end
34
+
35
+ do_parse
36
+ end
37
+
38
+ def next_token
39
+ @tokens.shift
40
+ end
41
+ ...end parser.ry/module_eval...
42
+ ##### State transition tables begin ###
43
+
44
+ racc_action_table = [
45
+ 4, 19, 5, 6, 20, 12, 13, 14, 15, 4,
46
+ 18, 5, 17, nil, 12, 13, 14, 15, 4, 8,
47
+ 5, 21, 20, 12, 13, 14, 15, 4, nil, 5 ]
48
+
49
+ racc_action_check = [
50
+ 20, 7, 20, 1, 7, 20, 20, 20, 20, 5,
51
+ 6, 5, 5, nil, 5, 5, 5, 5, 4, 4,
52
+ 4, 16, 16, 4, 4, 4, 4, 0, nil, 0 ]
53
+
54
+ racc_action_pointer = [
55
+ 25, 3, nil, nil, 16, 7, 10, -2, nil, nil,
56
+ nil, nil, nil, nil, nil, nil, 16, nil, nil, nil,
57
+ -2, nil, nil ]
58
+
59
+ racc_action_default = [
60
+ -15, -15, -1, -2, -15, -15, -15, -15, -4, -7,
61
+ -9, -10, -11, -12, -13, -14, -15, -6, 23, -3,
62
+ -15, -5, -8 ]
63
+
64
+ racc_goto_table = [
65
+ 7, 16, 3, 2, 1, 22 ]
66
+
67
+ racc_goto_check = [
68
+ 4, 4, 3, 2, 1, 5 ]
69
+
70
+ racc_goto_pointer = [
71
+ nil, 4, 3, 2, -4, -15 ]
72
+
73
+ racc_goto_default = [
74
+ nil, nil, 10, 11, nil, 9 ]
75
+
76
+ racc_reduce_table = [
77
+ 0, 0, :racc_error,
78
+ 1, 12, :_reduce_none,
79
+ 1, 12, :_reduce_none,
80
+ 3, 13, :_reduce_3,
81
+ 2, 13, :_reduce_4,
82
+ 3, 14, :_reduce_5,
83
+ 2, 14, :_reduce_6,
84
+ 1, 15, :_reduce_7,
85
+ 3, 15, :_reduce_8,
86
+ 1, 16, :_reduce_none,
87
+ 1, 16, :_reduce_none,
88
+ 1, 16, :_reduce_11,
89
+ 1, 16, :_reduce_12,
90
+ 1, 16, :_reduce_13,
91
+ 1, 16, :_reduce_14 ]
92
+
93
+ racc_reduce_n = 15
94
+
95
+ racc_shift_n = 23
96
+
97
+ racc_token_table = {
98
+ false => 0,
99
+ :error => 1,
100
+ :LIST_BEGIN => 2,
101
+ :LIST_END => 3,
102
+ :TUPLE_BEGIN => 4,
103
+ :TUPLE_END => 5,
104
+ :COMMA => 6,
105
+ :ATOM => 7,
106
+ :STRING => 8,
107
+ :INTEGER => 9,
108
+ :FLOAT => 10 }
109
+
110
+ racc_nt_base = 11
111
+
112
+ racc_use_result_var = true
113
+
114
+ Racc_arg = [
115
+ racc_action_table,
116
+ racc_action_check,
117
+ racc_action_default,
118
+ racc_action_pointer,
119
+ racc_goto_table,
120
+ racc_goto_check,
121
+ racc_goto_default,
122
+ racc_goto_pointer,
123
+ racc_nt_base,
124
+ racc_reduce_table,
125
+ racc_token_table,
126
+ racc_shift_n,
127
+ racc_reduce_n,
128
+ racc_use_result_var ]
129
+
130
+ Racc_token_to_s_table = [
131
+ "$end",
132
+ "error",
133
+ "LIST_BEGIN",
134
+ "LIST_END",
135
+ "TUPLE_BEGIN",
136
+ "TUPLE_END",
137
+ "COMMA",
138
+ "ATOM",
139
+ "STRING",
140
+ "INTEGER",
141
+ "FLOAT",
142
+ "$start",
143
+ "statement",
144
+ "list",
145
+ "tuple",
146
+ "elements",
147
+ "element" ]
148
+
149
+ Racc_debug_parser = true
150
+
151
+ ##### State transition tables end #####
152
+
153
+ # reduce 0 omitted
154
+
155
+ # reduce 1 omitted
156
+
157
+ # reduce 2 omitted
158
+
159
+ module_eval(<<'.,.,', 'parser.ry', 5)
160
+ def _reduce_3(val, _values, result)
161
+ result = val[1]
162
+ result
163
+ end
164
+ .,.,
165
+
166
+ module_eval(<<'.,.,', 'parser.ry', 6)
167
+ def _reduce_4(val, _values, result)
168
+ result = []
169
+ result
170
+ end
171
+ .,.,
172
+
173
+ module_eval(<<'.,.,', 'parser.ry', 8)
174
+ def _reduce_5(val, _values, result)
175
+ result = val[1]
176
+ result
177
+ end
178
+ .,.,
179
+
180
+ module_eval(<<'.,.,', 'parser.ry', 9)
181
+ def _reduce_6(val, _values, result)
182
+ result = []
183
+ result
184
+ end
185
+ .,.,
186
+
187
+ module_eval(<<'.,.,', 'parser.ry', 11)
188
+ def _reduce_7(val, _values, result)
189
+ result = [val[0]]
190
+ result
191
+ end
192
+ .,.,
193
+
194
+ module_eval(<<'.,.,', 'parser.ry', 12)
195
+ def _reduce_8(val, _values, result)
196
+ result << val[2]
197
+ result
198
+ end
199
+ .,.,
200
+
201
+ # reduce 9 omitted
202
+
203
+ # reduce 10 omitted
204
+
205
+ module_eval(<<'.,.,', 'parser.ry', 16)
206
+ def _reduce_11(val, _values, result)
207
+ result = val[0].to_sym
208
+ result
209
+ end
210
+ .,.,
211
+
212
+ module_eval(<<'.,.,', 'parser.ry', 17)
213
+ def _reduce_12(val, _values, result)
214
+ result = val[0]
215
+ result
216
+ end
217
+ .,.,
218
+
219
+ module_eval(<<'.,.,', 'parser.ry', 18)
220
+ def _reduce_13(val, _values, result)
221
+ result = val[0].to_i
222
+ result
223
+ end
224
+ .,.,
225
+
226
+ module_eval(<<'.,.,', 'parser.ry', 19)
227
+ def _reduce_14(val, _values, result)
228
+ result = val[0].to_f
229
+ result
230
+ end
231
+ .,.,
232
+
233
+ def _reduce_none(val, _values, result)
234
+ val[0]
235
+ end
236
+
237
+ end # class Parser
238
+ end # module ErlangConfigParser
@@ -0,0 +1,52 @@
1
+ class ErlangConfigParser::Parser
2
+ rule
3
+ statement : list
4
+ | tuple
5
+
6
+ list : LIST_BEGIN elements LIST_END { result = val[1] }
7
+ | LIST_BEGIN LIST_END { result = [] }
8
+
9
+ tuple : TUPLE_BEGIN elements TUPLE_END { result = val[1] }
10
+ | TUPLE_BEGIN TUPLE_END { result = [] }
11
+
12
+ elements : element { result = [val[0]] }
13
+ | elements COMMA element { result << val[2] }
14
+
15
+ element : list
16
+ | tuple
17
+ | ATOM { result = val[0].to_sym }
18
+ | STRING { result = val[0] }
19
+ | INTEGER { result = val[0].to_i }
20
+ | FLOAT { result = val[0].to_f }
21
+ end
22
+
23
+ ---- header
24
+ require "strscan"
25
+
26
+ ---- inner
27
+
28
+ def parse(str)
29
+ ss = StringScanner.new(str)
30
+ @tokens = []
31
+
32
+ until ss.eos?
33
+ ss.scan(/"(.+)"/) ? @tokens << [:STRING, ss[1]] :
34
+ ss.scan(/\d+\.\d+/) ? @tokens << [:FLOAT, ss.matched] :
35
+ ss.scan(/\d+/) ? @tokens << [:INTEGER, ss.matched] :
36
+ ss.scan(/\[/) ? @tokens << [:LIST_BEGIN, ss.matched] :
37
+ ss.scan(/\]/) ? @tokens << [:LIST_END, ss.matched] :
38
+ ss.scan(/{/) ? @tokens << [:TUPLE_BEGIN, ss.matched] :
39
+ ss.scan(/}/) ? @tokens << [:TUPLE_END, ss.matched] :
40
+ ss.scan(/'([-\w_@]+)'/) ? @tokens << [:ATOM, ss[1]] :
41
+ ss.scan(/[a-z][\w_@]+/) ? @tokens << [:ATOM, ss.matched] :
42
+ ss.scan(/,/) ? @tokens << [:COMMA, ss.matched] :
43
+ ss.scan(/\s/) ? nil :
44
+ (raise "scanner error")
45
+ end
46
+
47
+ do_parse
48
+ end
49
+
50
+ def next_token
51
+ @tokens.shift
52
+ end
@@ -0,0 +1,3 @@
1
+ module ErlangConfigParser
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: erlang_config_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - nownabe
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: racc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description:
70
+ email:
71
+ - nownabe@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - erlang_config_parser.gemspec
86
+ - lib/erlang_config_parser.rb
87
+ - lib/erlang_config_parser/parser.rb
88
+ - lib/erlang_config_parser/parser.ry
89
+ - lib/erlang_config_parser/version.rb
90
+ homepage: https://github.com/nownabe/erlang_config_parser
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.4.5.1
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: ErlangConfigParser can parse Erlang configs into Ruby objects.
114
+ test_files: []