rison 1.2.1 → 2.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/README.html DELETED
@@ -1,57 +0,0 @@
1
- <html>
2
- <head>
3
- <title>rison.rb</title>
4
- <style type="text/css" media="screen">
5
- html {
6
- height: 100%; margin-bottom: 1px;
7
- }
8
- body {
9
- margin: 0; padding: 30px;
10
- }
11
- h1, h2 {
12
- font-family: garamond;
13
- }
14
- code {
15
- font-family: "Panic Sans", "Bitstream Vera Sans Mono", Consolas, Monaco, monospace;
16
- font-size: 11px;
17
- }
18
- </style>
19
- </head>
20
- <body>
21
-
22
-
23
- <h1>rison<span style="color:#F99">.rb</span> <small>1.2.1</small></h1>
24
-
25
- <p>A <a href="http://dhaka.rubyforge.org/">Dhaka</a>-based <a href="http://mjtemplate.org/examples/rison.html">Rison</a> parser.</p>
26
-
27
- <h2>Installing</h2>
28
-
29
- <p><tt>sudo gem install rison</tt> (or <a href="http://rubyforge.org/frs/?group_id=4896">download from RubyForge</a>)</p>
30
-
31
- <h2>Examples</h2>
32
-
33
- <pre><code> require 'rison'
34
-
35
-
36
- Rison.load('!t') # => true
37
-
38
- Rison.load('!(1,2,3)') # => [1, 2, 3]
39
-
40
- Rison.load('(a:0)') # => {:a => 0}
41
-
42
- Rison.load('abc def') # => Rison::ParseError: invalid Rison string: "abc def"
43
-
44
-
45
- Rison.dump(true) # => '!t'
46
-
47
- Rison.dump([1, 2, 3]) # => '!(1,2,3)'
48
-
49
- Rison.dump({:a => 0}) # => '(a:0)'
50
-
51
- Rison.dump(Array) # => ArgumentError: cannot serialize: Array
52
-
53
- </code></pre>
54
-
55
-
56
- </body>
57
- </html>
@@ -1,172 +0,0 @@
1
- require 'rational'
2
- require 'dhaka'
3
- require 'rison/grammar'
4
-
5
- module Rison
6
- class Evaluator < Dhaka::Evaluator
7
-
8
- self.grammar = Grammar
9
-
10
- define_evaluation_rules do
11
-
12
- for_empty_object do
13
- {}
14
- end
15
-
16
- for_non_empty_object do
17
- evaluate(child_nodes[1])
18
- end
19
-
20
- # for_member_pair
21
-
22
- for_member_pairs do
23
- evaluate(child_nodes[2]).merge(evaluate(child_nodes[0]))
24
- end
25
-
26
- for_pair_key_value do
27
- { evaluate(child_nodes[0]) => evaluate(child_nodes[2]) }
28
- end
29
-
30
- for_empty_array do
31
- []
32
- end
33
-
34
- for_non_empty_array do
35
- evaluate(child_nodes[2])
36
- end
37
-
38
- for_element_value do
39
- [ evaluate(child_nodes[0]) ]
40
- end
41
-
42
- for_element_values do
43
- [ evaluate(child_nodes[0]) ] + evaluate(child_nodes[2])
44
- end
45
-
46
- # for_key_id do
47
-
48
- # for_key_string do
49
-
50
- # for_value_id do
51
-
52
- # for_value_string
53
-
54
- # for_value_number do
55
-
56
- # for_value_object do
57
-
58
- # for_value_array do
59
-
60
- for_value_true do
61
- true
62
- end
63
-
64
- for_value_false do
65
- false
66
- end
67
-
68
- for_value_null do
69
- nil
70
- end
71
-
72
- for_id_idstart do
73
- evaluate(child_nodes[0]).to_sym
74
- end
75
-
76
- for_id_idstart_idchars do
77
- (evaluate(child_nodes[0]) + evaluate(child_nodes[1])).to_sym
78
- end
79
-
80
- # for_idchars_idchar
81
-
82
- for_idchars_idchars do
83
- evaluate(child_nodes[0]) + evaluate(child_nodes[1])
84
- end
85
-
86
- for_idchars_int do
87
- evaluate(child_nodes[0]).to_s
88
- end
89
-
90
- for_idchar_char do
91
- child_nodes[0].token.value
92
- end
93
-
94
- # for_idchar_idstart
95
-
96
- for_idstart_char do
97
- child_nodes[0].token.value
98
- end
99
-
100
- for_empty_string do
101
- ''
102
- end
103
-
104
- for_non_empty_string do
105
- evaluate(child_nodes[1]).inject { |s, c| s + c }
106
- end
107
-
108
- for_strchars_char do
109
- [ evaluate(child_nodes[0]) ]
110
- end
111
-
112
- for_strchars_chars do
113
- [ evaluate(child_nodes[0]) ] + evaluate(child_nodes[1])
114
- end
115
-
116
- for_strchar_char do
117
- child_nodes[0].token.value
118
- end
119
-
120
- for_strchar_quoted_exclamation do
121
- '!'
122
- end
123
-
124
- for_strchar_quoted_single_quote do
125
- "'"
126
- end
127
-
128
- # for_strchar_idchar
129
-
130
- for_strchar_num do
131
- evaluate(child_nodes[0]).to_s
132
- end
133
-
134
- # for_number_int
135
-
136
- for_number_int_frac do
137
- evaluate(child_nodes[0]) + evaluate(child_nodes[1])
138
- end
139
-
140
- for_number_int_exp do
141
- evaluate(child_nodes[0]) * evaluate(child_nodes[1])
142
- end
143
-
144
- for_number_int_frac_exp do
145
- (evaluate(child_nodes[0]) + evaluate(child_nodes[1])) * evaluate(child_nodes[2])
146
- end
147
-
148
- for_integer_literal do
149
- token = child_nodes[0].token.value
150
- token =~ /^(-?)(\d+?)$/
151
-
152
- $1.empty?? $2.to_i : - $2.to_i
153
- end
154
-
155
- for_frac_literal do
156
- token = child_nodes[0].token.value
157
- token =~ /^\.(\d+?)$/
158
-
159
- Rational($1.to_i, 10 ** $1.length)
160
- end
161
-
162
- for_exponent_literal do
163
- token = child_nodes[0].token.value
164
- token =~ /^e(-?)(\d+?)$/
165
-
166
- 10 ** ($1.empty?? $2.to_i : - $2.to_i)
167
- end
168
-
169
- end
170
-
171
- end
172
- end
data/lib/rison/grammar.rb DELETED
@@ -1,114 +0,0 @@
1
- require 'dhaka'
2
-
3
- module Rison
4
- class Grammar < Dhaka::Grammar
5
-
6
- for_symbol(Dhaka::START_SYMBOL_NAME) do
7
- start %w| value |
8
- end
9
-
10
- for_symbol 'object' do
11
- empty_object %w| ( ) |
12
- non_empty_object %w| ( members ) |
13
- end
14
-
15
- for_symbol 'members' do
16
- member_pair %w| pair |
17
- member_pairs %w| pair , members |
18
- end
19
-
20
- for_symbol 'pair' do
21
- pair_key_value %w| key : value |
22
- end
23
-
24
- for_symbol 'array' do
25
- empty_array %w| ! ( ) |
26
- non_empty_array %w| ! ( elements ) |
27
- end
28
-
29
- for_symbol 'elements' do
30
- element_value %w| value |
31
- element_values %w| value , elements |
32
- end
33
-
34
- for_symbol 'key' do
35
- key_id %w| id |
36
- key_string %w| string |
37
- end
38
-
39
- for_symbol 'value' do
40
- value_id %w| id |
41
- value_string %w| string |
42
- value_number %w| number |
43
- value_object %w| object |
44
- value_array %w| array |
45
- value_true %w| !t |
46
- value_false %w| !f |
47
- value_null %w| !n |
48
- end
49
-
50
- for_symbol 'id' do
51
- id_idstart %w| idstart |
52
- id_idstart_idchars %w| idstart idchars |
53
- end
54
-
55
- for_symbol 'idchars' do
56
- idchars_idchar %w| idchar |
57
- idchars_idchars %w| idchar idchars |
58
- idchars_int %w| int |
59
- end
60
-
61
- for_symbol 'idchar' do
62
- # any Unicode character not in '!:(),*@$
63
- idchar_char %w| idchar_safe_token |
64
- idchar_idstart %w| idstart |
65
- end
66
-
67
- for_symbol 'idstart' do
68
- # any Unicode character not in -, digit, or idchar
69
- idstart_char %w| idstart_safe_token |
70
- end
71
-
72
- for_symbol 'string' do
73
- empty_string %w| ' ' |
74
- non_empty_string %w| ' strchars ' |
75
- end
76
-
77
- for_symbol 'strchars' do
78
- strchars_char %w| strchar |
79
- strchars_chars %w| strchar strchars |
80
- end
81
-
82
- for_symbol 'strchar' do
83
- # any Unicode character not in ' or !
84
- # !!
85
- # !'
86
- strchar_char %w| char_token |
87
- strchar_quoted_exclamation %w| !! |
88
- strchar_quoted_single_quote %w| !' |
89
- strchar_idchar %w| idchar |
90
- strchar_num %w| number |
91
- end
92
-
93
- for_symbol 'number' do
94
- number_int %w| int |
95
- number_int_frac %w| int frac |
96
- number_int_exp %w| int exp |
97
- number_int_frac_exp %w| int frac exp |
98
- end
99
-
100
- for_symbol 'int' do
101
- integer_literal %w| integer_token |
102
- end
103
-
104
- for_symbol 'frac' do
105
- frac_literal %w| frac_token |
106
- end
107
-
108
- for_symbol 'exp' do
109
- exponent_literal %w| exponent_token |
110
- end
111
-
112
- end
113
- end
114
-
data/lib/rison/lexer.rb DELETED
@@ -1,33 +0,0 @@
1
- require 'dhaka'
2
-
3
- module Rison
4
- class LexerSpec < Dhaka::LexerSpecification
5
-
6
- [ ['!!', nil],
7
- ["!'", nil],
8
- ['!t', nil],
9
- ['!f', nil],
10
- ['!n', nil],
11
-
12
- ['\(', '('],
13
- ['\)', ')'],
14
- ['!', '!'],
15
-
16
- [',', nil],
17
- [':', nil],
18
- ["'", nil],
19
-
20
- ['e-?\d+', 'exponent_token'],
21
- ['\.\d+', 'frac_token'],
22
- ['-?\d+', 'integer_token'],
23
-
24
- ["[^\\-0-9'!:(),*@$ ]", 'idstart_safe_token'],
25
- ["[^'!:(),*@$ ]", 'idchar_safe_token'],
26
- ["[^'!]", 'char_token']
27
-
28
- ].each do |(pattern, token)|
29
- for_pattern(pattern) { create_token(token || pattern) }
30
- end
31
-
32
- end
33
- end