ClsRuby 1.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.
Files changed (71) hide show
  1. data/LICENSE +26 -0
  2. data/README +55 -0
  3. data/THANKS +0 -0
  4. data/docs/base_formatting_methods +89 -0
  5. data/docs/base_parsing_methods +79 -0
  6. data/docs/constructor_params +131 -0
  7. data/docs/examples/log_single_line_format +3 -0
  8. data/docs/examples/service_description +3 -0
  9. data/docs/examples/sms-hist +3 -0
  10. data/docs/examples/tag_any +3 -0
  11. data/docs/fragments/custom_tag_field.rb +20 -0
  12. data/docs/fragments/custom_tag_include.rb +21 -0
  13. data/docs/fragments/field.cls +2 -0
  14. data/docs/fragments/include.cls +4 -0
  15. data/docs/fragments/inherit_tag_params.rb +21 -0
  16. data/docs/fragments/message.cls +6 -0
  17. data/docs/fragments/tag_field.rb +24 -0
  18. data/docs/fragments/tag_message.rb +74 -0
  19. data/docs/fragments/tags_order.rb +41 -0
  20. data/docs/principles +402 -0
  21. data/docs/std_tags_short_description +278 -0
  22. data/docs/syntax +227 -0
  23. data/docs/why_cls +178 -0
  24. data/examples/hex_stream.txt +1 -0
  25. data/examples/log_single_line_formatter.rb +79 -0
  26. data/examples/service_description.day_time.cfg +11 -0
  27. data/examples/service_description.rb +119 -0
  28. data/examples/sms-hist.rb +164 -0
  29. data/examples/space_concat.txt +3 -0
  30. data/examples/tag_any.rb +28 -0
  31. data/lib/cls-ruby/basic_scalars.rb +270 -0
  32. data/lib/cls-ruby/constraints/one_of.rb +36 -0
  33. data/lib/cls-ruby/default_formatter.rb +50 -0
  34. data/lib/cls-ruby/ex.rb +121 -0
  35. data/lib/cls-ruby/formatter.rb +31 -0
  36. data/lib/cls-ruby/lexers/char_classifier.rb +157 -0
  37. data/lib/cls-ruby/lexers/first_stage.rb +112 -0
  38. data/lib/cls-ruby/lexers/lexer.rb +74 -0
  39. data/lib/cls-ruby/oneline_formatter.rb +35 -0
  40. data/lib/cls-ruby/parser.rb +249 -0
  41. data/lib/cls-ruby/tag.rb +428 -0
  42. data/lib/cls-ruby/tag_any.rb +111 -0
  43. data/lib/cls-ruby/tag_no_value.rb +55 -0
  44. data/lib/cls-ruby/tag_scalar.rb +197 -0
  45. data/lib/cls-ruby/tag_scalar_helpers.rb +70 -0
  46. data/lib/cls-ruby/tag_scalar_vector.rb +148 -0
  47. data/lib/cls-ruby/tag_vector_of_different_tags.rb +172 -0
  48. data/lib/cls-ruby/tag_vector_of_tags.rb +116 -0
  49. data/lib/cls-ruby/vector_of_tags_impl.rb +129 -0
  50. data/lib/cls-ruby.rb +5 -0
  51. data/tests/tc_child_tag.rb +51 -0
  52. data/tests/tc_constraint_one_of.rb +47 -0
  53. data/tests/tc_format_helper.rb +27 -0
  54. data/tests/tc_formatters.rb +125 -0
  55. data/tests/tc_lexer.rb +124 -0
  56. data/tests/tc_lexer_char_classifier.rb +121 -0
  57. data/tests/tc_lexer_first_stage.rb +72 -0
  58. data/tests/tc_parser_simple.rb +93 -0
  59. data/tests/tc_scalar_parsers.rb +189 -0
  60. data/tests/tc_tag.rb +68 -0
  61. data/tests/tc_tag_no_value.rb +46 -0
  62. data/tests/tc_tag_scalar_int.rb +83 -0
  63. data/tests/tc_tag_scalar_nonspace_string.rb +46 -0
  64. data/tests/tc_tag_scalar_string.rb +47 -0
  65. data/tests/tc_tag_scalar_vector_int.rb +88 -0
  66. data/tests/tc_tag_scalar_vector_string.rb +48 -0
  67. data/tests/tc_tag_scalar_vector_string_empty.rb +40 -0
  68. data/tests/tc_tag_vector_of_different_tags.rb +109 -0
  69. data/tests/tc_tag_vector_of_tags.rb +103 -0
  70. data/tests/ts_cls_ruby.rb +7 -0
  71. metadata +140 -0
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ #
2
+ # Copyright (c) 2006-2007, Yauheni Akhotnikau
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # 1. Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ # this list of conditions and the following disclaimer in the documentation
12
+ # and/or other materials provided with the distribution.
13
+ # 3. The name of the author may not be used to endorse or promote products
14
+ # derived from this software without specific prior written permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17
+ # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18
+ # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19
+ # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
+ # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22
+ # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23
+ # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24
+ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25
+ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ #
data/README ADDED
@@ -0,0 +1,55 @@
1
+ = ClsRuby � CURL Like Syntax ��� Ruby
2
+
3
+ == ��������
4
+
5
+ Cls (CURL Like Syntax) -- ��� ���������� ��� ������ � ��������� ��������,
6
+ ��������� �������� ��� �������� �� ������ ���������� ����� ���������������� {CURL}[http://www.curl.com].
7
+
8
+ ������������� ���������� Cls ���� ����������� ��� ����� C++
9
+ ({cls_2}[http://eao197.narod.ru/projects.htm#cls_2]) � ������� ��������������
10
+ ��� ������ � ����������������� �������, ��� �������, ������� ������� � ��. ��
11
+ �������� ������������� �������� ��� ������ � ��������������� �� C++
12
+ ����������������� �������, ������, �������� � ��. � ��������� ���� ��������
13
+ ������� ClsRuby.
14
+
15
+ ClsRuby ����� ��������� ���������������� � C++��� ��������� (����
16
+ �������������� ����������� � ������������� ���������
17
+ escape-�������������������), ������ ClsRuby ��������� ������������ ������
18
+ cls_2.
19
+
20
+ == ��������
21
+
22
+ * {���������}[link://files/docs/syntax.html]
23
+ * {������ Cls, � �� XML ��� YAML?}[link://files/docs/why_cls.html]
24
+ * {�������� ������ � Cls. ��������}[link://files/docs/principles.html]
25
+ * {�������� ������ � Cls. �������� ���������� � ������������ �����}[link://files/docs/constructor_params.html]
26
+ * {�������� ������ � Cls. ������� �������� ������ ����� ClsRuby}[link://files/docs/std_tags_short_description.html]
27
+ * {�������� ������ � Cls. ������� ������ ������� ������� �������}[link://files/docs/base_parsing_methods.html]
28
+ * {�������� ������ � Cls. ������� ������ �������������� Cls-������}[link://files/docs/base_formatting_methods.html]
29
+
30
+ === ������� �������������
31
+
32
+ * {service_description}[link://files/docs/examples/service_description.html]
33
+ * {log_single_line_format}[link://files/docs/examples/log_single_line_format.html]
34
+ * {sms-hist}[link://files/docs/examples/sms-hist.html]
35
+ * {tag_any}[link://files/docs/examples/tag_any.html]
36
+
37
+ == �����������
38
+
39
+ ClsRuby ���������������� � ���� Gem-�. ��� ��� ����������� ����������
40
+ ��������������� ��������:
41
+
42
+ gem install ClsRuby
43
+
44
+ == ��������
45
+
46
+ ClsRuby ���������������� ��� BSD ��������� (��.
47
+ LICENSE[link://files/LICENSE.html]).
48
+
49
+ == �������������
50
+
51
+ Homepage:: http://eao197.narod.ru/cls
52
+ Email:: mailto://eao197@yahoo.com
53
+
54
+ # vim:ts=2:sts=2:sw=2:expandtab:ft=txt:tw=78
55
+
data/THANKS ADDED
File without changes
@@ -0,0 +1,89 @@
1
+ = �������� ������ � Cls. ������� ������ �������������� Cls-������
2
+
3
+ ClsRuby ��������� �� ������ ��������� ������� ������ � Cls-������, �� �
4
+ ����������� ����� ������. ��� ����� ����������:
5
+ - ����������� ����� Cls-�����, ������� ����� ���������� � �������� �����.
6
+ ������ ��� ������ ���� ������������, �.�. ��� ���� ������ ���� ������ �����
7
+ ClsRuby::Tag::tag_make_defined (��� ����� �����, ��������� �� ������������
8
+ ���� �� �������������);
9
+ - ������� ������-����������, ����������� ��������� ClsRuby::TagFormatter;
10
+ - �������� �������� � ����� ClsRuby::Tag::tag_format ��������� ����,
11
+ ����������� ��������������.
12
+
13
+ ClsRuby ������������� ������� ���������� ���������� ClsRuby::TagFormatter --
14
+ ������ ClsRuby::OneLineFormatter (������������� ���� Cls-����� � ���� ������)
15
+ � ClsRuby::DefaultFormatter (������� ���������� ������� � �������� ����� ���
16
+ ��������� ������ ������������������ Cls-������).
17
+
18
+ == ������ �������������� ����
19
+
20
+ ����� ��������� ����������� �������������� ���� {project-description}:
21
+ {project-description
22
+ {name <str> }
23
+ {comment <str> }
24
+ {source-files <str>* }
25
+ }
26
+ ��� ����� ��������� ��������� ProjectDescription, ������� ����� ���������
27
+ �������� ������� � ����� ���� TagProjectDescription:
28
+ require 'cls-ruby'
29
+ require 'cls-ruby/tag_no_value'
30
+ require 'cls-ruby/tag_scalar'
31
+ require 'cls-ruby/tag_scalar_vector'
32
+
33
+ require 'cls-ruby/default_formatter'
34
+
35
+ ProjectDescription = Struct.new( :name, :comment, :source_files )
36
+
37
+ class TagProjectDescription < ClsRuby::TagNoValue
38
+ mandatory_child_tag :name, ClsRuby::TagStringScalar
39
+ mandatory_child_tag :comment, ClsRuby::TagStringScalar
40
+ mandatory_child_tag :source_files, ClsRuby::TagScalarVector,
41
+ :format => ClsRuby::SCALAR_STRING,
42
+ :name => 'source-files'
43
+
44
+ default_tag_params :name => 'project-description'
45
+
46
+ # ����������� ��������� ������� ����� :value �, ���� �� �����,
47
+ # ���������� ��� �������� ��� ����������� ����.
48
+ def initialize( params = {} )
49
+ super( params )
50
+
51
+ tag_handle_opt_param( :value ) do |description|
52
+ @name.value = description.name
53
+ @comment.value = description.comment
54
+ @source_files.value = description.source_files
55
+
56
+ # ����������� ����� �������, ��� ��� ���������.
57
+ tag_make_defined
58
+ end
59
+ end
60
+ end
61
+
62
+ # �������� ���� � ���������� �������������� ���������.
63
+ to_be_formatted = TagProjectDescription.new(
64
+ :value => ProjectDescription.new( 'test',
65
+ 'this is a test project',
66
+ [ 'first.txt', 'second.txt', 'third.txt' ] ) )
67
+
68
+ # ����������� ����������� ���� �� ����������� ����� ������.
69
+ to_be_formatted.tag_format( ClsRuby::DefaultFormatter.new( STDOUT ) )
70
+
71
+ ������ ������� ������� ����� ��������� � ��������� ������ � ����������� �����
72
+ ������:
73
+ {project-description
74
+ {name "test" }
75
+ {comment "this is a test project" }
76
+ {source-files "first.txt" "second.txt" "third.txt" } }
77
+
78
+ == ���������� �������� ������� ��� ������� ���������� ClsRuby
79
+
80
+ ������ ClsRuby::OneLineFormatter � ClsRuby::DefaultFormatter �������� �
81
+ ������������ ������, ������� ������ ���� ��������� ������. ������������
82
+ ���������� � ������� ������� -- ��� ��������� ��������� ������ <tt><<</tt>.
83
+ ������ ����������, ��������, ������������� Ruby ������ IO, String � Array. ���
84
+ ��������� ������������ ������� ��������� ClsRuby ��� ��� ������ ���������
85
+ ������ � ����, ��� � � ������ (��������, ��� ������������ ���������� � ��).
86
+
87
+ # vim:ts=2:sts=2:sw=2:expandtab:ft=txt:tw=78
88
+
89
+
@@ -0,0 +1,79 @@
1
+ = �������� ������ � Cls. ������� ������ ������� ������� �������
2
+
3
+ ClsRuby ������������� ������� ������ ��� ������� Cls-������, ������������
4
+ � ������, ����� ��� ������������ ������� IO. ������ ������ ������� ���������
5
+ ������ �� �������.
6
+
7
+ == ClsRuby#parse_io
8
+
9
+ ����� ClsRuby#parse_io ������������ ��� ������� Cls-������, ������� ��������
10
+ ����� ������ IO. ���� ������ ����� ���� �������, ��������, � ����������
11
+ �������� ����� ��� � ������� ������ IO#popen.
12
+
13
+ ������ ������������� ClsRuby#parse_io:
14
+ parsed_output = IO.popen( 'some-cmd' ) do |output|
15
+ root_tag = SomeRootTag.new
16
+ ClsRuby::parse_io( output, 'some-cmd output', root_tag )
17
+ root_tag.value
18
+ end
19
+
20
+ == ClsRuby#parse_file
21
+
22
+ ����� ClsRuby#parse_file ������������ ��� ������� Cls-������, ������������
23
+ � �������� �����. ������ ����� ������ ��� ������ ���������������� ������ �
24
+ ������� Ruby.
25
+
26
+ ������ ������������� ClsRuby#parse_file:
27
+ root_tag = SomeConfigRootTag.new
28
+ ClsRuby::parse_file( 'some-config.cfg', root_tag )
29
+
30
+ == ClsRuby#parse_string
31
+
32
+ ����� ClsRuby#parse_string ������������ ��� ������� Cls-������, ������������ �
33
+ �������� ������� String. ������ ����� ������ ��� ���������� ����� � Cls-������
34
+ �� �����-���� �� Cls-��������. ��������, ����� Cls-���� �������� � ���������
35
+ ����� ���� ������.
36
+
37
+ ������ ������������� ClsRuby#parse_string:
38
+ cls_data = read_cls_data_from_somewhere
39
+ root_tag = SomeRootTag.new
40
+ ClsRuby::parse_string( cls_data, root_tag )
41
+
42
+ == ����� ���������
43
+
44
+ === ������ ClsRuby#parse_file � ClsRuby#parse_string ����� ���� �������������� �����
45
+
46
+ �������� �������� �� ������� Cls-������ ��������� ����� ClsRuby#parse_io.
47
+ ������ ClsRuby#parse_file � ClsRuby#parse_string �������� ����� ����
48
+ �������������� �������, ����������� ������ � �������� ����������������
49
+ ���������. � ���������������� �� parse_file � parse_string �������� �������
50
+ ��������� ��� parse_io.
51
+
52
+ ������ ���� ����� ���� ����� ��� ������������� �������� ������������ ������
53
+ ������� Cls-������ -- ������ ��������, ��� ��� ����� ����� ������� ����� ��
54
+ �������� ��� ClsRuby#parse_io, ��� � ������ parse_file � parse_string.
55
+
56
+ === ������ parse_* ����� ��������� ����� ������ ��������� ���� � �������� ����������
57
+
58
+ ����������� ���� ������� ������������� ������� parse_* ������������ ����� ����
59
+ �������� ��� �� ������� ������ -- �� ����������� � ������ parse_* ���������
60
+ ���������� � ������ root_tag. ������, ������ parse_* ����� �������� � �
61
+ �������, ����� ����� �������� ����� ������ ���� ���������:
62
+ first_root_tag = FirstRootTag.new
63
+ second_root_tag = SecondRootTag.new
64
+ third_root_tag = ThirdRootTag.new
65
+
66
+ ClsRuby::parse_string( cls_data,
67
+ first_root_tag,
68
+ second_root_tag,
69
+ third_root_tag )
70
+ ��� �� ����� �������:
71
+ # �������� ���� ��������� ��������������� ������� �
72
+ # ������������ � ���� ������� Array.
73
+ root_tags = make_root_tags
74
+
75
+ ClsRuby::parse_string( cls_data, *root_tags )
76
+
77
+
78
+ # vim:ts=2:sts=2:sw=2:expandtab:ft=txt:tw=78
79
+
@@ -0,0 +1,131 @@
1
+ = �������� ������ � Cls. �������� ���������� � ������������ �����
2
+
3
+ == ��������
4
+
5
+ ��� ������� ���������� ������������ ����� � ClsRuby ������������ ������������
6
+ �������� ���� Hash, ������� �������� ���� <����,��������>. ��������� Ruby
7
+ ��������� �������� ���� �������� ��� ����� ������������ �����������
8
+ ��������� � ������ ������ ����������������:
9
+ root = ClsRuby::TagNoValue.new :name => 'root', :mandatory => true
10
+ ����� :name � :mandatory �������� ������� ������������� ��������� ���� Hash
11
+ ��� ������� ClsRuby::TagNoValue.
12
+
13
+ ������������� ������������� ��������� ���� Hash ��������� ����� ���������
14
+ ��������� ���� � ����������� �������. ��������, ��� ClsRuby::TagNoValue
15
+ ������������ ��������� ������ ClsRuby::Tag �, � ���������� � �����, ����������
16
+ ����������� ���� :once.
17
+
18
+ ������ � ���������� ���� Hash ��� �� ��������� �������� � ����������� �������
19
+ ����������� ���������. ��-������, � ������� �������� �� ��������� ���
20
+ ���������:
21
+ class MyTag < ClsRuby::Tag
22
+ def initialize( params = { :mandatory = true } )
23
+ super( params )
24
+ ...
25
+ end
26
+ end
27
+ � ����� ������, ���� ��� �������� ������� MyTag �� ����� �������� ����������,
28
+ �� � ������� ����� ����� ������ Hash �� ��������� {:mandatory=>true}.
29
+
30
+ ��-������, �������� �� ��������� ����� ������������� � ���� ���������
31
+ ������������� �����������:
32
+ class MyTag < ClsRuby::Tag
33
+ def initialize( params = {} )
34
+ super( { :name => 'root', :mandatory => false }.merge( params ) )
35
+ ...
36
+ end
37
+ end
38
+ � ���� ������, ���� ������������ ���� �� ����� ����� :name � :mandatory, ��
39
+ ����� ����� ��������������� �� �������� �� ���������. ���� ��
40
+ ������������ ����� ��� ����� � ��������� params, �� ������ ��������
41
+ �� ��������� ����� �������������� �������� ������������� ��������.
42
+
43
+ ���������� ������ ������� �������� ����������� ������������ ������
44
+ ClsRuby::Tag#child_tag, Tag#mandatory_child_tag � Tag#default_tag_params.
45
+ ������� �� �������� ������� �� ���, ��� ��������� �������� ����� ����������� �
46
+ ���� ������� Hash, � ����� ������������ ��� �������� � ������������� ��������
47
+ �����.
48
+
49
+ === ��������� ���� �� ���������
50
+
51
+ ������ ������������� ������ Hash#merge ��� ������� ���������� �� ���������:
52
+ def initialize( params )
53
+ super( { :name => 'root' }.merge( params ) )
54
+ ...
55
+ end
56
+ ����� ��������������� ������� ClsRuby::Tag#default_tag_params, ��� ������
57
+ �������� ���� ����� �������������:
58
+ class MyTag < ClsRuby::Tag
59
+ default_tag_params :name => 'root'
60
+ ...
61
+ end
62
+
63
+ ��� ����� ������ ������������ ������ ClsRuby::Tag#default_tag_params ��������
64
+ ��, ��� � ������ ������������ ��������� �� ��������� �������������:
65
+ :include: docs/fragments/inherit_tag_params.rb
66
+ ��� ���� � ����������:
67
+ {:name=>"root", :mandatory=>true, :once=>true}
68
+
69
+ == ����������� ��������������
70
+
71
+ ����� ClsRuby::Tag ������������ ��������� ����� � ���������� ������������:
72
+ [_name_] ��� ����;
73
+ [_mandatory_] ������� ��������������/���������������� ����;
74
+ [_owner_] ������ �� ������������ ���. ���� ��� ������ ������, �� �����������
75
+ ������������� �������� tag_add ��� ������������� ����.
76
+
77
+ ���� ��� ������ ��������� �����-���� �������� (��������, ��� � ������ �
78
+ ClsRuby::TagScalar), �� ��� �������� ����� ���� ������ � ������������ �
79
+ ������� ����� :value.
80
+
81
+ ������������������ ���� ����� ������������ ����������� ����� (��������, :format
82
+ ��� ClsRuby::TagScalar � :once ��� ClsRuby::TagNoValue). ��� ����, �����
83
+ ���������� ������ �������������� ����� ������ ���������� ���������� � ��������
84
+ ������� ����.
85
+
86
+
87
+ == ������ � ���������� ����
88
+
89
+ ����� ��������� ���� �������� � ����������� �������� ������ ClsRuby::Tag, ��
90
+ ��� ������������ �� ������� ���������� �� ��������� (�������� �����������
91
+ default_tag_params). ������� ��� ��������� ������� � ������� ������ ����������
92
+ ���� ���������� ������������ ����� ClsRuby::Tag#tag_params, �.�. �� ����������
93
+ ������ �� Hash � �������������� ������� ����������.
94
+
95
+ === ������ � �������������� ���������� ����
96
+
97
+ � ����� � ���, ��� ����� ������ ��� ������� ���������� �� ���������, �����
98
+ ����� �������� ������������ ��� ��������� �������������� ���������� �
99
+ ������������ ������������ ����. ��������, ���� ����� ������������ ��� :value
100
+ ��� ����, ����� ����� ������� ��� ������������:
101
+ def initialize( params = {} )
102
+ super( params )
103
+
104
+ value = params.fetch( :value )
105
+ if value
106
+ ... # ���������
107
+ end
108
+ end
109
+ ������ ����� � ���, ��� ����� ������������ �������� ��������� ������������, ��
110
+ ��������� ������������ ��������� �������� �� ���������. ���������� ��� ������
111
+ ������������ ����� tag_params:
112
+ def initialize( params = {} )
113
+ super( params )
114
+
115
+ value = tag_params.fetch( :value )
116
+ if value
117
+ ... # ���������
118
+ end
119
+ end
120
+ ����, ��� ����� ������������, ������������ ����� Tag#tag_handle_opt_param:
121
+ def initialize( params )
122
+ super( params )
123
+
124
+ tag_handle_opt_param( :value ) do |v|
125
+ ...
126
+ tag_make_defined
127
+ end
128
+ end
129
+
130
+ # vim:ts=2:sts=2:sw=2:expandtab:ft=txt:tw=78
131
+
@@ -0,0 +1,3 @@
1
+ :include: examples/log_single_line_formatter.rb
2
+
3
+ # vim:ts=2:sts=2:sw=2:expandtab:ft=txt:tw=78
@@ -0,0 +1,3 @@
1
+ :include: examples/service_description.rb
2
+
3
+ # vim:ts=2:sts=2:sw=2:expandtab:ft=txt:tw=78
@@ -0,0 +1,3 @@
1
+ :include: examples/sms-hist.rb
2
+
3
+ # vim:ts=2:sts=2:sw=2:expandtab:ft=txt:tw=78
@@ -0,0 +1,3 @@
1
+ :include: examples/tag_any.rb
2
+
3
+ # vim:ts=2:sts=2:sw=2:expandtab:ft=txt:tw=78
@@ -0,0 +1,20 @@
1
+ require 'cls-ruby'
2
+ require 'cls-ruby/tag_no_value'
3
+ require 'cls-ruby/tag_scalar'
4
+
5
+ class TagField < ClsRuby::TagNoValue
6
+ mandatory_child_tag :name, ClsRuby::TagStringScalar
7
+ mandatory_child_tag :type, ClsRuby::TagScalar,
8
+ :format => ClsRuby::SCALAR_NONSPACE_STRING
9
+
10
+ default_tag_params :name => 'field'
11
+
12
+ # Getter-� �������� name � type.
13
+ def name; @name.value; end
14
+ def type; @type.value; end
15
+ end
16
+
17
+ tag = TagField.new
18
+ ClsRuby::parse_io( ARGF, '-', tag )
19
+ puts "#{tag.name}:#{tag.type}"
20
+
@@ -0,0 +1,21 @@
1
+ require 'cls-ruby'
2
+
3
+ class TagInclude < ClsRuby::Tag
4
+ default_tag_params :name => 'include'
5
+
6
+ def initialize( receiver, params = {} )
7
+ super( params )
8
+ # ��� �������� ���� ������.
9
+ @receiver = receiver
10
+ end
11
+
12
+ # ��� ��������� ���������� �������� ��������� ��� � ���������.
13
+ def tag_on_tok_string( value )
14
+ @receiver << value
15
+ end
16
+ end
17
+
18
+ files = []
19
+ tag = TagInclude.new( files )
20
+ ClsRuby::parse_io( ARGF, '-', tag )
21
+ puts files.join(', ')
@@ -0,0 +1,2 @@
1
+ {field {name "My"} {type InitMessage}}
2
+
@@ -0,0 +1,4 @@
1
+ {include "a"}
2
+ {include "b"}
3
+ {include "d" "f"}
4
+
@@ -0,0 +1,21 @@
1
+ require 'cls-ruby'
2
+ require 'cls-ruby/tag'
3
+
4
+ class MyBase < ClsRuby::Tag
5
+ default_tag_params :name => 'root'
6
+ end
7
+
8
+ class MyDerived < MyBase
9
+ default_tag_params :mandatory => true
10
+ end
11
+
12
+ class MyNextDerived < MyDerived
13
+ default_tag_params :once => true
14
+
15
+ def show_params
16
+ p tag_params
17
+ end
18
+ end
19
+
20
+ t = MyNextDerived.new
21
+ t.show_params
@@ -0,0 +1,6 @@
1
+ {message
2
+ {name Sample}
3
+ {field {name "trx"} {type TrxId}}
4
+ {field {name "user"} {type String}}
5
+ }
6
+
@@ -0,0 +1,24 @@
1
+ require 'cls-ruby'
2
+ require 'cls-ruby/tag_no_value'
3
+ require 'cls-ruby/tag_scalar'
4
+
5
+ Field = Struct.new( :name, :type )
6
+
7
+ class TagField < ClsRuby::TagNoValue
8
+ mandatory_child_tag :name, ClsRuby::TagStringScalar
9
+ mandatory_child_tag :type, ClsRuby::TagScalar,
10
+ :format => ClsRuby::SCALAR_NONSPACE_STRING
11
+
12
+ default_tag_params :name => 'field'
13
+
14
+ # Getter-� �������� name � type.
15
+ def value
16
+ Field.new( @name.value, @type.value )
17
+ end
18
+ end
19
+
20
+ tag = TagField.new
21
+ ClsRuby::parse_io( ARGF, '-', tag )
22
+ field = tag.value
23
+ puts "#{field.name}:#{field.type}"
24
+
@@ -0,0 +1,74 @@
1
+ require 'cls-ruby'
2
+ require 'cls-ruby/default_formatter'
3
+ require 'cls-ruby/tag_no_value'
4
+ require 'cls-ruby/tag_scalar'
5
+ require 'cls-ruby/tag_vector_of_tags'
6
+
7
+ Field = Struct.new( :name, :type )
8
+ Message = Struct.new( :name, :fields )
9
+
10
+ class TagField < ClsRuby::TagNoValue
11
+ mandatory_child_tag :name, ClsRuby::TagStringScalar
12
+ mandatory_child_tag :type, ClsRuby::TagScalar,
13
+ :format => ClsRuby::SCALAR_NONSPACE_STRING
14
+
15
+ default_tag_params :name => 'field'
16
+
17
+ # ���� ����� ���� :value, �� ����� ������������ �������������.
18
+ def initialize( params = {} )
19
+ super( params )
20
+ tag_handle_opt_param( :value ) do |field|
21
+ @name.value = field.name
22
+ @type.value = field.type
23
+ tag_make_defined
24
+ end
25
+ end
26
+
27
+ # Getter-� �������� name � type.
28
+ def value
29
+ Field.new( @name.value, @type.value )
30
+ end
31
+ end
32
+
33
+ class TagMessage < ClsRuby::TagNoValue
34
+ mandatory_child_tag :name, ClsRuby::TagScalar,
35
+ :format => ClsRuby::SCALAR_NONSPACE_STRING
36
+ child_tag :field, ClsRuby::TagVectorOfTags, :type => TagField
37
+
38
+ default_tag_params :name => 'message'
39
+
40
+ # ���� ����� ���� :value, �� ����� ������������ �������������.
41
+ def initialize( params = {} )
42
+ super( params )
43
+ tag_handle_opt_param( :value ) do |message|
44
+ @name.value = message.name
45
+ message.fields.each do |field|
46
+ @field.add_nested_tag( TagField.new( :value => field ) )
47
+ end
48
+ tag_make_defined
49
+ end
50
+ end
51
+
52
+ # ��������� ��������.
53
+ def value
54
+ r = Message.new
55
+ r.name = @name.value
56
+ r.fields = @field.collect_values_by( :value )
57
+ r
58
+ end
59
+ end
60
+
61
+ # ��������� �������� ���������.
62
+ in_tag = TagMessage.new
63
+ ClsRuby::parse_io( ARGF, '-', in_tag )
64
+
65
+ message = in_tag.value
66
+
67
+ # ��������� ��������� ��� ����������� ������.
68
+ message.fields << Field.new( 'id', 'String' )
69
+ message.fields << Field.new( 'timestamp', 'TimeStamp' )
70
+
71
+ # ���������� �������������� ��������� �� ����������� ������ ������.
72
+ out_tag = TagMessage.new( :value => message )
73
+ out_tag.tag_format( ClsRuby::DefaultFormatter.new( STDOUT ) )
74
+
@@ -0,0 +1,41 @@
1
+ require 'cls-ruby'
2
+ require 'cls-ruby/default_formatter'
3
+ require 'cls-ruby/tag_no_value'
4
+ require 'cls-ruby/tag_scalar'
5
+ require 'cls-ruby/tag_vector_of_tags'
6
+
7
+ # ���, ������� ���������� TagVectorOfTags.
8
+ #
9
+ class TagCompilationParams < ClsRuby::TagNoValue
10
+ child_tag :include_path, ClsRuby::TagVectorOfTags,
11
+ :type => ClsRuby::TagStringScalar,
12
+ :name => 'include-path'
13
+
14
+ child_tag :define, ClsRuby::TagVectorOfTags,
15
+ :type => ClsRuby::TagStringScalar
16
+
17
+ default_tag_params :name => 'compilation-params'
18
+ end
19
+
20
+ # ������� �����, � ������� ���� {include-path} � {define} ����������.
21
+ #
22
+ INPUT = <<END_OF_INPUT
23
+ {compilation-params
24
+ {include-path "/home/eao197" }
25
+ {define "NDEBUG" }
26
+ {include-path "/usr/share/include" }
27
+ {define "X86_ARCH" }
28
+ {include-path "/usr/local/include" }
29
+ {define "STATIC_LIB" }
30
+ }
31
+ END_OF_INPUT
32
+
33
+ # ������ �������� ������.
34
+ #
35
+ tag = TagCompilationParams.new
36
+ ClsRuby::parse_string( INPUT, tag )
37
+
38
+ # �������������� ���������� ������� � ���� ��������� ������.
39
+ #
40
+ tag.tag_format( ClsRuby::DefaultFormatter.new( STDOUT ) )
41
+