redsnow 0.2.1 → 0.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -0
- data/ext/snowcrash/bin/snowcrash +0 -0
- data/ext/snowcrash/snowcrash.xcworkspace/contents.xcworkspacedata +10 -0
- data/ext/snowcrash/src/ActionParser.h +35 -33
- data/ext/snowcrash/src/AssetParser.h +17 -17
- data/ext/snowcrash/src/Blueprint.h +101 -66
- data/ext/snowcrash/src/BlueprintParser.h +219 -10
- data/ext/snowcrash/src/BlueprintSourcemap.h +1 -1
- data/ext/snowcrash/src/BlueprintUtility.h +14 -14
- data/ext/snowcrash/src/CBlueprint.cc +29 -10
- data/ext/snowcrash/src/CBlueprint.h +19 -3
- data/ext/snowcrash/src/CBlueprintSourcemap.cc +20 -10
- data/ext/snowcrash/src/CBlueprintSourcemap.h +12 -3
- data/ext/snowcrash/src/CodeBlockUtility.h +25 -25
- data/ext/snowcrash/src/HTTP.cc +3 -0
- data/ext/snowcrash/src/HTTP.h +9 -6
- data/ext/snowcrash/src/HeadersParser.h +34 -14
- data/ext/snowcrash/src/ParameterParser.h +21 -21
- data/ext/snowcrash/src/ParametersParser.h +6 -5
- data/ext/snowcrash/src/PayloadParser.h +174 -129
- data/ext/snowcrash/src/RegexMatch.h +3 -3
- data/ext/snowcrash/src/ResourceGroupParser.h +5 -4
- data/ext/snowcrash/src/ResourceParser.h +30 -26
- data/ext/snowcrash/src/Section.cc +6 -6
- data/ext/snowcrash/src/Section.h +2 -2
- data/ext/snowcrash/src/SectionParser.h +41 -41
- data/ext/snowcrash/src/SectionParserData.h +10 -10
- data/ext/snowcrash/src/SectionProcessor.h +70 -30
- data/ext/snowcrash/src/Serialize.h +3 -3
- data/ext/snowcrash/src/SerializeJSON.cc +124 -96
- data/ext/snowcrash/src/SerializeJSON.h +1 -1
- data/ext/snowcrash/src/SerializeYAML.cc +71 -53
- data/ext/snowcrash/src/SerializeYAML.h +1 -1
- data/ext/snowcrash/src/Signature.cc +2 -2
- data/ext/snowcrash/src/Signature.h +1 -1
- data/ext/snowcrash/src/SourceAnnotation.h +23 -23
- data/ext/snowcrash/src/StringUtility.h +71 -9
- data/ext/snowcrash/src/SymbolTable.h +17 -17
- data/ext/snowcrash/src/UriTemplateParser.cc +5 -5
- data/ext/snowcrash/src/UriTemplateParser.h +9 -9
- data/ext/snowcrash/src/ValuesParser.h +2 -2
- data/ext/snowcrash/src/Version.h +1 -1
- data/ext/snowcrash/src/csnowcrash.cc +10 -8
- data/ext/snowcrash/src/snowcrash.cc +9 -9
- data/ext/snowcrash/src/snowcrash.h +6 -8
- data/ext/snowcrash/src/snowcrash/snowcrash.cc +14 -14
- data/ext/snowcrash/src/win/RegexMatch.cc +7 -7
- data/ext/snowcrash/tools/gyp/pylib/gyp/__init__.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/common.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/__init__.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/make.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/xcode.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/input.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/xcodeproj_file.pyc +0 -0
- data/ext/snowcrash/tools/homebrew/snowcrash.rb +1 -1
- data/lib/redsnow/binding.rb +8 -2
- data/lib/redsnow/blueprint.rb +4 -3
- data/lib/redsnow/sourcemap.rb +6 -4
- data/lib/redsnow/version.rb +1 -1
- metadata +4 -17
@@ -25,9 +25,9 @@ namespace snowcrash {
|
|
25
25
|
RequireBlueprintNameOption = (1 << 1), /// < Treat missing blueprint name as error
|
26
26
|
ExportSourcemapOption = (1 << 2) /// < Export source maps AST
|
27
27
|
};
|
28
|
-
|
28
|
+
|
29
29
|
typedef unsigned int BlueprintParserOptions;
|
30
|
-
|
30
|
+
|
31
31
|
/**
|
32
32
|
* \brief Section Parser Data
|
33
33
|
*
|
@@ -38,22 +38,22 @@ namespace snowcrash {
|
|
38
38
|
const mdp::ByteBuffer& src,
|
39
39
|
const Blueprint& bp)
|
40
40
|
: options(opts), sourceData(src), blueprint(bp) {}
|
41
|
-
|
41
|
+
|
42
42
|
/** Parser Options */
|
43
43
|
BlueprintParserOptions options;
|
44
|
-
|
44
|
+
|
45
45
|
/** Symbol Table */
|
46
46
|
SymbolTable symbolTable;
|
47
|
-
|
47
|
+
|
48
48
|
/** Symbol Table Sourcemap */
|
49
49
|
SymbolSourceMapTable symbolSourceMapTable;
|
50
50
|
|
51
51
|
/** Source Data */
|
52
52
|
const mdp::ByteBuffer& sourceData;
|
53
|
-
|
53
|
+
|
54
54
|
/** AST being parsed **/
|
55
55
|
const Blueprint& blueprint;
|
56
|
-
|
56
|
+
|
57
57
|
/** Sections Context */
|
58
58
|
typedef std::vector<SectionType> SectionsStack;
|
59
59
|
SectionsStack sectionsContext;
|
@@ -62,19 +62,19 @@ namespace snowcrash {
|
|
62
62
|
SectionType sectionContext() const {
|
63
63
|
return (sectionsContext.empty()) ? UndefinedSectionType : sectionsContext.back();
|
64
64
|
}
|
65
|
-
|
65
|
+
|
66
66
|
/** \returns Parent Section Context */
|
67
67
|
SectionType parentSectionContext() const {
|
68
68
|
if (sectionsContext.empty())
|
69
69
|
return UndefinedSectionType;
|
70
|
-
|
70
|
+
|
71
71
|
size_t size = sectionsContext.size();
|
72
72
|
if (size == 1)
|
73
73
|
return sectionsContext.back();
|
74
74
|
else
|
75
75
|
return sectionsContext[size-2];
|
76
76
|
}
|
77
|
-
|
77
|
+
|
78
78
|
/** \returns True if exporting source maps */
|
79
79
|
bool exportSourceMap() const {
|
80
80
|
return options & ExportSourcemapOption;
|
@@ -14,13 +14,13 @@
|
|
14
14
|
#include "Signature.h"
|
15
15
|
|
16
16
|
namespace snowcrash {
|
17
|
-
|
17
|
+
|
18
18
|
using mdp::MarkdownNode;
|
19
19
|
using mdp::MarkdownNodes;
|
20
20
|
using mdp::MarkdownNodeIterator;
|
21
|
-
|
21
|
+
|
22
22
|
typedef Collection<SectionType>::type SectionTypes;
|
23
|
-
|
23
|
+
|
24
24
|
/**
|
25
25
|
* Layout of the section being parsed
|
26
26
|
*/
|
@@ -31,24 +31,64 @@ namespace snowcrash {
|
|
31
31
|
};
|
32
32
|
|
33
33
|
/**
|
34
|
-
*
|
34
|
+
* \brief Complete compound product of parsing
|
35
|
+
*
|
36
|
+
* This structure owns all of the product data. As such
|
37
|
+
* it shouldn't be used internally unless there is a need
|
38
|
+
* for storing complete parser data. See %IntermediateParseResult.
|
35
39
|
*/
|
36
40
|
template<typename T>
|
37
41
|
struct ParseResult {
|
38
|
-
ParseResult(Report& report_,
|
39
|
-
T& node_,
|
40
|
-
SourceMap<T>& sourceMap_)
|
41
|
-
: report(report_), node(node_), sourceMap(sourceMap_) {}
|
42
42
|
|
43
|
-
ParseResult(Report& report_)
|
44
|
-
: report(report_)
|
43
|
+
ParseResult(const Report& report_ = Report())
|
44
|
+
: report(report_) {}
|
45
45
|
|
46
|
-
|
47
|
-
|
46
|
+
Report report; /// Parser's report
|
47
|
+
T node; /// Parsed AST node
|
48
|
+
SourceMap<T> sourceMap; /// Parsed AST node source map
|
49
|
+
};
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
|
51
|
+
/**
|
52
|
+
* \brief Partial product of parsing.
|
53
|
+
*
|
54
|
+
* This structure owns the node being parsed and its source map.
|
55
|
+
* Unlike %ParseResult it relies on shared parser report data making it
|
56
|
+
* ideal for holding temporary results while parsing items of a collection.
|
57
|
+
*/
|
58
|
+
template<typename T>
|
59
|
+
struct IntermediateParseResult {
|
60
|
+
|
61
|
+
explicit IntermediateParseResult(Report& report_)
|
62
|
+
: report(report_) {}
|
63
|
+
|
64
|
+
Report& report;
|
65
|
+
T node;
|
66
|
+
SourceMap<T> sourceMap;
|
67
|
+
};
|
68
|
+
|
69
|
+
/**
|
70
|
+
* \brief Reference wrapper for parsing data product
|
71
|
+
*
|
72
|
+
* Reference wrapper for %ParseResult and %IntermediateParseResult.
|
73
|
+
*/
|
74
|
+
template<typename T>
|
75
|
+
struct ParseResultRef {
|
76
|
+
|
77
|
+
ParseResultRef(ParseResult<T>& parseResult)
|
78
|
+
: report(parseResult.report), node(parseResult.node), sourceMap(parseResult.sourceMap) {}
|
79
|
+
|
80
|
+
ParseResultRef(IntermediateParseResult<T>& parseResult)
|
81
|
+
: report(parseResult.report), node(parseResult.node), sourceMap(parseResult.sourceMap) {}
|
82
|
+
|
83
|
+
ParseResultRef(Report& report_, T& node_, SourceMap<T>& sourceMap_)
|
84
|
+
: report(report_), node(node_), sourceMap(sourceMap_) {}
|
85
|
+
|
86
|
+
Report& report;
|
87
|
+
T& node;
|
88
|
+
SourceMap<T>& sourceMap;
|
89
|
+
|
90
|
+
private:
|
91
|
+
ParseResultRef();
|
52
92
|
};
|
53
93
|
|
54
94
|
/*
|
@@ -56,7 +96,7 @@ namespace snowcrash {
|
|
56
96
|
*/
|
57
97
|
template<typename T>
|
58
98
|
struct SectionProcessor;
|
59
|
-
|
99
|
+
|
60
100
|
/**
|
61
101
|
* \brief Section Processor Base
|
62
102
|
*
|
@@ -79,7 +119,7 @@ namespace snowcrash {
|
|
79
119
|
const MarkdownNodes& siblings,
|
80
120
|
SectionParserData& pd,
|
81
121
|
SectionLayout& layout,
|
82
|
-
|
122
|
+
const ParseResultRef<T>& out) {
|
83
123
|
|
84
124
|
return ++MarkdownNodeIterator(node);
|
85
125
|
}
|
@@ -88,7 +128,7 @@ namespace snowcrash {
|
|
88
128
|
static MarkdownNodeIterator processDescription(const MarkdownNodeIterator& node,
|
89
129
|
const MarkdownNodes& siblings,
|
90
130
|
SectionParserData& pd,
|
91
|
-
|
131
|
+
const ParseResultRef<T>& out) {
|
92
132
|
|
93
133
|
if (!out.node.description.empty()) {
|
94
134
|
TwoNewLines(out.node.description);
|
@@ -104,16 +144,16 @@ namespace snowcrash {
|
|
104
144
|
|
105
145
|
return ++MarkdownNodeIterator(node);
|
106
146
|
}
|
107
|
-
|
147
|
+
|
108
148
|
/** Process section-specific content Markdown node */
|
109
149
|
static MarkdownNodeIterator processContent(const MarkdownNodeIterator& node,
|
110
150
|
const MarkdownNodes& siblings,
|
111
151
|
SectionParserData& pd,
|
112
|
-
|
152
|
+
const ParseResultRef<T>& out) {
|
113
153
|
|
114
154
|
return ++MarkdownNodeIterator(node);
|
115
155
|
}
|
116
|
-
|
156
|
+
|
117
157
|
/**
|
118
158
|
* \brief Process nested sections Markdown node(s)
|
119
159
|
* \param node Node to process
|
@@ -125,17 +165,17 @@ namespace snowcrash {
|
|
125
165
|
static MarkdownNodeIterator processNestedSection(const MarkdownNodeIterator& node,
|
126
166
|
const MarkdownNodes& siblings,
|
127
167
|
SectionParserData& pd,
|
128
|
-
|
168
|
+
const ParseResultRef<T>& out) {
|
129
169
|
|
130
170
|
return node;
|
131
171
|
}
|
132
|
-
|
172
|
+
|
133
173
|
/** Process unexpected Markdown node */
|
134
174
|
static MarkdownNodeIterator processUnexpectedNode(const MarkdownNodeIterator& node,
|
135
175
|
const MarkdownNodes& siblings,
|
136
176
|
SectionParserData& pd,
|
137
177
|
SectionType& lastSectionType,
|
138
|
-
|
178
|
+
const ParseResultRef<T>& out) {
|
139
179
|
|
140
180
|
// WARN: Ignoring unexpected node
|
141
181
|
std::stringstream ss;
|
@@ -158,9 +198,9 @@ namespace snowcrash {
|
|
158
198
|
/** Final validation after processing */
|
159
199
|
static void finalize(const MarkdownNodeIterator& node,
|
160
200
|
SectionParserData& pd,
|
161
|
-
|
201
|
+
const ParseResultRef<T>& out) {
|
162
202
|
}
|
163
|
-
|
203
|
+
|
164
204
|
/** \return True if the node is a section description node */
|
165
205
|
static bool isDescriptionNode(const MarkdownNodeIterator& node,
|
166
206
|
SectionType sectionType) {
|
@@ -197,14 +237,14 @@ namespace snowcrash {
|
|
197
237
|
/** \return True if the node is unexpected in the current context */
|
198
238
|
static bool isUnexpectedNode(const MarkdownNodeIterator& node,
|
199
239
|
SectionType sectionType) {
|
200
|
-
|
240
|
+
|
201
241
|
SectionType keywordSectionType = SectionKeywordSignature(node);
|
202
242
|
SectionTypes nestedTypes = SectionProcessor<T>::nestedSectionTypes();
|
203
243
|
|
204
244
|
if (std::find(nestedTypes.begin(), nestedTypes.end(), keywordSectionType) != nestedTypes.end()) {
|
205
245
|
return true;
|
206
246
|
}
|
207
|
-
|
247
|
+
|
208
248
|
return (keywordSectionType == UndefinedSectionType);
|
209
249
|
}
|
210
250
|
|
@@ -217,13 +257,13 @@ namespace snowcrash {
|
|
217
257
|
static SectionType sectionType(const MarkdownNodeIterator& node) {
|
218
258
|
return UndefinedSectionType;
|
219
259
|
}
|
220
|
-
|
260
|
+
|
221
261
|
/** \return Nested %SectionType of the node */
|
222
262
|
static SectionType nestedSectionType(const MarkdownNodeIterator& node) {
|
223
263
|
return UndefinedSectionType;
|
224
264
|
}
|
225
265
|
};
|
226
|
-
|
266
|
+
|
227
267
|
/**
|
228
268
|
* Default Section Processor
|
229
269
|
*/
|
@@ -15,7 +15,7 @@
|
|
15
15
|
#define AST_SERIALIZATION_VERSION "2.1"
|
16
16
|
|
17
17
|
namespace snowcrash {
|
18
|
-
|
18
|
+
|
19
19
|
/**
|
20
20
|
* \brief Escape new lines in input string.
|
21
21
|
* \param input A string to escape its new lines.
|
@@ -24,14 +24,14 @@ namespace snowcrash {
|
|
24
24
|
* This function replaces all occurences of "\n" with "\\n".
|
25
25
|
*/
|
26
26
|
std::string EscapeNewlines(const std::string& input);
|
27
|
-
|
27
|
+
|
28
28
|
/**
|
29
29
|
* \brief Escape every double quote in input string.
|
30
30
|
* \param input A string to escape its double quotes.
|
31
31
|
* \return A new string with double quotes escaped.
|
32
32
|
*/
|
33
33
|
std::string EscapeDoubleQuotes(const std::string& input);
|
34
|
-
|
34
|
+
|
35
35
|
/**
|
36
36
|
* AST entities serialization keys
|
37
37
|
*/
|
@@ -47,22 +47,22 @@ static void indent(size_t level, std::ostream &os)
|
|
47
47
|
static void serialize(const std::string& key, const std::string& value, size_t level, bool object, std::ostream &os)
|
48
48
|
{
|
49
49
|
indent(level, os);
|
50
|
-
|
50
|
+
|
51
51
|
if (object) {
|
52
52
|
os << "{\n";
|
53
53
|
indent(level + 1, os);
|
54
54
|
}
|
55
|
-
|
55
|
+
|
56
56
|
serialize(key, os);
|
57
57
|
os << ": ";
|
58
|
-
|
58
|
+
|
59
59
|
std::string normValue = EscapeDoubleQuotes(value);
|
60
60
|
|
61
61
|
if (normValue.find("\n") != std::string::npos)
|
62
62
|
serialize(EscapeNewlines(normValue), os);
|
63
63
|
else
|
64
64
|
serialize(normValue, os);
|
65
|
-
|
65
|
+
|
66
66
|
if (object) {
|
67
67
|
os << "\n";
|
68
68
|
indent(level, os);
|
@@ -97,13 +97,13 @@ static void serialize(const std::string& key, const std::string& value, size_t l
|
|
97
97
|
indent(level, os);
|
98
98
|
|
99
99
|
os << "{\n";
|
100
|
-
|
100
|
+
|
101
101
|
serialize(SerializeKey::Name, key, level + 1, false, os);
|
102
102
|
os << NewLineItemBlock;
|
103
|
-
|
103
|
+
|
104
104
|
serialize(SerializeKey::Value, value, level + 1, false, os);
|
105
105
|
os << "\n";
|
106
|
-
|
106
|
+
|
107
107
|
indent(level, os);
|
108
108
|
os << "}";
|
109
109
|
}
|
@@ -236,9 +236,9 @@ static void serialize(const MetadataCollection& metadata, std::ostream &os)
|
|
236
236
|
indent(1, os);
|
237
237
|
serialize(SerializeKey::Metadata, os);
|
238
238
|
os << ": ";
|
239
|
-
|
239
|
+
|
240
240
|
serializeKeyValueCollection(metadata, 1, os);
|
241
|
-
|
241
|
+
|
242
242
|
os << NewLineItemBlock;
|
243
243
|
}
|
244
244
|
|
@@ -269,43 +269,43 @@ static void serialize(const Parameters& parameters, size_t level, std::ostream &
|
|
269
269
|
indent(level, os);
|
270
270
|
serialize(SerializeKey::Parameters, os);
|
271
271
|
os << ": [";
|
272
|
-
|
272
|
+
|
273
273
|
if (!parameters.empty()) {
|
274
274
|
os << "\n";
|
275
275
|
size_t i = 0;
|
276
276
|
|
277
277
|
for (Collection<Parameter>::const_iterator it = parameters.begin(); it != parameters.end(); ++i, ++it) {
|
278
|
-
|
278
|
+
|
279
279
|
if (i > 0 && i < parameters.size())
|
280
280
|
os << NewLineItemBlock;
|
281
281
|
|
282
282
|
indent(level + 1, os);
|
283
283
|
os << "{\n";
|
284
|
-
|
284
|
+
|
285
285
|
// Name
|
286
286
|
serialize(SerializeKey::Name, it->name, level + 2, false, os);
|
287
287
|
os << NewLineItemBlock;
|
288
|
-
|
288
|
+
|
289
289
|
// Description
|
290
290
|
serialize(SerializeKey::Description, it->description, level + 2, false, os);
|
291
291
|
os << NewLineItemBlock;
|
292
|
-
|
292
|
+
|
293
293
|
// Type
|
294
294
|
serialize(SerializeKey::Type, it->type, level + 2, false, os);
|
295
295
|
os << NewLineItemBlock;
|
296
|
-
|
296
|
+
|
297
297
|
// Requried
|
298
298
|
serialize(SerializeKey::Required, (it->use != OptionalParameterUse), level + 2, os);
|
299
299
|
os << NewLineItemBlock;
|
300
|
-
|
300
|
+
|
301
301
|
// Default
|
302
302
|
serialize(SerializeKey::Default, it->defaultValue, level + 2, false, os);
|
303
303
|
os << NewLineItemBlock;
|
304
|
-
|
304
|
+
|
305
305
|
// Example
|
306
306
|
serialize(SerializeKey::Example, it->exampleValue, level + 2, false, os);
|
307
307
|
os << NewLineItemBlock;
|
308
|
-
|
308
|
+
|
309
309
|
// Values
|
310
310
|
indent(level + 2, os);
|
311
311
|
serialize(SerializeKey::Values, os);
|
@@ -318,30 +318,30 @@ static void serialize(const Parameters& parameters, size_t level, std::ostream &
|
|
318
318
|
for (Collection<Value>::const_iterator val_it = it->values.begin();
|
319
319
|
val_it != it->values.end();
|
320
320
|
++j, ++val_it) {
|
321
|
-
|
321
|
+
|
322
322
|
if (j > 0 && j < it->values.size())
|
323
323
|
os << NewLineItemBlock;
|
324
|
-
|
324
|
+
|
325
325
|
serialize(SerializeKey::Value, *val_it, level + 3, true, os);
|
326
326
|
}
|
327
|
-
|
327
|
+
|
328
328
|
os << "\n";
|
329
329
|
indent(level + 2, os);
|
330
330
|
}
|
331
|
-
|
331
|
+
|
332
332
|
// Close Values
|
333
333
|
os << "]";
|
334
|
-
|
334
|
+
|
335
335
|
// Close Key / name object
|
336
336
|
os << "\n";
|
337
337
|
indent(level + 1, os);
|
338
338
|
os << "}";
|
339
339
|
}
|
340
|
-
|
340
|
+
|
341
341
|
os << std::endl;
|
342
342
|
indent(level, os);
|
343
343
|
}
|
344
|
-
|
344
|
+
|
345
345
|
os << "]";
|
346
346
|
}
|
347
347
|
|
@@ -445,7 +445,7 @@ static void serialize(const Headers& headers, size_t level, std::ostream &os)
|
|
445
445
|
indent(level, os);
|
446
446
|
serialize(SerializeKey::Headers, os);
|
447
447
|
os << ": ";
|
448
|
-
|
448
|
+
|
449
449
|
serializeKeyValueCollection(headers, level, os);
|
450
450
|
}
|
451
451
|
|
@@ -464,6 +464,46 @@ static void serialize(const Collection<SourceMap<Header> >::type& headers, size_
|
|
464
464
|
serializeSourceMapCollection(headers, level, os);
|
465
465
|
}
|
466
466
|
|
467
|
+
/**
|
468
|
+
* \brief Serialize a reference into output stream.
|
469
|
+
* \param reference A reference to serialize.
|
470
|
+
* \param os An output stream to serialize into.
|
471
|
+
*/
|
472
|
+
static void serialize(const Reference& reference, size_t level, std::ostream &os)
|
473
|
+
{
|
474
|
+
|
475
|
+
if (reference.id.empty()) {
|
476
|
+
return;
|
477
|
+
}
|
478
|
+
|
479
|
+
indent(level, os);
|
480
|
+
os << "\"" << SerializeKey::Reference << "\": {\n";
|
481
|
+
|
482
|
+
serialize(SerializeKey::Id, reference.id, level + 1, false, os);
|
483
|
+
os << "\n";
|
484
|
+
|
485
|
+
indent(level, os);
|
486
|
+
os << "}";
|
487
|
+
|
488
|
+
os << NewLineItemBlock;
|
489
|
+
}
|
490
|
+
|
491
|
+
/**
|
492
|
+
* \brief Serialize a reference source map into output stream.
|
493
|
+
* \param reference A reference source map to serialize.
|
494
|
+
* \param os An output stream to serialize into.
|
495
|
+
*/
|
496
|
+
static void serialize(const SourceMap<Reference>& reference, size_t level, std::ostream &os)
|
497
|
+
{
|
498
|
+
|
499
|
+
if (reference.sourceMap.empty()) {
|
500
|
+
return;
|
501
|
+
}
|
502
|
+
|
503
|
+
serialize(SerializeKey::Reference, reference, level, false, os);
|
504
|
+
os << NewLineItemBlock;
|
505
|
+
}
|
506
|
+
|
467
507
|
/**
|
468
508
|
* \brief Serialize a payload into output stream.
|
469
509
|
* \param payload A payload to serialize.
|
@@ -477,30 +517,21 @@ static void serialize(const Payload& payload, size_t level, std::ostream &os)
|
|
477
517
|
serialize(SerializeKey::Name, payload.name, level + 1, false, os);
|
478
518
|
os << NewLineItemBlock;
|
479
519
|
|
480
|
-
//
|
481
|
-
|
482
|
-
indent(level + 1, os);
|
483
|
-
os << "\"" << SerializeKey::Reference << "\": {\n";
|
484
|
-
|
485
|
-
serialize(SerializeKey::Id, payload.symbol, level + 2, false, os);
|
486
|
-
|
487
|
-
os << "\n";
|
488
|
-
indent(level + 1, os);
|
489
|
-
os << "}" << NewLineItemBlock;
|
490
|
-
}
|
520
|
+
// Reference
|
521
|
+
serialize(payload.reference, level + 1, os);
|
491
522
|
|
492
523
|
// Description
|
493
524
|
serialize(SerializeKey::Description, payload.description, level + 1, false, os);
|
494
525
|
os << NewLineItemBlock;
|
495
|
-
|
526
|
+
|
496
527
|
// Headers
|
497
528
|
serialize(payload.headers, level + 1, os);
|
498
529
|
os << NewLineItemBlock;
|
499
|
-
|
530
|
+
|
500
531
|
// Body
|
501
532
|
serialize(SerializeKey::Body, payload.body, level + 1, false, os);
|
502
533
|
os << NewLineItemBlock;
|
503
|
-
|
534
|
+
|
504
535
|
// Schema
|
505
536
|
serialize(SerializeKey::Schema, payload.schema, level + 1, false, os);
|
506
537
|
|
@@ -523,10 +554,7 @@ static void serialize(const SourceMap<Payload>& payload, size_t level, std::ostr
|
|
523
554
|
os << NewLineItemBlock;
|
524
555
|
|
525
556
|
// Symbol Reference
|
526
|
-
|
527
|
-
serialize(SerializeKey::Reference, payload.symbol, level + 1, false, os);
|
528
|
-
os << NewLineItemBlock;
|
529
|
-
}
|
557
|
+
serialize(payload.reference, level + 1, os);
|
530
558
|
|
531
559
|
// Description
|
532
560
|
serialize(SerializeKey::Description, payload.description, level + 1, false, os);
|
@@ -557,21 +585,21 @@ static void serialize(const TransactionExample& example, std::ostream &os)
|
|
557
585
|
{
|
558
586
|
indent(8, os);
|
559
587
|
os << "{\n";
|
560
|
-
|
588
|
+
|
561
589
|
// Name
|
562
590
|
serialize(SerializeKey::Name, example.name, 9, false, os);
|
563
591
|
os << NewLineItemBlock;
|
564
|
-
|
592
|
+
|
565
593
|
// Description
|
566
594
|
serialize(SerializeKey::Description, example.description, 9, false, os);
|
567
595
|
os << NewLineItemBlock;
|
568
|
-
|
596
|
+
|
569
597
|
// Requests
|
570
598
|
indent(9, os);
|
571
599
|
serialize(SerializeKey::Requests, os);
|
572
600
|
os << ": ";
|
573
601
|
os << "[";
|
574
|
-
|
602
|
+
|
575
603
|
if (!example.requests.empty()) {
|
576
604
|
os << "\n";
|
577
605
|
size_t i = 0;
|
@@ -579,26 +607,26 @@ static void serialize(const TransactionExample& example, std::ostream &os)
|
|
579
607
|
for (Collection<Request>::const_iterator it = example.requests.begin();
|
580
608
|
it != example.requests.end();
|
581
609
|
++i, ++it) {
|
582
|
-
|
610
|
+
|
583
611
|
if (i > 0 && i < example.requests.size())
|
584
612
|
os << NewLineItemBlock;
|
585
|
-
|
613
|
+
|
586
614
|
indent(10, os);
|
587
615
|
serialize(*it, 10, os);
|
588
616
|
}
|
589
|
-
|
617
|
+
|
590
618
|
os << "\n";
|
591
619
|
indent(9, os);
|
592
620
|
}
|
593
621
|
os << "]";
|
594
622
|
os << NewLineItemBlock;
|
595
|
-
|
623
|
+
|
596
624
|
// Responses
|
597
625
|
indent(9, os);
|
598
626
|
serialize(SerializeKey::Responses, os);
|
599
627
|
os << ": ";
|
600
628
|
os << "[";
|
601
|
-
|
629
|
+
|
602
630
|
if (!example.responses.empty()) {
|
603
631
|
os << "\n";
|
604
632
|
size_t i = 0;
|
@@ -606,19 +634,19 @@ static void serialize(const TransactionExample& example, std::ostream &os)
|
|
606
634
|
for (Collection<Response>::const_iterator it = example.responses.begin();
|
607
635
|
it != example.responses.end();
|
608
636
|
++i, ++it) {
|
609
|
-
|
637
|
+
|
610
638
|
if (i > 0 && i < example.responses.size())
|
611
639
|
os << NewLineItemBlock;
|
612
|
-
|
640
|
+
|
613
641
|
indent(10, os);
|
614
642
|
serialize(*it, 10, os);
|
615
643
|
}
|
616
|
-
|
644
|
+
|
617
645
|
os << "\n";
|
618
646
|
indent(9, os);
|
619
647
|
}
|
620
648
|
os << "]";
|
621
|
-
|
649
|
+
|
622
650
|
// Close the transaction
|
623
651
|
os << "\n";
|
624
652
|
indent(8, os);
|
@@ -711,29 +739,29 @@ static void serialize(const Action& action, std::ostream &os)
|
|
711
739
|
{
|
712
740
|
indent(6, os);
|
713
741
|
os << "{\n";
|
714
|
-
|
742
|
+
|
715
743
|
// Name
|
716
744
|
serialize(SerializeKey::Name, action.name, 7, false, os);
|
717
745
|
os << NewLineItemBlock;
|
718
|
-
|
746
|
+
|
719
747
|
// Description
|
720
748
|
serialize(SerializeKey::Description, action.description, 7, false, os);
|
721
749
|
os << NewLineItemBlock;
|
722
|
-
|
750
|
+
|
723
751
|
// HTTP Method
|
724
752
|
serialize(SerializeKey::Method, action.method, 7, false, os);
|
725
753
|
os << NewLineItemBlock;
|
726
|
-
|
754
|
+
|
727
755
|
// Parameters
|
728
756
|
serialize(action.parameters, 7, os);
|
729
757
|
os << NewLineItemBlock;
|
730
|
-
|
758
|
+
|
731
759
|
// Transactions
|
732
760
|
indent(7, os);
|
733
761
|
serialize(SerializeKey::Examples, os);
|
734
762
|
os << ": ";
|
735
763
|
os << "[";
|
736
|
-
|
764
|
+
|
737
765
|
if (!action.examples.empty()) {
|
738
766
|
os << "\n";
|
739
767
|
size_t i = 0;
|
@@ -741,19 +769,19 @@ static void serialize(const Action& action, std::ostream &os)
|
|
741
769
|
for (Collection<TransactionExample>::const_iterator it = action.examples.begin();
|
742
770
|
it != action.examples.end();
|
743
771
|
++i, ++it) {
|
744
|
-
|
772
|
+
|
745
773
|
if (i > 0 && i < action.examples.size())
|
746
774
|
os << NewLineItemBlock;
|
747
|
-
|
775
|
+
|
748
776
|
serialize(*it, os);
|
749
777
|
}
|
750
|
-
|
778
|
+
|
751
779
|
os << "\n";
|
752
780
|
indent(7, os);
|
753
781
|
}
|
754
|
-
|
782
|
+
|
755
783
|
os << "]";
|
756
|
-
|
784
|
+
|
757
785
|
// Close the action
|
758
786
|
os << "\n";
|
759
787
|
indent(6, os);
|
@@ -831,15 +859,15 @@ static void serialize(const Resource& resource, std::ostream &os)
|
|
831
859
|
// Name
|
832
860
|
serialize(SerializeKey::Name, resource.name, 5, false, os);
|
833
861
|
os << NewLineItemBlock;
|
834
|
-
|
862
|
+
|
835
863
|
// Description
|
836
864
|
serialize(SerializeKey::Description, resource.description, 5, false, os);
|
837
865
|
os << NewLineItemBlock;
|
838
|
-
|
866
|
+
|
839
867
|
// URI template
|
840
868
|
serialize(SerializeKey::URITemplate, resource.uriTemplate, 5, false, os);
|
841
869
|
os << NewLineItemBlock;
|
842
|
-
|
870
|
+
|
843
871
|
// Model
|
844
872
|
indent(5, os);
|
845
873
|
serialize(SerializeKey::Model, os);
|
@@ -848,15 +876,15 @@ static void serialize(const Resource& resource, std::ostream &os)
|
|
848
876
|
}
|
849
877
|
else {
|
850
878
|
os << ": ";
|
851
|
-
|
879
|
+
|
852
880
|
serialize(resource.model, 5, os);
|
853
881
|
}
|
854
882
|
os << NewLineItemBlock;
|
855
|
-
|
883
|
+
|
856
884
|
// Parameters
|
857
885
|
serialize(resource.parameters, 5, os);
|
858
886
|
os << NewLineItemBlock;
|
859
|
-
|
887
|
+
|
860
888
|
// Actions
|
861
889
|
indent(5, os);
|
862
890
|
serialize(SerializeKey::Actions, os);
|
@@ -870,23 +898,23 @@ static void serialize(const Resource& resource, std::ostream &os)
|
|
870
898
|
for (Collection<Action>::const_iterator it = resource.actions.begin();
|
871
899
|
it != resource.actions.end();
|
872
900
|
++i, ++it) {
|
873
|
-
|
901
|
+
|
874
902
|
if (i > 0 && i < resource.actions.size())
|
875
903
|
os << NewLineItemBlock;
|
876
|
-
|
904
|
+
|
877
905
|
serialize(*it, os);
|
878
906
|
}
|
879
|
-
|
907
|
+
|
880
908
|
os << "\n";
|
881
909
|
indent(5, os);
|
882
910
|
}
|
883
911
|
|
884
912
|
os << "]";
|
885
|
-
|
913
|
+
|
886
914
|
// Close the resource
|
887
915
|
os << "\n";
|
888
916
|
indent(4, os);
|
889
|
-
os << "}";
|
917
|
+
os << "}";
|
890
918
|
}
|
891
919
|
|
892
920
|
/**
|
@@ -969,21 +997,21 @@ static void serialize(const ResourceGroup& resourceGroup, std::ostream &os)
|
|
969
997
|
{
|
970
998
|
indent(2, os);
|
971
999
|
os << "{\n";
|
972
|
-
|
1000
|
+
|
973
1001
|
// Name
|
974
1002
|
serialize(SerializeKey::Name, resourceGroup.name, 3, false, os);
|
975
1003
|
os << NewLineItemBlock;
|
976
|
-
|
1004
|
+
|
977
1005
|
// Description
|
978
1006
|
serialize(SerializeKey::Description, resourceGroup.description, 3, false, os);
|
979
1007
|
os << NewLineItemBlock;
|
980
|
-
|
1008
|
+
|
981
1009
|
// Resources
|
982
1010
|
indent(3, os);
|
983
1011
|
serialize(SerializeKey::Resources, os);
|
984
1012
|
os << ": ";
|
985
1013
|
os << "[";
|
986
|
-
|
1014
|
+
|
987
1015
|
if (!resourceGroup.resources.empty()) {
|
988
1016
|
os << "\n";
|
989
1017
|
size_t i = 0;
|
@@ -991,21 +1019,21 @@ static void serialize(const ResourceGroup& resourceGroup, std::ostream &os)
|
|
991
1019
|
for (Collection<Resource>::const_iterator it = resourceGroup.resources.begin();
|
992
1020
|
it != resourceGroup.resources.end();
|
993
1021
|
++i, ++it) {
|
994
|
-
|
1022
|
+
|
995
1023
|
if (i > 0 && i < resourceGroup.resources.size())
|
996
1024
|
os << NewLineItemBlock;
|
997
|
-
|
1025
|
+
|
998
1026
|
serialize(*it, os);
|
999
1027
|
}
|
1000
|
-
|
1028
|
+
|
1001
1029
|
if (!resourceGroup.resources.empty()) {
|
1002
1030
|
os << "\n";
|
1003
1031
|
indent(3, os);
|
1004
1032
|
}
|
1005
1033
|
}
|
1006
|
-
|
1034
|
+
|
1007
1035
|
os << "]";
|
1008
|
-
|
1036
|
+
|
1009
1037
|
// Close the group
|
1010
1038
|
os << "\n";
|
1011
1039
|
indent(2, os);
|
@@ -1075,23 +1103,23 @@ static void serialize(const ResourceGroups& resourceGroups, std::ostream &os)
|
|
1075
1103
|
serialize(SerializeKey::ResourceGroups, os);
|
1076
1104
|
os << ": ";
|
1077
1105
|
os << "[";
|
1078
|
-
|
1106
|
+
|
1079
1107
|
if (!resourceGroups.empty()) {
|
1080
1108
|
os << "\n";
|
1081
1109
|
size_t i = 0;
|
1082
1110
|
|
1083
1111
|
for (Collection<ResourceGroup>::const_iterator it = resourceGroups.begin(); it != resourceGroups.end(); ++i, ++it) {
|
1084
|
-
|
1112
|
+
|
1085
1113
|
if (i > 0 && i < resourceGroups.size())
|
1086
1114
|
os << NewLineItemBlock;
|
1087
|
-
|
1115
|
+
|
1088
1116
|
serialize(*it, os);
|
1089
1117
|
}
|
1090
|
-
|
1118
|
+
|
1091
1119
|
os << "\n";
|
1092
1120
|
indent(1, os);
|
1093
1121
|
}
|
1094
|
-
|
1122
|
+
|
1095
1123
|
os << "]";
|
1096
1124
|
}
|
1097
1125
|
|
@@ -1134,11 +1162,11 @@ static void serialize(const Collection<SourceMap<ResourceGroup> >::type& resourc
|
|
1134
1162
|
static void serialize(const Blueprint& blueprint, std::ostream &os)
|
1135
1163
|
{
|
1136
1164
|
os << "{\n";
|
1137
|
-
|
1165
|
+
|
1138
1166
|
// AST Version
|
1139
1167
|
serialize(SerializeKey::ASTVersion, AST_SERIALIZATION_VERSION, 1, false, os);
|
1140
1168
|
os << NewLineItemBlock;
|
1141
|
-
|
1169
|
+
|
1142
1170
|
// Metadata
|
1143
1171
|
serialize(blueprint.metadata, os);
|
1144
1172
|
|
@@ -1152,7 +1180,7 @@ static void serialize(const Blueprint& blueprint, std::ostream &os)
|
|
1152
1180
|
|
1153
1181
|
// Resource Groups
|
1154
1182
|
serialize(blueprint.resourceGroups, os);
|
1155
|
-
|
1183
|
+
|
1156
1184
|
os << "\n}\n";
|
1157
1185
|
}
|
1158
1186
|
|