raabro 0.9.0 → 1.0.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.
- data/CHANGELOG.txt +13 -0
- data/README.md +3 -0
- data/lib/raabro.rb +292 -74
- data/spec/all_spec.rb +54 -0
- data/spec/alt_spec.rb +92 -12
- data/spec/eseq_spec.rb +112 -0
- data/spec/jseq_spec.rb +67 -0
- data/spec/ren_spec.rb +43 -0
- data/spec/rep_spec.rb +28 -16
- data/spec/rex_spec.rb +22 -11
- data/spec/sample_xel_spec.rb +110 -0
- data/spec/seq_spec.rb +165 -187
- data/spec/spec_helper.rb +57 -0
- data/spec/str_spec.rb +20 -16
- data/spec/tree_spec.rb +47 -0
- metadata +9 -2
data/spec/spec_helper.rb
CHANGED
@@ -5,6 +5,8 @@
|
|
5
5
|
# Sat Sep 19 21:12:35 JST 2015
|
6
6
|
#
|
7
7
|
|
8
|
+
require 'pp'
|
9
|
+
|
8
10
|
require 'raabro'
|
9
11
|
|
10
12
|
#
|
@@ -12,4 +14,59 @@ require 'raabro'
|
|
12
14
|
|
13
15
|
def ta(i); Raabro.str(nil, i, 'ta'); end
|
14
16
|
def to(i); Raabro.str(nil, i, 'to'); end
|
17
|
+
def tu(i); Raabro.str(nil, i, 'tu'); end
|
18
|
+
|
19
|
+
def to_plus(input); Raabro.rep(:tos, input, :to, 1); end
|
20
|
+
|
21
|
+
def nta(i); Raabro.str('the-ta', i, 'ta'); end
|
22
|
+
|
23
|
+
def cha(i); Raabro.rex(nil, i, /\A[a-z]/); end
|
24
|
+
def com(i); Raabro.str(nil, i, ','); end
|
25
|
+
|
26
|
+
def lt(i); Raabro.str(nil, i, '<'); end
|
27
|
+
def gt(i); Raabro.str(nil, i, '>'); end
|
28
|
+
|
29
|
+
def onex(i); Raabro.str(:onex, i, 'x'); end
|
30
|
+
def twox(i); Raabro.str(:twox, i, 'xx'); end
|
31
|
+
|
32
|
+
|
33
|
+
#
|
34
|
+
# test modules
|
35
|
+
|
36
|
+
module Sample; end
|
37
|
+
|
38
|
+
module Sample::Cal include Raabro
|
39
|
+
|
40
|
+
def sp(i); rex(nil, i, /\s+/); end
|
41
|
+
|
42
|
+
def num(i); rex(:num, i, /-?[0-9]+/); end
|
43
|
+
def op(i); rex(:op, i, /[+\-*\/]/); end
|
44
|
+
def item(i); alt(:item, i, :num, :op); end
|
45
|
+
|
46
|
+
def suite(i); jseq(nil, i, :item, :sp); end
|
47
|
+
|
48
|
+
# entry point
|
49
|
+
|
50
|
+
def parse(input)
|
51
|
+
|
52
|
+
all(nil, Raabro::Input.new(input, :prune => true), :suite)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
module Sample::Arith include Raabro
|
57
|
+
|
58
|
+
def number(i); rex(:number, i, /-?[0-9]+\s*/); end
|
59
|
+
def plus(i); rex(:plus, i, /\+\s*/); end
|
60
|
+
def minus(i); rex(:minus, i, /-\s*/); end
|
61
|
+
|
62
|
+
def addition(i); seq(:addition, i, :number, :plus, :op_or_num); end
|
63
|
+
def substraction(i); seq(:substraction, i, :number, :minus, :op_or_num); end
|
64
|
+
|
65
|
+
def op_or_num(i); alt(nil, i, :addition, :substraction, :number); end
|
66
|
+
|
67
|
+
def parse(input)
|
68
|
+
|
69
|
+
all(nil, Raabro::Input.new(input, prune: true), :op_or_num)
|
70
|
+
end
|
71
|
+
end
|
15
72
|
|
data/spec/str_spec.rb
CHANGED
@@ -10,63 +10,67 @@ require 'spec_helper'
|
|
10
10
|
|
11
11
|
describe Raabro do
|
12
12
|
|
13
|
-
before :each do
|
14
|
-
|
15
|
-
@input = Raabro::Input.new('toto')
|
16
|
-
end
|
17
|
-
|
18
13
|
describe '.str' do
|
19
14
|
|
20
15
|
it 'returns a tree with result == 0 in case of failure' do
|
21
16
|
|
22
|
-
|
17
|
+
i = Raabro::Input.new('toto')
|
18
|
+
|
19
|
+
t = Raabro.str(nil, i, 'nada')
|
23
20
|
|
24
21
|
expect(t.to_a).to eq(
|
25
22
|
[ nil, 0, 0, 0, nil, :str, [] ]
|
26
23
|
)
|
27
|
-
expect(
|
24
|
+
expect(i.offset).to eq(0)
|
28
25
|
end
|
29
26
|
|
30
27
|
it "returns a tree with result == 1 in case of success" do
|
31
28
|
|
32
|
-
|
29
|
+
i = Raabro::Input.new('toto')
|
30
|
+
|
31
|
+
t = Raabro.str(nil, i, 'toto')
|
33
32
|
|
34
33
|
expect(t.to_a).to eq(
|
35
34
|
[ nil, 1, 0, 4, nil, :str, [] ]
|
36
35
|
)
|
37
|
-
expect(
|
36
|
+
expect(i.offset).to eq(4)
|
38
37
|
end
|
39
38
|
|
40
39
|
it "names the result if there is a name" do
|
41
40
|
|
42
|
-
|
41
|
+
i = Raabro::Input.new('toto')
|
42
|
+
|
43
|
+
t = Raabro.str(:x, i, 'toto')
|
43
44
|
|
44
45
|
expect(t.to_a).to eq(
|
45
46
|
[ :x, 1, 0, 4, nil, :str, [] ]
|
46
47
|
)
|
47
|
-
expect(
|
48
|
+
expect(i.offset).to eq(4)
|
48
49
|
end
|
49
50
|
|
50
51
|
it "names in case of failure as well" do
|
51
52
|
|
52
|
-
|
53
|
+
i = Raabro::Input.new('toto')
|
54
|
+
|
55
|
+
t = Raabro.str(:y, i, 'nada')
|
53
56
|
|
54
57
|
expect(t.to_a).to eq(
|
55
58
|
[ :y, 0, 0, 0, nil, :str, [] ]
|
56
59
|
)
|
57
|
-
expect(
|
60
|
+
expect(i.offset).to eq(0)
|
58
61
|
end
|
59
62
|
|
60
63
|
it "accepts an empty input" do
|
61
64
|
|
62
|
-
|
65
|
+
i = Raabro::Input.new('toto')
|
66
|
+
i.offset = 4
|
63
67
|
|
64
|
-
t = Raabro.str(nil,
|
68
|
+
t = Raabro.str(nil, i, 'nada')
|
65
69
|
|
66
70
|
expect(t.to_a).to eq(
|
67
71
|
[ nil, 0, 4, 0, nil, :str, [] ]
|
68
72
|
)
|
69
|
-
expect(
|
73
|
+
expect(i.offset).to eq(4)
|
70
74
|
end
|
71
75
|
end
|
72
76
|
end
|
data/spec/tree_spec.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# specifying raabro
|
4
|
+
#
|
5
|
+
# Tue Sep 22 07:55:52 JST 2015
|
6
|
+
#
|
7
|
+
|
8
|
+
require 'spec_helper'
|
9
|
+
|
10
|
+
|
11
|
+
describe Raabro::Tree do
|
12
|
+
|
13
|
+
describe '.lookup' do
|
14
|
+
|
15
|
+
it 'returns the first node with the given name' do
|
16
|
+
|
17
|
+
t = Sample::Cal.parse('4 5 6 + 1 2 3 * +')
|
18
|
+
|
19
|
+
expect(
|
20
|
+
t.lookup('item').to_a(:leaves)
|
21
|
+
).to eq(
|
22
|
+
[ :item, 1, 0, 1, nil, :alt, [
|
23
|
+
[ :num, 1, 0, 1, nil, :rex, '4' ]
|
24
|
+
] ]
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '.gather' do
|
30
|
+
|
31
|
+
it 'returns all the nodes with a given name' do
|
32
|
+
|
33
|
+
t = Sample::Cal.parse('4 5 6 + 1 2 3 * +')
|
34
|
+
|
35
|
+
expect(
|
36
|
+
t.gather('op').collect { |n| n.to_a(:leaves) }
|
37
|
+
).to eq(
|
38
|
+
[
|
39
|
+
[ :op, 1, 6, 1, nil, :rex, '+' ],
|
40
|
+
[ :op, 1, 14, 1, nil, :rex, '*' ],
|
41
|
+
[ :op, 1, 16, 1, nil, :rex, '+' ]
|
42
|
+
]
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: raabro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-09-
|
12
|
+
date: 2015-09-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -52,13 +52,20 @@ extra_rdoc_files: []
|
|
52
52
|
files:
|
53
53
|
- Rakefile
|
54
54
|
- lib/raabro.rb
|
55
|
+
- spec/all_spec.rb
|
55
56
|
- spec/alt_spec.rb
|
57
|
+
- spec/eseq_spec.rb
|
58
|
+
- spec/jseq_spec.rb
|
59
|
+
- spec/ren_spec.rb
|
56
60
|
- spec/rep_spec.rb
|
57
61
|
- spec/rex_spec.rb
|
62
|
+
- spec/sample_xel_spec.rb
|
58
63
|
- spec/seq_spec.rb
|
59
64
|
- spec/spec_helper.rb
|
60
65
|
- spec/str_spec.rb
|
66
|
+
- spec/tree_spec.rb
|
61
67
|
- raabro.gemspec
|
68
|
+
- CHANGELOG.txt
|
62
69
|
- LICENSE.txt
|
63
70
|
- README.md
|
64
71
|
homepage: http://github.com/jmettraux/rufus-scheduler
|