redsnow 0.2.0 → 0.2.1
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 +3 -1
- data/README.md +12 -0
- data/ext/snowcrash/bin/snowcrash +0 -0
- data/ext/snowcrash/ext/markdown-parser/ext/sundown/src/markdown.c +5 -2
- data/ext/snowcrash/snowcrash.gyp +7 -2
- data/ext/snowcrash/src/ActionParser.h +141 -81
- data/ext/snowcrash/src/AssetParser.h +19 -11
- data/ext/snowcrash/src/Blueprint.h +44 -14
- data/ext/snowcrash/src/BlueprintParser.h +65 -51
- data/ext/snowcrash/src/BlueprintSourcemap.h +254 -0
- data/ext/snowcrash/src/BlueprintUtility.h +3 -24
- data/ext/snowcrash/src/CBlueprint.cc +40 -31
- data/ext/snowcrash/src/CBlueprint.h +54 -58
- data/ext/snowcrash/src/CBlueprintSourcemap.cc +620 -0
- data/ext/snowcrash/src/CBlueprintSourcemap.h +342 -0
- data/ext/snowcrash/src/CSourceAnnotation.cc +14 -0
- data/ext/snowcrash/src/CodeBlockUtility.h +42 -5
- data/ext/snowcrash/src/HeadersParser.h +84 -42
- data/ext/snowcrash/src/ParameterParser.h +110 -68
- data/ext/snowcrash/src/ParametersParser.h +26 -28
- data/ext/snowcrash/src/PayloadParser.h +164 -83
- data/ext/snowcrash/src/ResourceGroupParser.h +35 -41
- data/ext/snowcrash/src/ResourceParser.h +142 -97
- data/ext/snowcrash/src/SectionParser.h +15 -14
- data/ext/snowcrash/src/SectionParserData.h +11 -2
- data/ext/snowcrash/src/SectionProcessor.h +42 -18
- data/ext/snowcrash/src/Serialize.cc +2 -0
- data/ext/snowcrash/src/Serialize.h +3 -1
- data/ext/snowcrash/src/SerializeJSON.cc +608 -16
- data/ext/snowcrash/src/SerializeJSON.h +4 -1
- data/ext/snowcrash/src/SerializeYAML.cc +367 -19
- data/ext/snowcrash/src/SerializeYAML.h +4 -1
- data/ext/snowcrash/src/SymbolTable.h +12 -1
- data/ext/snowcrash/src/ValuesParser.h +12 -11
- data/ext/snowcrash/src/Version.h +1 -1
- data/ext/snowcrash/src/csnowcrash.cc +7 -3
- data/ext/snowcrash/src/csnowcrash.h +4 -2
- data/ext/snowcrash/src/snowcrash.cc +10 -11
- data/ext/snowcrash/src/snowcrash.h +3 -3
- data/ext/snowcrash/src/snowcrash/snowcrash.cc +38 -8
- data/ext/snowcrash/tools/homebrew/snowcrash.rb +1 -1
- data/lib/redsnow.rb +41 -2
- data/lib/redsnow/binding.rb +93 -8
- data/lib/redsnow/blueprint.rb +48 -25
- data/lib/redsnow/parseresult.rb +9 -2
- data/lib/redsnow/sourcemap.rb +369 -0
- data/lib/redsnow/version.rb +1 -1
- data/test/fixtures/sample-api-ast.json +1 -1
- data/test/fixtures/sample-api-sourcemap.json +169 -0
- data/test/redsnow_binding_test.rb +19 -2
- data/test/redsnow_options_test.rb +42 -0
- data/test/redsnow_parseresult_test.rb +5 -1
- data/test/redsnow_test.rb +5 -0
- metadata +11 -2
@@ -40,32 +40,40 @@ namespace snowcrash {
|
|
40
40
|
const MarkdownNodes& siblings,
|
41
41
|
SectionParserData& pd,
|
42
42
|
SectionLayout& layout,
|
43
|
-
|
44
|
-
Asset& out) {
|
43
|
+
ParseResult<Asset>& out) {
|
45
44
|
|
46
|
-
out = "";
|
47
|
-
CodeBlockUtility::signatureContentAsCodeBlock(node, pd, report, out);
|
45
|
+
out.node = "";
|
46
|
+
CodeBlockUtility::signatureContentAsCodeBlock(node, pd, out.report, out.node);
|
47
|
+
|
48
|
+
if (pd.exportSourceMap() && !out.node.empty()) {
|
49
|
+
out.sourceMap.sourceMap.append(node->sourceMap);
|
50
|
+
}
|
51
|
+
|
48
52
|
return ++MarkdownNodeIterator(node);
|
49
53
|
}
|
50
54
|
|
51
55
|
static MarkdownNodeIterator processDescription(const MarkdownNodeIterator& node,
|
52
56
|
const MarkdownNodes& siblings,
|
53
57
|
SectionParserData& pd,
|
54
|
-
|
55
|
-
|
58
|
+
ParseResult<Asset>& out) {
|
59
|
+
|
56
60
|
return node;
|
57
61
|
}
|
58
62
|
|
59
63
|
static MarkdownNodeIterator processContent(const MarkdownNodeIterator& node,
|
60
64
|
const MarkdownNodes& siblings,
|
61
65
|
SectionParserData& pd,
|
62
|
-
|
63
|
-
Asset& out) {
|
64
|
-
|
66
|
+
ParseResult<Asset>& out) {
|
65
67
|
|
66
68
|
mdp::ByteBuffer content;
|
67
|
-
CodeBlockUtility::contentAsCodeBlock(node, pd, report, content);
|
68
|
-
|
69
|
+
CodeBlockUtility::contentAsCodeBlock(node, pd, out.report, content);
|
70
|
+
|
71
|
+
out.node += content;
|
72
|
+
|
73
|
+
if (pd.exportSourceMap() && !content.empty()) {
|
74
|
+
out.sourceMap.sourceMap.append(node->sourceMap);
|
75
|
+
}
|
76
|
+
|
69
77
|
return ++MarkdownNodeIterator(node);
|
70
78
|
}
|
71
79
|
|
@@ -80,7 +80,16 @@ namespace snowcrash {
|
|
80
80
|
* E.g. "Content-Type: application/json"
|
81
81
|
*/
|
82
82
|
typedef KeyValuePair Header;
|
83
|
+
|
84
|
+
/** Metadata Collection */
|
85
|
+
typedef Collection<Metadata>::type MetadataCollection;
|
86
|
+
|
87
|
+
/** Headers */
|
88
|
+
typedef Collection<Header>::type Headers;
|
83
89
|
|
90
|
+
/** Collection of Parameter Values */
|
91
|
+
typedef Collection<Value>::type Values;
|
92
|
+
|
84
93
|
/** Parameter Use flag */
|
85
94
|
enum ParameterUse {
|
86
95
|
UndefinedParameterUse,
|
@@ -110,9 +119,12 @@ namespace snowcrash {
|
|
110
119
|
Value exampleValue;
|
111
120
|
|
112
121
|
/** Enumeration of possible values */
|
113
|
-
|
122
|
+
Values values;
|
114
123
|
};
|
115
124
|
|
125
|
+
/** Source Map of Collection of Parameters */
|
126
|
+
typedef Collection<Parameter>::type Parameters;
|
127
|
+
|
116
128
|
/** Name of a symbol */
|
117
129
|
typedef std::string SymbolName;
|
118
130
|
|
@@ -128,10 +140,10 @@ namespace snowcrash {
|
|
128
140
|
Description description;
|
129
141
|
|
130
142
|
/** Payload-specific Parameters */
|
131
|
-
|
143
|
+
Parameters parameters;
|
132
144
|
|
133
145
|
/** Payload-specific Headers */
|
134
|
-
|
146
|
+
Headers headers;
|
135
147
|
|
136
148
|
/** Body */
|
137
149
|
Asset body;
|
@@ -157,6 +169,12 @@ namespace snowcrash {
|
|
157
169
|
*/
|
158
170
|
typedef Payload Response;
|
159
171
|
|
172
|
+
/** Collection of Requests */
|
173
|
+
typedef Collection<Request>::type Requests;
|
174
|
+
|
175
|
+
/** Collection of Responses */
|
176
|
+
typedef Collection<Response>::type Responses;
|
177
|
+
|
160
178
|
/**
|
161
179
|
* An HTTP transaction example.
|
162
180
|
*/
|
@@ -169,12 +187,15 @@ namespace snowcrash {
|
|
169
187
|
Description description;
|
170
188
|
|
171
189
|
/** Requests */
|
172
|
-
|
190
|
+
Requests requests;
|
173
191
|
|
174
192
|
/** Responses */
|
175
|
-
|
193
|
+
Responses responses;
|
176
194
|
};
|
177
195
|
|
196
|
+
/** Collection of Transaction examples */
|
197
|
+
typedef Collection<TransactionExample>::type TransactionExamples;
|
198
|
+
|
178
199
|
/**
|
179
200
|
* Action
|
180
201
|
*/
|
@@ -190,7 +211,7 @@ namespace snowcrash {
|
|
190
211
|
Description description;
|
191
212
|
|
192
213
|
/** Action-specific Parameters */
|
193
|
-
|
214
|
+
Parameters parameters;
|
194
215
|
|
195
216
|
/**
|
196
217
|
* \brief Action-specific HTTP headers
|
@@ -204,12 +225,15 @@ namespace snowcrash {
|
|
204
225
|
*
|
205
226
|
* Use respective payload's header collection instead.
|
206
227
|
*/
|
207
|
-
DEPRECATED
|
228
|
+
DEPRECATED Headers headers;
|
208
229
|
|
209
230
|
/** Transactions examples */
|
210
|
-
|
231
|
+
TransactionExamples examples;
|
211
232
|
};
|
212
233
|
|
234
|
+
/** Collection of Actions */
|
235
|
+
typedef Collection<Action>::type Actions;
|
236
|
+
|
213
237
|
/**
|
214
238
|
* API Resource
|
215
239
|
*/
|
@@ -228,7 +252,7 @@ namespace snowcrash {
|
|
228
252
|
ResourceModel model;
|
229
253
|
|
230
254
|
/** Parameters */
|
231
|
-
|
255
|
+
Parameters parameters;
|
232
256
|
|
233
257
|
/**
|
234
258
|
* \brief Resource-specific HTTP Headers
|
@@ -242,12 +266,15 @@ namespace snowcrash {
|
|
242
266
|
*
|
243
267
|
* Use respective payload's header collection instead.
|
244
268
|
*/
|
245
|
-
DEPRECATED
|
269
|
+
DEPRECATED Headers headers;
|
246
270
|
|
247
271
|
/** A set of Actions specified for this Resource */
|
248
|
-
|
272
|
+
Actions actions;
|
249
273
|
};
|
250
274
|
|
275
|
+
/** Collection of Resources */
|
276
|
+
typedef Collection<Resource>::type Resources;
|
277
|
+
|
251
278
|
/**
|
252
279
|
* Group of API Resources
|
253
280
|
*/
|
@@ -260,9 +287,12 @@ namespace snowcrash {
|
|
260
287
|
Description description;
|
261
288
|
|
262
289
|
/** Resources */
|
263
|
-
|
290
|
+
Resources resources;
|
264
291
|
};
|
265
292
|
|
293
|
+
/** Collection of Resource groups */
|
294
|
+
typedef Collection<ResourceGroup>::type ResourceGroups;
|
295
|
+
|
266
296
|
/**
|
267
297
|
* \brief API Blueprint AST
|
268
298
|
*
|
@@ -272,7 +302,7 @@ namespace snowcrash {
|
|
272
302
|
struct Blueprint {
|
273
303
|
|
274
304
|
/** Metadata */
|
275
|
-
|
305
|
+
MetadataCollection metadata;
|
276
306
|
|
277
307
|
/** The API Name */
|
278
308
|
Name name;
|
@@ -281,7 +311,7 @@ namespace snowcrash {
|
|
281
311
|
Description description;
|
282
312
|
|
283
313
|
/** The set of API Resource Groups */
|
284
|
-
|
314
|
+
ResourceGroups resourceGroups;
|
285
315
|
};
|
286
316
|
}
|
287
317
|
|
@@ -19,9 +19,7 @@ namespace snowcrash {
|
|
19
19
|
|
20
20
|
const char* const ExpectedAPINameMessage = "expected API name, e.g. '# <API Name>'";
|
21
21
|
|
22
|
-
/** Internal type alias for Collection of Metadata */
|
23
|
-
typedef Collection<Metadata>::type MetadataCollection;
|
24
|
-
|
22
|
+
/** Internal type alias for Collection iterator of Metadata */
|
25
23
|
typedef Collection<Metadata>::iterator MetadataCollectionIterator;
|
26
24
|
|
27
25
|
/**
|
@@ -34,22 +32,27 @@ namespace snowcrash {
|
|
34
32
|
const MarkdownNodes& siblings,
|
35
33
|
SectionParserData& pd,
|
36
34
|
SectionLayout& layout,
|
37
|
-
|
38
|
-
Blueprint& out) {
|
35
|
+
ParseResult<Blueprint>& out) {
|
39
36
|
|
40
37
|
MarkdownNodeIterator cur = node;
|
41
38
|
|
42
39
|
while (cur != siblings.end() &&
|
43
40
|
cur->type == mdp::ParagraphMarkdownNodeType) {
|
44
41
|
|
45
|
-
MetadataCollection metadata;
|
46
|
-
parseMetadata(cur, pd,
|
42
|
+
ParseResult<MetadataCollection> metadata(out.report);
|
43
|
+
parseMetadata(cur, pd, metadata);
|
47
44
|
|
48
45
|
// First block is paragraph and is not metadata (no API name)
|
49
|
-
if (metadata.empty()) {
|
50
|
-
return processDescription(cur, siblings, pd,
|
46
|
+
if (metadata.node.empty()) {
|
47
|
+
return processDescription(cur, siblings, pd, out);
|
51
48
|
} else {
|
52
|
-
out.metadata.insert(out.metadata.end(), metadata.begin(), metadata.end());
|
49
|
+
out.node.metadata.insert(out.node.metadata.end(), metadata.node.begin(), metadata.node.end());
|
50
|
+
|
51
|
+
if (pd.exportSourceMap()) {
|
52
|
+
out.sourceMap.metadata.collection.insert(out.sourceMap.metadata.collection.end(),
|
53
|
+
metadata.sourceMap.collection.begin(),
|
54
|
+
metadata.sourceMap.collection.end());
|
55
|
+
}
|
53
56
|
}
|
54
57
|
|
55
58
|
cur++;
|
@@ -70,12 +73,16 @@ namespace snowcrash {
|
|
70
73
|
return cur;
|
71
74
|
}
|
72
75
|
|
73
|
-
out.name = cur->text;
|
74
|
-
TrimString(out.name);
|
76
|
+
out.node.name = cur->text;
|
77
|
+
TrimString(out.node.name);
|
78
|
+
|
79
|
+
if (pd.exportSourceMap() && !out.node.name.empty()) {
|
80
|
+
out.sourceMap.name.sourceMap = cur->sourceMap;
|
81
|
+
}
|
75
82
|
} else {
|
76
83
|
|
77
84
|
// Any other type of block, add to description
|
78
|
-
return processDescription(cur, siblings, pd,
|
85
|
+
return processDescription(cur, siblings, pd, out);
|
79
86
|
}
|
80
87
|
|
81
88
|
return ++MarkdownNodeIterator(cur);
|
@@ -84,37 +91,40 @@ namespace snowcrash {
|
|
84
91
|
static MarkdownNodeIterator processNestedSection(const MarkdownNodeIterator& node,
|
85
92
|
const MarkdownNodes& siblings,
|
86
93
|
SectionParserData& pd,
|
87
|
-
|
88
|
-
Blueprint& out) {
|
94
|
+
ParseResult<Blueprint>& out) {
|
89
95
|
|
90
96
|
if (pd.sectionContext() == ResourceGroupSectionType ||
|
91
97
|
pd.sectionContext() == ResourceSectionType) {
|
92
98
|
|
93
|
-
ResourceGroup resourceGroup;
|
94
|
-
MarkdownNodeIterator cur = ResourceGroupParser::parse(node, siblings, pd,
|
99
|
+
ParseResult<ResourceGroup> resourceGroup(out.report);
|
100
|
+
MarkdownNodeIterator cur = ResourceGroupParser::parse(node, siblings, pd, resourceGroup);
|
95
101
|
|
96
|
-
ResourceGroupIterator duplicate = findResourceGroup(out.resourceGroups, resourceGroup);
|
102
|
+
ResourceGroupIterator duplicate = findResourceGroup(out.node.resourceGroups, resourceGroup.node);
|
97
103
|
|
98
|
-
if (duplicate != out.resourceGroups.end()) {
|
104
|
+
if (duplicate != out.node.resourceGroups.end()) {
|
99
105
|
|
100
106
|
// WARN: duplicate resource group
|
101
107
|
std::stringstream ss;
|
102
108
|
|
103
|
-
if (resourceGroup.name.empty()) {
|
109
|
+
if (resourceGroup.node.name.empty()) {
|
104
110
|
ss << "anonymous group";
|
105
111
|
} else {
|
106
|
-
ss << "group '" << resourceGroup.name << "'";
|
112
|
+
ss << "group '" << resourceGroup.node.name << "'";
|
107
113
|
}
|
108
114
|
|
109
115
|
ss << " is already defined";
|
110
116
|
|
111
117
|
mdp::CharactersRangeSet sourceMap = mdp::BytesRangeSetToCharactersRangeSet(node->sourceMap, pd.sourceData);
|
112
|
-
report.warnings.push_back(Warning(ss.str(),
|
113
|
-
|
114
|
-
|
118
|
+
out.report.warnings.push_back(Warning(ss.str(),
|
119
|
+
DuplicateWarning,
|
120
|
+
sourceMap));
|
115
121
|
}
|
116
122
|
|
117
|
-
out.resourceGroups.push_back(resourceGroup);
|
123
|
+
out.node.resourceGroups.push_back(resourceGroup.node);
|
124
|
+
|
125
|
+
if (pd.exportSourceMap()) {
|
126
|
+
out.sourceMap.resourceGroups.collection.push_back(resourceGroup.sourceMap);
|
127
|
+
}
|
118
128
|
|
119
129
|
return cur;
|
120
130
|
}
|
@@ -161,26 +171,25 @@ namespace snowcrash {
|
|
161
171
|
|
162
172
|
static void finalize(const MarkdownNodeIterator& node,
|
163
173
|
SectionParserData& pd,
|
164
|
-
|
165
|
-
Blueprint& out) {
|
174
|
+
ParseResult<Blueprint>& out) {
|
166
175
|
|
167
|
-
if (!out.name.empty())
|
176
|
+
if (!out.node.name.empty())
|
168
177
|
return;
|
169
178
|
|
170
179
|
if (pd.options & RequireBlueprintNameOption) {
|
171
180
|
|
172
181
|
// ERR: No API name specified
|
173
182
|
mdp::CharactersRangeSet sourceMap = mdp::BytesRangeSetToCharactersRangeSet(node->sourceMap, pd.sourceData);
|
174
|
-
report.error = Error(ExpectedAPINameMessage,
|
175
|
-
|
176
|
-
|
183
|
+
out.report.error = Error(ExpectedAPINameMessage,
|
184
|
+
BusinessError,
|
185
|
+
sourceMap);
|
177
186
|
|
178
187
|
}
|
179
|
-
else if (!out.description.empty()) {
|
188
|
+
else if (!out.node.description.empty()) {
|
180
189
|
mdp::CharactersRangeSet sourceMap = mdp::BytesRangeSetToCharactersRangeSet(node->sourceMap, pd.sourceData);
|
181
|
-
report.warnings.push_back(Warning(ExpectedAPINameMessage,
|
182
|
-
|
183
|
-
|
190
|
+
out.report.warnings.push_back(Warning(ExpectedAPINameMessage,
|
191
|
+
APINameWarning,
|
192
|
+
sourceMap));
|
184
193
|
}
|
185
194
|
}
|
186
195
|
|
@@ -194,8 +203,7 @@ namespace snowcrash {
|
|
194
203
|
|
195
204
|
static void parseMetadata(const MarkdownNodeIterator& node,
|
196
205
|
SectionParserData& pd,
|
197
|
-
|
198
|
-
MetadataCollection& out) {
|
206
|
+
ParseResult<MetadataCollection>& out) {
|
199
207
|
|
200
208
|
mdp::ByteBuffer content = node->text;
|
201
209
|
TrimStringEnd(content);
|
@@ -209,28 +217,34 @@ namespace snowcrash {
|
|
209
217
|
Metadata metadata;
|
210
218
|
|
211
219
|
if (CodeBlockUtility::keyValueFromLine(*it, metadata)) {
|
212
|
-
out.push_back(metadata);
|
220
|
+
out.node.push_back(metadata);
|
221
|
+
|
222
|
+
if (pd.exportSourceMap()) {
|
223
|
+
SourceMap<Metadata> metadataSM;
|
224
|
+
metadataSM.sourceMap = node->sourceMap;
|
225
|
+
out.sourceMap.collection.push_back(metadataSM);
|
226
|
+
}
|
213
227
|
}
|
214
228
|
}
|
215
229
|
|
216
|
-
if (lines.size() == out.size()) {
|
230
|
+
if (lines.size() == out.node.size()) {
|
217
231
|
|
218
232
|
// Check duplicates
|
219
233
|
std::vector<mdp::ByteBuffer> duplicateKeys;
|
220
234
|
|
221
|
-
for (MetadataCollectionIterator it = out.begin();
|
222
|
-
it != out.end();
|
235
|
+
for (MetadataCollectionIterator it = out.node.begin();
|
236
|
+
it != out.node.end();
|
223
237
|
++it) {
|
224
238
|
|
225
239
|
MetadataCollectionIterator from = it;
|
226
|
-
if (++from == out.end())
|
240
|
+
if (++from == out.node.end())
|
227
241
|
break;
|
228
242
|
|
229
243
|
MetadataCollectionIterator duplicate = std::find_if(from,
|
230
|
-
out.end(),
|
244
|
+
out.node.end(),
|
231
245
|
std::bind2nd(MatchFirsts<Metadata>(), *it));
|
232
246
|
|
233
|
-
if (duplicate != out.end() &&
|
247
|
+
if (duplicate != out.node.end() &&
|
234
248
|
std::find(duplicateKeys.begin(), duplicateKeys.end(), it->first) == duplicateKeys.end()) {
|
235
249
|
|
236
250
|
duplicateKeys.push_back(it->first);
|
@@ -240,19 +254,19 @@ namespace snowcrash {
|
|
240
254
|
ss << "duplicate definition of '" << it->first << "'";
|
241
255
|
|
242
256
|
mdp::CharactersRangeSet sourceMap = mdp::BytesRangeSetToCharactersRangeSet(node->sourceMap, pd.sourceData);
|
243
|
-
report.warnings.push_back(Warning(ss.str(),
|
244
|
-
|
245
|
-
|
257
|
+
out.report.warnings.push_back(Warning(ss.str(),
|
258
|
+
DuplicateWarning,
|
259
|
+
sourceMap));
|
246
260
|
}
|
247
261
|
}
|
248
262
|
}
|
249
|
-
else if (!out.empty()) {
|
263
|
+
else if (!out.node.empty()) {
|
250
264
|
|
251
265
|
// WARN: malformed metadata block
|
252
266
|
mdp::CharactersRangeSet sourceMap = mdp::BytesRangeSetToCharactersRangeSet(node->sourceMap, pd.sourceData);
|
253
|
-
report.warnings.push_back(Warning("ignoring possible metadata, expected '<key> : <value>', one one per line",
|
254
|
-
|
255
|
-
|
267
|
+
out.report.warnings.push_back(Warning("ignoring possible metadata, expected '<key> : <value>', one one per line",
|
268
|
+
FormattingWarning,
|
269
|
+
sourceMap));
|
256
270
|
}
|
257
271
|
}
|
258
272
|
|
@@ -0,0 +1,254 @@
|
|
1
|
+
//
|
2
|
+
// BlueprintSourcemap.h
|
3
|
+
// snowcrash
|
4
|
+
//
|
5
|
+
// Created by Pavan Kumar Sunkara on 26/8/14.
|
6
|
+
// Copyright (c) 2014 Apiary Inc. All rights reserved.
|
7
|
+
//
|
8
|
+
|
9
|
+
#ifndef SNOWCRASH_BLUEPRINT_SOURCEMAP_H
|
10
|
+
#define SNOWCRASH_BLUEPRINT_SOURCEMAP_H
|
11
|
+
|
12
|
+
#include "Blueprint.h"
|
13
|
+
#include "MarkdownParser.h"
|
14
|
+
|
15
|
+
/**
|
16
|
+
* API Blueprint Sourcemap Abstract Syntax Tree
|
17
|
+
* ---------------------------------------------
|
18
|
+
*
|
19
|
+
* Data types in this documents define the API Blueprint Sourcemap AST.
|
20
|
+
*/
|
21
|
+
|
22
|
+
#define SOURCE_MAP_COLLECTION(T, TC) template<>\
|
23
|
+
struct SourceMap<TC> {\
|
24
|
+
Collection<SourceMap<T> >::type collection;\
|
25
|
+
};\
|
26
|
+
|
27
|
+
namespace snowcrash {
|
28
|
+
|
29
|
+
struct SourceMapBase {
|
30
|
+
mdp::BytesRangeSet sourceMap;
|
31
|
+
};
|
32
|
+
|
33
|
+
template<typename T>
|
34
|
+
struct SourceMap : public SourceMapBase {
|
35
|
+
};
|
36
|
+
|
37
|
+
/** Source Map of Metadata Collection */
|
38
|
+
SOURCE_MAP_COLLECTION(Metadata, MetadataCollection)
|
39
|
+
|
40
|
+
/** Source Map of Headers */
|
41
|
+
// 'Metadata' type is same as 'Header'
|
42
|
+
|
43
|
+
/** Source Map of Collection of Parameter values */
|
44
|
+
SOURCE_MAP_COLLECTION(Value, Values)
|
45
|
+
|
46
|
+
/** Source Map Structure for Parameter */
|
47
|
+
template<>
|
48
|
+
struct SourceMap<Parameter> : public SourceMapBase {
|
49
|
+
|
50
|
+
/** Source Map of Parameter Name */
|
51
|
+
SourceMap<Name> name;
|
52
|
+
|
53
|
+
/** Source Map of Parameter Description */
|
54
|
+
SourceMap<Description> description;
|
55
|
+
|
56
|
+
/** Source Map of Parameter Type */
|
57
|
+
SourceMap<Type> type;
|
58
|
+
|
59
|
+
/** Source Map of Required flag */
|
60
|
+
SourceMap<ParameterUse> use;
|
61
|
+
|
62
|
+
/** Source Map of Default Value, applicable only when `required == false` */
|
63
|
+
SourceMap<Value> defaultValue;
|
64
|
+
|
65
|
+
/** Source Map of Example Value */
|
66
|
+
SourceMap<Value> exampleValue;
|
67
|
+
|
68
|
+
/** Enumeration of possible values */
|
69
|
+
SourceMap<Values> values;
|
70
|
+
};
|
71
|
+
|
72
|
+
/** Source Map of Collection of Parameters */
|
73
|
+
SOURCE_MAP_COLLECTION(Parameter, Parameters)
|
74
|
+
|
75
|
+
/**
|
76
|
+
* Source Map Structure for Payload
|
77
|
+
*/
|
78
|
+
template<>
|
79
|
+
struct SourceMap<Payload> : public SourceMapBase {
|
80
|
+
|
81
|
+
/** Source Map of a Payload Name */
|
82
|
+
SourceMap<Name> name;
|
83
|
+
|
84
|
+
/** Source Map of Payload Description */
|
85
|
+
SourceMap<Description> description;
|
86
|
+
|
87
|
+
/** Payload-specific Parameters */
|
88
|
+
SourceMap<Parameters> parameters;
|
89
|
+
|
90
|
+
/** Payload-specific Headers */
|
91
|
+
SourceMap<Headers> headers;
|
92
|
+
|
93
|
+
/** Source Map of Body */
|
94
|
+
SourceMap<Asset> body;
|
95
|
+
|
96
|
+
/** Source Map of Schema */
|
97
|
+
SourceMap<Asset> schema;
|
98
|
+
|
99
|
+
/** Source Map of Symbol */
|
100
|
+
SourceMap<SymbolName> symbol;
|
101
|
+
};
|
102
|
+
|
103
|
+
/** Source Map of Collection of Requests */
|
104
|
+
SOURCE_MAP_COLLECTION(Request, Requests)
|
105
|
+
|
106
|
+
/** Source Map of Collection of Responses */
|
107
|
+
// 'Response' type is same as 'Request'
|
108
|
+
|
109
|
+
/**
|
110
|
+
* Source Map Structure for an HTTP transaction example.
|
111
|
+
*/
|
112
|
+
template<>
|
113
|
+
struct SourceMap<TransactionExample> : public SourceMapBase {
|
114
|
+
|
115
|
+
/** Source Map of an example name */
|
116
|
+
SourceMap<Name> name;
|
117
|
+
|
118
|
+
/** Source Map of Description */
|
119
|
+
SourceMap<Description> description;
|
120
|
+
|
121
|
+
/** Requests */
|
122
|
+
SourceMap<Requests> requests;
|
123
|
+
|
124
|
+
/** Responses */
|
125
|
+
SourceMap<Responses> responses;
|
126
|
+
};
|
127
|
+
|
128
|
+
/** Source Map of Collection of Transaction examples */
|
129
|
+
SOURCE_MAP_COLLECTION(TransactionExample, TransactionExamples)
|
130
|
+
|
131
|
+
/**
|
132
|
+
* Source Map Structure for Action
|
133
|
+
*/
|
134
|
+
template<>
|
135
|
+
struct SourceMap<Action> : public SourceMapBase {
|
136
|
+
|
137
|
+
/** Source Map of HTTP method */
|
138
|
+
SourceMap<HTTPMethod> method;
|
139
|
+
|
140
|
+
/** Source Map of an Action name */
|
141
|
+
SourceMap<Name> name;
|
142
|
+
|
143
|
+
/** Source Map of Description */
|
144
|
+
SourceMap<Description> description;
|
145
|
+
|
146
|
+
/** Action-specific Parameters */
|
147
|
+
SourceMap<Parameters> parameters;
|
148
|
+
|
149
|
+
/**
|
150
|
+
* \brief Action-specific HTTP headers
|
151
|
+
*
|
152
|
+
* DEPRECATION WARNING:
|
153
|
+
* --------------------
|
154
|
+
*
|
155
|
+
* This AST node is build for deprecated API Blueprint syntax
|
156
|
+
* and as such it will be removed in a future version of
|
157
|
+
* Snow Crash.
|
158
|
+
*
|
159
|
+
* Use respective payload's header collection instead.
|
160
|
+
*/
|
161
|
+
DEPRECATED SourceMap<Headers> headers;
|
162
|
+
|
163
|
+
/** Transactions examples */
|
164
|
+
SourceMap<TransactionExamples> examples;
|
165
|
+
};
|
166
|
+
|
167
|
+
/** Source Map of Collection of Actions */
|
168
|
+
SOURCE_MAP_COLLECTION(Action, Actions)
|
169
|
+
|
170
|
+
/**
|
171
|
+
* Source Map Structure for API Resource
|
172
|
+
*/
|
173
|
+
template<>
|
174
|
+
struct SourceMap<Resource> : public SourceMapBase {
|
175
|
+
|
176
|
+
/** Source Map of URI template */
|
177
|
+
SourceMap<URITemplate> uriTemplate;
|
178
|
+
|
179
|
+
/** Source Map of a Resource Name */
|
180
|
+
SourceMap<Name> name;
|
181
|
+
|
182
|
+
/** Source Map of Description of the resource */
|
183
|
+
SourceMap<Description> description;
|
184
|
+
|
185
|
+
/** Model representing this Resource */
|
186
|
+
SourceMap<ResourceModel> model;
|
187
|
+
|
188
|
+
/** Parameters */
|
189
|
+
SourceMap<Parameters> parameters;
|
190
|
+
|
191
|
+
/**
|
192
|
+
* \brief Resource-specific HTTP Headers
|
193
|
+
*
|
194
|
+
* DEPRECATION WARNING:
|
195
|
+
* --------------------
|
196
|
+
*
|
197
|
+
* This AST node is build for deprecated API Blueprint syntax
|
198
|
+
* and as such it will be removed in a future version of
|
199
|
+
* Snow Crash.
|
200
|
+
*
|
201
|
+
* Use respective payload's header collection instead.
|
202
|
+
*/
|
203
|
+
DEPRECATED SourceMap<Headers> headers;
|
204
|
+
|
205
|
+
/** A set of Actions specified for this Resource */
|
206
|
+
SourceMap<Actions> actions;
|
207
|
+
};
|
208
|
+
|
209
|
+
/** Source Map of Collection of Resources */
|
210
|
+
SOURCE_MAP_COLLECTION(Resource, Resources)
|
211
|
+
|
212
|
+
/**
|
213
|
+
* Source Map Structure for Group of API Resources
|
214
|
+
*/
|
215
|
+
template<>
|
216
|
+
struct SourceMap<ResourceGroup> : public SourceMapBase {
|
217
|
+
|
218
|
+
/** Source Map of a Group Name */
|
219
|
+
SourceMap<Name> name;
|
220
|
+
|
221
|
+
/** Source Map of Group description */
|
222
|
+
SourceMap<Description> description;
|
223
|
+
|
224
|
+
/** Resources */
|
225
|
+
SourceMap<Resources> resources;
|
226
|
+
};
|
227
|
+
|
228
|
+
/** Source Map of Collection of Resource groups */
|
229
|
+
SOURCE_MAP_COLLECTION(ResourceGroup, ResourceGroups)
|
230
|
+
|
231
|
+
/**
|
232
|
+
* \brief API Blueprint Sourcemap AST
|
233
|
+
*
|
234
|
+
* This is top-level (or root if you prefer) of API Blueprint Sourcemap abstract syntax tree.
|
235
|
+
* Start reading a parsed API here.
|
236
|
+
*/
|
237
|
+
template<>
|
238
|
+
struct SourceMap<Blueprint> : public SourceMapBase {
|
239
|
+
|
240
|
+
/** Source Map of API Blueprint metadata */
|
241
|
+
SourceMap<MetadataCollection> metadata;
|
242
|
+
|
243
|
+
/** Source Map of the API Name */
|
244
|
+
SourceMap<Name> name;
|
245
|
+
|
246
|
+
/** Source Map of an API Overview description */
|
247
|
+
SourceMap<Description> description;
|
248
|
+
|
249
|
+
/** The set of API Resource Groups */
|
250
|
+
SourceMap<ResourceGroups> resourceGroups;
|
251
|
+
};
|
252
|
+
}
|
253
|
+
|
254
|
+
#endif
|