redsnow 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -0
- data/ext/snowcrash/Makefile +1 -1
- data/ext/snowcrash/bin/snowcrash +0 -0
- data/ext/snowcrash/configure +9 -9
- data/ext/snowcrash/ext/markdown-parser/Makefile +87 -0
- data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/CONTRIBUTING.md +0 -0
- data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/Makefile +2 -1
- data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/Makefile.win +0 -0
- data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/examples/smartypants.c +0 -0
- data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/examples/sundown.c +0 -0
- data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/html/houdini.h +0 -0
- data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/html/houdini_href_e.c +0 -0
- data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/html/houdini_html_e.c +0 -0
- data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/html/html.c +0 -0
- data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/html/html.h +0 -0
- data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/html/html_smartypants.c +0 -0
- data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/html_block_names.txt +0 -0
- data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/src/autolink.c +0 -0
- data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/src/autolink.h +0 -0
- data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/src/buffer.c +0 -0
- data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/src/buffer.h +1 -1
- data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/src/html_blocks.h +0 -0
- data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/src/markdown.c +9 -3
- data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/src/markdown.h +0 -0
- data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/src/src_map.c +11 -7
- data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/src/src_map.h +1 -1
- data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/src/stack.c +0 -0
- data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/src/stack.h +0 -0
- data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/sundown.def +0 -0
- data/ext/snowcrash/ext/markdown-parser/msvc/markdown/markdown.vcproj +188 -0
- data/ext/snowcrash/ext/markdown-parser/msvc/msvc.sln +38 -0
- data/ext/snowcrash/ext/markdown-parser/msvc/sundown/sundown.vcproj +206 -0
- data/ext/snowcrash/ext/markdown-parser/src/ByteBuffer.cc +92 -0
- data/ext/snowcrash/ext/markdown-parser/src/ByteBuffer.h +82 -0
- data/ext/snowcrash/ext/markdown-parser/src/MarkdownNode.cc +152 -0
- data/ext/snowcrash/ext/markdown-parser/src/MarkdownNode.h +103 -0
- data/ext/snowcrash/ext/markdown-parser/src/MarkdownParser.cc +388 -0
- data/ext/snowcrash/{src → ext/markdown-parser/src}/MarkdownParser.h +43 -33
- data/ext/snowcrash/snowcrash.gyp +114 -63
- data/ext/snowcrash/src/ActionParser.h +334 -398
- data/ext/snowcrash/src/AssetParser.h +82 -171
- data/ext/snowcrash/src/Blueprint.h +7 -2
- data/ext/snowcrash/src/BlueprintParser.h +212 -286
- data/ext/snowcrash/src/BlueprintUtility.h +2 -2
- data/ext/snowcrash/src/CBlueprint.h +1 -1
- data/ext/snowcrash/src/CSourceAnnotation.cc +11 -11
- data/ext/snowcrash/src/CSourceAnnotation.h +9 -9
- data/ext/snowcrash/src/CodeBlockUtility.h +199 -149
- data/ext/snowcrash/src/HeadersParser.h +197 -0
- data/ext/snowcrash/src/ParameterParser.h +429 -0
- data/ext/snowcrash/src/ParametersParser.h +136 -211
- data/ext/snowcrash/src/PayloadParser.h +458 -562
- data/ext/snowcrash/src/Platform.h +0 -3
- data/ext/snowcrash/src/ResourceGroupParser.h +183 -164
- data/ext/snowcrash/src/ResourceParser.h +325 -493
- data/ext/snowcrash/src/Section.cc +42 -0
- data/ext/snowcrash/src/Section.h +47 -0
- data/ext/snowcrash/src/SectionParser.h +229 -0
- data/ext/snowcrash/src/SectionParserData.h +81 -0
- data/ext/snowcrash/src/SectionProcessor.h +211 -0
- data/ext/snowcrash/src/Signature.cc +74 -0
- data/ext/snowcrash/src/Signature.h +32 -0
- data/ext/snowcrash/src/SourceAnnotation.h +7 -20
- data/ext/snowcrash/src/StringUtility.h +30 -10
- data/ext/snowcrash/src/SymbolTable.h +7 -7
- data/ext/snowcrash/src/UriTemplateParser.cc +10 -10
- data/ext/snowcrash/src/UriTemplateParser.h +11 -14
- data/ext/snowcrash/src/ValuesParser.h +122 -0
- data/ext/snowcrash/src/Version.h +2 -2
- data/ext/snowcrash/src/csnowcrash.cc +5 -5
- data/ext/snowcrash/src/csnowcrash.h +3 -3
- data/ext/snowcrash/src/snowcrash.cc +74 -4
- data/ext/snowcrash/src/snowcrash.h +9 -4
- data/ext/snowcrash/src/snowcrash/snowcrash.cc +16 -16
- data/ext/snowcrash/tools/homebrew/snowcrash.rb +3 -2
- data/ext/snowcrash/vcbuild.bat +13 -4
- data/lib/redsnow.rb +5 -5
- data/lib/redsnow/binding.rb +1 -1
- data/lib/redsnow/blueprint.rb +33 -2
- data/lib/redsnow/parseresult.rb +7 -4
- data/lib/redsnow/version.rb +1 -1
- data/test/redsnow_binding_test.rb +6 -6
- data/test/redsnow_parseresult_test.rb +1 -1
- metadata +62 -42
- data/ext/snowcrash/src/BlockUtility.h +0 -186
- data/ext/snowcrash/src/BlueprintParserCore.h +0 -190
- data/ext/snowcrash/src/BlueprintSection.h +0 -140
- data/ext/snowcrash/src/DescriptionSectionUtility.h +0 -156
- data/ext/snowcrash/src/HeaderParser.h +0 -289
- data/ext/snowcrash/src/ListBlockUtility.h +0 -273
- data/ext/snowcrash/src/ListUtility.h +0 -95
- data/ext/snowcrash/src/MarkdownBlock.cc +0 -176
- data/ext/snowcrash/src/MarkdownBlock.h +0 -93
- data/ext/snowcrash/src/MarkdownParser.cc +0 -266
- data/ext/snowcrash/src/ParameterDefinitonParser.h +0 -645
- data/ext/snowcrash/src/Parser.cc +0 -71
- data/ext/snowcrash/src/Parser.h +0 -29
- data/ext/snowcrash/src/ParserCore.cc +0 -120
- data/ext/snowcrash/src/ParserCore.h +0 -82
- data/ext/snowcrash/src/SectionUtility.h +0 -142
@@ -1,645 +0,0 @@
|
|
1
|
-
//
|
2
|
-
// ParameterDefinitonParser.h
|
3
|
-
// snowcrash
|
4
|
-
//
|
5
|
-
// Created by Zdenek Nemec on 9/1/13.
|
6
|
-
// Copyright (c) 2013 Apiary Inc. All rights reserved.
|
7
|
-
//
|
8
|
-
|
9
|
-
#ifndef SNOWCRASH_PARAMETERDEFINITIONPARSER_H
|
10
|
-
#define SNOWCRASH_PARAMETERDEFINITIONPARSER_H
|
11
|
-
|
12
|
-
#include <sstream>
|
13
|
-
#include "BlueprintParserCore.h"
|
14
|
-
#include "Blueprint.h"
|
15
|
-
#include "RegexMatch.h"
|
16
|
-
#include "StringUtility.h"
|
17
|
-
#include "ListBlockUtility.h"
|
18
|
-
#include "SectionUtility.h"
|
19
|
-
#include "DescriptionSectionUtility.h"
|
20
|
-
|
21
|
-
/** Parameter Value regex */
|
22
|
-
#define PARAMETER_VALUE "`([^`]+)`"
|
23
|
-
|
24
|
-
/** Parameter Identifier */
|
25
|
-
#define PARAMETER_IDENTIFIER "(([[:alnum:]_.-])*|(%[A-Fa-f0-9]{2})*)+"
|
26
|
-
|
27
|
-
/** Lead in and out for comma separated values regex */
|
28
|
-
#define CSV_LEADINOUT "[[:blank:]]*,?[[:blank:]]*"
|
29
|
-
|
30
|
-
namespace snowcrashconst {
|
31
|
-
|
32
|
-
/** Parameter Required matching regex */
|
33
|
-
const char* const ParameterRequiredRegex = "^[[:blank:]]*[Rr]equired[[:blank:]]*$";
|
34
|
-
|
35
|
-
/** Parameter Optional matching regex */
|
36
|
-
const char* const ParameterOptionalRegex = "^[[:blank:]]*[Oo]ptional[[:blank:]]*$";
|
37
|
-
|
38
|
-
/** Additonal Parameter Traits Example matching regex */
|
39
|
-
const char* const AdditionalTraitsExampleRegex = CSV_LEADINOUT "`([^`]*)`" CSV_LEADINOUT;
|
40
|
-
|
41
|
-
/** Additonal Parameter Traits Use matching regex */
|
42
|
-
const char* const AdditionalTraitsUseRegex = CSV_LEADINOUT "([Oo]ptional|[Rr]equired)" CSV_LEADINOUT;
|
43
|
-
|
44
|
-
/** Additonal Parameter Traits Type matching regex */
|
45
|
-
const char* const AdditionalTraitsTypeRegex = CSV_LEADINOUT "([^,]*)" CSV_LEADINOUT;
|
46
|
-
|
47
|
-
/** Parameter Values matching regex */
|
48
|
-
const char* const ParameterValuesRegex = "^[[:blank:]]*[Vv]alues[[:blank:]]*$";
|
49
|
-
|
50
|
-
/** Values expected content */
|
51
|
-
const char* const ExpectedValuesContent = "nested list of possible parameter values, one element per list item e.g. '`value`'";
|
52
|
-
|
53
|
-
const std::string DescriptionIdentifier = "...";
|
54
|
-
}
|
55
|
-
|
56
|
-
namespace snowcrash {
|
57
|
-
|
58
|
-
/**
|
59
|
-
* Classifier of internal list items, ParameterCollection context.
|
60
|
-
*/
|
61
|
-
template <>
|
62
|
-
FORCEINLINE SectionType ClassifyInternaListBlock<Parameter>(const BlockIterator& begin,
|
63
|
-
const BlockIterator& end) {
|
64
|
-
|
65
|
-
|
66
|
-
if (begin->type != ListBlockBeginType &&
|
67
|
-
begin->type != ListItemBlockBeginType)
|
68
|
-
return UndefinedSectionType;
|
69
|
-
|
70
|
-
SourceData remainingContent;
|
71
|
-
SourceData content = GetListItemSignature(begin, end, remainingContent);
|
72
|
-
|
73
|
-
content = TrimString(content);
|
74
|
-
|
75
|
-
if (RegexMatch(content, snowcrashconst::ParameterValuesRegex))
|
76
|
-
return ParameterValuesSectionType;
|
77
|
-
|
78
|
-
return UndefinedSectionType;
|
79
|
-
}
|
80
|
-
|
81
|
-
/** Children blocks classifier */
|
82
|
-
template <>
|
83
|
-
FORCEINLINE SectionType ClassifyChildrenListBlock<Parameter>(const BlockIterator& begin,
|
84
|
-
const BlockIterator& end) {
|
85
|
-
|
86
|
-
SectionType type = ClassifyInternaListBlock<Parameter>(begin, end);
|
87
|
-
if (type != UndefinedSectionType)
|
88
|
-
return type;
|
89
|
-
|
90
|
-
return UndefinedSectionType;
|
91
|
-
}
|
92
|
-
|
93
|
-
/** Determine if a signature is a valid parameter*/
|
94
|
-
FORCEINLINE bool IsValidParameterSignature(const SourceData& signature) {
|
95
|
-
|
96
|
-
SourceData innerSignature = signature;
|
97
|
-
innerSignature = TrimString(innerSignature);
|
98
|
-
|
99
|
-
if (innerSignature.length() == 0) {
|
100
|
-
return false; // Empty string, invalid
|
101
|
-
}
|
102
|
-
|
103
|
-
size_t firstSpace = innerSignature.find(" ");
|
104
|
-
if (firstSpace == std::string::npos) {
|
105
|
-
return RegexMatch(innerSignature, "^" PARAMETER_IDENTIFIER "$");
|
106
|
-
}
|
107
|
-
|
108
|
-
std::string paramName = innerSignature.substr(0, firstSpace);
|
109
|
-
if (!RegexMatch(paramName, "^" PARAMETER_IDENTIFIER "$")) {
|
110
|
-
return false; // Invalid param name
|
111
|
-
}
|
112
|
-
// Remove param name
|
113
|
-
innerSignature = innerSignature.substr(firstSpace + 1);
|
114
|
-
|
115
|
-
size_t descriptionPos = innerSignature.find(snowcrashconst::DescriptionIdentifier);
|
116
|
-
// Remove description
|
117
|
-
if (descriptionPos != std::string::npos) {
|
118
|
-
innerSignature = innerSignature.substr(0, descriptionPos);
|
119
|
-
innerSignature = TrimString(innerSignature);
|
120
|
-
}
|
121
|
-
|
122
|
-
size_t attributesPos = innerSignature.find("(");
|
123
|
-
if (attributesPos != std::string::npos) {
|
124
|
-
size_t endOfAttributesPos = innerSignature.find_last_of(")");
|
125
|
-
if (endOfAttributesPos == std::string::npos) {
|
126
|
-
return false; // Expecting close of attributes
|
127
|
-
}
|
128
|
-
// Remove attributes
|
129
|
-
innerSignature = innerSignature.substr(0, attributesPos);
|
130
|
-
innerSignature = TrimString(innerSignature);
|
131
|
-
}
|
132
|
-
|
133
|
-
if (innerSignature.length() == 0) {
|
134
|
-
return true;
|
135
|
-
}
|
136
|
-
|
137
|
-
if (innerSignature.substr(0,1) == "=") {
|
138
|
-
innerSignature = innerSignature.substr(1);
|
139
|
-
innerSignature = TrimString(innerSignature);
|
140
|
-
if (innerSignature.length() == 0) {
|
141
|
-
return false; // No default value
|
142
|
-
}
|
143
|
-
if (innerSignature.substr(0,1) == "`" && innerSignature.substr(innerSignature.length()-1,1) == "`") {
|
144
|
-
return true;
|
145
|
-
}
|
146
|
-
}
|
147
|
-
|
148
|
-
return false;
|
149
|
-
}
|
150
|
-
|
151
|
-
/**
|
152
|
-
* Returns true if given block has a parameter definition signature, false otherwise.
|
153
|
-
*/
|
154
|
-
FORCEINLINE bool HasParameterDefinitionSignature(const BlockIterator& begin,
|
155
|
-
const BlockIterator& end) {
|
156
|
-
|
157
|
-
if (begin->type != ListBlockBeginType &&
|
158
|
-
begin->type != ListItemBlockBeginType)
|
159
|
-
return false;
|
160
|
-
|
161
|
-
// Since we are too generic make sure the signature is not inner list
|
162
|
-
SectionType listSection = ClassifyInternaListBlock<Parameter>(begin, end);
|
163
|
-
if (listSection != UndefinedSectionType)
|
164
|
-
return false;
|
165
|
-
|
166
|
-
// Or any other reserved keyword
|
167
|
-
if (HasParametersSignature(begin, end))
|
168
|
-
return false;
|
169
|
-
|
170
|
-
SourceData remainingContent;
|
171
|
-
SourceData content = GetListItemSignature(begin, end, remainingContent);
|
172
|
-
content = TrimString(content);
|
173
|
-
return IsValidParameterSignature(content);
|
174
|
-
}
|
175
|
-
|
176
|
-
/**
|
177
|
-
* Block Classifier, Parameter context.
|
178
|
-
*/
|
179
|
-
template <>
|
180
|
-
FORCEINLINE SectionType ClassifyBlock<Parameter>(const BlockIterator& begin,
|
181
|
-
const BlockIterator& end,
|
182
|
-
const SectionType& context) {
|
183
|
-
|
184
|
-
if (context == UndefinedSectionType) {
|
185
|
-
if (HasParameterDefinitionSignature(begin, end))
|
186
|
-
return ParameterDefinitionSectionType;
|
187
|
-
}
|
188
|
-
else if (context == ParameterDefinitionSectionType) {
|
189
|
-
|
190
|
-
if (begin->type == ListItemBlockEndType ||
|
191
|
-
begin->type == ListBlockEndType)
|
192
|
-
return UndefinedSectionType;
|
193
|
-
|
194
|
-
SectionType listSection = ClassifyInternaListBlock<Parameter>(begin, end);
|
195
|
-
if (listSection != UndefinedSectionType)
|
196
|
-
return listSection;
|
197
|
-
|
198
|
-
if (begin->type == ListBlockBeginType)
|
199
|
-
return ForeignSectionType; // Foreign nested list-item
|
200
|
-
|
201
|
-
if (begin->type == ListItemBlockBeginType)
|
202
|
-
return UndefinedSectionType;
|
203
|
-
}
|
204
|
-
else if (context == ParameterValuesSectionType ||
|
205
|
-
context == ForeignSectionType) {
|
206
|
-
|
207
|
-
if (begin->type == ListItemBlockEndType ||
|
208
|
-
begin->type == ListBlockEndType)
|
209
|
-
return UndefinedSectionType;
|
210
|
-
|
211
|
-
SectionType listSection = ClassifyInternaListBlock<Parameter>(begin, end);
|
212
|
-
if (listSection != UndefinedSectionType)
|
213
|
-
return listSection;
|
214
|
-
|
215
|
-
return ForeignSectionType;
|
216
|
-
}
|
217
|
-
|
218
|
-
return (context == ParameterDefinitionSectionType) ? context : UndefinedSectionType;
|
219
|
-
}
|
220
|
-
|
221
|
-
/**
|
222
|
-
* Parameter section parser.
|
223
|
-
*/
|
224
|
-
template<>
|
225
|
-
struct SectionParser<Parameter> {
|
226
|
-
|
227
|
-
static ParseSectionResult ParseSection(const BlueprintSection& section,
|
228
|
-
const BlockIterator& cur,
|
229
|
-
BlueprintParserCore& parser,
|
230
|
-
Parameter& parameter) {
|
231
|
-
|
232
|
-
ParseSectionResult result = std::make_pair(Result(), cur);
|
233
|
-
switch (section.type) {
|
234
|
-
|
235
|
-
case ParameterDefinitionSectionType:
|
236
|
-
result = HandleParmeterDefinitionSection(section, cur, parser, parameter);
|
237
|
-
break;
|
238
|
-
|
239
|
-
case ParameterValuesSectionType:
|
240
|
-
result = HandleValuesSection(section, cur, parser, parameter);
|
241
|
-
break;
|
242
|
-
|
243
|
-
case ForeignSectionType:
|
244
|
-
result = HandleForeignSection<Parameter>(section, cur, parser.sourceData);
|
245
|
-
break;
|
246
|
-
|
247
|
-
case UndefinedSectionType:
|
248
|
-
result.second = CloseList(cur, section.bounds.second);
|
249
|
-
break;
|
250
|
-
|
251
|
-
default:
|
252
|
-
result.first.error = UnexpectedBlockError(section, cur, parser.sourceData);
|
253
|
-
break;
|
254
|
-
}
|
255
|
-
|
256
|
-
return result;
|
257
|
-
}
|
258
|
-
|
259
|
-
|
260
|
-
static void Finalize(const SectionBounds& bounds,
|
261
|
-
BlueprintParserCore& parser,
|
262
|
-
Parameter& parameter,
|
263
|
-
Result& result) {}
|
264
|
-
|
265
|
-
/** Parse a parameter definition top-level section blocks. */
|
266
|
-
static ParseSectionResult HandleParmeterDefinitionSection(const BlueprintSection& section,
|
267
|
-
const BlockIterator& cur,
|
268
|
-
BlueprintParserCore& parser,
|
269
|
-
Parameter& parameter) {
|
270
|
-
|
271
|
-
ParseSectionResult result = std::make_pair(Result(), cur);
|
272
|
-
BlockIterator sectionCur = cur;
|
273
|
-
|
274
|
-
// Signature
|
275
|
-
if (sectionCur == section.bounds.first) {
|
276
|
-
ProcessSignature(section, sectionCur, parser.sourceData, result.first, parameter);
|
277
|
-
result.second = SkipSignatureBlock(sectionCur, section.bounds.second);
|
278
|
-
return result;
|
279
|
-
}
|
280
|
-
|
281
|
-
// Description
|
282
|
-
result = ParseDescriptionBlock<Parameter>(section,
|
283
|
-
sectionCur,
|
284
|
-
parser.sourceData,
|
285
|
-
parameter);
|
286
|
-
return result;
|
287
|
-
|
288
|
-
}
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
/**
|
293
|
-
* Retrieve and process parameter definition signature.
|
294
|
-
*/
|
295
|
-
static void ProcessSignature(const BlueprintSection& section,
|
296
|
-
const BlockIterator& cur,
|
297
|
-
const SourceData& sourceData,
|
298
|
-
Result& result,
|
299
|
-
Parameter& parameter) {
|
300
|
-
|
301
|
-
// Set default values
|
302
|
-
parameter.use = UndefinedParameterUse;
|
303
|
-
|
304
|
-
// Process signature
|
305
|
-
SourceData remainingContent;
|
306
|
-
SourceData signature = GetListItemSignature(cur, section.bounds.second, remainingContent);
|
307
|
-
|
308
|
-
TrimString(signature);
|
309
|
-
|
310
|
-
if (IsValidParameterSignature(signature)) {
|
311
|
-
|
312
|
-
SourceData innerSignature = signature;
|
313
|
-
innerSignature = TrimString(innerSignature);
|
314
|
-
|
315
|
-
size_t firstSpace = innerSignature.find(" ");
|
316
|
-
if (firstSpace == std::string::npos) {
|
317
|
-
// Name
|
318
|
-
parameter.name = signature;
|
319
|
-
}
|
320
|
-
else {
|
321
|
-
parameter.name = innerSignature.substr(0, firstSpace);
|
322
|
-
innerSignature = innerSignature.substr(firstSpace + 1);
|
323
|
-
size_t descriptionPos = innerSignature.find(snowcrashconst::DescriptionIdentifier);
|
324
|
-
if (descriptionPos != std::string::npos) {
|
325
|
-
// Description
|
326
|
-
parameter.description = innerSignature.substr(descriptionPos);
|
327
|
-
parameter.description = TrimString(parameter.description.replace(0, snowcrashconst::DescriptionIdentifier.length(), ""));
|
328
|
-
innerSignature = innerSignature.substr(0, descriptionPos);
|
329
|
-
innerSignature = TrimString(innerSignature);
|
330
|
-
}
|
331
|
-
|
332
|
-
size_t attributesPos = innerSignature.find("(");
|
333
|
-
if (attributesPos != std::string::npos) {
|
334
|
-
size_t endOfAttributesPos = innerSignature.find_last_of(")");
|
335
|
-
if (endOfAttributesPos - attributesPos > 1) {
|
336
|
-
std::string attributes = innerSignature.substr(attributesPos, endOfAttributesPos - attributesPos);
|
337
|
-
attributes = attributes.substr(1);
|
338
|
-
ProcessSignatureAdditionalTraits(section, cur, attributes, sourceData, result, parameter);
|
339
|
-
innerSignature = innerSignature.substr(0, attributesPos);
|
340
|
-
innerSignature = TrimString(innerSignature);
|
341
|
-
}
|
342
|
-
}
|
343
|
-
|
344
|
-
if (innerSignature.length() > 0) {
|
345
|
-
// Remove =
|
346
|
-
parameter.defaultValue = innerSignature;
|
347
|
-
parameter.defaultValue.erase(std::remove(parameter.defaultValue.begin(), parameter.defaultValue.end(), '='), parameter.defaultValue.end());
|
348
|
-
parameter.defaultValue.erase(std::remove(parameter.defaultValue.begin(), parameter.defaultValue.end(), '`'), parameter.defaultValue.end());
|
349
|
-
parameter.defaultValue = TrimString(parameter.defaultValue);
|
350
|
-
}
|
351
|
-
}
|
352
|
-
// Check possible required vs default clash
|
353
|
-
if (parameter.use != OptionalParameterUse &&
|
354
|
-
!parameter.defaultValue.empty()) {
|
355
|
-
|
356
|
-
// WARN: Required vs default clash
|
357
|
-
std::stringstream ss;
|
358
|
-
ss << "specifying parameter '" << parameter.name << "' as required supersedes its default value"\
|
359
|
-
", declare the parameter as 'optional' to specify its default value";
|
360
|
-
|
361
|
-
BlockIterator nameBlock = ListItemNameBlock(cur, section.bounds.second);
|
362
|
-
SourceCharactersBlock sourceBlock = CharacterMapForBlock(nameBlock, cur, section.bounds, sourceData);
|
363
|
-
result.warnings.push_back(Warning(ss.str(),
|
364
|
-
LogicalErrorWarning,
|
365
|
-
sourceBlock));
|
366
|
-
}
|
367
|
-
}
|
368
|
-
else {
|
369
|
-
// ERR: unable to parse
|
370
|
-
BlockIterator nameBlock = ListItemNameBlock(cur, section.bounds.second);
|
371
|
-
SourceCharactersBlock sourceBlock = CharacterMapForBlock(nameBlock, cur, section.bounds, sourceData);
|
372
|
-
result.error = (Error("unable to parse parameter specification",
|
373
|
-
BusinessError,
|
374
|
-
sourceBlock));
|
375
|
-
}
|
376
|
-
}
|
377
|
-
|
378
|
-
|
379
|
-
/** Parse additional parameter attributes from abbrev definition bracket */
|
380
|
-
static void ProcessSignatureAdditionalTraits(const BlueprintSection& section,
|
381
|
-
const BlockIterator& cur,
|
382
|
-
const SourceData& additionalTraits,
|
383
|
-
const SourceData& sourceData,
|
384
|
-
Result& result,
|
385
|
-
Parameter& parameter)
|
386
|
-
{
|
387
|
-
|
388
|
-
// Cherry pick example value, if any
|
389
|
-
std::string source = additionalTraits;
|
390
|
-
TrimString(source);
|
391
|
-
CaptureGroups captureGroups;
|
392
|
-
if (RegexCapture(source, snowcrashconst::AdditionalTraitsExampleRegex, captureGroups) &&
|
393
|
-
captureGroups.size() > 1) {
|
394
|
-
|
395
|
-
parameter.exampleValue = captureGroups[1];
|
396
|
-
std::string::size_type pos = source.find(captureGroups[0]);
|
397
|
-
if (pos != std::string::npos)
|
398
|
-
source.replace(pos, captureGroups[0].length(), std::string());
|
399
|
-
}
|
400
|
-
|
401
|
-
// Cherry pick use attribute, if any
|
402
|
-
captureGroups.clear();
|
403
|
-
if (RegexCapture(source, snowcrashconst::AdditionalTraitsUseRegex, captureGroups) &&
|
404
|
-
captureGroups.size() > 1) {
|
405
|
-
|
406
|
-
parameter.use = (RegexMatch(captureGroups[1], snowcrashconst::ParameterOptionalRegex)) ? OptionalParameterUse : RequiredParameterUse;
|
407
|
-
|
408
|
-
std::string::size_type pos = source.find(captureGroups[0]);
|
409
|
-
if (pos != std::string::npos)
|
410
|
-
source.replace(pos, captureGroups[0].length(), std::string());
|
411
|
-
}
|
412
|
-
|
413
|
-
// Finish with type
|
414
|
-
captureGroups.clear();
|
415
|
-
if (RegexCapture(source, snowcrashconst::AdditionalTraitsTypeRegex, captureGroups) &&
|
416
|
-
captureGroups.size() > 1) {
|
417
|
-
|
418
|
-
parameter.type = captureGroups[1];
|
419
|
-
|
420
|
-
std::string::size_type pos = source.find(captureGroups[0]);
|
421
|
-
if (pos != std::string::npos)
|
422
|
-
source.replace(pos, captureGroups[0].length(), std::string());
|
423
|
-
}
|
424
|
-
|
425
|
-
// Check whats left
|
426
|
-
TrimString(source);
|
427
|
-
if (!source.empty()) {
|
428
|
-
// WARN: Additional parameters traits warning
|
429
|
-
std::stringstream ss;
|
430
|
-
ss << "unable to parse additional parameter traits";
|
431
|
-
ss << ", expected '([required | optional], [<type>], [`<example value>`])'";
|
432
|
-
ss << ", e.g. '(optional, string, `Hello World`)'";
|
433
|
-
|
434
|
-
BlockIterator nameBlock = ListItemNameBlock(cur, section.bounds.second);
|
435
|
-
SourceCharactersBlock sourceBlock = CharacterMapForBlock(nameBlock, cur, section.bounds, sourceData);
|
436
|
-
result.warnings.push_back(Warning(ss.str(),
|
437
|
-
FormattingWarning,
|
438
|
-
sourceBlock));
|
439
|
-
|
440
|
-
parameter.type.clear();
|
441
|
-
parameter.exampleValue.clear();
|
442
|
-
parameter.use = UndefinedParameterUse;
|
443
|
-
}
|
444
|
-
}
|
445
|
-
|
446
|
-
/** Parse possible values enumeration section blocks. */
|
447
|
-
static ParseSectionResult HandleValuesSection(const BlueprintSection& section,
|
448
|
-
const BlockIterator& cur,
|
449
|
-
BlueprintParserCore& parser,
|
450
|
-
Parameter& parameter) {
|
451
|
-
|
452
|
-
ParseSectionResult result = std::make_pair(Result(), cur);
|
453
|
-
|
454
|
-
// Check redefinition
|
455
|
-
if (!parameter.values.empty()) {
|
456
|
-
// WARN: parameter values are already defined
|
457
|
-
std::stringstream ss;
|
458
|
-
ss << "overshadowing previous 'values' definition";
|
459
|
-
ss << " for parameter '" << parameter.name << "'";
|
460
|
-
|
461
|
-
BlockIterator nameBlock = ListItemNameBlock(cur, section.bounds.second);
|
462
|
-
SourceCharactersBlock sourceBlock = CharacterMapForBlock(nameBlock, cur, section.bounds, parser.sourceData);
|
463
|
-
result.first.warnings.push_back(Warning(ss.str(),
|
464
|
-
RedefinitionWarning,
|
465
|
-
sourceBlock));
|
466
|
-
}
|
467
|
-
|
468
|
-
// Clear any previous content
|
469
|
-
parameter.values.clear();
|
470
|
-
|
471
|
-
// Check additional content in signature
|
472
|
-
CheckSignatureAdditionalContent(section,
|
473
|
-
cur,
|
474
|
-
parser.sourceData,
|
475
|
-
"'values:' keyword",
|
476
|
-
snowcrashconst::ExpectedValuesContent,
|
477
|
-
result.first);
|
478
|
-
|
479
|
-
// Parse inner list of entities
|
480
|
-
BlockIterator sectionCur = SkipSignatureBlock(cur, section.bounds.second);
|
481
|
-
BlockIterator endCur = cur;
|
482
|
-
if (endCur->type == ListBlockBeginType)
|
483
|
-
++endCur;
|
484
|
-
endCur = SkipToClosingBlock(endCur, section.bounds.second, ListItemBlockBeginType, ListItemBlockEndType);
|
485
|
-
|
486
|
-
if (sectionCur != endCur) {
|
487
|
-
|
488
|
-
// Iterate over list blocks, try to parse any nested lists of possible elements
|
489
|
-
for (; sectionCur != endCur; ++sectionCur) {
|
490
|
-
|
491
|
-
if (sectionCur->type == QuoteBlockBeginType)
|
492
|
-
sectionCur = SkipToClosingBlock(sectionCur, endCur, QuoteBlockBeginType, QuoteBlockEndType);
|
493
|
-
|
494
|
-
bool entitiesParsed = false;
|
495
|
-
if (sectionCur->type == ListBlockBeginType) {
|
496
|
-
if (parameter.values.empty()) {
|
497
|
-
|
498
|
-
// Try to parse some values
|
499
|
-
ParseSectionResult valuesResult = ParseValuesEntities(sectionCur,
|
500
|
-
section.bounds,
|
501
|
-
parser,
|
502
|
-
parameter.values);
|
503
|
-
result.first += valuesResult.first;
|
504
|
-
sectionCur = valuesResult.second;
|
505
|
-
if (result.first.error.code != Error::OK)
|
506
|
-
return result;
|
507
|
-
|
508
|
-
entitiesParsed = true;
|
509
|
-
}
|
510
|
-
else {
|
511
|
-
sectionCur = SkipToClosingBlock(sectionCur, endCur, ListBlockBeginType, ListBlockEndType);
|
512
|
-
}
|
513
|
-
}
|
514
|
-
|
515
|
-
if (!entitiesParsed) {
|
516
|
-
// WARN: ignoring extraneous content
|
517
|
-
std::stringstream ss;
|
518
|
-
ss << "ignoring additional content in the 'values' attribute of the '";
|
519
|
-
ss << parameter.name << "' parameter";
|
520
|
-
ss << ", " << snowcrashconst::ExpectedValuesContent;
|
521
|
-
|
522
|
-
SourceCharactersBlock sourceBlock = CharacterMapForBlock(sectionCur, cur, section.bounds, parser.sourceData);
|
523
|
-
result.first.warnings.push_back(Warning(ss.str(),
|
524
|
-
IgnoringWarning,
|
525
|
-
sourceBlock));
|
526
|
-
}
|
527
|
-
}
|
528
|
-
}
|
529
|
-
|
530
|
-
if (parameter.values.empty()) {
|
531
|
-
// WARN: empty definition
|
532
|
-
std::stringstream ss;
|
533
|
-
ss << "no possible values specified for parameter '" << parameter.name << "'";
|
534
|
-
SourceCharactersBlock sourceBlock = CharacterMapForBlock(sectionCur, cur, section.bounds, parser.sourceData);
|
535
|
-
result.first.warnings.push_back(Warning(ss.str(),
|
536
|
-
EmptyDefinitionWarning,
|
537
|
-
sourceBlock));
|
538
|
-
}
|
539
|
-
|
540
|
-
if((!parameter.exampleValue.empty() || !parameter.defaultValue.empty()) && !parameter.values.empty()) {
|
541
|
-
CheckExampleAndDefaultValue(section, sectionCur, parser, parameter, result);
|
542
|
-
}
|
543
|
-
|
544
|
-
endCur = CloseList(sectionCur, section.bounds.second);
|
545
|
-
result.second = endCur;
|
546
|
-
return result;
|
547
|
-
}
|
548
|
-
|
549
|
-
/** Parse entities in values attribute */
|
550
|
-
static ParseSectionResult ParseValuesEntities(const BlockIterator& cur,
|
551
|
-
const SectionBounds& bounds,
|
552
|
-
BlueprintParserCore& parser,
|
553
|
-
Collection<Value>::type& values) {
|
554
|
-
|
555
|
-
ParseSectionResult result = std::make_pair(Result(), cur);
|
556
|
-
|
557
|
-
if (cur->type != ListBlockBeginType)
|
558
|
-
return result;
|
559
|
-
|
560
|
-
BlockIterator sectionCur = ContentBlock(cur, bounds.second);
|
561
|
-
|
562
|
-
while (sectionCur != bounds.second &&
|
563
|
-
sectionCur->type == ListItemBlockBeginType) {
|
564
|
-
|
565
|
-
sectionCur = SkipToClosingBlock(sectionCur, bounds.second, ListItemBlockBeginType, ListItemBlockEndType);
|
566
|
-
|
567
|
-
CaptureGroups captureGroups;
|
568
|
-
std::string content = sectionCur->content;
|
569
|
-
if (content.empty()) {
|
570
|
-
// Not inline list, map from source
|
571
|
-
content = MapSourceData(parser.sourceData, sectionCur->sourceMap);
|
572
|
-
}
|
573
|
-
|
574
|
-
RegexCapture(content, PARAMETER_VALUE, captureGroups);
|
575
|
-
if (captureGroups.size() > 1) {
|
576
|
-
values.push_back(captureGroups[1]);
|
577
|
-
}
|
578
|
-
else {
|
579
|
-
// WARN: Ignoring unexpected content
|
580
|
-
TrimString(content);
|
581
|
-
std::stringstream ss;
|
582
|
-
ss << "ignoring the '" << content << "' element";
|
583
|
-
ss << ", expected '`" << content << "`'";
|
584
|
-
|
585
|
-
SourceCharactersBlock sourceBlock = CharacterMapForBlock(sectionCur, cur, bounds, parser.sourceData);
|
586
|
-
result.first.warnings.push_back(Warning(ss.str(),
|
587
|
-
IgnoringWarning,
|
588
|
-
sourceBlock));
|
589
|
-
}
|
590
|
-
|
591
|
-
++sectionCur;
|
592
|
-
}
|
593
|
-
|
594
|
-
result.second = sectionCur;
|
595
|
-
return result;
|
596
|
-
}
|
597
|
-
|
598
|
-
static void CheckExampleAndDefaultValue(const BlueprintSection& section,
|
599
|
-
const BlockIterator& cur,
|
600
|
-
const BlueprintParserCore& parser,
|
601
|
-
const Parameter& parameter,
|
602
|
-
ParseSectionResult& result) {
|
603
|
-
|
604
|
-
bool isExampleFound = false;
|
605
|
-
bool isDefaultFound = false;
|
606
|
-
|
607
|
-
for (Collection<Value>::const_iterator it = parameter.values.begin(); it != parameter.values.end(); ++it){
|
608
|
-
if(parameter.exampleValue == *it) {
|
609
|
-
isExampleFound = true;
|
610
|
-
}
|
611
|
-
if(parameter.defaultValue == *it) {
|
612
|
-
isDefaultFound = true;
|
613
|
-
}
|
614
|
-
}
|
615
|
-
|
616
|
-
if(!parameter.exampleValue.empty() && !isExampleFound) {
|
617
|
-
// WARN: missing example in values.
|
618
|
-
std::stringstream ss;
|
619
|
-
ss << "the example value '" << parameter.exampleValue << "' of parameter '"<< parameter.name <<"' is not in its list of expected values";
|
620
|
-
SourceCharactersBlock sourceBlock = CharacterMapForBlock(cur, section.bounds.second, section.bounds, parser.sourceData);
|
621
|
-
result.first.warnings.push_back(Warning(ss.str(),
|
622
|
-
LogicalErrorWarning,
|
623
|
-
sourceBlock));
|
624
|
-
}
|
625
|
-
|
626
|
-
if(!parameter.defaultValue.empty() && !isDefaultFound) {
|
627
|
-
// WARN: missing default in values.
|
628
|
-
std::stringstream ss;
|
629
|
-
ss << "the default value '" << parameter.defaultValue << "' of parameter '"<< parameter.name <<"' is not in its list of expected values";
|
630
|
-
SourceCharactersBlock sourceBlock = CharacterMapForBlock(cur, section.bounds.second, section.bounds, parser.sourceData);
|
631
|
-
result.first.warnings.push_back(Warning(ss.str(),
|
632
|
-
LogicalErrorWarning,
|
633
|
-
sourceBlock));
|
634
|
-
}
|
635
|
-
|
636
|
-
return;
|
637
|
-
}
|
638
|
-
|
639
|
-
|
640
|
-
};
|
641
|
-
|
642
|
-
typedef BlockParser<Parameter, SectionParser<Parameter> > ParameterDefinitionParser;
|
643
|
-
}
|
644
|
-
|
645
|
-
#endif
|