citrus 2.3.2 → 2.3.3
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/README +30 -10
- data/Rakefile +1 -1
- data/citrus.gemspec +1 -1
- data/doc/syntax.markdown +9 -9
- data/examples/calc.citrus +2 -3
- data/examples/calc.rb +79 -72
- data/examples/ipaddress.citrus +16 -0
- data/examples/ipaddress.rb +23 -0
- data/examples/ipv4address.citrus +26 -0
- data/examples/ipv4address.rb +49 -0
- data/examples/{ip.citrus → ipv6address.citrus} +1 -40
- data/examples/ipv6address.rb +55 -0
- data/lib/citrus.rb +267 -157
- data/lib/citrus/file.rb +58 -64
- data/lib/citrus/version.rb +9 -0
- data/test/alias_test.rb +1 -1
- data/test/file_test.rb +101 -139
- data/test/helper.rb +0 -116
- data/test/match_test.rb +0 -1
- data/test/memoized_input_test.rb +1 -1
- data/test/multibyte_test.rb +57 -6
- data/test/parse_error_test.rb +4 -2
- metadata +112 -108
- data/examples/ip.rb +0 -77
- data/test/calc_file_test.rb +0 -16
- data/test/calc_test.rb +0 -11
data/test/helper.rb
CHANGED
@@ -44,120 +44,4 @@ class Test::Unit::TestCase
|
|
44
44
|
[ :word, zero_or_more([ ' ', :word ]) ]
|
45
45
|
end
|
46
46
|
end
|
47
|
-
|
48
|
-
module CalcTestMethods
|
49
|
-
# A helper method that tests the successful parsing and evaluation of the
|
50
|
-
# given mathematical expression.
|
51
|
-
def do_test(expr, grammar)
|
52
|
-
match = grammar.parse(expr)
|
53
|
-
assert(match)
|
54
|
-
assert_equal(expr, match)
|
55
|
-
assert_equal(expr.length, match.length)
|
56
|
-
assert_equal(eval(expr), match.value)
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_int
|
60
|
-
do_test('3')
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_float
|
64
|
-
do_test('1.5')
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_addition
|
68
|
-
do_test('1+2')
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_addition_multi
|
72
|
-
do_test('1+2+3')
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_addition_float
|
76
|
-
do_test('1.5+3')
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_subtraction
|
80
|
-
do_test('3-2')
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_subtraction_float
|
84
|
-
do_test('4.5-3')
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_multiplication
|
88
|
-
do_test('2*5')
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_multiplication_float
|
92
|
-
do_test('1.5*3')
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_division
|
96
|
-
do_test('20/5')
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_division_float
|
100
|
-
do_test('4.5/3')
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_complex
|
104
|
-
do_test('7*4+3.5*(4.5/3)')
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_complex_spaced
|
108
|
-
do_test('7 * 4 + 3.5 * (4.5 / 3)')
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_complex_with_underscores
|
112
|
-
do_test('(12_000 / 3) * 2.5')
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_modulo
|
116
|
-
do_test('3 % 2 + 4')
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_exponent
|
120
|
-
do_test('2**9')
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_exponent_float
|
124
|
-
do_test('2**2.2')
|
125
|
-
end
|
126
|
-
|
127
|
-
def test_negative_exponent
|
128
|
-
do_test('2**-3')
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_exponent_exponent
|
132
|
-
do_test('2**2**2')
|
133
|
-
end
|
134
|
-
|
135
|
-
def test_exponent_group
|
136
|
-
do_test('2**(3+1)')
|
137
|
-
end
|
138
|
-
|
139
|
-
def test_negative
|
140
|
-
do_test('-5')
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_double_negative
|
144
|
-
do_test('--5')
|
145
|
-
end
|
146
|
-
|
147
|
-
def test_complement
|
148
|
-
do_test('~4')
|
149
|
-
end
|
150
|
-
|
151
|
-
def test_double_complement
|
152
|
-
do_test('~~4')
|
153
|
-
end
|
154
|
-
|
155
|
-
def test_mixed_unary
|
156
|
-
do_test('~-4')
|
157
|
-
end
|
158
|
-
|
159
|
-
def test_complex_with_negatives
|
160
|
-
do_test('4 * -7 / (8.0 + 1_2)**2')
|
161
|
-
end
|
162
|
-
end
|
163
47
|
end
|
data/test/match_test.rb
CHANGED
data/test/memoized_input_test.rb
CHANGED
data/test/multibyte_test.rb
CHANGED
@@ -1,32 +1,83 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require File.expand_path('../helper', __FILE__)
|
2
4
|
|
3
5
|
class MultibyteTest < Test::Unit::TestCase
|
4
6
|
grammar :Multibyte do
|
5
7
|
rule :string do
|
6
|
-
"
|
8
|
+
"ä"
|
7
9
|
end
|
8
10
|
|
9
11
|
rule :regexp do
|
10
|
-
|
12
|
+
/(ä)+/
|
11
13
|
end
|
12
14
|
|
13
15
|
rule :character_class do
|
14
|
-
/[
|
16
|
+
/[ä]+/
|
17
|
+
end
|
18
|
+
|
19
|
+
rule :dot do
|
20
|
+
DOT
|
15
21
|
end
|
16
22
|
end
|
17
23
|
|
18
24
|
def test_multibyte_string
|
19
|
-
m = Multibyte.parse("
|
25
|
+
m = Multibyte.parse("ä", :root => :string)
|
20
26
|
assert(m)
|
21
27
|
end
|
22
28
|
|
23
29
|
def test_multibyte_regexp
|
24
|
-
m = Multibyte.parse("
|
30
|
+
m = Multibyte.parse("äää", :root => :regexp)
|
25
31
|
assert(m)
|
26
32
|
end
|
27
33
|
|
28
34
|
def test_multibyte_character_class
|
29
|
-
m = Multibyte.parse("
|
35
|
+
m = Multibyte.parse("äää", :root => :character_class)
|
36
|
+
assert(m)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_multibyte_dot
|
40
|
+
m = Multibyte.parse("ä", :root => :dot)
|
41
|
+
assert(m)
|
42
|
+
end
|
43
|
+
|
44
|
+
Citrus.eval(<<-CITRUS)
|
45
|
+
grammar Multibyte2
|
46
|
+
rule string
|
47
|
+
"ä"
|
48
|
+
end
|
49
|
+
|
50
|
+
rule regexp
|
51
|
+
/(ä)+/
|
52
|
+
end
|
53
|
+
|
54
|
+
rule character_class
|
55
|
+
[ä]+
|
56
|
+
end
|
57
|
+
|
58
|
+
rule dot
|
59
|
+
.+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
CITRUS
|
63
|
+
|
64
|
+
def test_multibyte2_string
|
65
|
+
m = Multibyte2.parse("ä", :root => :string)
|
66
|
+
assert(m)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_multibyte2_regexp
|
70
|
+
m = Multibyte2.parse("äää", :root => :regexp)
|
71
|
+
assert(m)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_multibyte2_character_class
|
75
|
+
m = Multibyte2.parse("äää", :root => :character_class)
|
76
|
+
assert(m)
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_multibyte2_dot
|
80
|
+
m = Multibyte2.parse("äää", :root => :dot)
|
30
81
|
assert(m)
|
31
82
|
end
|
32
83
|
end
|
data/test/parse_error_test.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require File.expand_path('../helper', __FILE__)
|
2
4
|
|
3
5
|
class ParseErrorTest < Test::Unit::TestCase
|
@@ -32,10 +34,10 @@ class ParseErrorTest < Test::Unit::TestCase
|
|
32
34
|
|
33
35
|
def test_single_line
|
34
36
|
begin
|
35
|
-
Sentence.parse('Once upon
|
37
|
+
Sentence.parse('Once upon ä time.')
|
36
38
|
rescue ParseError => e
|
37
39
|
assert_equal(10, e.offset)
|
38
|
-
assert_equal('Once upon
|
40
|
+
assert_equal('Once upon ä time.', e.line)
|
39
41
|
assert_equal(1, e.line_number)
|
40
42
|
assert_equal(10, e.line_offset)
|
41
43
|
end
|
metadata
CHANGED
@@ -3,32 +3,33 @@ name: citrus
|
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
version: 2.3.
|
6
|
+
- 2
|
7
|
+
- 3
|
8
|
+
- 3
|
9
|
+
version: 2.3.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
|
-
|
12
|
+
- Michael Jackson
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-17 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rake
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :development
|
32
|
+
version_requirements: *id001
|
32
33
|
description: Parsing Expressions for Ruby
|
33
34
|
email: mjijackson@gmail.com
|
34
35
|
executables: []
|
@@ -36,112 +37,115 @@ executables: []
|
|
36
37
|
extensions: []
|
37
38
|
|
38
39
|
extra_rdoc_files:
|
39
|
-
|
40
|
+
- README
|
40
41
|
files:
|
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
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
42
|
+
- benchmark/seqpar.citrus
|
43
|
+
- benchmark/seqpar.gnuplot
|
44
|
+
- benchmark/seqpar.rb
|
45
|
+
- doc/background.markdown
|
46
|
+
- doc/example.markdown
|
47
|
+
- doc/extras.markdown
|
48
|
+
- doc/index.markdown
|
49
|
+
- doc/license.markdown
|
50
|
+
- doc/links.markdown
|
51
|
+
- doc/syntax.markdown
|
52
|
+
- doc/testing.markdown
|
53
|
+
- examples/calc.citrus
|
54
|
+
- examples/calc.rb
|
55
|
+
- examples/ipaddress.citrus
|
56
|
+
- examples/ipaddress.rb
|
57
|
+
- examples/ipv4address.citrus
|
58
|
+
- examples/ipv4address.rb
|
59
|
+
- examples/ipv6address.citrus
|
60
|
+
- examples/ipv6address.rb
|
61
|
+
- lib/citrus/file.rb
|
62
|
+
- lib/citrus/version.rb
|
63
|
+
- lib/citrus.rb
|
64
|
+
- test/_files/alias.citrus
|
65
|
+
- test/_files/grammar1.citrus
|
66
|
+
- test/_files/grammar2.citrus
|
67
|
+
- test/_files/rule1.citrus
|
68
|
+
- test/_files/rule2.citrus
|
69
|
+
- test/_files/rule3.citrus
|
70
|
+
- test/_files/super.citrus
|
71
|
+
- test/_files/super2.citrus
|
72
|
+
- test/alias_test.rb
|
73
|
+
- test/and_predicate_test.rb
|
74
|
+
- test/but_predicate_test.rb
|
75
|
+
- test/choice_test.rb
|
76
|
+
- test/extension_test.rb
|
77
|
+
- test/file_test.rb
|
78
|
+
- test/grammar_test.rb
|
79
|
+
- test/helper.rb
|
80
|
+
- test/input_test.rb
|
81
|
+
- test/label_test.rb
|
82
|
+
- test/match_test.rb
|
83
|
+
- test/memoized_input_test.rb
|
84
|
+
- test/multibyte_test.rb
|
85
|
+
- test/not_predicate_test.rb
|
86
|
+
- test/parse_error_test.rb
|
87
|
+
- test/repeat_test.rb
|
88
|
+
- test/sequence_test.rb
|
89
|
+
- test/string_terminal_test.rb
|
90
|
+
- test/super_test.rb
|
91
|
+
- test/terminal_test.rb
|
92
|
+
- citrus.gemspec
|
93
|
+
- Rakefile
|
94
|
+
- README
|
91
95
|
has_rdoc: true
|
92
96
|
homepage: http://mjijackson.com/citrus
|
93
97
|
licenses: []
|
94
98
|
|
95
99
|
post_install_message:
|
96
100
|
rdoc_options:
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
101
|
+
- --line-numbers
|
102
|
+
- --inline-source
|
103
|
+
- --title
|
104
|
+
- Citrus
|
105
|
+
- --main
|
106
|
+
- Citrus
|
103
107
|
require_paths:
|
104
|
-
|
108
|
+
- lib
|
105
109
|
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
106
111
|
requirements:
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
version: "0"
|
112
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
113
119
|
requirements:
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
version: "0"
|
119
125
|
requirements: []
|
120
126
|
|
121
127
|
rubyforge_project:
|
122
|
-
rubygems_version: 1.3.
|
128
|
+
rubygems_version: 1.3.7
|
123
129
|
signing_key:
|
124
130
|
specification_version: 3
|
125
131
|
summary: Parsing Expressions for Ruby
|
126
132
|
test_files:
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
- test/super_test.rb
|
147
|
-
- test/terminal_test.rb
|
133
|
+
- test/alias_test.rb
|
134
|
+
- test/and_predicate_test.rb
|
135
|
+
- test/but_predicate_test.rb
|
136
|
+
- test/choice_test.rb
|
137
|
+
- test/extension_test.rb
|
138
|
+
- test/file_test.rb
|
139
|
+
- test/grammar_test.rb
|
140
|
+
- test/input_test.rb
|
141
|
+
- test/label_test.rb
|
142
|
+
- test/match_test.rb
|
143
|
+
- test/memoized_input_test.rb
|
144
|
+
- test/multibyte_test.rb
|
145
|
+
- test/not_predicate_test.rb
|
146
|
+
- test/parse_error_test.rb
|
147
|
+
- test/repeat_test.rb
|
148
|
+
- test/sequence_test.rb
|
149
|
+
- test/string_terminal_test.rb
|
150
|
+
- test/super_test.rb
|
151
|
+
- test/terminal_test.rb
|