msgpack-idl 0.1.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/AUTHORS +1 -0
- data/ChangeLog +5 -0
- data/README +22 -0
- data/bin/msgpack-idl +3 -0
- data/lib/msgpack/idl/ast.rb +251 -0
- data/lib/msgpack/idl/command/example.rb +135 -0
- data/lib/msgpack/idl/command/idl.rb +262 -0
- data/lib/msgpack/idl/error.rb +60 -0
- data/lib/msgpack/idl/evaluator.rb +616 -0
- data/lib/msgpack/idl/generator.rb +58 -0
- data/lib/msgpack/idl/ir.rb +403 -0
- data/lib/msgpack/idl/module.rb +45 -0
- data/lib/msgpack/idl/parser/rule.rb +499 -0
- data/lib/msgpack/idl/parser/transform.rb +260 -0
- data/lib/msgpack/idl/parser.rb +84 -0
- data/lib/msgpack/idl/version.rb +7 -0
- metadata +111 -0
@@ -0,0 +1,260 @@
|
|
1
|
+
#
|
2
|
+
# MessagePack IDL Processor
|
3
|
+
#
|
4
|
+
# Copyright (C) 2011 FURUHASHI Sadayuki
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module MessagePack
|
19
|
+
module IDL
|
20
|
+
|
21
|
+
|
22
|
+
class ParsletTransform < Parslet::Transform
|
23
|
+
rule(:sequence_x => simple(:x)) {
|
24
|
+
x
|
25
|
+
}
|
26
|
+
|
27
|
+
rule(:sequence_xs => simple(:xs)) {
|
28
|
+
xs
|
29
|
+
}
|
30
|
+
|
31
|
+
rule(:sequence => simple(:x)) {
|
32
|
+
x ? AST::Sequence.new([x]) : AST::Sequence.new
|
33
|
+
}
|
34
|
+
|
35
|
+
rule(:sequence => sequence(:x)) {
|
36
|
+
AST::Sequence.new(x)
|
37
|
+
}
|
38
|
+
|
39
|
+
|
40
|
+
rule(:val_int => simple(:i)) {
|
41
|
+
i.to_i
|
42
|
+
}
|
43
|
+
|
44
|
+
rule(:val_optional => simple(:x)) {
|
45
|
+
AST::FIELD_OPTIONAL
|
46
|
+
}
|
47
|
+
|
48
|
+
rule(:val_required => simple(:x)) {
|
49
|
+
AST::FIELD_REQUIRED
|
50
|
+
}
|
51
|
+
|
52
|
+
rule(:val_override => simple(:x)) {
|
53
|
+
AST::FUNC_OVERRIDE
|
54
|
+
}
|
55
|
+
|
56
|
+
rule(:val_remove => simple(:x)) {
|
57
|
+
AST::FUNC_REMOVE
|
58
|
+
}
|
59
|
+
|
60
|
+
rule(:val_add => simple(:x)) {
|
61
|
+
AST::FUNC_ADD
|
62
|
+
}
|
63
|
+
|
64
|
+
|
65
|
+
rule(:name => simple(:n)) {
|
66
|
+
n.to_s
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
rule(:field_id => simple(:i),
|
71
|
+
:field_modifier => simple(:m),
|
72
|
+
:field_type => simple(:t),
|
73
|
+
:field_name => simple(:n),
|
74
|
+
:field_value => simple(:v)) {
|
75
|
+
m = m() ? m() : AST::FIELD_REQUIRED
|
76
|
+
if v == nil
|
77
|
+
AST::Field.new(i, t, m, n)
|
78
|
+
else
|
79
|
+
AST::ValueAssignedField.new(i, t, m, n, v)
|
80
|
+
end
|
81
|
+
}
|
82
|
+
|
83
|
+
rule(:generic_type => simple(:n),
|
84
|
+
:type_params => simple(:tp)) {
|
85
|
+
if tp
|
86
|
+
AST::GenericType.new(n, tp)
|
87
|
+
else
|
88
|
+
AST::Type.new(n)
|
89
|
+
end
|
90
|
+
}
|
91
|
+
|
92
|
+
rule(:field_type => simple(:t),
|
93
|
+
:field_type_maybe => simple(:n)) {
|
94
|
+
nullable = !!n
|
95
|
+
if t.is_a?(AST::GenericType)
|
96
|
+
AST::GenericType.new(t.name, t.type_params, nullable)
|
97
|
+
else
|
98
|
+
AST::Type.new(t.name, nullable)
|
99
|
+
end
|
100
|
+
}
|
101
|
+
|
102
|
+
|
103
|
+
rule(:message_name => simple(:n),
|
104
|
+
:message_body => sequence(:b),
|
105
|
+
:super_class => simple(:sc)) {
|
106
|
+
AST::Message.new(n, sc, b)
|
107
|
+
}
|
108
|
+
|
109
|
+
rule(:exception_name => simple(:n),
|
110
|
+
:exception_body => sequence(:b),
|
111
|
+
:super_class => simple(:sc)) {
|
112
|
+
AST::Exception.new(n, sc, b)
|
113
|
+
}
|
114
|
+
|
115
|
+
|
116
|
+
rule(:enum_field_id => simple(:i),
|
117
|
+
:enum_field_name => simple(:n)) {
|
118
|
+
AST::EnumField.new(i, n)
|
119
|
+
}
|
120
|
+
|
121
|
+
rule(:enum_name => simple(:n),
|
122
|
+
:enum_body => sequence(:b)) {
|
123
|
+
AST::Enum.new(n, b)
|
124
|
+
}
|
125
|
+
|
126
|
+
|
127
|
+
rule(:return_type => simple(:rt),
|
128
|
+
:func_name => simple(:n),
|
129
|
+
:func_args => simple(:a),
|
130
|
+
:func_throws => simple(:ex)) {
|
131
|
+
AST::Func.new(n, rt, a, ex)
|
132
|
+
}
|
133
|
+
|
134
|
+
rule(:service_description => sequence(:s)) {
|
135
|
+
current = AST::ServiceVersion.new(0, [])
|
136
|
+
versions = [current]
|
137
|
+
s.each {|l|
|
138
|
+
case l
|
139
|
+
when Integer
|
140
|
+
v = versions.find {|v| v.version == l }
|
141
|
+
if v
|
142
|
+
current = v
|
143
|
+
else
|
144
|
+
current = AST::ServiceVersion.new(l, [])
|
145
|
+
versions << current
|
146
|
+
end
|
147
|
+
else
|
148
|
+
current.funcs << l
|
149
|
+
end
|
150
|
+
}
|
151
|
+
versions
|
152
|
+
}
|
153
|
+
|
154
|
+
rule(:service_name => simple(:n),
|
155
|
+
:service_version => simple(:v),
|
156
|
+
:service_funcs => sequence(:fs)) {
|
157
|
+
AST::Service.new(n, v, fs)
|
158
|
+
}
|
159
|
+
|
160
|
+
|
161
|
+
rule(:scope_service => simple(:s),
|
162
|
+
:scope_service_version => simple(:v),
|
163
|
+
:scope_name => simple(:n),
|
164
|
+
:scope_default => simple(:d)) {
|
165
|
+
if d
|
166
|
+
AST::Scope.new(s, v, n, true)
|
167
|
+
else
|
168
|
+
AST::Scope.new(s, v, n, false)
|
169
|
+
end
|
170
|
+
}
|
171
|
+
|
172
|
+
rule(:application_name => simple(:n),
|
173
|
+
:application_body => sequence(:b)) {
|
174
|
+
AST::Application.new(n, b)
|
175
|
+
}
|
176
|
+
|
177
|
+
|
178
|
+
rule(:namespace_name => simple(:n)) {
|
179
|
+
AST::Namespace.new(n, nil)
|
180
|
+
}
|
181
|
+
|
182
|
+
rule(:namespace_name => simple(:n),
|
183
|
+
:namespace_lang => simple(:l)) {
|
184
|
+
AST::Namespace.new(n, l)
|
185
|
+
}
|
186
|
+
|
187
|
+
|
188
|
+
rule(:path => simple(:n)) {
|
189
|
+
n
|
190
|
+
}
|
191
|
+
|
192
|
+
rule(:include => simple(:n)) {
|
193
|
+
AST::Include.new(n.to_s)
|
194
|
+
}
|
195
|
+
|
196
|
+
|
197
|
+
rule(:document => sequence(:es)) {
|
198
|
+
AST::Document.new(es)
|
199
|
+
}
|
200
|
+
|
201
|
+
|
202
|
+
rule(:literal_const => simple(:n)) {
|
203
|
+
AST::ConstLiteral.new(n)
|
204
|
+
}
|
205
|
+
|
206
|
+
rule(:literal_enum_name => simple(:n),
|
207
|
+
:literal_enum_field => simple(:f)) {
|
208
|
+
AST::EnumLiteral.new(n, f)
|
209
|
+
}
|
210
|
+
|
211
|
+
rule(:literal_int => simple(:i)) {
|
212
|
+
AST::IntLiteral.new(i.to_i)
|
213
|
+
}
|
214
|
+
|
215
|
+
rule(:literal_float => simple(:f)) {
|
216
|
+
AST::FloatLiteral.new(f.to_f)
|
217
|
+
}
|
218
|
+
|
219
|
+
rule(:literal_str_dq => simple(:s)) {
|
220
|
+
s.to_s.gsub(/\\(.)/) {|e|
|
221
|
+
eval("\"\\#{$~[1]}\"") # TODO escape
|
222
|
+
}
|
223
|
+
}
|
224
|
+
|
225
|
+
rule(:literal_str_sq => simple(:s)) {
|
226
|
+
s.to_s
|
227
|
+
}
|
228
|
+
|
229
|
+
rule(:literal_str_seq => sequence(:ss)) {
|
230
|
+
AST::StringLiteral.new(ss.join)
|
231
|
+
}
|
232
|
+
|
233
|
+
rule(:literal_nil => simple(:_)) {
|
234
|
+
AST::NilLiteral.new
|
235
|
+
}
|
236
|
+
|
237
|
+
rule(:literal_true => simple(:_)) {
|
238
|
+
AST::TrueLiteral.new
|
239
|
+
}
|
240
|
+
|
241
|
+
rule(:literal_false => simple(:_)) {
|
242
|
+
AST::FalseLiteral.new
|
243
|
+
}
|
244
|
+
|
245
|
+
#rule(:literal_list => simple(:a)) {
|
246
|
+
# AST::ListLiteral.new(Array.new(a))
|
247
|
+
#}
|
248
|
+
|
249
|
+
#rule(:literal_map => simple(:ps)) {
|
250
|
+
# AST::MapLiteral.new(Array.new(ps))
|
251
|
+
#}
|
252
|
+
|
253
|
+
#rule(:literal_map_key => simple(:k), :literal_map_value => simple(:v)) {
|
254
|
+
# AST::MapLiteralPair.new(k, v)
|
255
|
+
#}
|
256
|
+
end
|
257
|
+
|
258
|
+
|
259
|
+
end
|
260
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
#
|
2
|
+
# MessagePack IDL Processor
|
3
|
+
#
|
4
|
+
# Copyright (C) 2011 FURUHASHI Sadayuki
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module MessagePack
|
19
|
+
module IDL
|
20
|
+
|
21
|
+
|
22
|
+
class Parser
|
23
|
+
include ProcessorModule
|
24
|
+
|
25
|
+
require 'stringio'
|
26
|
+
|
27
|
+
def initialize(search_paths = [])
|
28
|
+
@search_paths = search_paths
|
29
|
+
@parslet = ParsletParser.new
|
30
|
+
@transform = ParsletTransform.new
|
31
|
+
@ast = []
|
32
|
+
end
|
33
|
+
|
34
|
+
attr_reader :ast
|
35
|
+
|
36
|
+
def parse(src, fname, dir)
|
37
|
+
begin
|
38
|
+
tree = @parslet.parse(src)
|
39
|
+
ast = @transform.apply(tree)
|
40
|
+
rescue Parslet::ParseFailed => error
|
41
|
+
msg = @parslet.print_error(error, fname, StringIO.new).string
|
42
|
+
raise SyntaxError, msg
|
43
|
+
end
|
44
|
+
ast.each {|e|
|
45
|
+
if e.class == AST::Include
|
46
|
+
parse_include(e.path, dir, fname)
|
47
|
+
else
|
48
|
+
@ast << e
|
49
|
+
end
|
50
|
+
}
|
51
|
+
self
|
52
|
+
end
|
53
|
+
|
54
|
+
def parse_file(path)
|
55
|
+
parse(File.read(path), File.basename(path), File.dirname(path))
|
56
|
+
end
|
57
|
+
|
58
|
+
protected
|
59
|
+
def parse_include(inc, dir, fname)
|
60
|
+
if dir
|
61
|
+
search_paths = @search_paths + [File.expand_path(dir)]
|
62
|
+
else
|
63
|
+
search_paths = @search_paths
|
64
|
+
end
|
65
|
+
search_paths.each {|dir|
|
66
|
+
real_path = File.join(dir, inc)
|
67
|
+
if File.file?(real_path)
|
68
|
+
return parse_file(real_path)
|
69
|
+
end
|
70
|
+
}
|
71
|
+
raise IncludeError, format_include_error(inc, fname)
|
72
|
+
end
|
73
|
+
|
74
|
+
def format_include_error(inc, fname)
|
75
|
+
[
|
76
|
+
"#{fname}:",
|
77
|
+
" Can't include file #{inc}"
|
78
|
+
].join("\n")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: msgpack-idl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- FURUHASHI Sadayuki
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-23 00:00:00 +09:00
|
19
|
+
default_executable: msgpack-idl
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: parslet
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 23
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 2
|
33
|
+
- 0
|
34
|
+
version: 0.2.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
version: "0"
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
description:
|
52
|
+
email: frsyuki@users.sourceforge.jp
|
53
|
+
executables:
|
54
|
+
- msgpack-idl
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files: []
|
58
|
+
|
59
|
+
files:
|
60
|
+
- AUTHORS
|
61
|
+
- ChangeLog
|
62
|
+
- README
|
63
|
+
- lib/msgpack/idl/ast.rb
|
64
|
+
- lib/msgpack/idl/command/example.rb
|
65
|
+
- lib/msgpack/idl/command/idl.rb
|
66
|
+
- lib/msgpack/idl/error.rb
|
67
|
+
- lib/msgpack/idl/evaluator.rb
|
68
|
+
- lib/msgpack/idl/generator.rb
|
69
|
+
- lib/msgpack/idl/ir.rb
|
70
|
+
- lib/msgpack/idl/module.rb
|
71
|
+
- lib/msgpack/idl/parser.rb
|
72
|
+
- lib/msgpack/idl/parser/rule.rb
|
73
|
+
- lib/msgpack/idl/parser/transform.rb
|
74
|
+
- lib/msgpack/idl/version.rb
|
75
|
+
- bin/msgpack-idl
|
76
|
+
has_rdoc: true
|
77
|
+
homepage: http://msgpack.org/
|
78
|
+
licenses: []
|
79
|
+
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options:
|
82
|
+
- --charset=UTF-8
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
requirements: []
|
104
|
+
|
105
|
+
rubyforge_project: msgpack
|
106
|
+
rubygems_version: 1.3.7
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: MessagePack IDL Processor
|
110
|
+
test_files: []
|
111
|
+
|