redsnow 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +34 -0
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +20 -0
  5. data/CHANGELOG.md +4 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE +21 -0
  8. data/README.md +62 -0
  9. data/Rakefile +36 -0
  10. data/Vagrantfile +20 -0
  11. data/ext/snowcrash/Makefile +64 -0
  12. data/ext/snowcrash/Vagrantfile +20 -0
  13. data/ext/snowcrash/bin/snowcrash +0 -0
  14. data/ext/snowcrash/common.gypi +163 -0
  15. data/ext/snowcrash/config.gypi +10 -0
  16. data/ext/snowcrash/config.mk +5 -0
  17. data/ext/snowcrash/configure +213 -0
  18. data/ext/snowcrash/provisioning.sh +15 -0
  19. data/ext/snowcrash/snowcrash.gyp +141 -0
  20. data/ext/snowcrash/src/ActionParser.h +503 -0
  21. data/ext/snowcrash/src/AssetParser.h +215 -0
  22. data/ext/snowcrash/src/BlockUtility.h +186 -0
  23. data/ext/snowcrash/src/Blueprint.h +283 -0
  24. data/ext/snowcrash/src/BlueprintParser.h +347 -0
  25. data/ext/snowcrash/src/BlueprintParserCore.h +190 -0
  26. data/ext/snowcrash/src/BlueprintSection.h +140 -0
  27. data/ext/snowcrash/src/BlueprintUtility.h +126 -0
  28. data/ext/snowcrash/src/CBlueprint.cc +600 -0
  29. data/ext/snowcrash/src/CBlueprint.h +354 -0
  30. data/ext/snowcrash/src/CSourceAnnotation.cc +140 -0
  31. data/ext/snowcrash/src/CSourceAnnotation.h +106 -0
  32. data/ext/snowcrash/src/CodeBlockUtility.h +189 -0
  33. data/ext/snowcrash/src/DescriptionSectionUtility.h +156 -0
  34. data/ext/snowcrash/src/HTTP.cc +46 -0
  35. data/ext/snowcrash/src/HTTP.h +105 -0
  36. data/ext/snowcrash/src/HeaderParser.h +289 -0
  37. data/ext/snowcrash/src/ListBlockUtility.h +273 -0
  38. data/ext/snowcrash/src/ListUtility.h +95 -0
  39. data/ext/snowcrash/src/MarkdownBlock.cc +176 -0
  40. data/ext/snowcrash/src/MarkdownBlock.h +93 -0
  41. data/ext/snowcrash/src/MarkdownParser.cc +266 -0
  42. data/ext/snowcrash/src/MarkdownParser.h +88 -0
  43. data/ext/snowcrash/src/ParameterDefinitonParser.h +570 -0
  44. data/ext/snowcrash/src/ParametersParser.h +252 -0
  45. data/ext/snowcrash/src/Parser.cc +71 -0
  46. data/ext/snowcrash/src/Parser.h +29 -0
  47. data/ext/snowcrash/src/ParserCore.cc +120 -0
  48. data/ext/snowcrash/src/ParserCore.h +82 -0
  49. data/ext/snowcrash/src/PayloadParser.h +672 -0
  50. data/ext/snowcrash/src/Platform.h +54 -0
  51. data/ext/snowcrash/src/RegexMatch.h +32 -0
  52. data/ext/snowcrash/src/ResourceGroupParser.h +195 -0
  53. data/ext/snowcrash/src/ResourceParser.h +584 -0
  54. data/ext/snowcrash/src/SectionUtility.h +142 -0
  55. data/ext/snowcrash/src/Serialize.cc +52 -0
  56. data/ext/snowcrash/src/Serialize.h +69 -0
  57. data/ext/snowcrash/src/SerializeJSON.cc +601 -0
  58. data/ext/snowcrash/src/SerializeJSON.h +21 -0
  59. data/ext/snowcrash/src/SerializeYAML.cc +336 -0
  60. data/ext/snowcrash/src/SerializeYAML.h +21 -0
  61. data/ext/snowcrash/src/SourceAnnotation.h +177 -0
  62. data/ext/snowcrash/src/StringUtility.h +109 -0
  63. data/ext/snowcrash/src/SymbolTable.h +83 -0
  64. data/ext/snowcrash/src/UriTemplateParser.cc +195 -0
  65. data/ext/snowcrash/src/UriTemplateParser.h +243 -0
  66. data/ext/snowcrash/src/Version.h +39 -0
  67. data/ext/snowcrash/src/csnowcrash.cc +23 -0
  68. data/ext/snowcrash/src/csnowcrash.h +38 -0
  69. data/ext/snowcrash/src/posix/RegexMatch.cc +99 -0
  70. data/ext/snowcrash/src/snowcrash.cc +18 -0
  71. data/ext/snowcrash/src/snowcrash.h +41 -0
  72. data/ext/snowcrash/src/snowcrash/snowcrash.cc +170 -0
  73. data/ext/snowcrash/src/win/RegexMatch.cc +78 -0
  74. data/ext/snowcrash/sundown/CONTRIBUTING.md +10 -0
  75. data/ext/snowcrash/sundown/Makefile +83 -0
  76. data/ext/snowcrash/sundown/Makefile.win +33 -0
  77. data/ext/snowcrash/sundown/examples/smartypants.c +72 -0
  78. data/ext/snowcrash/sundown/examples/sundown.c +80 -0
  79. data/ext/snowcrash/sundown/html/houdini.h +37 -0
  80. data/ext/snowcrash/sundown/html/houdini_href_e.c +108 -0
  81. data/ext/snowcrash/sundown/html/houdini_html_e.c +84 -0
  82. data/ext/snowcrash/sundown/html/html.c +647 -0
  83. data/ext/snowcrash/sundown/html/html.h +77 -0
  84. data/ext/snowcrash/sundown/html/html_smartypants.c +389 -0
  85. data/ext/snowcrash/sundown/html_block_names.txt +25 -0
  86. data/ext/snowcrash/sundown/src/autolink.c +297 -0
  87. data/ext/snowcrash/sundown/src/autolink.h +51 -0
  88. data/ext/snowcrash/sundown/src/buffer.c +225 -0
  89. data/ext/snowcrash/sundown/src/buffer.h +96 -0
  90. data/ext/snowcrash/sundown/src/html_blocks.h +206 -0
  91. data/ext/snowcrash/sundown/src/markdown.c +2701 -0
  92. data/ext/snowcrash/sundown/src/markdown.h +147 -0
  93. data/ext/snowcrash/sundown/src/src_map.c +200 -0
  94. data/ext/snowcrash/sundown/src/src_map.h +58 -0
  95. data/ext/snowcrash/sundown/src/stack.c +81 -0
  96. data/ext/snowcrash/sundown/src/stack.h +29 -0
  97. data/ext/snowcrash/sundown/sundown.def +20 -0
  98. data/ext/snowcrash/tools/gyp/AUTHORS +11 -0
  99. data/ext/snowcrash/tools/gyp/DEPS +24 -0
  100. data/ext/snowcrash/tools/gyp/OWNERS +1 -0
  101. data/ext/snowcrash/tools/gyp/PRESUBMIT.py +120 -0
  102. data/ext/snowcrash/tools/gyp/buildbot/buildbot_run.py +190 -0
  103. data/ext/snowcrash/tools/gyp/codereview.settings +10 -0
  104. data/ext/snowcrash/tools/gyp/data/win/large-pdb-shim.cc +12 -0
  105. data/ext/snowcrash/tools/gyp/gyp +8 -0
  106. data/ext/snowcrash/tools/gyp/gyp.bat +5 -0
  107. data/ext/snowcrash/tools/gyp/gyp_main.py +18 -0
  108. data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSNew.py +340 -0
  109. data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSProject.py +208 -0
  110. data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSSettings.py +1063 -0
  111. data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSToolFile.py +58 -0
  112. data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSUserFile.py +147 -0
  113. data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSUtil.py +267 -0
  114. data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSVersion.py +409 -0
  115. data/ext/snowcrash/tools/gyp/pylib/gyp/__init__.py +537 -0
  116. data/ext/snowcrash/tools/gyp/pylib/gyp/__init__.pyc +0 -0
  117. data/ext/snowcrash/tools/gyp/pylib/gyp/common.py +521 -0
  118. data/ext/snowcrash/tools/gyp/pylib/gyp/common.pyc +0 -0
  119. data/ext/snowcrash/tools/gyp/pylib/gyp/easy_xml.py +157 -0
  120. data/ext/snowcrash/tools/gyp/pylib/gyp/flock_tool.py +49 -0
  121. data/ext/snowcrash/tools/gyp/pylib/gyp/generator/__init__.py +0 -0
  122. data/ext/snowcrash/tools/gyp/pylib/gyp/generator/__init__.pyc +0 -0
  123. data/ext/snowcrash/tools/gyp/pylib/gyp/generator/android.py +1069 -0
  124. data/ext/snowcrash/tools/gyp/pylib/gyp/generator/cmake.py +1143 -0
  125. data/ext/snowcrash/tools/gyp/pylib/gyp/generator/dump_dependency_json.py +81 -0
  126. data/ext/snowcrash/tools/gyp/pylib/gyp/generator/eclipse.py +335 -0
  127. data/ext/snowcrash/tools/gyp/pylib/gyp/generator/gypd.py +87 -0
  128. data/ext/snowcrash/tools/gyp/pylib/gyp/generator/gypsh.py +56 -0
  129. data/ext/snowcrash/tools/gyp/pylib/gyp/generator/make.py +2181 -0
  130. data/ext/snowcrash/tools/gyp/pylib/gyp/generator/make.pyc +0 -0
  131. data/ext/snowcrash/tools/gyp/pylib/gyp/generator/msvs.py +3335 -0
  132. data/ext/snowcrash/tools/gyp/pylib/gyp/generator/ninja.py +2156 -0
  133. data/ext/snowcrash/tools/gyp/pylib/gyp/generator/xcode.py +1224 -0
  134. data/ext/snowcrash/tools/gyp/pylib/gyp/generator/xcode.pyc +0 -0
  135. data/ext/snowcrash/tools/gyp/pylib/gyp/input.py +2809 -0
  136. data/ext/snowcrash/tools/gyp/pylib/gyp/input.pyc +0 -0
  137. data/ext/snowcrash/tools/gyp/pylib/gyp/mac_tool.py +510 -0
  138. data/ext/snowcrash/tools/gyp/pylib/gyp/msvs_emulation.py +972 -0
  139. data/ext/snowcrash/tools/gyp/pylib/gyp/ninja_syntax.py +160 -0
  140. data/ext/snowcrash/tools/gyp/pylib/gyp/ordered_dict.py +289 -0
  141. data/ext/snowcrash/tools/gyp/pylib/gyp/win_tool.py +292 -0
  142. data/ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.py +1440 -0
  143. data/ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyc +0 -0
  144. data/ext/snowcrash/tools/gyp/pylib/gyp/xcodeproj_file.py +2889 -0
  145. data/ext/snowcrash/tools/gyp/pylib/gyp/xcodeproj_file.pyc +0 -0
  146. data/ext/snowcrash/tools/gyp/pylib/gyp/xml_fix.py +69 -0
  147. data/ext/snowcrash/tools/gyp/pylintrc +307 -0
  148. data/ext/snowcrash/tools/gyp/samples/samples +81 -0
  149. data/ext/snowcrash/tools/gyp/samples/samples.bat +5 -0
  150. data/ext/snowcrash/tools/gyp/setup.py +19 -0
  151. data/ext/snowcrash/tools/gyp/tools/Xcode/Specifications/gyp.pbfilespec +27 -0
  152. data/ext/snowcrash/tools/gyp/tools/Xcode/Specifications/gyp.xclangspec +226 -0
  153. data/ext/snowcrash/tools/gyp/tools/emacs/gyp.el +252 -0
  154. data/ext/snowcrash/tools/gyp/tools/graphviz.py +100 -0
  155. data/ext/snowcrash/tools/gyp/tools/pretty_gyp.py +155 -0
  156. data/ext/snowcrash/tools/gyp/tools/pretty_sln.py +168 -0
  157. data/ext/snowcrash/tools/gyp/tools/pretty_vcproj.py +329 -0
  158. data/ext/snowcrash/tools/homebrew/snowcrash.rb +11 -0
  159. data/ext/snowcrash/vcbuild.bat +184 -0
  160. data/lib/redsnow.rb +31 -0
  161. data/lib/redsnow/binding.rb +132 -0
  162. data/lib/redsnow/blueprint.rb +365 -0
  163. data/lib/redsnow/object.rb +18 -0
  164. data/lib/redsnow/parseresult.rb +107 -0
  165. data/lib/redsnow/version.rb +4 -0
  166. data/provisioning.sh +20 -0
  167. data/redsnow.gemspec +35 -0
  168. data/test/_helper.rb +15 -0
  169. data/test/fixtures/sample-api-ast.json +97 -0
  170. data/test/fixtures/sample-api.apib +20 -0
  171. data/test/redsnow_binding_test.rb +35 -0
  172. data/test/redsnow_parseresult_test.rb +50 -0
  173. data/test/redsnow_test.rb +285 -0
  174. metadata +358 -0
@@ -0,0 +1,21 @@
1
+ //
2
+ // SerializeJSON.h
3
+ // snowcrash
4
+ //
5
+ // Created by Zdenek Nemec on 4/27/13.
6
+ // Copyright (c) 2013 Apiary Inc. All rights reserved.
7
+ //
8
+
9
+ #ifndef SNOWCRASH_SERIALIZE_JSON_H
10
+ #define SNOWCRASH_SERIALIZE_JSON_H
11
+
12
+ #include <ostream>
13
+ #include "Blueprint.h"
14
+
15
+ namespace snowcrash {
16
+
17
+ // Naive JSON serialization to ostream
18
+ void SerializeJSON(const snowcrash::Blueprint& blueprint, std::ostream &os);
19
+ }
20
+
21
+ #endif
@@ -0,0 +1,336 @@
1
+ //
2
+ // SerializeYAML.cc
3
+ // snowcrash
4
+ //
5
+ // Created by Zdenek Nemec on 5/3/13.
6
+ // Copyright (c) 2013 Apiary Inc. All rights reserved.
7
+ //
8
+
9
+ #include "Serialize.h"
10
+ #include "SerializeYAML.h"
11
+
12
+ using namespace snowcrash;
13
+
14
+ static std::string ReservedCharacters = "#-[]:|>!*&%@`,{}?\'";
15
+
16
+ /** Normalizes string value for use in YAML and checks whether quotation is need */
17
+ static std::string NormalizeStringValue(const std::string& value, bool& needsQuotation)
18
+ {
19
+ std::string normalizedValue = value;
20
+ if (normalizedValue.find("\"") != std::string::npos)
21
+ normalizedValue = EscapeDoubleQuotes(normalizedValue);
22
+
23
+ if (value.find("\n") != std::string::npos)
24
+ normalizedValue = EscapeNewlines(normalizedValue);
25
+
26
+ needsQuotation = (normalizedValue != value);
27
+ if (!needsQuotation) {
28
+ for (std::string::const_iterator it = value.begin() ; it < value.end() ; ++it){
29
+ needsQuotation = ReservedCharacters.find(*it) != std::string::npos;
30
+ if (needsQuotation)
31
+ break;
32
+ }
33
+ }
34
+
35
+ return normalizedValue;
36
+ }
37
+
38
+
39
+ /** Insert array item mark */
40
+ static void ArrayItemLeadIn(size_t level, std::ostream &os)
41
+ {
42
+ if (level < 1)
43
+ return;
44
+
45
+ for (size_t i = 0; i < level - 1; ++i)
46
+ os << " ";
47
+
48
+ os << "- ";
49
+ }
50
+
51
+ /** Serialize key value pair */
52
+ static void serialize(const std::string& key, const std::string& value, size_t level, std::ostream &os, bool implicitQuotation = true)
53
+ {
54
+ if (key.empty())
55
+ return;
56
+
57
+ for (size_t i = 0; i < level; ++i)
58
+ os << " ";
59
+
60
+ if (!value.empty()) {
61
+
62
+ os << key << ": ";
63
+
64
+ bool needsQuotation = false;
65
+ std::string normalizedValue = NormalizeStringValue(value, needsQuotation);
66
+
67
+ if (implicitQuotation) {
68
+ // Always use quotation
69
+ os << "\"" << normalizedValue << "\"";
70
+ }
71
+ else {
72
+ if (needsQuotation)
73
+ os << "\"" << normalizedValue << "\"";
74
+ else
75
+ os << value;
76
+ }
77
+
78
+ os << std::endl;
79
+ }
80
+ else
81
+ os << key << ":\n";
82
+ }
83
+
84
+ /** Serializes key value collection */
85
+ static void serializeKeyValueCollection(const Collection<KeyValuePair>::type& collection, size_t level, std::ostream &os)
86
+ {
87
+ for (Collection<KeyValuePair>::const_iterator it = collection.begin(); it != collection.end(); ++it) {
88
+
89
+ // Array item
90
+ ArrayItemLeadIn(level + 1, os);
91
+
92
+ // Name
93
+ serialize(SerializeKey::Name, it->first, 0, os);
94
+
95
+ // Value
96
+ serialize(SerializeKey::Value, it->second, level + 1, os);
97
+ }
98
+ }
99
+
100
+ /** Serialize Metadata */
101
+ static void serialize(const Collection<Metadata>::type& metadata, std::ostream &os)
102
+ {
103
+ serialize(SerializeKey::Metadata, std::string(), 0, os);
104
+
105
+ if (metadata.empty())
106
+ return;
107
+
108
+ serializeKeyValueCollection(metadata, 0, os);
109
+ }
110
+
111
+ /** Serialize Headers */
112
+ static void serialize(const Collection<Header>::type& headers, size_t level, std::ostream &os)
113
+ {
114
+ serializeKeyValueCollection(headers, level, os);
115
+ }
116
+
117
+ /** Serialize Parameters */
118
+ static void serialize(const Collection<Parameter>::type& parameters, size_t level, std::ostream &os)
119
+ {
120
+ for (Collection<Parameter>::const_iterator it = parameters.begin(); it != parameters.end(); ++it) {
121
+
122
+ // Array item
123
+ ArrayItemLeadIn(level + 1, os);
124
+
125
+ // Key / name
126
+ serialize(SerializeKey::Name, it->name, 0, os);
127
+
128
+ // Description
129
+ serialize(SerializeKey::Description, it->description, level + 1, os);
130
+
131
+ // Type
132
+ serialize(SerializeKey::Type, it->type, level + 1, os);
133
+
134
+ // Required
135
+ serialize(SerializeKey::Required, (it->use == OptionalParameterUse) ? "false" : "true", level + 1, os, false);
136
+
137
+ // Default
138
+ serialize(SerializeKey::Default, it->defaultValue, level + 1, os);
139
+
140
+ // Example
141
+ serialize(SerializeKey::Example, it->exampleValue, level + 1, os);
142
+
143
+ // Values
144
+ serialize(SerializeKey::Values, std::string(), level + 1, os);
145
+
146
+ if (!it->values.empty()) {
147
+ for (Collection<Value>::const_iterator val_it = it->values.begin();
148
+ val_it != it->values.end();
149
+ ++val_it) {
150
+
151
+ ArrayItemLeadIn(level + 2, os);
152
+
153
+ serialize(SerializeKey::Value, *val_it, 0, os);
154
+ }
155
+ }
156
+ }
157
+ }
158
+
159
+ /** Serialize Payload */
160
+ static void serialize(const Payload& payload, size_t level, bool array, std::ostream &os)
161
+ {
162
+ for (size_t i = 0; i < level - 1; i++) {
163
+ os << " ";
164
+ }
165
+
166
+ if (array)
167
+ os << "- ";
168
+ else
169
+ os << " ";
170
+
171
+ // Name
172
+ serialize(SerializeKey::Name, payload.name, 0, os);
173
+
174
+ // Description
175
+ serialize(SerializeKey::Description, payload.description, level, os);
176
+
177
+ // Headers
178
+ serialize(SerializeKey::Headers, std::string(), level, os);
179
+ if (!payload.headers.empty()) {
180
+ serialize(payload.headers, level, os);
181
+ }
182
+
183
+ // Body
184
+ serialize(SerializeKey::Body, payload.body, level, os);
185
+
186
+ // Schema
187
+ serialize(SerializeKey::Schema, payload.schema, level, os);
188
+
189
+ }
190
+
191
+ // Serialize Transaction Example
192
+ static void serialize(const TransactionExample& example, std::ostream &os)
193
+ {
194
+ os << " - "; // indent 4
195
+ // Name
196
+ serialize(SerializeKey::Name, example.name, 0, os);
197
+
198
+ // Description
199
+ serialize(SerializeKey::Description, example.description, 4, os);
200
+
201
+ // Requests
202
+ serialize(SerializeKey::Requests, std::string(), 4, os);
203
+ if (!example.requests.empty()) {
204
+ for (Collection<Request>::const_iterator it = example.requests.begin(); it != example.requests.end(); ++it) {
205
+ serialize(*it, 5, true, os);
206
+ }
207
+ }
208
+
209
+ // Responses
210
+ serialize(SerializeKey::Responses, std::string(), 4, os);
211
+ if (!example.responses.empty()) {
212
+ for (Collection<Response>::const_iterator it = example.responses.begin(); it != example.responses.end(); ++it) {
213
+ serialize(*it, 5, true, os);
214
+ }
215
+ }
216
+ }
217
+
218
+ /** Serialize Action */
219
+ static void serialize(const Action& action, std::ostream &os)
220
+ {
221
+ os << " - "; // indent 3
222
+
223
+ // Name
224
+ serialize(SerializeKey::Name, action.name, 0, os);
225
+
226
+ // Description
227
+ serialize(SerializeKey::Description, action.description, 3, os);
228
+
229
+ // HTTP method
230
+ serialize(SerializeKey::Method, action.method, 3, os);
231
+
232
+ // Parameters
233
+ serialize(SerializeKey::Parameters, std::string(), 3, os);
234
+ if (!action.parameters.empty())
235
+ serialize(action.parameters, 3, os);
236
+
237
+ // Examples
238
+ serialize(SerializeKey::Examples, std::string(), 3, os);
239
+ if (!action.examples.empty()) {
240
+ for (Collection<TransactionExample>::const_iterator it = action.examples.begin();
241
+ it != action.examples.end();
242
+ ++it) {
243
+ serialize(*it, os);
244
+ }
245
+ }
246
+ }
247
+
248
+ /** Serialize Resource */
249
+ static void serialize(const Resource& resource, std::ostream &os)
250
+ {
251
+ os << " - "; // indent 2
252
+
253
+ // Name
254
+ serialize(SerializeKey::Name, resource.name, 0, os);
255
+
256
+ // Description
257
+ serialize(SerializeKey::Description, resource.description, 2, os);
258
+
259
+ // URI Template
260
+ serialize(SerializeKey::URITemplate, resource.uriTemplate, 2, os);
261
+
262
+ // Model
263
+ serialize(SerializeKey::Model, std::string(), 2, os);
264
+ if (!resource.model.name.empty())
265
+ serialize(resource.model, 3, false, os);
266
+
267
+ // Parameters
268
+ serialize(SerializeKey::Parameters, std::string(), 2, os);
269
+ if (!resource.parameters.empty())
270
+ serialize(resource.parameters, 2, os);
271
+
272
+ // Actions
273
+ serialize(SerializeKey::Actions, std::string(), 2, os);
274
+
275
+ if (resource.actions.empty())
276
+ return;
277
+
278
+ for (Collection<Action>::const_iterator it = resource.actions.begin(); it != resource.actions.end(); ++it) {
279
+ serialize(*it, os);
280
+ }
281
+ }
282
+
283
+ /** Serialize Resource Group */
284
+ static void serialize(const ResourceGroup& group, std::ostream &os)
285
+ {
286
+ os << "- "; // indent 1
287
+
288
+ // Name
289
+ serialize(SerializeKey::Name, group.name, 0, os);
290
+
291
+ // Description
292
+ serialize(SerializeKey::Description, group.description, 1, os);
293
+
294
+ // Resources
295
+ serialize(SerializeKey::Resources, std::string(), 1, os);
296
+
297
+ if (group.resources.empty())
298
+ return;
299
+
300
+ for (Collection<Resource>::const_iterator it = group.resources.begin(); it != group.resources.end(); ++it) {
301
+ serialize(*it, os);
302
+ }
303
+ }
304
+
305
+ /** Serialize Blueprint */
306
+ static void serialize(const Blueprint& blueprint, std::ostream &os)
307
+ {
308
+ // AST Version
309
+ serialize(SerializeKey::ASTVersion, AST_SERIALIZATION_VERSION, 0, os, false);
310
+
311
+ // Metadata
312
+ serialize(blueprint.metadata, os);
313
+
314
+ // API Name
315
+ serialize(SerializeKey::Name, blueprint.name, 0, os);
316
+
317
+ // API Description
318
+ serialize(SerializeKey::Description, blueprint.description, 0, os);
319
+
320
+ // Resource Groups
321
+ serialize(SerializeKey::ResourceGroups, std::string(), 0, os);
322
+ if (blueprint.resourceGroups.empty())
323
+ return;
324
+
325
+ for (Collection<ResourceGroup>::type::const_iterator it = blueprint.resourceGroups.begin();
326
+ it != blueprint.resourceGroups.end();
327
+ ++it) {
328
+
329
+ serialize(*it, os);
330
+ }
331
+ }
332
+
333
+ void snowcrash::SerializeYAML(const snowcrash::Blueprint& blueprint, std::ostream &os)
334
+ {
335
+ serialize(blueprint, os);
336
+ }
@@ -0,0 +1,21 @@
1
+ //
2
+ // SerializeYAML.h
3
+ // snowcrash
4
+ //
5
+ // Created by Zdenek Nemec on 5/3/13.
6
+ // Copyright (c) 2013 Apiary Inc. All rights reserved.
7
+ //
8
+
9
+ #ifndef SNOWCRASH_SERIALIZE_YAML_H
10
+ #define SNOWCRASH_SERIALIZE_YAML_H
11
+
12
+ #include <ostream>
13
+ #include "Blueprint.h"
14
+
15
+ namespace snowcrash {
16
+
17
+ // Naive YAML serialization to ostream
18
+ void SerializeYAML(const snowcrash::Blueprint& blueprint, std::ostream &os);
19
+ }
20
+
21
+ #endif
@@ -0,0 +1,177 @@
1
+ //
2
+ // SourceAnnotation.h
3
+ // snowcrash
4
+ //
5
+ // Created by Zdenek Nemec on 7/12/13.
6
+ // Copyright (c) 2013 Apiary Inc. All rights reserved.
7
+ //
8
+
9
+ #ifndef SNOWCRASH_SOURCEANNOTATION_H
10
+ #define SNOWCRASH_SOURCEANNOTATION_H
11
+
12
+ #include <string>
13
+ #include <vector>
14
+
15
+ namespace snowcrash {
16
+
17
+ /**
18
+ * \brief A character range within the source code string.
19
+ */
20
+ struct SourceCharactersRange {
21
+ size_t location;
22
+ size_t length;
23
+ };
24
+
25
+ /**
26
+ * \brief A block (set of ranges) of source code characters. A character map.
27
+ *
28
+ * NOTE: The block does not have to be continuous.
29
+ */
30
+ typedef std::vector<SourceCharactersRange> SourceCharactersBlock;
31
+
32
+ /**
33
+ * \brief A source data annotation.
34
+ *
35
+ * Annotation bound to a source data block. Includes an
36
+ * annotation code and an optional message.
37
+ */
38
+ struct SourceAnnotation {
39
+
40
+ /**
41
+ * \brief Default annotation code representing success.
42
+ */
43
+ static const int OK;
44
+
45
+ /**
46
+ * \brief %SourceAnnotation default constructor.
47
+ *
48
+ * Creates an empty annotation with the default annotation code.
49
+ */
50
+ SourceAnnotation() : code(OK) {}
51
+
52
+ /**
53
+ * \brief %SourceAnnotation copy constructor.
54
+ * \param rhs An annotation to be copied.
55
+ */
56
+ SourceAnnotation(const SourceAnnotation& rhs) {
57
+
58
+ this->message = rhs.message;
59
+ this->code = rhs.code;
60
+ this->location = rhs.location;
61
+ }
62
+
63
+ /**
64
+ * \brief %SourceAnnotation constructor.
65
+ * \param message An annotation message.
66
+ * \param code Annotation code.
67
+ * \param location A location of the annotation.
68
+ */
69
+ SourceAnnotation(const std::string& message,
70
+ int code = OK,
71
+ const SourceCharactersBlock& location = SourceCharactersBlock()) {
72
+
73
+ this->message = message;
74
+ this->code = code;
75
+
76
+ this->location.clear();
77
+ if (!location.empty())
78
+ this->location.assign(location.begin(), location.end());
79
+ }
80
+
81
+ /** \brief %SourceAnnotation destructor. */
82
+ ~SourceAnnotation() {}
83
+
84
+ /**
85
+ * \brief %SourceAnnotation assignment operator
86
+ * \param rhs An annotation to be assigned to this annotation.
87
+ */
88
+ SourceAnnotation& operator=(const SourceAnnotation& rhs) {
89
+ this->message = rhs.message;
90
+ this->code = rhs.code;
91
+ this->location = rhs.location;
92
+ return *this;
93
+ }
94
+
95
+ /** The location of this annotation within the source data buffer. */
96
+ SourceCharactersBlock location;
97
+
98
+ /** An annotation code. */
99
+ int code;
100
+
101
+ /** A annotation message. */
102
+ std::string message;
103
+ };
104
+
105
+ /**
106
+ * Error source annotation.
107
+ */
108
+ typedef SourceAnnotation Error;
109
+
110
+ /**
111
+ * Error codes
112
+ */
113
+ enum ErrorCode {
114
+ NoError = 0,
115
+ ApplicationError = 1,
116
+ BusinessError = 2,
117
+ SymbolError = 3
118
+ };
119
+
120
+ /**
121
+ * Warning source annotation.
122
+ */
123
+ typedef SourceAnnotation Warning;
124
+
125
+ /**
126
+ * Warning codes
127
+ */
128
+ enum WarningCode {
129
+ NoWarning = 0,
130
+ APINameWarning = 1,
131
+ DuplicateWarning = 2,
132
+ FormattingWarning = 3,
133
+ RedefinitionWarning = 4,
134
+ IgnoringWarning = 5,
135
+ EmptyDefinitionWarning = 6,
136
+ NotEmptyDefinitionWarning = 7,
137
+ LogicalErrorWarning = 8,
138
+ DeprecatedWarning = 9,
139
+ IndentationWarning = 10,
140
+ AmbiguityWarning = 11,
141
+ URIWarning = 12
142
+ };
143
+
144
+ /**
145
+ * A set of warning source annotations.
146
+ */
147
+ typedef std::vector<Warning> Warnings;
148
+
149
+ /**
150
+ * \brief A parsing result Report.
151
+ *
152
+ * Result of a source data parsing operation.
153
+ * Composed of ONE error source annotation
154
+ * and a set of warning source annotations.
155
+ */
156
+ struct Result {
157
+
158
+ /**
159
+ * \brief Append a result to this one, replacing the error source annotation.
160
+ *
161
+ * NOTE: A binding does not need to wrap this action.
162
+ */
163
+ Result& operator+=(const Result& rhs) {
164
+ error = rhs.error;
165
+ warnings.insert(warnings.end(), rhs.warnings.begin(), rhs.warnings.end());
166
+ return *this;
167
+ }
168
+
169
+ /** Result error source annotation */
170
+ Error error;
171
+
172
+ /** Result warning source annotations */
173
+ Warnings warnings;
174
+ };
175
+ }
176
+
177
+ #endif