RuCodeGen 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/NEWS +3 -0
- data/README +7 -1
- data/Rakefile +4 -1
- data/bin/rcgtool +138 -0
- data/docs/AdHoc +154 -0
- data/docs/CmdLineHandler +186 -0
- data/docs/examples/cmd_line_handler/generator +3 -0
- data/examples/cmd_line_handler/generator.rb +74 -0
- data/examples/cpp/custom/submit_deliver/submit_deliver_gen.rb +1 -1
- data/examples/cpp/value_incapsulator/cg-cfg.rb +1 -1
- data/examples/cpp/value_incapsulator/cg-host_config.rb +1 -1
- data/lib/rucodegen/adhoc/templates/cpp-open-ns/g.rb +136 -0
- data/lib/rucodegen/cmd_line_handler.rb +169 -0
- data/lib/rucodegen/run_mode.rb +29 -38
- data/lib/rucodegen/version.rb +10 -0
- data/tests/tc_cmd_line_handler.rb +64 -0
- data/tests/tc_run_mode.rb +0 -10
- data/tests/ts_rucodegen.rb +1 -0
- metadata +22 -4
data/LICENSE
CHANGED
data/NEWS
CHANGED
data/README
CHANGED
@@ -6,7 +6,13 @@ RuCodeGen
|
|
6
6
|
������ � ���������� ���������� ��� ��������� ���������������, � ���������� ������� ���������������.
|
7
7
|
|
8
8
|
��������� ��. {docs/Principle}[link://files/docs/Principle.html] �
|
9
|
-
{docs/EmbeddedRuCodeGen}[link://files/docs/EmbeddedRuCodeGen.html].
|
9
|
+
{docs/EmbeddedRuCodeGen}[link://files/docs/EmbeddedRuCodeGen.html]. � ������
|
10
|
+
0.3.0 ��� ������������ DSL ��������� ����������� ����������� � �������
|
11
|
+
���������� ��������� ������, ��.
|
12
|
+
{docs/CmdLineHandler}[link://files/docs/CmdLineHandler.html].
|
13
|
+
|
14
|
+
������� � ������ 0.3.0 RuCodeGen ������������ ��� �� adhoc-���������, ��.
|
15
|
+
{docs/AdHoc}[link://files/docs/AdHoc.html].
|
10
16
|
|
11
17
|
== ������� ��������������
|
12
18
|
|
data/Rakefile
CHANGED
@@ -3,8 +3,10 @@ Gem::manage_gems
|
|
3
3
|
|
4
4
|
require 'rake/gempackagetask'
|
5
5
|
|
6
|
+
require 'lib/rucodegen/version'
|
7
|
+
|
6
8
|
PKG_NAME =
|
7
|
-
PKG_VERSION =
|
9
|
+
PKG_VERSION = RuCodeGen::VERSION
|
8
10
|
|
9
11
|
spec = Gem::Specification.new do |s|
|
10
12
|
s.name = "RuCodeGen"
|
@@ -16,6 +18,7 @@ spec = Gem::Specification.new do |s|
|
|
16
18
|
s.summary = "Simple code generation tool"
|
17
19
|
s.files = FileList[ "{bin,tests,lib,docs,examples}/**/*" ].
|
18
20
|
exclude( "rdoc" ).to_a
|
21
|
+
s.executables = 'rcgtool'
|
19
22
|
s.require_path = "lib"
|
20
23
|
s.autorequire = "rucodegen"
|
21
24
|
s.test_file = "tests/ts_rucodegen.rb"
|
data/bin/rcgtool
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
# ������, ������� �������� �� ������ ad-hoc ����������� �� �����
|
2
|
+
# ���������������� �������.
|
3
|
+
|
4
|
+
require 'optparse'
|
5
|
+
require 'ostruct'
|
6
|
+
|
7
|
+
module RuCodeGenAdHoc
|
8
|
+
|
9
|
+
module Impl
|
10
|
+
|
11
|
+
# ����������� ��� ����������������� ������� � �������.
|
12
|
+
STD_CODEGEN_SCRIPT_NAME = 'g.rb'
|
13
|
+
|
14
|
+
# ������ ���������� ��������� ������.
|
15
|
+
#
|
16
|
+
# ���������� ������ �� ���������� ��������.
|
17
|
+
# template_name:: ��� ���������� ��� ������������� �������.
|
18
|
+
# list:: �������� true, ���� ������ ������������ ������ ��������� ��������.
|
19
|
+
# include_paths:: �������� ������ �������������� ����� ��� ������ ��������.
|
20
|
+
#
|
21
|
+
# ��������� ������ �������, ���� ��� ����� �������� --help.
|
22
|
+
#
|
23
|
+
def Impl.parse_args
|
24
|
+
result = OpenStruct.new(
|
25
|
+
:template_name => nil,
|
26
|
+
:list => false,
|
27
|
+
:include_paths => [] )
|
28
|
+
|
29
|
+
parser = OptionParser.new
|
30
|
+
|
31
|
+
parser.banner = <<BANNER
|
32
|
+
RuCodeGen Ad-Hoc generation runner
|
33
|
+
|
34
|
+
Usage:
|
35
|
+
|
36
|
+
rcgtool [<options>] template-name [<template-options>]
|
37
|
+
|
38
|
+
BANNER
|
39
|
+
|
40
|
+
parser.on_head( '-l', '--list', 'Show list of available templates' ) do
|
41
|
+
result.list = true
|
42
|
+
end
|
43
|
+
|
44
|
+
parser.on_head( '-I', '--include-path PATH',
|
45
|
+
'Additional path to looking for templates' ) do |p|
|
46
|
+
result.include_paths << p
|
47
|
+
end
|
48
|
+
|
49
|
+
parser.on_head( '-h', '--help', 'Show this message' ) do
|
50
|
+
puts parser
|
51
|
+
exit( 1 )
|
52
|
+
end
|
53
|
+
|
54
|
+
parser.order!( ARGV ) do |nonarg|
|
55
|
+
# ������ �� ����� � ����� ������ �������.
|
56
|
+
result.template_name = nonarg
|
57
|
+
parser.terminate
|
58
|
+
end
|
59
|
+
|
60
|
+
if !result.template_name && !result.list
|
61
|
+
$stderr.puts "template_name must be specified"
|
62
|
+
exit( 2 )
|
63
|
+
end
|
64
|
+
|
65
|
+
result
|
66
|
+
end
|
67
|
+
|
68
|
+
# ����� ������ ��������� ��������.
|
69
|
+
def Impl.show_templates_list( include_paths )
|
70
|
+
include_paths.each do |path|
|
71
|
+
templates_found = []
|
72
|
+
Dir.glob( File.join( path, '*' ), File::FNM_PATHNAME ) do |dir|
|
73
|
+
probe_name = File.join( dir, STD_CODEGEN_SCRIPT_NAME )
|
74
|
+
if File.readable?( probe_name )
|
75
|
+
templates_found << File.basename( dir )
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
templates_found.sort.each do |template|
|
80
|
+
puts template + " (#{path})"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# ����� ������� ���� � ������� �� ����� �������.
|
86
|
+
#
|
87
|
+
# ���� ����� ���������� ��������, �� ������������ nil.
|
88
|
+
#
|
89
|
+
def Impl.find_full_template_path( template_name, include_paths )
|
90
|
+
include_paths.each do |path|
|
91
|
+
probe_name = File.join( path, template_name, STD_CODEGEN_SCRIPT_NAME )
|
92
|
+
if File.readable?( probe_name )
|
93
|
+
return probe_name
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
nil
|
98
|
+
end
|
99
|
+
|
100
|
+
# ����� � ���������� ���������� ������� � ��������� ������� �����.
|
101
|
+
def Impl.find_and_run_template( template_name, include_paths )
|
102
|
+
full_path = find_full_template_path( template_name, include_paths )
|
103
|
+
if full_path
|
104
|
+
require full_path
|
105
|
+
else
|
106
|
+
$stderr.puts "#{template_name}: template not found in:\n\t" +
|
107
|
+
include_paths.join( "\n\t" )
|
108
|
+
exit( 3 )
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end # Impl
|
113
|
+
|
114
|
+
# ���������� �������� ������.
|
115
|
+
def RuCodeGenAdHoc.run_ad_hoc_generation
|
116
|
+
options = Impl.parse_args
|
117
|
+
|
118
|
+
# � ������ ������ �������� ����� �������� �����������
|
119
|
+
# ���� � ��������� ������ ������.
|
120
|
+
options.include_paths << File.join(
|
121
|
+
File.dirname( __FILE__ ),
|
122
|
+
'../lib/rucodegen/adhoc/templates' )
|
123
|
+
|
124
|
+
if options.list
|
125
|
+
Impl.show_templates_list( options.include_paths )
|
126
|
+
else
|
127
|
+
Impl.find_and_run_template(
|
128
|
+
options.template_name,
|
129
|
+
options.include_paths )
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
end # RuCodeGenAdHoc
|
134
|
+
|
135
|
+
RuCodeGenAdHoc.run_ad_hoc_generation
|
136
|
+
|
137
|
+
# vim:ft=ruby:
|
138
|
+
|
data/docs/AdHoc
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
= AdHoc ���������
|
2
|
+
|
3
|
+
== ��������
|
4
|
+
|
5
|
+
�������������� ����� ������ RuCodeGen, ����� �� Ruby ��������� DSL-������,
|
6
|
+
������� ����������� ��� ��������� �������, � ������� � ���������� ����������
|
7
|
+
���� ��� ��������� ������, ��������� �� ������ �������. � ���������, ���
|
8
|
+
��������� ��������, � ������� ��������� ��������� DSL-������ � ���������
|
9
|
+
Ruby-����� �� ������:
|
10
|
+
* ��������� ��������� ��� ����� ������. ��������, ������ �������� �������,
|
11
|
+
������� � ������ ������ ����� ��������� � ������ � ������� ������� �/���
|
12
|
+
������������ �����������;
|
13
|
+
* ��������� ���������� ���� (���������� ����������) ��� ������� � ���������
|
14
|
+
��������.
|
15
|
+
|
16
|
+
��������, ���� �� ������ ���������� ���-������ ������ ��� ����� C++ ������
|
17
|
+
����������� ������� ����� ���� ��������� ��������� (��� ��������� ���-��
|
18
|
+
�������) � �������� ������� C++ ����. ��������, �������� ���-������ �����:
|
19
|
+
rcgtool cpp-new-file -o my/project/header.hpp
|
20
|
+
�������� ���� <tt>my/project/header.hpp</tt> ����:
|
21
|
+
/*
|
22
|
+
* Copyright (C) 2007 ...
|
23
|
+
* ...
|
24
|
+
*/
|
25
|
+
/*!
|
26
|
+
* \since v.3.4.6
|
27
|
+
* \file my/project/header.hpp
|
28
|
+
* \brief <DESCRIBE YOUR FILE HERE!>
|
29
|
+
*/
|
30
|
+
#if !defined( MY_PROJECT_HEADER_HPP )
|
31
|
+
#define MY_PROJECT_HEADER_HPP
|
32
|
+
|
33
|
+
#endif
|
34
|
+
|
35
|
+
��� �� ������� ��������� � ������������� � �����-������ ��������� ���. �
|
36
|
+
���������, � ��������� {VIM}[http://www.vim.org], ������� ��������� ���������� �� ���� �������
|
37
|
+
������� ���������� �������� ������, � ����� �������� ���� �������� �� ���������
|
38
|
+
������ �������. �����, ��������, ����� �������� � VIM ������:
|
39
|
+
namespace my::project::details
|
40
|
+
�������� ��, ������ �������:
|
41
|
+
:'<,'>!rcgtool cpp-open-ns
|
42
|
+
����� ���� ���������� ������ ����� �������� ��:
|
43
|
+
namespace my {
|
44
|
+
|
45
|
+
namespace project {
|
46
|
+
|
47
|
+
namespace details {
|
48
|
+
|
49
|
+
} /* namespace details */
|
50
|
+
|
51
|
+
} /* namespace project */
|
52
|
+
|
53
|
+
} /* namespace my */
|
54
|
+
|
55
|
+
�.�. ����� ���������� ������� ������������� RuCodeGen 0.1.0 � 0.2.0 �����
|
56
|
+
�������, ��� ���������� ������������ "�����������", ��� ��� �� ������� ��������
|
57
|
+
ad-hoc, ����������. ������ ���� ��������� ���� ������� � ������ RuCodeGen
|
58
|
+
0.3.0.
|
59
|
+
|
60
|
+
== ������� ������
|
61
|
+
|
62
|
+
������� ������ ad-hoc ���������� ������� � ���, ��� RuCodeGen �������� � ����
|
63
|
+
��������� ������� rcgtool, ������� �������� ��� ������������� ������� � �����
|
64
|
+
���������� ��� ����� �������. ������� rcgtool ���� ������ ����� ��������� ��
|
65
|
+
��������� �, ���� ������ ������, ��������� ��� �� ���������� ��� ���������
|
66
|
+
ruby-������. ��� ���� ������� ������� ���������� �������� ������������� �����
|
67
|
+
����������.
|
68
|
+
|
69
|
+
����� �������, ������ ad-hoc ������ ������������ �� ���� ����������
|
70
|
+
ruby-���������, � rcgtool �������� ����� ���� ������������ ����� ��������.
|
71
|
+
|
72
|
+
��������� ������ �������� ��������������� ����������, �� ����� ��������� �����
|
73
|
+
��������:
|
74
|
+
* ������������� ��������� ��������� ������;
|
75
|
+
* ������������� ���������� ���������;
|
76
|
+
* ��������� ���������� ����� �����;
|
77
|
+
* ��������� ���������� �������� ��� ������-���� ������������ ��������;
|
78
|
+
* ����� ������ � �������������
|
79
|
+
* � �.�. � �.�. � ����� ����������.
|
80
|
+
|
81
|
+
��������������, ad-hoc ������ ����� �������� ���������� ����� ������ �:
|
82
|
+
* �����-���� ���� (� ������� ������������ ��� �������� ������������� ������);
|
83
|
+
* �� ����������� ����� ������ (��������� ��� ��������� � VIM-�);
|
84
|
+
* ����-���� ���.
|
85
|
+
|
86
|
+
== ������ ������� rcgtool
|
87
|
+
|
88
|
+
������:
|
89
|
+
RuCodeGen Ad-Hoc generation runner
|
90
|
+
|
91
|
+
Usage:
|
92
|
+
|
93
|
+
rcgtool [<options>] template-name [<template-options>]
|
94
|
+
|
95
|
+
-h, --help Show this message
|
96
|
+
-I, --include-path PATH Additional path to looking for templates
|
97
|
+
-l, --list Show list of available templates
|
98
|
+
|
99
|
+
��� ������������ ���������:
|
100
|
+
[<i>-I, --include-path</i>] �������������� ���� ��� ������ ad-hoc ��������.
|
101
|
+
[<i>-l, --list</i>] ��������� rcgtool ���������� ������ �������� ��������.
|
102
|
+
|
103
|
+
�� ��������� rcgtool ���� ������� � ��������
|
104
|
+
<tt>../lib/rucodegen/adhoc/templates</tt> ������������ ���� ��������, � �������
|
105
|
+
��������� �������� ���� <tt>rcgtool</tt> �� ������� RuCodeGen. �.�., ��
|
106
|
+
���������, rcgtool ���� ������� � ������� ����������� RuCodeGen. ��������
|
107
|
+
<i>-I</i> ��������� ��������� ������ ��������� ��� ������ ��������.
|
108
|
+
|
109
|
+
�������� <i>template-name</i> ������ ��������� ��� ad-hoc �������. ���������
|
110
|
+
����� <i>template-name</i> �������������� ��������� <i>template-options</i>
|
111
|
+
�������� rcgtool �� �������������� � ���������� � ad-hoc ������.
|
112
|
+
|
113
|
+
== ������� ad-hoc �������
|
114
|
+
|
115
|
+
���� ��������� ad-hoc �������� ��������� � ����� ��������� ���������. ������� � ������ 0.3.0 �������� ������ ���� ������:
|
116
|
+
|
117
|
+
[cpp-open-ns] �� ����� C++ ������������ ���� ���������� �������� ���� �
|
118
|
+
��������� � ��������� ����� ������������ ����.
|
119
|
+
|
120
|
+
��������:
|
121
|
+
rcgtool cpp-open-ns -n my::project
|
122
|
+
�������� � ������ �� ����������� ����� ������:
|
123
|
+
namespace my {
|
124
|
+
|
125
|
+
namespace project {
|
126
|
+
|
127
|
+
} /* namespace project */
|
128
|
+
|
129
|
+
} /* namespace my */
|
130
|
+
|
131
|
+
��� �� cpp-open-ns ����� �������� ��� ������������ ���� �� ������������ �����:
|
132
|
+
echo "my::project" | rcgtool cpp-open-ns
|
133
|
+
���
|
134
|
+
echo "namespace my::project" | rcgtool cpp-open-ns
|
135
|
+
��� �������� � ������ �� ����������.
|
136
|
+
|
137
|
+
����������� ��������� ������ �� ������������ ����� ��������� ������������ cpp-open-ns �� ��������� VIM � ������� ������� <tt>:!<cmd></tt>.
|
138
|
+
|
139
|
+
== ��� �� ���� ������������ ad-hoc �������
|
140
|
+
|
141
|
+
Ad-hoc ������ -- ��� ruby-���� � ������ <tt>g.rb</tt>, ������� ������������� �
|
142
|
+
����������� � ������ �������. ��������, ������ cpp-open-ns, ���������� � ����
|
143
|
+
����� <tt>cpp-open-ns/g.rb</tt>.
|
144
|
+
|
145
|
+
���������� ����� g.rb ����������� � ruby-�������������, ����������� ������
|
146
|
+
rcgtool, � ������� ��������� require. ��������������, g.rb ������ ���� �������
|
147
|
+
���, ����� �� �������������� �������� ���� ������. ������� �������� ������� ���
|
148
|
+
����� �����. �.�. g.rb ������ ���� ��������������� ����������, ������� �����
|
149
|
+
��������� �� ���������� � ��� rcgtool.
|
150
|
+
|
151
|
+
���� ������� g.rb ���������� ��������� ��������� ������, �� �� �����
|
152
|
+
������������ ARGV, �.�. rcgtool � ����� ������� ������� �� ARGV ��� �����������
|
153
|
+
���������.
|
154
|
+
|
data/docs/CmdLineHandler
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
= ��������
|
2
|
+
|
3
|
+
���������� �������������, ��� ��� ����������� ��� ������������� ��������� �����
|
4
|
+
���������� � DSL-��������. ������� RuCodeGen ��� ���� �� ���� ������ ����������
|
5
|
+
��������� ������. �� �� �������� ���������� ��������, ����� ��������� ������
|
6
|
+
���������� ���� ����� �������� �� �������������� �������. ��������, ����� ����
|
7
|
+
������������� C++ ��� � ����������� �������� ��� ��� ���. ��������� ������
|
8
|
+
���������� � DSL-�������� �� ����� ������. ������� ������� ��������� ��������
|
9
|
+
������� � ��������� ������. �� ��� ����� ����������� ���� ����� �����
|
10
|
+
����������� ����������� � ������ � ����������� ��������� ������.
|
11
|
+
|
12
|
+
����� ����������� ���� ��������� � ������ 0.3.0 � ������� ������
|
13
|
+
RuCodeGen::OptionHandler � ������� RuCodeGen::RunMode::add_option_handler �
|
14
|
+
RuCodeGen::RunMode::options.
|
15
|
+
|
16
|
+
= ������� ������
|
17
|
+
|
18
|
+
����������� ������������� DSL ����������� ������� �������. � ����� ������ DSL
|
19
|
+
����������� ��� RuCodeGen, ������� ��������� ��������� ��������� ������. �����
|
20
|
+
���� RuCodeGen ��������� ��� ������������������ DSL-�������� ����������.
|
21
|
+
|
22
|
+
�� ����� ����� ������ DSL-������ ����� ���������������� � RuCodeGen �����
|
23
|
+
����������� ��������, ���������� �� ��������� ����������� �����������
|
24
|
+
���������� ��������� ������. ������ ����� ������ ������ ������������� ���������
|
25
|
+
RuCodeGen::OptionHandler.
|
26
|
+
|
27
|
+
����� RuCodeGen ���������� � ������� ���������� ��������� ������, �� �������
|
28
|
+
������ OptionParser ��� ������ � ��������� ������� � ������ OpenStruct ���
|
29
|
+
���������� ����������� �������. ������� ������� OptionHandler ������
|
30
|
+
����������� ���������������� � OptionParser ����������� ��� ��������� �
|
31
|
+
��������� � OpenStruct �������� �� ���������. ����� ���� RuCodeGen ���������
|
32
|
+
������ ��������� ������. ����� ������� ������� OptionHandler ���������������
|
33
|
+
����������� ��������� ������������ ���������� �������� � ������� OpenStruct.
|
34
|
+
|
35
|
+
����� �����, ���� �� ��������� �����-���� ������, �������������� ������
|
36
|
+
OpenStruct ���������� �������� ����������� � ������� ������
|
37
|
+
RuCodeGen::RunMode::options.
|
38
|
+
|
39
|
+
= �������� ������������ OptionHandler
|
40
|
+
|
41
|
+
��� �������� ������������ OptionHandler ���������� �������������� �� ������
|
42
|
+
RuCodeGen::OptionHandler � �������������� ����� OptionHandler#setup.
|
43
|
+
|
44
|
+
��������, ����� ���������� ������������ �������������� ���������
|
45
|
+
<tt>--debug-logs</tt> � <tt>--skip-comments</tt>. ��� ����� ��������� ���������
|
46
|
+
OptionHandler:
|
47
|
+
module ComplexGenerator
|
48
|
+
class OptionHandler < RuCodeGen::OptionHandler
|
49
|
+
def setup( parser, result )
|
50
|
+
# �� ��������� �� ����� ��������� ���������� ������.
|
51
|
+
result.complexgen_debug_logs = false
|
52
|
+
# �� ��������� �� ����� ������� �����������.
|
53
|
+
result.complexgen_skip_comments = false
|
54
|
+
|
55
|
+
parser.on( '--debug-logs', 'generate gebug output' ) do
|
56
|
+
result.complexgen_debug_logs = true
|
57
|
+
end
|
58
|
+
|
59
|
+
parser.on( '--skip-comments', 'skip comments in the result code' ) do
|
60
|
+
result.complexgen_skip_comments = true
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
RuCodeGen::RunMode.add_option_handler( ComplexGenerator.OptionHandler.new )
|
66
|
+
|
67
|
+
������ ������� OptionHandler ��� ����������. ��� ������� DSL-������� � ������
|
68
|
+
<tt>--help</tt> ����� ������ �������� �������������� ����������
|
69
|
+
<tt>--debug-logs</tt> � <tt>--skip-comments</tt>.
|
70
|
+
|
71
|
+
���� �� �� ����� <tt>--help</tt> ������� �������� ������������ ��������������
|
72
|
+
����������, �� � OptionHandler ���������� �������������� ����� banner:
|
73
|
+
module ComplexGenerator
|
74
|
+
class OptionHandler < RuCodeGen::OptionHandler
|
75
|
+
def banner
|
76
|
+
"Complex generator.\n" +
|
77
|
+
"Copyright (C) 2007 ...\n" +
|
78
|
+
"For addition information please visit http://...\n"
|
79
|
+
end
|
80
|
+
...
|
81
|
+
end
|
82
|
+
end
|
83
|
+
RuCodeGen::RunMode.add_option_handler( ComplexGenerator.OptionHandler.new )
|
84
|
+
RuCodeGen ������������ ��� ������ �� ���� ������������������ ��������
|
85
|
+
OptionHandler � ���������� ����� ���� ����� ����� ����� ������� ���������� �
|
86
|
+
��������� ���������� ��������� ������.
|
87
|
+
|
88
|
+
���� ��������� ��������� � �������������� ��������, �� ����������
|
89
|
+
�������������� ����� check. ��������, ����� ���� ���������
|
90
|
+
<tt>--gen-high-speed-code</tt> � <tt>--debug-logs</tt>, ������� ������
|
91
|
+
������������ ���������. ��������������� ����� �������� � �������� ���������
|
92
|
+
����� ��������� �������:
|
93
|
+
module ComplexGenerator
|
94
|
+
class OptionHandler < RuCodeGen::OptionHandler
|
95
|
+
def setup( parser, result )
|
96
|
+
# �� ��������� ������������ ������� ���.
|
97
|
+
result.complexgen_gen_high_speed_code = false
|
98
|
+
# �� ��������� �� ����� ��������� ���������� ������.
|
99
|
+
result.complexgen_debug_logs = false
|
100
|
+
...
|
101
|
+
|
102
|
+
parser.on( '--gen-high-speed-code',
|
103
|
+
'generate processor dependent, high speed code' ) do
|
104
|
+
result.complexgen_gen_high_speed_code = true
|
105
|
+
end
|
106
|
+
parser.on( '--debug-logs', 'generate gebug output' ) do
|
107
|
+
result.complexgen_debug_logs = true
|
108
|
+
end
|
109
|
+
...
|
110
|
+
end
|
111
|
+
|
112
|
+
def check( result )
|
113
|
+
fail '--gen-high-speed-code and --debug-logs cannot ' +
|
114
|
+
'be used together' if result.complexgen_gen_high_speed_code &&
|
115
|
+
result.complexgen_debug_logs
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
RuCodeGen::RunMode.add_option_handler( ComplexGenerator.OptionHandler.new )
|
120
|
+
|
121
|
+
= ����������� ������������ OptionHandler
|
122
|
+
|
123
|
+
����������� OptionHandler ������ ���� ��������������� �� ����, ��� RuCodeGen
|
124
|
+
������� ����������. ������� ����� ����� ������ ��� ����� ����� ����������� ����
|
125
|
+
������������� ��� ��������� ������� � ��������:
|
126
|
+
module ComplexGenerator
|
127
|
+
class OptionHandler < RuCodeGen::OptionHandler
|
128
|
+
...
|
129
|
+
end
|
130
|
+
class Description
|
131
|
+
...
|
132
|
+
end
|
133
|
+
class Generator
|
134
|
+
...
|
135
|
+
end
|
136
|
+
end
|
137
|
+
RuCodeGen::RunMode.add_option_handler( ComplexGenerator.OptionHandler.new )
|
138
|
+
|
139
|
+
����� �������, ComplexGenerator::OptionHandler ����� ��������������� �
|
140
|
+
RuCodeGen ����� ��, ��� ������ � DSL-������� ����� ��������� �������� ������
|
141
|
+
ComplexGenerator.
|
142
|
+
|
143
|
+
= ��������� ������� � ����������� ���������� ��������� ������
|
144
|
+
|
145
|
+
��������� ������� � ����������� ���������� ��������� ������ �������� �����
|
146
|
+
����� RuCodeGen::RunMode.options. �� ����� ���� ���� ������ �����������: ����
|
147
|
+
����� ����� ��������� ����������, ���� �� ���������� �� ����, ��� RuCodeGen
|
148
|
+
������ ��������� ��������� ��������� ������. �.�. ������ ���������� �
|
149
|
+
RuCodeGen::RunMode.options �� ����� ������ DSL-�������.
|
150
|
+
|
151
|
+
��� ��������, ��� � ����� ������ DSL-�������, ����� ������������ �������� �
|
152
|
+
����������� � RuCodeGen �����������, ����� ��������� ������ ����������.
|
153
|
+
�������������, ����������� ���� ��� �������� <b>�� �����</b>:
|
154
|
+
def complexgen_dsl( &blk )
|
155
|
+
data = ComplexGenerator::Description.new
|
156
|
+
blk[ data ]
|
157
|
+
|
158
|
+
RuCodeGen::Generators.add(
|
159
|
+
RuCodeGen::FilenameProducer.produce( $0, data.get_file ),
|
160
|
+
# ������!!! ����� ��������� ������ ��� ����������.
|
161
|
+
ComplexGenerator.Generator.new(
|
162
|
+
data,
|
163
|
+
RuCodeGen::RunMode.options.complexgen_gen_high_speed_code,
|
164
|
+
RuCodeGen::RunMode.options.complexgen_debug_logs,
|
165
|
+
RuCodeGen::RunMode.options.complexgen_skip_comments ) )
|
166
|
+
end
|
167
|
+
������ ����� ������ � ���������� ��������� ������ ����� ������������ ������
|
168
|
+
������ generate:
|
169
|
+
module ComplexGenerator
|
170
|
+
...
|
171
|
+
class Generator
|
172
|
+
def generate( to )
|
173
|
+
if RuCodeGen::RunMode::options.complexgen_gen_high_speed_code
|
174
|
+
...
|
175
|
+
elsif RuCodeGen::RuCodeGen::options.complexgen_debug_logs
|
176
|
+
...
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
= ������
|
183
|
+
|
184
|
+
������ ����������� � ������������� ������������ OptionHandler ����� ������� �
|
185
|
+
�����
|
186
|
+
{cmd_line_handler/generator}[link://files/docs/examples/cmd_line_handler/generator.html]
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#
|
2
|
+
# ������, ������� ������������� ������������� ������������
|
3
|
+
# OptionHandler.
|
4
|
+
#
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
|
8
|
+
require 'RuCodeGen'
|
9
|
+
|
10
|
+
class LinesGenerator
|
11
|
+
def initialize
|
12
|
+
@file = nil
|
13
|
+
@lines = []
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_reader :lines
|
17
|
+
|
18
|
+
def get_file; @file; end
|
19
|
+
def file( v ); @file = v; end
|
20
|
+
|
21
|
+
def line( length ); @lines << length; end
|
22
|
+
|
23
|
+
class OptionHandler < RuCodeGen::OptionHandler
|
24
|
+
def banner
|
25
|
+
"Just a test of OptionHandler usage\n"
|
26
|
+
end
|
27
|
+
|
28
|
+
def setup( parser, result )
|
29
|
+
result.lines_segment = '-'
|
30
|
+
|
31
|
+
parser.on( "-l", "--line TYPE", [ "single", "double" ],
|
32
|
+
{ 'single' => '-', 'double' => '=' },
|
33
|
+
"type of line (single or double)" ) do |type|
|
34
|
+
result.lines_segment = type
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Generator
|
40
|
+
def initialize( lines )
|
41
|
+
@lines = lines
|
42
|
+
end
|
43
|
+
|
44
|
+
def generate( to )
|
45
|
+
segment_type = RuCodeGen::RunMode.options.lines_segment
|
46
|
+
@lines.each do |length|
|
47
|
+
to << segment_type * length << "\n"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
RuCodeGen::RunMode.add_option_handler( LinesGenerator::OptionHandler.new )
|
54
|
+
|
55
|
+
def lines( &blk )
|
56
|
+
data = LinesGenerator.new
|
57
|
+
blk[ data ]
|
58
|
+
|
59
|
+
RuCodeGen::Generators.add(
|
60
|
+
RuCodeGen::FilenameProducer.produce( $0, data.get_file ),
|
61
|
+
LinesGenerator::Generator.new( data.lines ) )
|
62
|
+
end
|
63
|
+
|
64
|
+
if __FILE__ == $0
|
65
|
+
|
66
|
+
lines { |d|
|
67
|
+
d.file :script_relative => 'lines.txt'
|
68
|
+
|
69
|
+
d.line 3
|
70
|
+
d.line 5
|
71
|
+
d.line 8
|
72
|
+
}
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
=begin
|
2
|
+
��������� C++ ���� �� ��������� ������������ ����.
|
3
|
+
|
4
|
+
��������, ��� ����� ������������ ���� some::long::name ����������:
|
5
|
+
namespace some {
|
6
|
+
namespace long {
|
7
|
+
namespace name {
|
8
|
+
|
9
|
+
} /* namespace name */
|
10
|
+
} /* namespace long */
|
11
|
+
} /* namespace some */
|
12
|
+
|
13
|
+
���� ����� �� ������ � ��������� ������ � ���������� --name, �� ���
|
14
|
+
����������� �� ������������ �����. ��� ���� �������������� ������
|
15
|
+
������ ����:
|
16
|
+
name
|
17
|
+
namespace name
|
18
|
+
|
19
|
+
=end
|
20
|
+
|
21
|
+
require 'optparse'
|
22
|
+
|
23
|
+
module RuCodeGen
|
24
|
+
|
25
|
+
module AdHoc
|
26
|
+
|
27
|
+
module CppOpenNamespace
|
28
|
+
|
29
|
+
module Impl
|
30
|
+
|
31
|
+
# ������ ���������� ������� ����������.
|
32
|
+
#
|
33
|
+
# names:: ������ ���� ����������� ���� ��� ���������.
|
34
|
+
#
|
35
|
+
Options = Struct.new( :names )
|
36
|
+
|
37
|
+
# ������ ����� ��������� ������.
|
38
|
+
#
|
39
|
+
# ������������ ������ Options
|
40
|
+
#
|
41
|
+
# ���� � ��������� ������ ������ ����� '--help', �� ������ ����������
|
42
|
+
# �������� �������, � ������ �� �����������.
|
43
|
+
#
|
44
|
+
def Impl.parse_options( args )
|
45
|
+
res = Options.new( [] )
|
46
|
+
|
47
|
+
parser = OptionParser.new
|
48
|
+
parser.banner = <<BANNER
|
49
|
+
Generate C++ code for implementing namespace(s) with given name(s)
|
50
|
+
|
51
|
+
Usage:
|
52
|
+
|
53
|
+
rcgtool cpp-open-ns [<options>]
|
54
|
+
|
55
|
+
For example:
|
56
|
+
|
57
|
+
rcgtool cpp-open-ns -n some::long::name
|
58
|
+
|
59
|
+
will generate:
|
60
|
+
|
61
|
+
namespace some {
|
62
|
+
namespace long {
|
63
|
+
namespace name {
|
64
|
+
} /* namespace name */
|
65
|
+
} /* namespace long */
|
66
|
+
} /* namespace some */
|
67
|
+
|
68
|
+
BANNER
|
69
|
+
|
70
|
+
parser.on( '-h', '--help', 'Shows this message' ) do
|
71
|
+
puts parser
|
72
|
+
exit 1
|
73
|
+
end
|
74
|
+
|
75
|
+
parser.on( '-n', '--name NS', 'Name of namespace for processing' ) do |n|
|
76
|
+
res.names << n
|
77
|
+
end
|
78
|
+
|
79
|
+
parser.parse!( args )
|
80
|
+
|
81
|
+
res
|
82
|
+
end
|
83
|
+
|
84
|
+
# ��������� ���� ��� ������ �������� ������������ ����.
|
85
|
+
def Impl.generate_one( name, options )
|
86
|
+
splitted = name.split( /\s*::\s*/ )
|
87
|
+
splitted.each do |part|
|
88
|
+
puts "namespace #{part} {\n\n"
|
89
|
+
end
|
90
|
+
splitted.reverse.each do |part|
|
91
|
+
puts "} /* namespace #{part} */\n\n"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# ���������� ���������, ������� ��������� ������, �������
|
96
|
+
# ����� ��������� �������� ����������� ����.
|
97
|
+
LINE_WITH_NAMESPACE_NAME_REGEX = /^\s*(namespace\s+)?([[:graph:]]+)\s*$/
|
98
|
+
|
99
|
+
# ������ ����� �� ������������ ����� �� ��� ��� ���� ���
|
100
|
+
# ������������� ����������� ��������� LINE_WITH_NAMESPACE_NAME_REGEX
|
101
|
+
# � �������� �������� ����������� ���� �� ���.
|
102
|
+
def Impl.read_stdin
|
103
|
+
result = []
|
104
|
+
while line = ARGF.gets
|
105
|
+
if ( m = LINE_WITH_NAMESPACE_NAME_REGEX.match( line ) )
|
106
|
+
result << m[ 2 ]
|
107
|
+
end
|
108
|
+
end
|
109
|
+
result
|
110
|
+
end
|
111
|
+
|
112
|
+
end # module Impl
|
113
|
+
|
114
|
+
# ��������� ���� �� ����������� ����� ������.
|
115
|
+
def CppOpenNamespace.generate( args )
|
116
|
+
options = Impl.parse_options( args )
|
117
|
+
names = options.names
|
118
|
+
names = Impl.read_stdin if 0 == names.size
|
119
|
+
|
120
|
+
names.each do |name|
|
121
|
+
Impl.generate_one( name, options )
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end # CppOpenNamespace
|
126
|
+
|
127
|
+
end # AdHoc
|
128
|
+
|
129
|
+
end # RuCodeGen
|
130
|
+
|
131
|
+
begin
|
132
|
+
RuCodeGen::AdHoc::CppOpenNamespace.generate( ARGV )
|
133
|
+
rescue => x
|
134
|
+
$stderr.puts x
|
135
|
+
end
|
136
|
+
|
@@ -0,0 +1,169 @@
|
|
1
|
+
#
|
2
|
+
# �������� ��� ������� ���������� ��������� ������.
|
3
|
+
#
|
4
|
+
|
5
|
+
require 'ostruct'
|
6
|
+
require 'optparse'
|
7
|
+
|
8
|
+
require 'rucodegen/version'
|
9
|
+
|
10
|
+
module RuCodeGen
|
11
|
+
|
12
|
+
# ������� ����� ��� �������� ������������� ��� ������-���� ����������
|
13
|
+
# ����� ��������� ������.
|
14
|
+
#
|
15
|
+
# ������ �������� � �������������:
|
16
|
+
# class MyOptionHandler < RuCodeGen::OptionHandler
|
17
|
+
# def banner
|
18
|
+
# "My super cool generator v.1.0.23-beta3"
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# def setup( parser, result )
|
22
|
+
# parser.on( "-C", "--cool OPTION", "cool generator option" ) do |p|
|
23
|
+
# result.cool_option = p
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# def check( result )
|
28
|
+
# fail "Cool generator must be activated by --cool" unless result.cool_option
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# <i>����������.</i> ������ OptionHandler#banner � OptionHandler#check
|
33
|
+
# �������� ��������������� � ����� ���������� �� ���������. �������������
|
34
|
+
# �� ����� ������ � ������ �������������.
|
35
|
+
#
|
36
|
+
class OptionHandler
|
37
|
+
# �������������� ������, ������� ����� ������������ ��� ������
|
38
|
+
# ������� � ��������� ������ ��������� ������.
|
39
|
+
#
|
40
|
+
# ������ ���������� nil, ���� ������ �� ���������.
|
41
|
+
#
|
42
|
+
def banner
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
|
46
|
+
# ��������� ������� ����� ��������� ������ �� ������������� ���
|
47
|
+
# ���������� �����.
|
48
|
+
#
|
49
|
+
# [_parser_] ������ ���� OptionParser, ����������� ������ ��������� ������.
|
50
|
+
# [_result_] ������ ���� OpenStruct, � ������� ������ ���������� ����������
|
51
|
+
# ������� ���������� ��������� ������.
|
52
|
+
#
|
53
|
+
def setup( parser, result )
|
54
|
+
fail "OptionHandler#setup must be defined in derived class"
|
55
|
+
end
|
56
|
+
|
57
|
+
# �������� ������������ �������� ����������� �����, ������������� ���
|
58
|
+
# ����������� ����������.
|
59
|
+
#
|
60
|
+
# ���� �������������� �������� �� �����, �� ������ ����� ����� ��
|
61
|
+
# ����������������.
|
62
|
+
#
|
63
|
+
# [_result_] ������ ���� OpenStruct, � ������� ���������� ����������
|
64
|
+
# ������� ���������� ��������� ������.
|
65
|
+
#
|
66
|
+
def check( result )
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
# �����, ���������� �� ������ ����������� ����� RuCodeGen.
|
72
|
+
#
|
73
|
+
class RuCodeGenOptionHandler < OptionHandler
|
74
|
+
# ���������� ����� �������������.
|
75
|
+
BUILD = :build
|
76
|
+
# ����� �������������� �������������.
|
77
|
+
REBUILD = :rebuild
|
78
|
+
# ����� ������� ����������� �������������.
|
79
|
+
CLEAN = :clean
|
80
|
+
# ����� �������� �������������.
|
81
|
+
DRY_RUN = :dry_run
|
82
|
+
|
83
|
+
# ������� ����, ��� ������� ����� ��� �� ���������.
|
84
|
+
UNKNOWN = :unknown
|
85
|
+
|
86
|
+
def setup( parser, result )
|
87
|
+
# ���� �������� -m �� ������, �� �� ��������� �����������
|
88
|
+
# ����� build.
|
89
|
+
result.rucodegen_mode = BUILD
|
90
|
+
|
91
|
+
all_modes = %w[ build rebuild clean dry-run ]
|
92
|
+
all_modes_aliases = {
|
93
|
+
"build" => BUILD,
|
94
|
+
"rebuild" => REBUILD,
|
95
|
+
"clean" => CLEAN,
|
96
|
+
"dry_run" => DRY_RUN
|
97
|
+
}
|
98
|
+
|
99
|
+
parser.on( "-m", "--mode MODE", all_modes, all_modes_aliases,
|
100
|
+
"run mode", "(#{all_modes.join(', ')})" ) do |run_mode|
|
101
|
+
result.rucodegen_mode = run_mode
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# �����, ���������� �� �������� ���� ������������� ��� �����������
|
107
|
+
# OptionHandler � �� ������ ��������� ������.
|
108
|
+
#
|
109
|
+
class CmdLineHandler
|
110
|
+
def initialize
|
111
|
+
# �������� ����� ���������� ������ ����� ���������
|
112
|
+
# ���������� ������ parse.
|
113
|
+
@options = nil
|
114
|
+
|
115
|
+
# � ������ ������������ ����� �� ����������� ������� ����������.
|
116
|
+
@handlers = [ RuCodeGenOptionHandler.new ]
|
117
|
+
end
|
118
|
+
|
119
|
+
# ��������� ���������� �������������� �����������.
|
120
|
+
def add_option_handler( handler )
|
121
|
+
@handlers << handler
|
122
|
+
end
|
123
|
+
|
124
|
+
# ������ � ����������� ������.
|
125
|
+
#
|
126
|
+
# ����������� ����������, ���� ��������� ������� ��� �� ����.
|
127
|
+
#
|
128
|
+
def options
|
129
|
+
fail "Options are not parsed yet" unless @options
|
130
|
+
@options
|
131
|
+
end
|
132
|
+
|
133
|
+
# ���������� ������� ��������� ������.
|
134
|
+
#
|
135
|
+
def parse( args )
|
136
|
+
result = OpenStruct.new
|
137
|
+
parser = OptionParser.new
|
138
|
+
|
139
|
+
parser.banner = make_banner
|
140
|
+
|
141
|
+
@handlers.each do |h| h.setup( parser, result ) end
|
142
|
+
|
143
|
+
parser.on_tail( "-h", "--help", "show this screen" ) do
|
144
|
+
puts parser
|
145
|
+
exit
|
146
|
+
end
|
147
|
+
|
148
|
+
parser.parse!( args )
|
149
|
+
|
150
|
+
@handlers.each do |h| h.check( result ) end
|
151
|
+
|
152
|
+
@options = result
|
153
|
+
end
|
154
|
+
|
155
|
+
private
|
156
|
+
# ������������ ������ �������.
|
157
|
+
#
|
158
|
+
def make_banner
|
159
|
+
banner = "RuCodeGen #{VERSION}. (C) 2005-2007 Yauheni Akhotnikau\n"
|
160
|
+
@handlers.each do |h|
|
161
|
+
b = h.banner
|
162
|
+
banner += "\n" + b if b
|
163
|
+
end
|
164
|
+
banner + "\n"
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
end # module RuCodeGen
|
169
|
+
|
data/lib/rucodegen/run_mode.rb
CHANGED
@@ -4,6 +4,8 @@
|
|
4
4
|
|
5
5
|
require 'optparse'
|
6
6
|
|
7
|
+
require 'rucodegen/cmd_line_handler.rb'
|
8
|
+
|
7
9
|
module RuCodeGen
|
8
10
|
|
9
11
|
# �����, �������� ������� �������� �������� ����������� ������ ������
|
@@ -23,56 +25,28 @@ module RuCodeGen
|
|
23
25
|
class RunMode
|
24
26
|
|
25
27
|
# ���������� ����� �������������.
|
26
|
-
BUILD =
|
28
|
+
BUILD = RuCodeGenOptionHandler::BUILD
|
27
29
|
# ����� �������������� �������������.
|
28
|
-
REBUILD =
|
30
|
+
REBUILD = RuCodeGenOptionHandler::REBUILD
|
29
31
|
# ����� ������� ����������� �������������.
|
30
|
-
CLEAN =
|
32
|
+
CLEAN = RuCodeGenOptionHandler::CLEAN
|
31
33
|
# ����� �������� �������������.
|
32
|
-
DRY_RUN =
|
34
|
+
DRY_RUN = RuCodeGenOptionHandler::DRY_RUN
|
33
35
|
|
34
36
|
# ������� ����, ��� ������� ����� ��� �� ���������.
|
35
|
-
UNKNOWN =
|
36
|
-
# ������� ����, ��� ������ ������� � ������ help.
|
37
|
-
HELP = 5
|
37
|
+
UNKNOWN = RuCodeGenOptionHandler::UNKNOWN
|
38
38
|
|
39
39
|
# ������� ����� ������.
|
40
40
|
@@mode = UNKNOWN
|
41
41
|
|
42
|
+
# ���������� ���������� ��������� ������.
|
43
|
+
@@cmd_line_handler = CmdLineHandler.new
|
44
|
+
|
42
45
|
# ����������� ������ ������ ����������� �������� ����������
|
43
46
|
# ��������� ������.
|
44
47
|
def RunMode.detect
|
45
|
-
|
46
|
-
|
47
|
-
options = OptionParser.new do |opts|
|
48
|
-
all_modes = %w[ build rebuild clean dry-run ]
|
49
|
-
all_modes_aliases = {
|
50
|
-
"build" => BUILD,
|
51
|
-
"rebuild" => REBUILD,
|
52
|
-
"clean" => CLEAN,
|
53
|
-
"dry_run" => DRY_RUN
|
54
|
-
}
|
55
|
-
|
56
|
-
opts.on( "-m", "--mode MODE", all_modes, all_modes_aliases,
|
57
|
-
"run mode", "(#{all_modes.join(', ')})" ) do |run_mode|
|
58
|
-
mode = run_mode
|
59
|
-
end
|
60
|
-
|
61
|
-
opts.on( "-h", "--help", "show this screen" ) do
|
62
|
-
puts opts
|
63
|
-
mode = HELP
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
if 0 != ARGV.size
|
68
|
-
options.parse!
|
69
|
-
fail "run mode must be specified" if UNKNOWN == mode
|
70
|
-
else
|
71
|
-
# ������ ��� ���������� �������� ����� ���������� �������������.
|
72
|
-
mode = BUILD
|
73
|
-
end
|
74
|
-
|
75
|
-
@@mode = mode
|
48
|
+
@@cmd_line_handler.parse( ARGV )
|
49
|
+
@@mode = options.rucodegen_mode
|
76
50
|
end
|
77
51
|
|
78
52
|
# ��������� �������� ������ ������.
|
@@ -83,6 +57,23 @@ class RunMode
|
|
83
57
|
@@mode
|
84
58
|
end
|
85
59
|
|
60
|
+
# ���������� ��� ������ ����������� ���������� ��������� ������.
|
61
|
+
#
|
62
|
+
# [_handler_] ������, ����������� ��������� OptionHandler.
|
63
|
+
#
|
64
|
+
def RunMode.add_option_handler( handler )
|
65
|
+
@@cmd_line_handler.add_option_handler( handler )
|
66
|
+
end
|
67
|
+
|
68
|
+
# ��������� ������ ����� ��������� ������.
|
69
|
+
#
|
70
|
+
# ��������� ���������� ��� ������� ��������� � ����� �� ����,
|
71
|
+
# ��� ����� ��������� ������ ����� ���������.
|
72
|
+
#
|
73
|
+
def RunMode.options
|
74
|
+
@@cmd_line_handler.options
|
75
|
+
end
|
76
|
+
|
86
77
|
end # class RunMode
|
87
78
|
|
88
79
|
end # module RuCodeGen
|
@@ -0,0 +1,64 @@
|
|
1
|
+
$:.unshift( File.dirname( __FILE__ ) + "/../lib" )
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
require 'rucodegen/cmd_line_handler.rb'
|
6
|
+
|
7
|
+
class TC_CmdLineHandler < Test::Unit::TestCase
|
8
|
+
class MyHandler < RuCodeGen::OptionHandler
|
9
|
+
class ValueNotSpecifiedError < RuntimeError
|
10
|
+
end
|
11
|
+
|
12
|
+
def banner
|
13
|
+
"Just a test\n"
|
14
|
+
end
|
15
|
+
|
16
|
+
def setup( parser, result )
|
17
|
+
result.cool_mode = false
|
18
|
+
parser.on( "--cool", "just a cool option" ) do
|
19
|
+
result.cool_mode = true
|
20
|
+
end
|
21
|
+
|
22
|
+
parser.on( "--value VAL", "mandatory option" ) do |v|
|
23
|
+
result.value = v
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def check( result )
|
28
|
+
fail ValueNotSpecifiedError.new( "--value missed" ) unless result.value
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def setup
|
33
|
+
@cmd_line_handler = RuCodeGen::CmdLineHandler.new
|
34
|
+
@cmd_line_handler.add_option_handler( MyHandler.new )
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_access_option_without_parsing
|
38
|
+
assert_raise( RuntimeError ) do
|
39
|
+
@cmd_line_handler.options
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_no_value_option
|
44
|
+
assert_raise( MyHandler::ValueNotSpecifiedError ) do
|
45
|
+
@cmd_line_handler.parse( [] )
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_value
|
50
|
+
@cmd_line_handler.parse( [ "--value", "TEST" ] )
|
51
|
+
assert_equal( "TEST", @cmd_line_handler.options.value )
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_cool_mode_off
|
55
|
+
@cmd_line_handler.parse( [ "--value", "TEST" ] )
|
56
|
+
assert_equal( false, @cmd_line_handler.options.cool_mode )
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_cool_mode_on
|
60
|
+
@cmd_line_handler.parse( [ "--value", "TEST", "--cool" ] )
|
61
|
+
assert_equal( true, @cmd_line_handler.options.cool_mode )
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
data/tests/tc_run_mode.rb
CHANGED
@@ -26,16 +26,6 @@ class TC_RunMode < Test::Unit::TestCase
|
|
26
26
|
assert_equal RUNMODE::BUILD, RUNMODE.mode
|
27
27
|
end
|
28
28
|
|
29
|
-
def test_help_mode_short
|
30
|
-
ARGV << "-h"
|
31
|
-
assert_equal RUNMODE::HELP, RUNMODE.mode
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_help_mode_long
|
35
|
-
ARGV << "--help"
|
36
|
-
assert_equal RUNMODE::HELP, RUNMODE.mode
|
37
|
-
end
|
38
|
-
|
39
29
|
def test_modes_short
|
40
30
|
modes = {
|
41
31
|
"build" => RUNMODE::BUILD,
|
data/tests/ts_rucodegen.rb
CHANGED
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: RuCodeGen
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.3.0
|
7
|
+
date: 2007-06-04 00:00:00 +04:00
|
8
8
|
summary: Simple code generation tool
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -29,6 +29,7 @@ post_install_message:
|
|
29
29
|
authors:
|
30
30
|
- Yauheni Akhotnikau
|
31
31
|
files:
|
32
|
+
- bin/rcgtool
|
32
33
|
- tests/embedded_data
|
33
34
|
- tests/embedded_data/host_config
|
34
35
|
- tests/embedded_data/host_config/embedded.txt
|
@@ -45,6 +46,7 @@ files:
|
|
45
46
|
- tests/embedded_data/in_no_fragments.txt
|
46
47
|
- tests/generators_test_extension.rb
|
47
48
|
- tests/tc_class_attribute.rb
|
49
|
+
- tests/tc_cmd_line_handler.rb
|
48
50
|
- tests/tc_codegen_initiator.rb
|
49
51
|
- tests/tc_embedded_extract_fragments.rb
|
50
52
|
- tests/tc_embedded_run_rucodegen.rb
|
@@ -55,7 +57,12 @@ files:
|
|
55
57
|
- tests/tc_value_incapsulator_gen.rb
|
56
58
|
- tests/ts_rucodegen.rb
|
57
59
|
- lib/rucodegen
|
60
|
+
- lib/rucodegen/adhoc
|
61
|
+
- lib/rucodegen/adhoc/templates
|
62
|
+
- lib/rucodegen/adhoc/templates/cpp-open-ns
|
63
|
+
- lib/rucodegen/adhoc/templates/cpp-open-ns/g.rb
|
58
64
|
- lib/rucodegen/begin_end.rb
|
65
|
+
- lib/rucodegen/cmd_line_handler.rb
|
59
66
|
- lib/rucodegen/codegen.rb
|
60
67
|
- lib/rucodegen/embedded.rb
|
61
68
|
- lib/rucodegen/filename_producer.rb
|
@@ -63,9 +70,14 @@ files:
|
|
63
70
|
- lib/rucodegen/generators.rb
|
64
71
|
- lib/rucodegen/run_mode.rb
|
65
72
|
- lib/rucodegen/value_incapsulator.rb
|
73
|
+
- lib/rucodegen/version.rb
|
66
74
|
- lib/rucodegen.rb
|
75
|
+
- docs/AdHoc
|
76
|
+
- docs/CmdLineHandler
|
67
77
|
- docs/EmbeddedRuCodeGen
|
68
78
|
- docs/examples
|
79
|
+
- docs/examples/cmd_line_handler
|
80
|
+
- docs/examples/cmd_line_handler/generator
|
69
81
|
- docs/examples/cpp
|
70
82
|
- docs/examples/cpp/custom
|
71
83
|
- docs/examples/cpp/custom/submit_deliver
|
@@ -75,6 +87,8 @@ files:
|
|
75
87
|
- docs/examples/cpp/value_incapsulator/host_config
|
76
88
|
- docs/Principle
|
77
89
|
- docs/ValueIncapsulator
|
90
|
+
- examples/cmd_line_handler
|
91
|
+
- examples/cmd_line_handler/generator.rb
|
78
92
|
- examples/cpp
|
79
93
|
- examples/cpp/custom
|
80
94
|
- examples/cpp/custom/submit_deliver
|
@@ -103,8 +117,12 @@ extra_rdoc_files:
|
|
103
117
|
- Rakefile
|
104
118
|
- LICENSE
|
105
119
|
- NEWS
|
120
|
+
- docs/AdHoc
|
121
|
+
- docs/CmdLineHandler
|
106
122
|
- docs/EmbeddedRuCodeGen
|
107
123
|
- docs/examples
|
124
|
+
- docs/examples/cmd_line_handler
|
125
|
+
- docs/examples/cmd_line_handler/generator
|
108
126
|
- docs/examples/cpp
|
109
127
|
- docs/examples/cpp/custom
|
110
128
|
- docs/examples/cpp/custom/submit_deliver
|
@@ -114,8 +132,8 @@ extra_rdoc_files:
|
|
114
132
|
- docs/examples/cpp/value_incapsulator/host_config
|
115
133
|
- docs/Principle
|
116
134
|
- docs/ValueIncapsulator
|
117
|
-
executables:
|
118
|
-
|
135
|
+
executables:
|
136
|
+
- rcgtool
|
119
137
|
extensions: []
|
120
138
|
|
121
139
|
requirements: []
|