xamplr-gen 1.9.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/.document +5 -0
- data/.gitignore +22 -0
- data/COPYING +619 -0
- data/LICENSE +4 -0
- data/Makefile +11 -0
- data/README.md +33 -0
- data/Rakefile +66 -0
- data/VERSION +1 -0
- data/bin/xampl-gen +17 -0
- data/features/step_definitions/xamplr-gen_steps.rb +0 -0
- data/features/support/env.rb +6 -0
- data/features/xamplr-gen.feature +9 -0
- data/lib/xamplr-gen.rb +13 -0
- data/lib/xamplr-gen/.cvsignore +1 -0
- data/lib/xamplr-gen/graphml-out.rb +449 -0
- data/lib/xamplr-gen/my.gen.elements.xml +461 -0
- data/lib/xamplr-gen/simpleTemplate/danger.rx +4 -0
- data/lib/xamplr-gen/simpleTemplate/obsolete/input-c.r4 +35 -0
- data/lib/xamplr-gen/simpleTemplate/obsolete/play.r6.txt +12 -0
- data/lib/xamplr-gen/simpleTemplate/obsolete/play_more.r6.txt +20 -0
- data/lib/xamplr-gen/simpleTemplate/obsolete/test001.r5 +8 -0
- data/lib/xamplr-gen/simpleTemplate/obsolete/test002.r5 +13 -0
- data/lib/xamplr-gen/simpleTemplate/obsolete/test003.r5 +37 -0
- data/lib/xamplr-gen/simpleTemplate/old/r6.000.rb +122 -0
- data/lib/xamplr-gen/simpleTemplate/old/r6.001.rb +145 -0
- data/lib/xamplr-gen/simpleTemplate/play.r6 +12 -0
- data/lib/xamplr-gen/simpleTemplate/play_more.r6 +20 -0
- data/lib/xamplr-gen/simpleTemplate/play_noblanks.r6 +21 -0
- data/lib/xamplr-gen/simpleTemplate/playq.r6 +16 -0
- data/lib/xamplr-gen/simpleTemplate/r6.rb +87 -0
- data/lib/xamplr-gen/simpleTemplate/simple-template.rb +75 -0
- data/lib/xamplr-gen/templates/.cvsignore +3 -0
- data/lib/xamplr-gen/templates/child.template +47 -0
- data/lib/xamplr-gen/templates/child_indexed.template +89 -0
- data/lib/xamplr-gen/templates/child_modules.template +5 -0
- data/lib/xamplr-gen/templates/element_classes.template +11 -0
- data/lib/xamplr-gen/templates/element_data.template +283 -0
- data/lib/xamplr-gen/templates/element_empty.template +277 -0
- data/lib/xamplr-gen/templates/element_mixed.template +278 -0
- data/lib/xamplr-gen/templates/element_simple.template +277 -0
- data/lib/xamplr-gen/templates/package.template +38 -0
- data/lib/xamplr-gen/xampl-cl-gen.rb +89 -0
- data/lib/xamplr-gen/xampl-generator.rb +561 -0
- data/lib/xamplr-gen/xampl-hand-generated.rb +1534 -0
- data/lib/xamplr-gen/yuml-out.rb +127 -0
- data/licence.rb +17 -0
- data/test/helper.rb +10 -0
- data/test/test_xamplr-gen.rb +7 -0
- data/xamplr-gen.gemspec +98 -0
- metadata +124 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
|
|
2
|
+
| fields = %w( foo bar foobar barfoo )
|
3
|
+
|
|
4
|
+
| macro('field'){|name| "int #{ name };" }
|
5
|
+
|
|
6
|
+
| macro('setter') do |name|
|
7
|
+
| <<-c
|
8
|
+
| int set_#{ name }(self, value)
|
9
|
+
| object * self;
|
10
|
+
| int value;
|
11
|
+
| {
|
12
|
+
| return( self->#{ name } = value );
|
13
|
+
| }
|
14
|
+
| c
|
15
|
+
| end
|
16
|
+
|
|
17
|
+
| macro('getter') do |name|
|
18
|
+
| <<-c
|
19
|
+
| int get_#{ name }(self)
|
20
|
+
| object * self;
|
21
|
+
| {
|
22
|
+
| return( self->#{ name } );
|
23
|
+
| }
|
24
|
+
| c
|
25
|
+
| end
|
26
|
+
|
27
|
+
struct object {
|
28
|
+
|
|
29
|
+
| fields.each{|f| field f}
|
30
|
+
|
|
31
|
+
};
|
32
|
+
|
33
|
+
|
|
34
|
+
| fields.each{|f| setter(f); getter(f); }
|
35
|
+
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
|
|
2
|
+
| some_number = 42
|
3
|
+
| def gen_some_number
|
4
|
+
| 42 + rand
|
5
|
+
| end
|
6
|
+
|
|
7
|
+
|
8
|
+
Hello there (play)! #{@message}
|
9
|
+
|
10
|
+
some number: [[[#{some_number}]]]
|
11
|
+
gen some number: [[[#{gen_some_number}]]]
|
12
|
+
play __________________________________________________________
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
|
2
|
+
| some_number = 42
|
3
|
+
| def gen_some_number
|
4
|
+
| 42 + rand
|
5
|
+
| end
|
6
|
+
|
|
7
|
+
|
8
|
+
Hello there(play_more)! #{@message}
|
9
|
+
|
10
|
+
|
|
11
|
+
| another_number = 99
|
12
|
+
| result << play()
|
13
|
+
|
|
14
|
+
|
15
|
+
some number: [[[#{some_number}]]]
|
16
|
+
gen some number: [[[#{gen_some_number}]]]
|
17
|
+
another number: [[[#{another_number}]]]
|
18
|
+
|
19
|
+
play again:... #{play}
|
20
|
+
play_more _____________________________________________________
|
@@ -0,0 +1,37 @@
|
|
1
|
+
|
|
2
|
+
| fields = %w( foo bar foobar barfoo )
|
3
|
+
|
|
4
|
+
| macro('field'){|name| "int #{ name };" }
|
5
|
+
|
|
6
|
+
| macro('setter') do |name|
|
7
|
+
| <<-c
|
8
|
+
| int set_#{ name }(self, value)
|
9
|
+
| object * self;
|
10
|
+
| int value;
|
11
|
+
| {
|
12
|
+
| return( self->#{ name } = value );
|
13
|
+
| }
|
14
|
+
| c
|
15
|
+
| end
|
16
|
+
|
|
17
|
+
| macro('getter') do |name|
|
18
|
+
| <<-c
|
19
|
+
| int get_#{ name }(self)
|
20
|
+
| object * self;
|
21
|
+
| {
|
22
|
+
| return( self->#{ name } );
|
23
|
+
| }
|
24
|
+
| c
|
25
|
+
| end
|
26
|
+
|
27
|
+
struct object {
|
28
|
+
|
|
29
|
+
| fields.each{|f| field f}
|
30
|
+
|
|
31
|
+
};
|
32
|
+
|
33
|
+
|
|
34
|
+
| fields.each{|f| setter(f); getter(f); }
|
35
|
+
|
|
36
|
+
|
37
|
+
|
@@ -0,0 +1,122 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
module TemplateEngine
|
3
|
+
attr_accessor :files
|
4
|
+
|
5
|
+
def macro(name, &block)
|
6
|
+
Kernel.send(:define_method, name) { |*args|
|
7
|
+
puts block.call(args)
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
def build_script(template_file_name, method_name)
|
12
|
+
|
13
|
+
# Build the definition of a method (called 'method_name') that
|
14
|
+
# will execute the template (in the file 'template_file_name'). There will
|
15
|
+
# be an optional argument that defaults to the empty string (and so this
|
16
|
+
# method will, by default, build a new string representing the result). If
|
17
|
+
# the argument is supplied, it must respond to the "<<" (append) method.
|
18
|
+
#
|
19
|
+
# The result variable is available in the template. To write to the result
|
20
|
+
# from Ruby code, result << sprintf("hello %s", "world") in the template
|
21
|
+
# will get its output where expected.
|
22
|
+
|
23
|
+
File.open(template_file_name) do | file |
|
24
|
+
r = "
|
25
|
+
def #{method_name}(result=\"\")
|
26
|
+
tmp = ""
|
27
|
+
result << \"\"
|
28
|
+
"
|
29
|
+
while line = file.gets
|
30
|
+
if line[0] == ?|
|
31
|
+
r << " #{line[1..-1]}"
|
32
|
+
else
|
33
|
+
r << " result << \"#{line.chomp.gsub("\"", "\\\"")}\\n\"\n"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
r << "
|
37
|
+
result
|
38
|
+
end
|
39
|
+
"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def compile_scripts()
|
44
|
+
files.each { | script_name |
|
45
|
+
method_name = File::basename(script_name, ".*")
|
46
|
+
the_script = build_script(script_name, method_name)
|
47
|
+
puts the_script
|
48
|
+
instance_eval the_script
|
49
|
+
}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
###
|
54
|
+
### and this is how it can be used...
|
55
|
+
###
|
56
|
+
|
57
|
+
# Define a class to hold the template methods. There is an attribute 'message'
|
58
|
+
# that can be set by the program invoking the template, and referred to by the
|
59
|
+
# templates.
|
60
|
+
|
61
|
+
class R6_Template
|
62
|
+
include TemplateEngine
|
63
|
+
attr_accessor :message
|
64
|
+
end
|
65
|
+
|
66
|
+
# Assume that the command line arguments are all specifying the names of a
|
67
|
+
# template file. Open the file and pass it to the build script method. When
|
68
|
+
# the script is built, 'eval' it.
|
69
|
+
|
70
|
+
engine = R6_Template.new
|
71
|
+
engine.files = [ "play.r6", "play_more.r6", "playq.r6"];
|
72
|
+
engine.compile_scripts
|
73
|
+
|
74
|
+
exit
|
75
|
+
|
76
|
+
# For illustrative purposes, go over the command line arguments and execute
|
77
|
+
# the corresponding method defined above.
|
78
|
+
|
79
|
+
engine.files.each { | script_name |
|
80
|
+
method_name = File::basename(script_name, ".*")
|
81
|
+
engine.message = sprintf("this is script '%s'", method_name)
|
82
|
+
puts "#{method_name}*******************"
|
83
|
+
what = engine.send(method_name);
|
84
|
+
puts "{{{#{what}}}}*******************"
|
85
|
+
}
|
86
|
+
|
87
|
+
# This time call the play method directly. There must be a template
|
88
|
+
# called 'play' (sans extenstion) for this to work.
|
89
|
+
|
90
|
+
engine.message = "this is script 'play' -- called explicitly"
|
91
|
+
puts "!!play!!*******************"
|
92
|
+
what = engine.play()
|
93
|
+
puts "{{{#{what}}}}*******************"
|
94
|
+
|
95
|
+
# Now do the same thing as the illustrative loop above but writing to a file
|
96
|
+
# with the script name and a ".out" extension.
|
97
|
+
|
98
|
+
engine.files.each { | script_name |
|
99
|
+
method_name = File::basename(script_name, ".*")
|
100
|
+
engine.message = sprintf("this is script '%s'", method_name)
|
101
|
+
File.open(sprintf("%s.out", method_name), "w") { | file |
|
102
|
+
engine.send(method_name, file);
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
# Write to a file called "play-x.out", again, there must be a play template
|
107
|
+
# defined.
|
108
|
+
|
109
|
+
engine.message = "this is script 'play' -- called explicitly"
|
110
|
+
File.open("play-x.out", "w") { | file |
|
111
|
+
engine.play(file)
|
112
|
+
}
|
113
|
+
|
114
|
+
# Build up a single string by applying all the templates
|
115
|
+
long_string = ""
|
116
|
+
engine.files.each { | script_name |
|
117
|
+
method_name = File::basename(script_name, ".*")
|
118
|
+
engine.message = sprintf("this is script '%s'", method_name)
|
119
|
+
what = engine.send(method_name, long_string);
|
120
|
+
}
|
121
|
+
puts "!!{{{#{long_string}}}}!!*******************"
|
122
|
+
|
@@ -0,0 +1,145 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
module TemplateEngine
|
4
|
+
attr_accessor :method_to_file_name, :file_name_to_method
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@method_to_file_name = Hash.new()
|
8
|
+
@file_name_to_method = Hash.new()
|
9
|
+
end
|
10
|
+
|
11
|
+
# def macro(name, &block)
|
12
|
+
# Kernel.send(:define_method, name) { |*args|
|
13
|
+
# puts block.call(args)
|
14
|
+
# }
|
15
|
+
# end
|
16
|
+
|
17
|
+
def build_script(template_file_name, method_name)
|
18
|
+
|
19
|
+
# Build the definition of a method (called 'method_name') that
|
20
|
+
# will execute the template (in the file 'template_file_name'). There will
|
21
|
+
# be an optional argument that defaults to the empty string (and so this
|
22
|
+
# method will, by default, build a new string representing the result). If
|
23
|
+
# the argument is supplied, it must respond to the "<<" (append) method.
|
24
|
+
#
|
25
|
+
# The result variable is available in the template. To write to the result
|
26
|
+
# from Ruby code, result << sprintf("hello %s", "world") in the template
|
27
|
+
# will get its output where expected.
|
28
|
+
|
29
|
+
File.open(template_file_name) do | file |
|
30
|
+
tmp = ""
|
31
|
+
r = "
|
32
|
+
def #{method_name}(result=\"\")
|
33
|
+
result << \"\"
|
34
|
+
"
|
35
|
+
while line = file.gets
|
36
|
+
if line[0] == ?|
|
37
|
+
if (0 < tmp.length)
|
38
|
+
r << " result << \"#{tmp.gsub("\"", "\\\"")}\""
|
39
|
+
tmp = ""
|
40
|
+
end
|
41
|
+
r << " #{line[1..-1]}"
|
42
|
+
else
|
43
|
+
#tmp << line.chomp << "\n"
|
44
|
+
tmp << line
|
45
|
+
end
|
46
|
+
end
|
47
|
+
r << " result << \"#{tmp.gsub("\"", "\\\"")}\""
|
48
|
+
r << "
|
49
|
+
result
|
50
|
+
end
|
51
|
+
"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def compile_scripts(files)
|
56
|
+
files.each { | script_name |
|
57
|
+
method_name = File::basename(script_name, ".*")
|
58
|
+
|
59
|
+
method_to_file_name[method_name] = script_name;
|
60
|
+
file_name_to_method[script_name] = method_name;
|
61
|
+
|
62
|
+
the_script = build_script(script_name, method_name)
|
63
|
+
puts the_script
|
64
|
+
instance_eval the_script
|
65
|
+
}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
###
|
70
|
+
### and this is how it can be used...
|
71
|
+
###
|
72
|
+
|
73
|
+
# Define a class to hold the template methods. There is an attribute 'message'
|
74
|
+
# that can be set by the program invoking the template, and referred to by the
|
75
|
+
# templates.
|
76
|
+
|
77
|
+
class R6_Template
|
78
|
+
include TemplateEngine
|
79
|
+
attr_accessor :message
|
80
|
+
end
|
81
|
+
|
82
|
+
# Assume that the command line arguments are all specifying the names of a
|
83
|
+
# template file. Open the file and pass it to the build script method. When
|
84
|
+
# the script is built, 'eval' it.
|
85
|
+
|
86
|
+
files = [ "play.r6", "play_more.r6", "playq.r6", "play_noblanks.r6"];
|
87
|
+
|
88
|
+
engine = R6_Template.new
|
89
|
+
engine.compile_scripts(files)
|
90
|
+
|
91
|
+
# For illustrative purposes, go over the command line arguments and execute
|
92
|
+
# the corresponding method defined above.
|
93
|
+
|
94
|
+
files.each { | script_name |
|
95
|
+
method_name = File::basename(script_name, ".*")
|
96
|
+
engine.message = sprintf("this is script '%s'", method_name)
|
97
|
+
puts "#{method_name}*******************"
|
98
|
+
what = engine.send(method_name);
|
99
|
+
puts "{{{#{what}}}}*******************"
|
100
|
+
}
|
101
|
+
|
102
|
+
# This time call the play method directly. There must be a template
|
103
|
+
# called 'play' (sans extenstion) for this to work.
|
104
|
+
|
105
|
+
engine.message = "this is script 'play' -- called explicitly"
|
106
|
+
puts "!!play!!*******************"
|
107
|
+
what = engine.play()
|
108
|
+
puts "{{{#{what}}}}*******************"
|
109
|
+
|
110
|
+
# Now do the same thing as the illustrative loop above but writing to a file
|
111
|
+
# with the script name and a ".out" extension.
|
112
|
+
|
113
|
+
files.each { | script_name |
|
114
|
+
method_name = File::basename(script_name, ".*")
|
115
|
+
engine.message = sprintf("this is script '%s'", method_name)
|
116
|
+
File.open(sprintf("%s.out", method_name), "w") { | file |
|
117
|
+
engine.send(method_name, file);
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
# Write to a file called "play-x.out", again, there must be a play template
|
122
|
+
# defined.
|
123
|
+
|
124
|
+
engine.message = "this is script 'play' -- called explicitly"
|
125
|
+
File.open("play-x.out", "w") { | file |
|
126
|
+
engine.play(file)
|
127
|
+
}
|
128
|
+
|
129
|
+
# Build up a single string by applying all the templates
|
130
|
+
long_string = ""
|
131
|
+
files.each { | script_name |
|
132
|
+
method_name = File::basename(script_name, ".*")
|
133
|
+
engine.message = sprintf("this is script '%s'", method_name)
|
134
|
+
what = engine.send(method_name, long_string);
|
135
|
+
}
|
136
|
+
puts "!!{{{#{long_string}}}}!!*******************"
|
137
|
+
|
138
|
+
# This will fail, because the template methods are only defined on the
|
139
|
+
# instance of the engine that compiled them.
|
140
|
+
#
|
141
|
+
#engine2 = R6_Template.new
|
142
|
+
#engine2.message = "this is script 'play' -- called explicitly"
|
143
|
+
#File.open("play-x.out", "w") { | file |
|
144
|
+
# engine2.play(file)
|
145
|
+
#}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
|
|
2
|
+
| some_number = 42
|
3
|
+
| def gen_some_number
|
4
|
+
| 42 + rand
|
5
|
+
| end
|
6
|
+
|
|
7
|
+
|
8
|
+
Hello there (play)! #{@message}
|
9
|
+
|
10
|
+
some number: [[[#{some_number}]]]
|
11
|
+
gen some number: [[[#{gen_some_number}]]]
|
12
|
+
play __________________________________________________________
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
|
2
|
+
| some_number = 42
|
3
|
+
| def gen_some_number
|
4
|
+
| 42 + rand
|
5
|
+
| end
|
6
|
+
|
|
7
|
+
|
8
|
+
Hello there(play_more)! #{@message}
|
9
|
+
|
10
|
+
|
|
11
|
+
| another_number = 99
|
12
|
+
| result << play()
|
13
|
+
|
|
14
|
+
|
15
|
+
some number: [[[#{some_number}]]]
|
16
|
+
gen some number: [[[#{gen_some_number}]]]
|
17
|
+
another number: [[[#{another_number}]]]
|
18
|
+
|
19
|
+
play again:... #{play}
|
20
|
+
play_more _____________________________________________________
|