talk 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/talk +103 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7fc025a61346588f9645f6ecd1bb9450f092bf1
|
4
|
+
data.tar.gz: f6e49406e45c550e9a4492936af318650133be43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3e3c0f6acff21efb2bbe29249489b7db50183ba5745cbccf5a6cc4c9f62b79576796942451784ae8c083e6017764a4281806f2b4172a2e0cf2b459dad3ac1a9
|
7
|
+
data.tar.gz: 5dc5c0994dba93d32f4699ec1e5c14935e6babd945cd09b093e5205ac233a45e7b20410ee31f926801c0802ad285f254cf652561fa8db9f5a8c3a2c9d1dba6e5
|
data/bin/talk
CHANGED
@@ -5,8 +5,30 @@ lib = File.join(basepath, 'lib')
|
|
5
5
|
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
6
6
|
|
7
7
|
require 'talk'
|
8
|
-
require 'pp'
|
9
8
|
require 'json'
|
9
|
+
require 'trollop'
|
10
|
+
require 'pp'
|
11
|
+
|
12
|
+
$opts = Trollop::options do
|
13
|
+
version "Talk 2.0 (c) 2013 Jonas Acres"
|
14
|
+
banner <<-EOS
|
15
|
+
Talk is a compile-to-source protocol specification language.
|
16
|
+
|
17
|
+
Usage:
|
18
|
+
talk [options] [source directories]
|
19
|
+
where [options] are:
|
20
|
+
EOS
|
21
|
+
|
22
|
+
opt :target, "Generate output based on specified target name", :type => :string, :multi => true
|
23
|
+
opt :targets, "List valid targets"
|
24
|
+
opt :omit, "Strip a top-level tag", :type => :string, :multi => true
|
25
|
+
opt :include, "Limit to a top-level tag", :type => :string, :multi => true
|
26
|
+
opt :no, "Do not render specified tag type at any level", :type => :string, :multi => true
|
27
|
+
opt :json, "Dump raw JSON to console"
|
28
|
+
opt :upgrade, "Upgrade old-style protocols to new-style"
|
29
|
+
end
|
30
|
+
|
31
|
+
Trollop::die :omit, "cannot be combined with include" if $opts[:omit].length > 0 and $opts[:include].length > 0
|
10
32
|
|
11
33
|
$parser = Talk::Parser.new
|
12
34
|
|
@@ -17,6 +39,7 @@ def process_file(file)
|
|
17
39
|
end
|
18
40
|
|
19
41
|
if File.directory?(file) then
|
42
|
+
$parser.basepath = file
|
20
43
|
Dir.glob(File.join(file, "/**/*.talk")).each do |subfile|
|
21
44
|
process_file(subfile)
|
22
45
|
end
|
@@ -25,12 +48,87 @@ def process_file(file)
|
|
25
48
|
end
|
26
49
|
end
|
27
50
|
|
28
|
-
|
29
|
-
|
30
|
-
|
51
|
+
def find_target_named(results, target_name)
|
52
|
+
return nil if results[:target].nil?
|
53
|
+
idx = results[:target].find_index { |target| target[:name] == target_name }
|
54
|
+
return results[:target][idx] unless idx.nil?
|
55
|
+
nil
|
56
|
+
end
|
57
|
+
|
58
|
+
def render_target(results, target_name)
|
59
|
+
target = find_target_named(results, target_name)
|
60
|
+
if target.nil? then
|
61
|
+
puts "Unknown target #{target_name}"
|
62
|
+
exit 1
|
63
|
+
end
|
64
|
+
|
65
|
+
lang = Talk::Language.language_named(target[:language])
|
66
|
+
if lang.nil? then
|
67
|
+
puts "Target #{target[:name]} has unsupported language #{target[:language]}"
|
68
|
+
exit 1
|
69
|
+
else
|
70
|
+
lang.render(results, target)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def render_targets(results)
|
75
|
+
$opts[:target].each { |target_name| render_target(results, target_name) }
|
76
|
+
end
|
77
|
+
|
78
|
+
def list_targets(results)
|
79
|
+
results[:target].each { |target| puts "\t#{target[:name]} (#{target[:language]})" }
|
80
|
+
end
|
81
|
+
|
82
|
+
def process_files
|
83
|
+
ARGV.each { |file| process_file(file) }
|
84
|
+
$parser.results
|
85
|
+
end
|
86
|
+
|
87
|
+
def strip_tag(container, tag)
|
88
|
+
if container.is_a? Array then
|
89
|
+
return container.map! { |v| strip_tag(v, tag) }
|
90
|
+
elsif not container.is_a? Hash then
|
91
|
+
return container
|
92
|
+
end
|
93
|
+
|
94
|
+
container.delete(tag)
|
95
|
+
container.each { |k, v| container[k] = strip_tag(v, tag) }
|
96
|
+
end
|
97
|
+
|
98
|
+
def strip_tags(container, tags)
|
99
|
+
tags.each { |tag| container = strip_tag(container, tag.to_sym) }
|
100
|
+
container
|
101
|
+
end
|
102
|
+
|
103
|
+
def strip_omitted(results, omitted)
|
104
|
+
omitted.each { |tag| results.delete(tag.to_sym) }
|
105
|
+
end
|
106
|
+
|
107
|
+
def strip_nonincluded(results, included)
|
108
|
+
included.map! { |key| key.to_sym }
|
109
|
+
trimmed = {}
|
110
|
+
(results.keys.select { |key| included.include? key }).each { |key| trimmed[key] = results[key] }
|
111
|
+
trimmed
|
112
|
+
end
|
113
|
+
|
114
|
+
def upgrade_protocols(results)
|
115
|
+
methods = {}
|
116
|
+
results[:method].each { |method| methods[method[:name].to_sym] = method }
|
117
|
+
results[:protocol].each do |proto|
|
118
|
+
proto[:method].map! { |method| methods[method.to_sym] }
|
31
119
|
end
|
120
|
+
results.delete(:method)
|
121
|
+
end
|
32
122
|
|
33
|
-
|
123
|
+
begin
|
124
|
+
results = process_files
|
125
|
+
results = strip_tags(results, $opts[:no])
|
126
|
+
results = strip_omitted(results, $opts[:omit]) unless $opts[:omit].empty?
|
127
|
+
results = strip_nonincluded(results, $opts[:include]) unless $opts[:include].empty?
|
128
|
+
upgrade_protocols(results) if $opts[:upgrade]
|
129
|
+
puts JSON.generate(results) if $opts[:json]
|
130
|
+
list_targets(results) if $opts[:targets]
|
131
|
+
render_targets(results)
|
34
132
|
rescue Talk::ParseError => e
|
35
133
|
puts e
|
36
134
|
exit 1
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: talk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Acres
|
@@ -39,7 +39,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
39
|
version: '0'
|
40
40
|
requirements: []
|
41
41
|
rubyforge_project:
|
42
|
-
rubygems_version: 2.0.
|
42
|
+
rubygems_version: 2.0.14
|
43
43
|
signing_key:
|
44
44
|
specification_version: 4
|
45
45
|
summary: Compile-to-source protocol contract specification language
|