orenono 0.0.3 → 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/CHANGELOG.md +22 -0
- data/README.md +1 -1
- data/lib/generator.rb +78 -77
- data/lib/orenono/version.rb +1 -1
- data/spec/generator_spec.rb +87 -71
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 738786a3a96cb7467591f48251ab94546f7e36aa
|
4
|
+
data.tar.gz: 8c10f6afe9b82519971c907465db4b893730e99a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62050e69055938347175cd12a2c272ac03771e7f5f9acee0e16aa7cb7e5724c5ed1117ae16668f1fb2ec672f6db994e018c96e778e7331e7d756f8a36a686763
|
7
|
+
data.tar.gz: 21f6e72b2cce2642fdeab4b42c0bf69b3eb9e265320ca094efdec1c2fc29a9f970f7e72af9c1fdcd840e1ad5581b60dbc7b2cd117f1284b8717abe1b29c2e15a
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
## v.0.1.3
|
2
|
+
2015/05/05
|
3
|
+
|
4
|
+
### New Features
|
5
|
+
* Support multibyte in generator.
|
6
|
+
|
7
|
+
## v.0.0.3
|
8
|
+
2014/09/11
|
9
|
+
|
10
|
+
### New Features
|
11
|
+
* Support Brainf*ck code generator from ASCII code text.
|
12
|
+
|
13
|
+
## v.0.0.2
|
14
|
+
2014/09/10
|
15
|
+
|
16
|
+
### New Features
|
17
|
+
* Support brainf*ck to your syntax converter.
|
18
|
+
|
19
|
+
## v.0.0.1
|
20
|
+
2014/08/31
|
21
|
+
|
22
|
+
* first release
|
data/README.md
CHANGED
@@ -269,7 +269,7 @@ Hello, world!
|
|
269
269
|
|
270
270
|
## Contributing
|
271
271
|
|
272
|
-
1. Fork it ( https://github.com/
|
272
|
+
1. Fork it ( https://github.com/tbpgr/orenono/fork )
|
273
273
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
274
274
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
275
275
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/generator.rb
CHANGED
@@ -1,77 +1,78 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'orenono_dsl'
|
3
|
-
require 'orenono_dsl_model'
|
4
|
-
|
5
|
-
# rubocop:disable LineLength
|
6
|
-
module Orenono
|
7
|
-
# Brainf*ck code generator
|
8
|
-
class Generator
|
9
|
-
attr_reader :tables, :init_codes, :pointer, :config
|
10
|
-
|
11
|
-
def self.generate(text, config)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
codes << bf.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
@
|
25
|
-
@
|
26
|
-
@
|
27
|
-
|
28
|
-
config.
|
29
|
-
|
30
|
-
|
31
|
-
config.
|
32
|
-
config.
|
33
|
-
config.
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
@tables[@pointer]
|
41
|
-
@
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
@
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
@
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
@
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
77
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'orenono_dsl'
|
3
|
+
require 'orenono_dsl_model'
|
4
|
+
|
5
|
+
# rubocop:disable LineLength
|
6
|
+
module Orenono
|
7
|
+
# Brainf*ck code generator
|
8
|
+
class Generator
|
9
|
+
attr_reader :tables, :init_codes, :pointer, :config
|
10
|
+
|
11
|
+
def self.generate(text, config)
|
12
|
+
bytes = text.bytes.to_a
|
13
|
+
bf = new(bytes[0], config)
|
14
|
+
bytes.each_with_object([bf.init_codes]) do |char, codes|
|
15
|
+
codes << bf.diff(char)
|
16
|
+
codes << bf.output
|
17
|
+
end.join
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(char, config)
|
21
|
+
char_code = char
|
22
|
+
repeat = char_code / 10
|
23
|
+
rest = char_code % 10
|
24
|
+
@tables = []
|
25
|
+
@pointer = 0
|
26
|
+
@config = config
|
27
|
+
@init_codes = ten_increment(config) +
|
28
|
+
config.start_loop +
|
29
|
+
config.next_cursol +
|
30
|
+
increment(repeat) +
|
31
|
+
config.previous_cursol +
|
32
|
+
config.decrement +
|
33
|
+
config.end_loop +
|
34
|
+
config.next_cursol +
|
35
|
+
increment(rest)
|
36
|
+
@tables[@pointer] = char_code
|
37
|
+
end
|
38
|
+
|
39
|
+
def increment(count = 1)
|
40
|
+
@tables[@pointer] = 0 unless @tables[@pointer]
|
41
|
+
@tables[@pointer] += count
|
42
|
+
@config.increment * count
|
43
|
+
end
|
44
|
+
|
45
|
+
def decrement(count = 1)
|
46
|
+
@tables[@pointer] -= count
|
47
|
+
@config.decrement * count
|
48
|
+
end
|
49
|
+
|
50
|
+
def diff(char_code)
|
51
|
+
diff_of_code = char_code - @tables[@pointer]
|
52
|
+
return '' if diff_of_code.zero?
|
53
|
+
@tables[@pointer] += diff_of_code
|
54
|
+
diff_of_code > 0 ? (@config.increment * diff_of_code) : (@config.decrement * diff_of_code.abs)
|
55
|
+
end
|
56
|
+
|
57
|
+
def next_pointer(count = 1)
|
58
|
+
@pointer += count
|
59
|
+
@config.next_cursol * count
|
60
|
+
end
|
61
|
+
|
62
|
+
def previous_pointer(count = 1)
|
63
|
+
@pointer -= count
|
64
|
+
@config.previous_cursol * count
|
65
|
+
end
|
66
|
+
|
67
|
+
def output(count = 1)
|
68
|
+
@config.display * count
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def ten_increment(config)
|
74
|
+
config.increment * 10
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
# rubocop:enable LineLength
|
data/lib/orenono/version.rb
CHANGED
data/spec/generator_spec.rb
CHANGED
@@ -1,71 +1,87 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
require 'generator'
|
4
|
-
|
5
|
-
# rubocop:disable Tab, UnusedMethodArgument, LineLength
|
6
|
-
describe Orenono::Generator do
|
7
|
-
context :generate do
|
8
|
-
cases = [
|
9
|
-
{
|
10
|
-
case_no: 1,
|
11
|
-
case_title: 'default case',
|
12
|
-
config: Orenono::DslModel.new.tap do |e|
|
13
|
-
e.increment = '+'
|
14
|
-
e.decrement = '-'
|
15
|
-
e.start_loop = '['
|
16
|
-
e.end_loop = ']'
|
17
|
-
e.next_cursol = '>'
|
18
|
-
e.previous_cursol = '<'
|
19
|
-
e.display = '.'
|
20
|
-
e.read = ','
|
21
|
-
end,
|
22
|
-
text: 'Hello, world!',
|
23
|
-
expected: '++++++++++[>+++++++<-]>++.+++++++++++++++++++++++++++++.+++++++..+++.-------------------------------------------------------------------.------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------.+++.------.--------.-------------------------------------------------------------------.'
|
24
|
-
},
|
25
|
-
{
|
26
|
-
case_no: 2,
|
27
|
-
case_title: 'original case',
|
28
|
-
config: Orenono::DslModel.new.tap do |e|
|
29
|
-
e.increment = 'add'
|
30
|
-
e.decrement = 'diff'
|
31
|
-
e.start_loop = 'start'
|
32
|
-
e.end_loop = 'end'
|
33
|
-
e.next_cursol = 'next'
|
34
|
-
e.previous_cursol = 'previous'
|
35
|
-
e.display = 'display'
|
36
|
-
e.read = 'read'
|
37
|
-
end,
|
38
|
-
text: 'Hello, world!',
|
39
|
-
expected: 'addaddaddaddaddaddaddaddaddaddstartnextaddaddaddaddaddaddaddpreviousdiffendnextaddadddisplayaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddadddisplayaddaddaddaddaddaddadddisplaydisplayaddaddadddisplaydiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdisplaydiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdisplayaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddadddisplaydiffdiffdiffdiffdiffdiffdiffdiffdisplayaddaddadddisplaydiffdiffdiffdiffdiffdiffdisplaydiffdiffdiffdiffdiffdiffdiffdiffdisplaydiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdisplay'
|
40
|
-
}
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'generator'
|
4
|
+
|
5
|
+
# rubocop:disable Tab, UnusedMethodArgument, LineLength
|
6
|
+
describe Orenono::Generator do
|
7
|
+
context :generate do
|
8
|
+
cases = [
|
9
|
+
{
|
10
|
+
case_no: 1,
|
11
|
+
case_title: 'default case',
|
12
|
+
config: Orenono::DslModel.new.tap do |e|
|
13
|
+
e.increment = '+'
|
14
|
+
e.decrement = '-'
|
15
|
+
e.start_loop = '['
|
16
|
+
e.end_loop = ']'
|
17
|
+
e.next_cursol = '>'
|
18
|
+
e.previous_cursol = '<'
|
19
|
+
e.display = '.'
|
20
|
+
e.read = ','
|
21
|
+
end,
|
22
|
+
text: 'Hello, world!',
|
23
|
+
expected: '++++++++++[>+++++++<-]>++.+++++++++++++++++++++++++++++.+++++++..+++.-------------------------------------------------------------------.------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------.+++.------.--------.-------------------------------------------------------------------.'
|
24
|
+
},
|
25
|
+
{
|
26
|
+
case_no: 2,
|
27
|
+
case_title: 'original case',
|
28
|
+
config: Orenono::DslModel.new.tap do |e|
|
29
|
+
e.increment = 'add'
|
30
|
+
e.decrement = 'diff'
|
31
|
+
e.start_loop = 'start'
|
32
|
+
e.end_loop = 'end'
|
33
|
+
e.next_cursol = 'next'
|
34
|
+
e.previous_cursol = 'previous'
|
35
|
+
e.display = 'display'
|
36
|
+
e.read = 'read'
|
37
|
+
end,
|
38
|
+
text: 'Hello, world!',
|
39
|
+
expected: 'addaddaddaddaddaddaddaddaddaddstartnextaddaddaddaddaddaddaddpreviousdiffendnextaddadddisplayaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddadddisplayaddaddaddaddaddaddadddisplaydisplayaddaddadddisplaydiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdisplaydiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdisplayaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddadddisplaydiffdiffdiffdiffdiffdiffdiffdiffdisplayaddaddadddisplaydiffdiffdiffdiffdiffdiffdisplaydiffdiffdiffdiffdiffdiffdiffdiffdisplaydiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdisplay'
|
40
|
+
},
|
41
|
+
{
|
42
|
+
case_no: 3,
|
43
|
+
case_title: 'multibyte case',
|
44
|
+
config: Orenono::DslModel.new.tap do |e|
|
45
|
+
e.increment = '+'
|
46
|
+
e.decrement = '-'
|
47
|
+
e.start_loop = '['
|
48
|
+
e.end_loop = ']'
|
49
|
+
e.next_cursol = '>'
|
50
|
+
e.previous_cursol = '<'
|
51
|
+
e.display = '.'
|
52
|
+
e.read = ','
|
53
|
+
end,
|
54
|
+
text: 'こんにちわ世界',
|
55
|
+
expected: '++++++++++[>++++++++++++++++++++++<-]>+++++++.--------------------------------------------------------------------------------------------------.++++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------------------------------------------------------------------------------------------------.+++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------------------------------------------------------------------------------------------------.+++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------------------------------------.----------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------------------------------.---------.'
|
56
|
+
}
|
57
|
+
]
|
58
|
+
|
59
|
+
cases.each do |c|
|
60
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
61
|
+
begin
|
62
|
+
case_before c
|
63
|
+
|
64
|
+
# -- given --
|
65
|
+
# nothing
|
66
|
+
|
67
|
+
# -- when --
|
68
|
+
actual = Orenono::Generator.generate(c[:text], c[:config])
|
69
|
+
|
70
|
+
# -- then --
|
71
|
+
expect(actual).to eq(c[:expected])
|
72
|
+
ensure
|
73
|
+
case_after c
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def case_before(c)
|
78
|
+
# implement each case before
|
79
|
+
end
|
80
|
+
|
81
|
+
def case_after(c)
|
82
|
+
# implement each case after
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
# rubocop:enable Tab, UnusedMethodArgument, LineLength
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: orenono
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tbpgr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- .rspec
|
66
66
|
- .rubocop.yml
|
67
67
|
- .travis.yml
|
68
|
+
- CHANGELOG.md
|
68
69
|
- Gemfile
|
69
70
|
- LICENSE.txt
|
70
71
|
- README.md
|
@@ -121,3 +122,4 @@ test_files:
|
|
121
122
|
- spec/generator_spec.rb
|
122
123
|
- spec/orenono_core_spec.rb
|
123
124
|
- spec/spec_helper.rb
|
125
|
+
has_rdoc:
|