raabro 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,11 @@
2
2
  = raabro CHANGELOG.txt
3
3
 
4
4
 
5
+ == raabro 1.1.2 released 2016-04-04
6
+
7
+ - add Raabro.pp(tree)
8
+
9
+
5
10
  == raabro 1.1.1 released 2016-04-03
6
11
 
7
12
  - Tree#clast
@@ -1,4 +1,3 @@
1
-
2
1
  #--
3
2
  # Copyright (c) 2015-2016, John Mettraux, jmettraux@gmail.com
4
3
  #
@@ -26,7 +25,7 @@
26
25
 
27
26
  module Raabro
28
27
 
29
- VERSION = '1.1.1'
28
+ VERSION = '1.1.2'
30
29
 
31
30
  class Input
32
31
 
@@ -506,5 +505,51 @@ module Raabro
506
505
  extend ModuleMethods
507
506
 
508
507
  make_includable
508
+
509
+ # Black 0;30 Dark Gray 1;30
510
+ # Blue 0;34 Light Blue 1;34
511
+ # Green 0;32 Light Green 1;32
512
+ # Cyan 0;36 Light Cyan 1;36
513
+ # Red 0;31 Light Red 1;31
514
+ # Purple 0;35 Light Purple 1;35
515
+ # Brown 0;33 Yellow 1;33
516
+ # Light Gray 0;37 White 1;37
517
+
518
+ def self.pp(tree, depth=0)
519
+
520
+ _rs, _dg, _gn, _yl, _bl, _lg =
521
+ $stdout.tty? ?
522
+ [ "", "", "", "", "", "" ] :
523
+ [ '', '', '', '', '', '' ]
524
+
525
+ lc = tree.result == 1 ? _gn : _dg
526
+ nc = tree.result == 1 ? _bl : _lg
527
+ nc = lc if tree.name == nil
528
+ sc = tree.result == 1 ? _yl : _dg
529
+
530
+ str =
531
+ if tree.children.size == 0
532
+ " #{sc}#{tree.string.length == 0 ? "''" : tree.string.inspect}"
533
+ else
534
+ ''
535
+ end
536
+
537
+ print "#{_dg}t---\n" if depth == 0
538
+
539
+ print "#{' ' * depth}"
540
+ print "#{lc}#{tree.result}"
541
+ print " #{nc}#{tree.name.inspect} #{lc}#{tree.offset},#{tree.length}"
542
+ print str
543
+ print "#{_rs}\n"
544
+
545
+ tree.children.each { |c| self.pp(c, depth + 1) }
546
+
547
+ if depth == 0
548
+ print _dg
549
+ print "input ln: #{tree.input.string.length}, tree ln: #{tree.length} "
550
+ print "---t\n"
551
+ print _rs
552
+ end
553
+ end
509
554
  end
510
555
 
@@ -22,7 +22,7 @@ a very dumb PEG parser library
22
22
  #s.files = `git ls-files`.split("\n")
23
23
  s.files = Dir[
24
24
  'Rakefile',
25
- 'lib/**/*.rb', 'spec/**/*.rb', 'test/**/*.rb',
25
+ 'lib/**/*.rb',# 'spec/**/*.rb', 'test/**/*.rb',
26
26
  '*.gemspec', '*.txt', '*.rdoc', '*.md'
27
27
  ]
28
28
 
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: 1.1.1
4
+ version: 1.1.2
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: 2016-04-02 00:00:00.000000000 Z
12
+ date: 2016-04-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -35,20 +35,6 @@ extensions: []
35
35
  extra_rdoc_files: []
36
36
  files:
37
37
  - lib/raabro.rb
38
- - spec/all_spec.rb
39
- - spec/alt_spec.rb
40
- - spec/eseq_spec.rb
41
- - spec/jseq_spec.rb
42
- - spec/ren_spec.rb
43
- - spec/rep_spec.rb
44
- - spec/rex_spec.rb
45
- - spec/sample_spec.rb
46
- - spec/sample_xel_spec.rb
47
- - spec/sample_xell_spec.rb
48
- - spec/seq_spec.rb
49
- - spec/spec_helper.rb
50
- - spec/str_spec.rb
51
- - spec/tree_spec.rb
52
38
  - raabro.gemspec
53
39
  - CHANGELOG.txt
54
40
  - LICENSE.txt
@@ -1,54 +0,0 @@
1
-
2
- #
3
- # specifying raabro
4
- #
5
- # Mon Sep 21 05:56:18 JST 2015
6
- #
7
-
8
- require 'spec_helper'
9
-
10
-
11
- describe Raabro do
12
-
13
- describe '.all' do
14
-
15
- it 'fails when not all the input is consumed' do
16
-
17
- i = Raabro::Input.new('tototota')
18
-
19
- t = Raabro.all(nil, i, :to_plus)
20
-
21
- expect(t.to_a(:leaves => true)).to eq(
22
- [ nil, 0, 0, 0, nil, :all, [
23
- [ :tos, 1, 0, 6, nil, :rep, [
24
- [ nil, 1, 0, 2, nil, :str, 'to' ],
25
- [ nil, 1, 2, 2, nil, :str, 'to' ],
26
- [ nil, 1, 4, 2, nil, :str, 'to' ],
27
- [ nil, 0, 6, 0, nil, :str, [] ]
28
- ] ]
29
- ] ]
30
- )
31
- expect(i.offset).to eq(0)
32
- end
33
-
34
- it 'succeeds when all the input is consumed' do
35
-
36
- i = Raabro::Input.new('tototo')
37
-
38
- t = Raabro.all(nil, i, :to_plus)
39
-
40
- expect(t.to_a(:leaves => true)).to eq(
41
- [ nil, 1, 0, 6, nil, :all, [
42
- [ :tos, 1, 0, 6, nil, :rep, [
43
- [ nil, 1, 0, 2, nil, :str, 'to' ],
44
- [ nil, 1, 2, 2, nil, :str, 'to' ],
45
- [ nil, 1, 4, 2, nil, :str, 'to' ],
46
- [ nil, 0, 6, 0, nil, :str, [] ]
47
- ] ]
48
- ] ]
49
- )
50
- expect(i.offset).to eq(6)
51
- end
52
- end
53
- end
54
-
@@ -1,169 +0,0 @@
1
-
2
- #
3
- # specifying raabro
4
- #
5
- # Sun Sep 20 07:31:53 JST 2015
6
- #
7
-
8
- require 'spec_helper'
9
-
10
-
11
- describe Raabro do
12
-
13
- describe '.alt' do
14
-
15
- it "returns a tree with result == 0 in case of failure" do
16
-
17
- i = Raabro::Input.new('tutu')
18
-
19
- t = Raabro.alt(nil, i, :ta, :to)
20
-
21
- expect(t.to_a(:leaves => true)).to eq(
22
- [ nil, 0, 0, 0, nil, :alt, [
23
- [ nil, 0, 0, 0, nil, :str, [] ],
24
- [ nil, 0, 0, 0, nil, :str, [] ]
25
- ] ]
26
- )
27
- expect(i.offset).to eq(0)
28
- end
29
-
30
- it "succeeds (1st alternative)" do
31
-
32
- i = Raabro::Input.new('tato')
33
-
34
- t = Raabro.alt(nil, i, :ta, :to)
35
-
36
- expect(t.to_a(:leaves => true)).to eq(
37
- [ nil, 1, 0, 2, nil, :alt, [
38
- [ nil, 1, 0, 2, nil, :str, 'ta' ]
39
- ] ]
40
- )
41
- expect(i.offset).to eq(2)
42
- end
43
-
44
- it "succeeds (2nd alternative)" do
45
-
46
- i = Raabro::Input.new('tato')
47
-
48
- t = Raabro.alt(nil, i, :to, :ta)
49
-
50
- expect(t.to_a(:leaves => true)).to eq(
51
- [ nil, 1, 0, 2, nil, :alt, [
52
- [ nil, 0, 0, 0, nil, :str, [] ],
53
- [ nil, 1, 0, 2, nil, :str, 'ta' ]
54
- ] ]
55
- )
56
- expect(i.offset).to eq(2)
57
- end
58
-
59
- it 'prunes' do
60
-
61
- i = Raabro::Input.new('tato', :prune => true)
62
-
63
- t = Raabro.alt(nil, i, :to, :ta)
64
-
65
- expect(t.to_a(:leaves => true)).to eq(
66
- [ nil, 1, 0, 2, nil, :alt, [
67
- [ nil, 1, 0, 2, nil, :str, 'ta' ]
68
- ] ]
69
- )
70
- expect(i.offset).to eq(2)
71
- end
72
-
73
- context 'when not greedy (default)' do
74
-
75
- it 'goes with the first successful result' do
76
-
77
- i = Raabro::Input.new('xx')
78
-
79
- t = Raabro.alt(nil, i, :onex, :twox)
80
-
81
- expect(t.to_a(:leaves => true)).to eq(
82
- [ nil, 1, 0, 1, nil, :alt, [
83
- [ :onex, 1, 0, 1, nil, :str, 'x' ]
84
- ] ]
85
- )
86
- expect(i.offset).to eq(1)
87
- end
88
- end
89
-
90
- context 'when greedy (last argument set to true)' do
91
-
92
- it 'takes the longest successful result' do
93
-
94
- i = Raabro::Input.new('xx')
95
-
96
- t = Raabro.alt(nil, i, :onex, :twox, true)
97
-
98
- expect(t.to_a(:leaves => true)).to eq(
99
- [ nil, 1, 0, 2, nil, :altg, [
100
- [ :onex, 0, 0, 1, nil, :str, [] ],
101
- [ :twox, 1, 0, 2, nil, :str, 'xx' ]
102
- ] ]
103
- )
104
- expect(i.offset).to eq(2)
105
- end
106
- end
107
- end
108
-
109
- describe '.altg' do
110
-
111
- it 'is greedy, always' do
112
-
113
- i = Raabro::Input.new('xx')
114
-
115
- t = Raabro.altg(nil, i, :onex, :twox)
116
-
117
- expect(t.to_a(:leaves => true)).to eq(
118
- [ nil, 1, 0, 2, nil, :altg, [
119
- [ :onex, 0, 0, 1, nil, :str, [] ],
120
- [ :twox, 1, 0, 2, nil, :str, 'xx' ]
121
- ] ]
122
- )
123
- expect(i.offset).to eq(2)
124
- end
125
-
126
- it 'prunes' do
127
-
128
- i = Raabro::Input.new('xx', :prune => true)
129
-
130
- t = Raabro.altg(nil, i, :onex, :twox)
131
-
132
- expect(t.to_a(:leaves => true)).to eq(
133
- [ nil, 1, 0, 2, nil, :altg, [
134
- [ :twox, 1, 0, 2, nil, :str, 'xx' ]
135
- ] ]
136
- )
137
- expect(i.offset).to eq(2)
138
- end
139
-
140
- it 'declares a single winner' do
141
-
142
- i = Raabro::Input.new('xx', :prune => true)
143
-
144
- t = Raabro.altg(nil, i, :twox, :onex)
145
-
146
- expect(t.to_a(:leaves => true)).to eq(
147
- [ nil, 1, 0, 2, nil, :altg, [
148
- [ :twox, 1, 0, 2, nil, :str, 'xx' ]
149
- ] ]
150
- )
151
- expect(i.offset).to eq(2)
152
- end
153
-
154
- it 'takes the longest and latest winner' do
155
-
156
- i = Raabro::Input.new('xx', :prune => true)
157
-
158
- t = Raabro.altg(nil, i, :twox, :onex, :deux)
159
-
160
- expect(t.to_a(:leaves => true)).to eq(
161
- [ nil, 1, 0, 2, nil, :altg, [
162
- [ :deux, 1, 0, 2, nil, :str, 'xx' ]
163
- ] ]
164
- )
165
- expect(i.offset).to eq(2)
166
- end
167
- end
168
- end
169
-
@@ -1,166 +0,0 @@
1
-
2
- #
3
- # specifying raabro
4
- #
5
- # Mon Sep 21 10:15:35 JST 2015
6
- #
7
-
8
- require 'spec_helper'
9
-
10
-
11
- describe Raabro do
12
-
13
- describe '.eseq' do
14
-
15
- it 'parses successfully' do
16
-
17
- i = Raabro::Input.new('<a,b>')
18
-
19
- t = Raabro.eseq(:list, i, :lt, :cha, :com, :gt)
20
-
21
- expect(t.to_a(:leaves => true)).to eq(
22
- [ :list, 1, 0, 5, nil, :eseq, [
23
- [ nil, 1, 0, 1, nil, :str, '<' ],
24
- [ nil, 1, 1, 1, nil, :rex, 'a' ],
25
- [ nil, 1, 2, 1, nil, :str, ',' ],
26
- [ nil, 1, 3, 1, nil, :rex, 'b' ],
27
- [ nil, 0, 4, 0, nil, :str, [] ],
28
- [ nil, 1, 4, 1, nil, :str, '>' ]
29
- ] ]
30
- )
31
- expect(i.offset).to eq(5)
32
- end
33
-
34
- it 'prunes' do
35
-
36
- i = Raabro::Input.new('<a,b>', :prune => true)
37
-
38
- t = Raabro.eseq(:list, i, :lt, :cha, :com, :gt)
39
-
40
- expect(t.to_a(:leaves => true)).to eq(
41
- [ :list, 1, 0, 5, nil, :eseq, [
42
- [ nil, 1, 0, 1, nil, :str, '<' ],
43
- [ nil, 1, 1, 1, nil, :rex, 'a' ],
44
- [ nil, 1, 2, 1, nil, :str, ',' ],
45
- [ nil, 1, 3, 1, nil, :rex, 'b' ],
46
- [ nil, 1, 4, 1, nil, :str, '>' ]
47
- ] ]
48
- )
49
- expect(i.offset).to eq(5)
50
- end
51
-
52
- it 'parses <>' do
53
-
54
- i = Raabro::Input.new('<>', :prune => true)
55
-
56
- t = Raabro.eseq(:list, i, :lt, :cha, :com, :gt)
57
-
58
- expect(t.to_a(:leaves => true)).to eq(
59
- [ :list, 1, 0, 2, nil, :eseq, [
60
- [ nil, 1, 0, 1, nil, :str, '<' ],
61
- [ nil, 1, 1, 1, nil, :str, '>' ]
62
- ] ]
63
- )
64
- expect(i.offset).to eq(2)
65
- end
66
-
67
- context 'no start parser' do
68
-
69
- it 'parses successfully' do
70
-
71
- i = Raabro::Input.new('a,b>', prune: false)
72
-
73
- t = Raabro.eseq(:list, i, nil, :cha, :com, :gt)
74
-
75
- expect(t.to_a(:leaves => true)).to eq(
76
- [ :list, 1, 0, 4, nil, :eseq, [
77
- [ nil, 1, 0, 1, nil, :rex, 'a' ],
78
- [ nil, 1, 1, 1, nil, :str, ',' ],
79
- [ nil, 1, 2, 1, nil, :rex, 'b' ],
80
- [ nil, 0, 3, 0, nil, :str, [] ],
81
- [ nil, 1, 3, 1, nil, :str, '>' ]
82
- ] ]
83
- )
84
- expect(i.offset).to eq(4)
85
- end
86
- end
87
-
88
- context 'no end parser' do
89
-
90
- it 'parses successfully' do
91
-
92
- i = Raabro::Input.new('<a,b')
93
-
94
- t = Raabro.eseq(:list, i, :lt, :cha, :com, nil)
95
-
96
- expect(t.to_a(:leaves => true)).to eq(
97
- [ :list, 1, 0, 4, nil, :eseq, [
98
- [ nil, 1, 0, 1, nil, :str, '<' ],
99
- [ nil, 1, 1, 1, nil, :rex, 'a' ],
100
- [ nil, 1, 2, 1, nil, :str, ',' ],
101
- [ nil, 1, 3, 1, nil, :rex, 'b' ],
102
- [ nil, 0, 4, 0, nil, :str, [] ]
103
- ] ]
104
- )
105
- expect(i.offset).to eq(4)
106
- end
107
-
108
- it 'prunes' do
109
-
110
- i = Raabro::Input.new('<a,b', :prune => true)
111
-
112
- t = Raabro.eseq(:list, i, :lt, :cha, :com, nil)
113
-
114
- expect(t.to_a(:leaves => true)).to eq(
115
- [ :list, 1, 0, 4, nil, :eseq, [
116
- [ nil, 1, 0, 1, nil, :str, '<' ],
117
- [ nil, 1, 1, 1, nil, :rex, 'a' ],
118
- [ nil, 1, 2, 1, nil, :str, ',' ],
119
- [ nil, 1, 3, 1, nil, :rex, 'b' ]
120
- ] ]
121
- )
122
- expect(i.offset).to eq(4)
123
- end
124
- end
125
-
126
- context 'no progress' do
127
-
128
- it 'parses <>' do
129
-
130
- i = Raabro::Input.new('<>', :prune => true)
131
-
132
- t = arr(i)
133
-
134
- expect(t.to_a(:leaves => true)).to eq(
135
- [ nil, 1, 0, 2, nil, :eseq, [
136
- [ nil, 1, 0, 1, nil, :str, '<' ],
137
- [ nil, 1, 1, 0, nil, :rex, '' ],
138
- [ nil, 1, 1, 1, nil, :str, '>' ]
139
- ] ]
140
- )
141
- expect(i.offset).to eq(2)
142
- end
143
-
144
- it 'parses <a,,a>' do
145
-
146
- i = Raabro::Input.new('<a,,a>', :prune => true)
147
-
148
- t = arr(i)
149
-
150
- expect(t.to_a(:leaves => true)).to eq(
151
- [ nil, 1, 0, 6, nil, :eseq, [
152
- [ nil, 1, 0, 1, nil, :str, '<' ],
153
- [ nil, 1, 1, 1, nil, :rex, 'a' ],
154
- [ nil, 1, 2, 1, nil, :rex, ',' ],
155
- [ nil, 1, 3, 0, nil, :rex, '' ],
156
- [ nil, 1, 3, 1, nil, :rex, ',' ],
157
- [ nil, 1, 4, 1, nil, :rex, 'a' ],
158
- [ nil, 1, 5, 1, nil, :str, '>' ]
159
- ] ]
160
- )
161
- expect(i.offset).to eq(6)
162
- end
163
- end
164
- end
165
- end
166
-