citrus 2.2.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,19 +7,19 @@ class SequenceTest < Test::Unit::TestCase
7
7
  end
8
8
 
9
9
  def test_exec
10
- a = Rule.new('a')
11
- b = Rule.new('b')
12
- c = Rule.new('c')
10
+ a = Rule.for('a')
11
+ b = Rule.for('b')
12
+ c = Rule.for('c')
13
13
  rule = Sequence.new([ a, b, c ])
14
14
 
15
15
  events = rule.exec(Input.new(''))
16
16
  assert_equal([], events)
17
17
 
18
18
  expected_events = [
19
- rule.id,
20
- a.id, CLOSE, 1,
21
- b.id, CLOSE, 1,
22
- c.id, CLOSE, 1,
19
+ rule,
20
+ a, CLOSE, 1,
21
+ b, CLOSE, 1,
22
+ c, CLOSE, 1,
23
23
  CLOSE, 3
24
24
  ]
25
25
 
@@ -32,10 +32,24 @@ class SequenceTest < Test::Unit::TestCase
32
32
  assert_equal('"a" "b"', rule.to_s)
33
33
  end
34
34
 
35
- def test_to_s_embed
35
+ def test_to_s_with_label
36
+ rule = Sequence.new(%w<a b>)
37
+ rule.label = 'a_label'
38
+ assert_equal('a_label:("a" "b")', rule.to_s)
39
+ end
40
+
41
+ def test_to_embedded_s
36
42
  rule1 = Sequence.new(%w<a b>)
37
43
  rule2 = Sequence.new(%w<c d>)
38
44
  rule = Sequence.new([rule1, rule2])
39
45
  assert_equal('("a" "b") ("c" "d")', rule.to_s)
40
46
  end
47
+
48
+ def test_to_embedded_s_with_label
49
+ rule1 = Sequence.new(%w<a b>)
50
+ rule2 = Sequence.new(%w<c d>)
51
+ rule2.label = 'a_label'
52
+ rule = Sequence.new([rule1, rule2])
53
+ assert_equal('("a" "b") a_label:("c" "d")', rule.to_s)
54
+ end
41
55
  end
@@ -6,10 +6,15 @@ class StringTerminalTest < Test::Unit::TestCase
6
6
  assert(rule.terminal?)
7
7
  end
8
8
 
9
+ def test_eql?
10
+ rule = StringTerminal.new('abc')
11
+ assert_equal('abc', rule)
12
+ end
13
+
9
14
  def test_exec
10
15
  rule = StringTerminal.new('abc')
11
16
  events = rule.exec(Input.new('abc'))
12
- assert_equal([rule.id, CLOSE, 3], events)
17
+ assert_equal([rule, CLOSE, 3], events)
13
18
  end
14
19
 
15
20
  def test_exec_miss
@@ -27,20 +32,20 @@ class StringTerminalTest < Test::Unit::TestCase
27
32
  def test_exec_long
28
33
  rule = StringTerminal.new('abc')
29
34
  events = rule.exec(Input.new('abcd'))
30
- assert_equal([rule.id, CLOSE, 3], events)
35
+ assert_equal([rule, CLOSE, 3], events)
31
36
  end
32
37
 
33
38
  def test_exec_case_insensitive
34
39
  rule = StringTerminal.new('abc', Regexp::IGNORECASE)
35
40
 
36
41
  events = rule.exec(Input.new('abc'))
37
- assert_equal([rule.id, CLOSE, 3], events)
42
+ assert_equal([rule, CLOSE, 3], events)
38
43
 
39
44
  events = rule.exec(Input.new('ABC'))
40
- assert_equal([rule.id, CLOSE, 3], events)
45
+ assert_equal([rule, CLOSE, 3], events)
41
46
 
42
47
  events = rule.exec(Input.new('Abc'))
43
- assert_equal([rule.id, CLOSE, 3], events)
48
+ assert_equal([rule, CLOSE, 3], events)
44
49
  end
45
50
 
46
51
  def test_to_s
data/test/super_test.rb CHANGED
@@ -7,7 +7,7 @@ class SuperTest < Test::Unit::TestCase
7
7
  end
8
8
 
9
9
  def test_exec
10
- ghi = Rule.new('ghi')
10
+ ghi = Rule.for('ghi')
11
11
  grammar1 = Grammar.new {
12
12
  rule :a, 'abc'
13
13
  }
@@ -16,20 +16,23 @@ class SuperTest < Test::Unit::TestCase
16
16
  rule :a, any(ghi, sup)
17
17
  }
18
18
  rule_2a = grammar2.rule(:a)
19
+ rule_2a_als = rule_2a.rules[0]
19
20
  rule_2a_sup = rule_2a.rules[1]
20
21
  rule_1a = grammar1.rule(:a)
21
22
 
22
23
  events = rule_2a.exec(Input.new('abc'))
23
24
  assert_equal([
24
- rule_2a.id,
25
- rule_2a_sup.id,
26
- rule_1a.id, CLOSE, 3,
27
- CLOSE, 3,
25
+ rule_2a,
26
+ rule_2a_sup, CLOSE, 3,
28
27
  CLOSE, 3
29
28
  ], events)
30
29
 
31
30
  events = rule_2a.exec(Input.new('ghi'))
32
- assert_equal([rule_2a.id, ghi.id, CLOSE, 3, CLOSE, 3], events)
31
+ assert_equal([
32
+ rule_2a,
33
+ rule_2a_als, CLOSE, 3,
34
+ CLOSE, 3
35
+ ], events)
33
36
  end
34
37
 
35
38
  def test_exec_miss
@@ -64,21 +67,15 @@ class SuperTest < Test::Unit::TestCase
64
67
 
65
68
  events = rule_2a.exec(Input.new('abc'))
66
69
  assert_equal([
67
- rule_2a.id,
68
- rule_2a_sup.id,
69
- rule_1a.id, CLOSE, 3,
70
- CLOSE, 3,
70
+ rule_2a,
71
+ rule_2a_sup, CLOSE, 3,
71
72
  CLOSE, 3
72
73
  ], events)
73
74
 
74
75
  events = rule_2a.exec(Input.new('def'))
75
76
  assert_equal([
76
- rule_2a.id,
77
- rule_2a_als.id,
78
- rule_2b.id,
79
- rule_1b.id, CLOSE, 3,
80
- CLOSE, 3,
81
- CLOSE, 3,
77
+ rule_2a,
78
+ rule_2a_als, CLOSE, 3,
82
79
  CLOSE, 3
83
80
  ], events)
84
81
  end
@@ -87,4 +84,10 @@ class SuperTest < Test::Unit::TestCase
87
84
  rule = Super.new
88
85
  assert_equal('super', rule.to_s)
89
86
  end
87
+
88
+ def test_to_s_with_label
89
+ rule = Super.new
90
+ rule.label = 'a_label'
91
+ assert_equal('a_label:super', rule.to_s)
92
+ end
90
93
  end
@@ -6,16 +6,21 @@ class TerminalTest < Test::Unit::TestCase
6
6
  assert(rule.terminal?)
7
7
  end
8
8
 
9
+ def test_eql?
10
+ rule = Terminal.new(/abc/i)
11
+ assert_equal(rule, /abc/i)
12
+ end
13
+
9
14
  def test_exec
10
15
  rule = Terminal.new(/\d+/)
11
16
  events = rule.exec(Input.new('123'))
12
- assert_equal([rule.id, CLOSE, 3], events)
17
+ assert_equal([rule, CLOSE, 3], events)
13
18
  end
14
19
 
15
20
  def test_exec_long
16
21
  rule = Terminal.new(/\d+/)
17
22
  events = rule.exec(Input.new('123 456'))
18
- assert_equal([rule.id, CLOSE, 3], events)
23
+ assert_equal([rule, CLOSE, 3], events)
19
24
  end
20
25
 
21
26
  def test_exec_miss
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: citrus
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ prerelease: false
5
+ segments:
6
+ - 2
7
+ - 3
8
+ - 0
9
+ version: 2.3.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Michael Jackson
@@ -9,19 +14,22 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-11-16 00:00:00 -08:00
17
+ date: 2010-12-28 00:00:00 -08:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: rake
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
20
25
  requirements:
21
26
  - - ">="
22
27
  - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
23
30
  version: "0"
24
- version:
31
+ type: :development
32
+ version_requirements: *id001
25
33
  description: Parsing Expressions for Ruby
26
34
  email: mjijackson@gmail.com
27
35
  executables: []
@@ -31,8 +39,6 @@ extensions: []
31
39
  extra_rdoc_files:
32
40
  - README
33
41
  files:
34
- - benchmark/after.dat
35
- - benchmark/before.dat
36
42
  - benchmark/seqpar.citrus
37
43
  - benchmark/seqpar.gnuplot
38
44
  - benchmark/seqpar.rb
@@ -53,7 +59,6 @@ files:
53
59
  - test/_files/alias.citrus
54
60
  - test/_files/grammar1.citrus
55
61
  - test/_files/grammar2.citrus
56
- - test/_files/grammar3.citrus
57
62
  - test/_files/rule1.citrus
58
63
  - test/_files/rule2.citrus
59
64
  - test/_files/rule3.citrus
@@ -98,21 +103,25 @@ rdoc_options:
98
103
  require_paths:
99
104
  - lib
100
105
  required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
101
107
  requirements:
102
108
  - - ">="
103
109
  - !ruby/object:Gem::Version
110
+ segments:
111
+ - 0
104
112
  version: "0"
105
- version:
106
113
  required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
107
115
  requirements:
108
116
  - - ">="
109
117
  - !ruby/object:Gem::Version
118
+ segments:
119
+ - 0
110
120
  version: "0"
111
- version:
112
121
  requirements: []
113
122
 
114
123
  rubyforge_project:
115
- rubygems_version: 1.3.5
124
+ rubygems_version: 1.3.7
116
125
  signing_key:
117
126
  specification_version: 3
118
127
  summary: Parsing Expressions for Ruby
data/benchmark/after.dat DELETED
@@ -1,192 +0,0 @@
1
- 12 0
2
- 30 0
3
- 35 0
4
- 1749 19
5
- 1962 9
6
- 2383 20
7
- 3728 29
8
- 3919 30
9
- 3952 30
10
- 3995 30
11
- 4063 30
12
- 4325 40
13
- 4527 39
14
- 4570 39
15
- 4607 50
16
- 4654 40
17
- 4679 39
18
- 4774 40
19
- 4968 40
20
- 5059 50
21
- 5383 39
22
- 5915 49
23
- 6109 50
24
- 6122 49
25
- 6218 50
26
- 6332 50
27
- 6681 59
28
- 7440 60
29
- 7530 60
30
- 7605 70
31
- 8155 60
32
- 8402 69
33
- 8420 70
34
- 8617 80
35
- 8635 70
36
- 8841 79
37
- 8843 79
38
- 8852 69
39
- 9151 80
40
- 9271 80
41
- 9521 80
42
- 9525 80
43
- 9566 80
44
- 9584 80
45
- 9642 70
46
- 10138 89
47
- 10181 80
48
- 10225 80
49
- 10338 80
50
- 10449 89
51
- 10629 90
52
- 10763 89
53
- 10817 89
54
- 11059 90
55
- 11062 90
56
- 11215 89
57
- 11698 99
58
- 11891 99
59
- 11945 100
60
- 11956 100
61
- 12018 100
62
- 12053 100
63
- 12178 99
64
- 12283 100
65
- 12326 109
66
- 12430 99
67
- 12438 99
68
- 12572 99
69
- 12638 99
70
- 12687 99
71
- 12703 109
72
- 12896 109
73
- 12922 109
74
- 12996 99
75
- 13137 110
76
- 13211 129
77
- 13462 109
78
- 13477 109
79
- 13576 109
80
- 13577 120
81
- 13584 110
82
- 13605 109
83
- 13631 109
84
- 14216 120
85
- 14237 120
86
- 14260 130
87
- 14367 119
88
- 14371 120
89
- 14741 120
90
- 14893 120
91
- 14910 120
92
- 14917 129
93
- 14977 130
94
- 15049 119
95
- 15191 130
96
- 15382 129
97
- 15618 129
98
- 15623 130
99
- 15629 129
100
- 15856 129
101
- 16496 130
102
- 16512 159
103
- 16956 129
104
- 17074 140
105
- 17237 139
106
- 17371 150
107
- 17568 149
108
- 17945 140
109
- 18147 149
110
- 18343 150
111
- 18417 160
112
- 18823 159
113
- 18970 149
114
- 19285 170
115
- 19333 160
116
- 19500 160
117
- 19548 150
118
- 19634 160
119
- 19673 160
120
- 19689 179
121
- 19909 169
122
- 20054 160
123
- 20107 169
124
- 20248 169
125
- 20580 169
126
- 20744 169
127
- 20806 189
128
- 20954 169
129
- 21034 179
130
- 21187 179
131
- 21303 189
132
- 21450 169
133
- 21626 179
134
- 21931 179
135
- 21950 169
136
- 22359 189
137
- 22626 190
138
- 22638 180
139
- 22772 189
140
- 22885 190
141
- 22897 190
142
- 23114 190
143
- 23242 189
144
- 23428 189
145
- 23452 209
146
- 23495 199
147
- 23499 189
148
- 23558 190
149
- 23744 190
150
- 23881 219
151
- 23945 189
152
- 24361 210
153
- 24501 210
154
- 24642 199
155
- 24672 200
156
- 24694 210
157
- 24706 210
158
- 24931 210
159
- 25065 210
160
- 25140 199
161
- 25402 210
162
- 25702 209
163
- 25743 209
164
- 27139 230
165
- 27316 240
166
- 27333 229
167
- 27414 220
168
- 27771 230
169
- 27798 229
170
- 28583 240
171
- 28906 239
172
- 29025 240
173
- 29209 240
174
- 29272 239
175
- 29273 250
176
- 29359 240
177
- 29577 240
178
- 30886 259
179
- 31170 250
180
- 31593 259
181
- 32460 269
182
- 32486 259
183
- 32630 269
184
- 33010 269
185
- 33137 289
186
- 33142 280
187
- 33739 280
188
- 39880 319
189
- 39940 339
190
- 42952 350
191
- 43227 350
192
- 52855 439