redsnow 0.0.8
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 +7 -0
- data/.gitignore +34 -0
- data/.gitmodules +3 -0
- data/.travis.yml +20 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +62 -0
- data/Rakefile +36 -0
- data/Vagrantfile +20 -0
- data/ext/snowcrash/Makefile +64 -0
- data/ext/snowcrash/Vagrantfile +20 -0
- data/ext/snowcrash/bin/snowcrash +0 -0
- data/ext/snowcrash/common.gypi +163 -0
- data/ext/snowcrash/config.gypi +10 -0
- data/ext/snowcrash/config.mk +5 -0
- data/ext/snowcrash/configure +213 -0
- data/ext/snowcrash/provisioning.sh +15 -0
- data/ext/snowcrash/snowcrash.gyp +141 -0
- data/ext/snowcrash/src/ActionParser.h +503 -0
- data/ext/snowcrash/src/AssetParser.h +215 -0
- data/ext/snowcrash/src/BlockUtility.h +186 -0
- data/ext/snowcrash/src/Blueprint.h +283 -0
- data/ext/snowcrash/src/BlueprintParser.h +347 -0
- data/ext/snowcrash/src/BlueprintParserCore.h +190 -0
- data/ext/snowcrash/src/BlueprintSection.h +140 -0
- data/ext/snowcrash/src/BlueprintUtility.h +126 -0
- data/ext/snowcrash/src/CBlueprint.cc +600 -0
- data/ext/snowcrash/src/CBlueprint.h +354 -0
- data/ext/snowcrash/src/CSourceAnnotation.cc +140 -0
- data/ext/snowcrash/src/CSourceAnnotation.h +106 -0
- data/ext/snowcrash/src/CodeBlockUtility.h +189 -0
- data/ext/snowcrash/src/DescriptionSectionUtility.h +156 -0
- data/ext/snowcrash/src/HTTP.cc +46 -0
- data/ext/snowcrash/src/HTTP.h +105 -0
- data/ext/snowcrash/src/HeaderParser.h +289 -0
- data/ext/snowcrash/src/ListBlockUtility.h +273 -0
- data/ext/snowcrash/src/ListUtility.h +95 -0
- data/ext/snowcrash/src/MarkdownBlock.cc +176 -0
- data/ext/snowcrash/src/MarkdownBlock.h +93 -0
- data/ext/snowcrash/src/MarkdownParser.cc +266 -0
- data/ext/snowcrash/src/MarkdownParser.h +88 -0
- data/ext/snowcrash/src/ParameterDefinitonParser.h +570 -0
- data/ext/snowcrash/src/ParametersParser.h +252 -0
- data/ext/snowcrash/src/Parser.cc +71 -0
- data/ext/snowcrash/src/Parser.h +29 -0
- data/ext/snowcrash/src/ParserCore.cc +120 -0
- data/ext/snowcrash/src/ParserCore.h +82 -0
- data/ext/snowcrash/src/PayloadParser.h +672 -0
- data/ext/snowcrash/src/Platform.h +54 -0
- data/ext/snowcrash/src/RegexMatch.h +32 -0
- data/ext/snowcrash/src/ResourceGroupParser.h +195 -0
- data/ext/snowcrash/src/ResourceParser.h +584 -0
- data/ext/snowcrash/src/SectionUtility.h +142 -0
- data/ext/snowcrash/src/Serialize.cc +52 -0
- data/ext/snowcrash/src/Serialize.h +69 -0
- data/ext/snowcrash/src/SerializeJSON.cc +601 -0
- data/ext/snowcrash/src/SerializeJSON.h +21 -0
- data/ext/snowcrash/src/SerializeYAML.cc +336 -0
- data/ext/snowcrash/src/SerializeYAML.h +21 -0
- data/ext/snowcrash/src/SourceAnnotation.h +177 -0
- data/ext/snowcrash/src/StringUtility.h +109 -0
- data/ext/snowcrash/src/SymbolTable.h +83 -0
- data/ext/snowcrash/src/UriTemplateParser.cc +195 -0
- data/ext/snowcrash/src/UriTemplateParser.h +243 -0
- data/ext/snowcrash/src/Version.h +39 -0
- data/ext/snowcrash/src/csnowcrash.cc +23 -0
- data/ext/snowcrash/src/csnowcrash.h +38 -0
- data/ext/snowcrash/src/posix/RegexMatch.cc +99 -0
- data/ext/snowcrash/src/snowcrash.cc +18 -0
- data/ext/snowcrash/src/snowcrash.h +41 -0
- data/ext/snowcrash/src/snowcrash/snowcrash.cc +170 -0
- data/ext/snowcrash/src/win/RegexMatch.cc +78 -0
- data/ext/snowcrash/sundown/CONTRIBUTING.md +10 -0
- data/ext/snowcrash/sundown/Makefile +83 -0
- data/ext/snowcrash/sundown/Makefile.win +33 -0
- data/ext/snowcrash/sundown/examples/smartypants.c +72 -0
- data/ext/snowcrash/sundown/examples/sundown.c +80 -0
- data/ext/snowcrash/sundown/html/houdini.h +37 -0
- data/ext/snowcrash/sundown/html/houdini_href_e.c +108 -0
- data/ext/snowcrash/sundown/html/houdini_html_e.c +84 -0
- data/ext/snowcrash/sundown/html/html.c +647 -0
- data/ext/snowcrash/sundown/html/html.h +77 -0
- data/ext/snowcrash/sundown/html/html_smartypants.c +389 -0
- data/ext/snowcrash/sundown/html_block_names.txt +25 -0
- data/ext/snowcrash/sundown/src/autolink.c +297 -0
- data/ext/snowcrash/sundown/src/autolink.h +51 -0
- data/ext/snowcrash/sundown/src/buffer.c +225 -0
- data/ext/snowcrash/sundown/src/buffer.h +96 -0
- data/ext/snowcrash/sundown/src/html_blocks.h +206 -0
- data/ext/snowcrash/sundown/src/markdown.c +2701 -0
- data/ext/snowcrash/sundown/src/markdown.h +147 -0
- data/ext/snowcrash/sundown/src/src_map.c +200 -0
- data/ext/snowcrash/sundown/src/src_map.h +58 -0
- data/ext/snowcrash/sundown/src/stack.c +81 -0
- data/ext/snowcrash/sundown/src/stack.h +29 -0
- data/ext/snowcrash/sundown/sundown.def +20 -0
- data/ext/snowcrash/tools/gyp/AUTHORS +11 -0
- data/ext/snowcrash/tools/gyp/DEPS +24 -0
- data/ext/snowcrash/tools/gyp/OWNERS +1 -0
- data/ext/snowcrash/tools/gyp/PRESUBMIT.py +120 -0
- data/ext/snowcrash/tools/gyp/buildbot/buildbot_run.py +190 -0
- data/ext/snowcrash/tools/gyp/codereview.settings +10 -0
- data/ext/snowcrash/tools/gyp/data/win/large-pdb-shim.cc +12 -0
- data/ext/snowcrash/tools/gyp/gyp +8 -0
- data/ext/snowcrash/tools/gyp/gyp.bat +5 -0
- data/ext/snowcrash/tools/gyp/gyp_main.py +18 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSNew.py +340 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSProject.py +208 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSSettings.py +1063 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSToolFile.py +58 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSUserFile.py +147 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSUtil.py +267 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSVersion.py +409 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/__init__.py +537 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/__init__.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/common.py +521 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/common.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/easy_xml.py +157 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/flock_tool.py +49 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/__init__.py +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/__init__.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/android.py +1069 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/cmake.py +1143 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/dump_dependency_json.py +81 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/eclipse.py +335 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/gypd.py +87 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/gypsh.py +56 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/make.py +2181 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/make.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/msvs.py +3335 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/ninja.py +2156 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/xcode.py +1224 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/xcode.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/input.py +2809 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/input.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/mac_tool.py +510 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/msvs_emulation.py +972 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/ninja_syntax.py +160 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/ordered_dict.py +289 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/win_tool.py +292 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.py +1440 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/xcodeproj_file.py +2889 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/xcodeproj_file.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/xml_fix.py +69 -0
- data/ext/snowcrash/tools/gyp/pylintrc +307 -0
- data/ext/snowcrash/tools/gyp/samples/samples +81 -0
- data/ext/snowcrash/tools/gyp/samples/samples.bat +5 -0
- data/ext/snowcrash/tools/gyp/setup.py +19 -0
- data/ext/snowcrash/tools/gyp/tools/Xcode/Specifications/gyp.pbfilespec +27 -0
- data/ext/snowcrash/tools/gyp/tools/Xcode/Specifications/gyp.xclangspec +226 -0
- data/ext/snowcrash/tools/gyp/tools/emacs/gyp.el +252 -0
- data/ext/snowcrash/tools/gyp/tools/graphviz.py +100 -0
- data/ext/snowcrash/tools/gyp/tools/pretty_gyp.py +155 -0
- data/ext/snowcrash/tools/gyp/tools/pretty_sln.py +168 -0
- data/ext/snowcrash/tools/gyp/tools/pretty_vcproj.py +329 -0
- data/ext/snowcrash/tools/homebrew/snowcrash.rb +11 -0
- data/ext/snowcrash/vcbuild.bat +184 -0
- data/lib/redsnow.rb +31 -0
- data/lib/redsnow/binding.rb +132 -0
- data/lib/redsnow/blueprint.rb +365 -0
- data/lib/redsnow/object.rb +18 -0
- data/lib/redsnow/parseresult.rb +107 -0
- data/lib/redsnow/version.rb +4 -0
- data/provisioning.sh +20 -0
- data/redsnow.gemspec +35 -0
- data/test/_helper.rb +15 -0
- data/test/fixtures/sample-api-ast.json +97 -0
- data/test/fixtures/sample-api.apib +20 -0
- data/test/redsnow_binding_test.rb +35 -0
- data/test/redsnow_parseresult_test.rb +50 -0
- data/test/redsnow_test.rb +285 -0
- metadata +358 -0
@@ -0,0 +1,252 @@
|
|
1
|
+
//
|
2
|
+
// ParametersParser.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_PARAMETERSPARSER_H
|
10
|
+
#define SNOWCRASH_PARAMETERSPARSER_H
|
11
|
+
|
12
|
+
#include <sstream>
|
13
|
+
#include "BlueprintParserCore.h"
|
14
|
+
#include "Blueprint.h"
|
15
|
+
#include "RegexMatch.h"
|
16
|
+
#include "StringUtility.h"
|
17
|
+
#include "BlockUtility.h"
|
18
|
+
#include "ParameterDefinitonParser.h"
|
19
|
+
|
20
|
+
namespace snowcrashconst {
|
21
|
+
|
22
|
+
/** Parameters matching regex */
|
23
|
+
const char* const ParametersRegex = "^[[:blank:]]*[Pp]arameters?[[:blank:]]*$";
|
24
|
+
|
25
|
+
/** Expected parameters content */
|
26
|
+
const char* const ExpectedParametersContent = "a nested list of parameters, one parameter per list item";
|
27
|
+
|
28
|
+
/** No parameters specified message */
|
29
|
+
const char* const NoParametersMessage = "no parameters specified, expected a nested list of parameters, one parameter per list item";
|
30
|
+
}
|
31
|
+
|
32
|
+
namespace snowcrash {
|
33
|
+
|
34
|
+
/** Internal type alias for Collection of Paramaeter */
|
35
|
+
typedef Collection<Parameter>::type ParameterCollection;
|
36
|
+
|
37
|
+
|
38
|
+
/** Finds a parameter inside a parameters collection */
|
39
|
+
FORCEINLINE ParameterCollection::iterator FindParameter(ParameterCollection& parameters,
|
40
|
+
const Parameter& parameter) {
|
41
|
+
return std::find_if(parameters.begin(),
|
42
|
+
parameters.end(),
|
43
|
+
std::bind2nd(MatchName<Parameter>(), parameter));
|
44
|
+
}
|
45
|
+
|
46
|
+
/**
|
47
|
+
* Returns true if given block has parameters signature, false otherwise.
|
48
|
+
*/
|
49
|
+
FORCEINLINE bool HasParametersSignature(const BlockIterator& begin,
|
50
|
+
const BlockIterator& end) {
|
51
|
+
|
52
|
+
if (begin->type != ListBlockBeginType &&
|
53
|
+
begin->type != ListItemBlockBeginType)
|
54
|
+
return false;
|
55
|
+
|
56
|
+
SourceData remainingContent;
|
57
|
+
SourceData content = GetListItemSignature(begin, end, remainingContent);
|
58
|
+
TrimString(content);
|
59
|
+
return RegexMatch(content, snowcrashconst::ParametersRegex);
|
60
|
+
}
|
61
|
+
|
62
|
+
/** Children List Block Classifier, ParameterCollection context. */
|
63
|
+
template <>
|
64
|
+
FORCEINLINE SectionType ClassifyChildrenListBlock<ParameterCollection>(const BlockIterator& begin,
|
65
|
+
const BlockIterator& end){
|
66
|
+
// TODO:
|
67
|
+
return UndefinedSectionType;
|
68
|
+
}
|
69
|
+
|
70
|
+
/** Block Classifier, ParameterCollection context. */
|
71
|
+
template <>
|
72
|
+
FORCEINLINE SectionType ClassifyBlock<ParameterCollection>(const BlockIterator& begin,
|
73
|
+
const BlockIterator& end,
|
74
|
+
const SectionType& context) {
|
75
|
+
|
76
|
+
if (context == UndefinedSectionType) {
|
77
|
+
if (HasParametersSignature(begin, end))
|
78
|
+
return ParametersSectionType;
|
79
|
+
}
|
80
|
+
else if (context == ParametersSectionType) {
|
81
|
+
|
82
|
+
if (begin->type == ListItemBlockEndType ||
|
83
|
+
begin->type == ListBlockEndType)
|
84
|
+
return UndefinedSectionType;
|
85
|
+
|
86
|
+
if (HasParameterDefinitionSignature(begin, end))
|
87
|
+
return ParameterDefinitionSectionType;
|
88
|
+
|
89
|
+
if (begin->type == ListBlockBeginType)
|
90
|
+
return ForeignSectionType; // Foreign nested list-item
|
91
|
+
|
92
|
+
if (begin->type == ListItemBlockBeginType)
|
93
|
+
return UndefinedSectionType;
|
94
|
+
}
|
95
|
+
else if (context == ParameterDefinitionSectionType ||
|
96
|
+
context == ForeignSectionType) {
|
97
|
+
|
98
|
+
if (begin->type == ListItemBlockEndType ||
|
99
|
+
begin->type == ListBlockEndType)
|
100
|
+
return UndefinedSectionType;
|
101
|
+
|
102
|
+
if (HasParameterDefinitionSignature(begin, end))
|
103
|
+
return ParameterDefinitionSectionType;
|
104
|
+
|
105
|
+
return ForeignSectionType;
|
106
|
+
}
|
107
|
+
|
108
|
+
return (context == ParametersSectionType) ? context : UndefinedSectionType;
|
109
|
+
}
|
110
|
+
|
111
|
+
/**
|
112
|
+
* Parameters section parser.
|
113
|
+
*/
|
114
|
+
template<>
|
115
|
+
struct SectionParser<ParameterCollection> {
|
116
|
+
|
117
|
+
static ParseSectionResult ParseSection(const BlueprintSection& section,
|
118
|
+
const BlockIterator& cur,
|
119
|
+
BlueprintParserCore& parser,
|
120
|
+
ParameterCollection& parameters) {
|
121
|
+
|
122
|
+
ParseSectionResult result = std::make_pair(Result(), cur);
|
123
|
+
switch (section.type) {
|
124
|
+
case ParametersSectionType:
|
125
|
+
result = HandleParmetersSection(section, cur, parser, parameters);
|
126
|
+
break;
|
127
|
+
|
128
|
+
case ParameterDefinitionSectionType:
|
129
|
+
result = HandleParmeterDefinitionSection(section, cur, parser, parameters);
|
130
|
+
break;
|
131
|
+
|
132
|
+
case ForeignSectionType:
|
133
|
+
result = HandleForeignSection<ParameterCollection>(section, cur, parser.sourceData);
|
134
|
+
break;
|
135
|
+
|
136
|
+
case UndefinedSectionType:
|
137
|
+
result.second = CloseList(cur, section.bounds.second);
|
138
|
+
break;
|
139
|
+
|
140
|
+
default:
|
141
|
+
result.first.error = UnexpectedBlockError(section, cur, parser.sourceData);
|
142
|
+
break;
|
143
|
+
}
|
144
|
+
|
145
|
+
return result;
|
146
|
+
}
|
147
|
+
|
148
|
+
static void Finalize(const SectionBounds& bounds,
|
149
|
+
BlueprintParserCore& parser,
|
150
|
+
ParameterCollection& parameters,
|
151
|
+
Result& result) {}
|
152
|
+
|
153
|
+
/**
|
154
|
+
* \brief Parse Parameters top-level section blocks.
|
155
|
+
* \param section Actual section being parsed.
|
156
|
+
* \param cur The actual position within Markdown block buffer.
|
157
|
+
* \param parser Parser's instance.
|
158
|
+
* \param payload An output buffer to write parameters into.
|
159
|
+
* \return A block parser section result.
|
160
|
+
*/
|
161
|
+
static ParseSectionResult HandleParmetersSection(const BlueprintSection& section,
|
162
|
+
const BlockIterator& cur,
|
163
|
+
BlueprintParserCore& parser,
|
164
|
+
ParameterCollection& parameters) {
|
165
|
+
|
166
|
+
ParseSectionResult result = std::make_pair(Result(), cur);
|
167
|
+
BlockIterator sectionCur = cur;
|
168
|
+
|
169
|
+
// Signature
|
170
|
+
if (sectionCur == section.bounds.first) {
|
171
|
+
|
172
|
+
CheckSignatureAdditionalContent(section,
|
173
|
+
sectionCur,
|
174
|
+
parser.sourceData,
|
175
|
+
"'parameters' keyword",
|
176
|
+
snowcrashconst::ExpectedParametersContent,
|
177
|
+
result.first);
|
178
|
+
result.second = SkipSignatureBlock(sectionCur, section.bounds.second);
|
179
|
+
return result;
|
180
|
+
}
|
181
|
+
|
182
|
+
// Unexpected description
|
183
|
+
if (sectionCur->type == QuoteBlockBeginType) {
|
184
|
+
sectionCur = SkipToClosingBlock(sectionCur, section.bounds.second, QuoteBlockBeginType, QuoteBlockEndType);
|
185
|
+
}
|
186
|
+
else if (sectionCur->type == ListBlockBeginType) {
|
187
|
+
sectionCur = SkipToClosingBlock(sectionCur, section.bounds.second, ListBlockBeginType, ListItemBlockEndType);
|
188
|
+
}
|
189
|
+
|
190
|
+
if (!CheckCursor(section, sectionCur, parser.sourceData, result.first))
|
191
|
+
return result;
|
192
|
+
|
193
|
+
// WARN: on ignoring additional content
|
194
|
+
std::stringstream ss;
|
195
|
+
ss << "ignoring additional content in the 'parameters' definition, expected " << snowcrashconst::ExpectedParametersContent;
|
196
|
+
|
197
|
+
SourceCharactersBlock sourceBlock = CharacterMapForBlock(sectionCur, cur, section.bounds, parser.sourceData);
|
198
|
+
result.first.warnings.push_back(Warning(ss.str(),
|
199
|
+
IgnoringWarning,
|
200
|
+
sourceBlock));
|
201
|
+
|
202
|
+
if (sectionCur != section.bounds.second)
|
203
|
+
result.second = ++sectionCur;
|
204
|
+
|
205
|
+
return result;
|
206
|
+
}
|
207
|
+
|
208
|
+
/** Parse a parameter definition top-level section blocks. */
|
209
|
+
static ParseSectionResult HandleParmeterDefinitionSection(const BlueprintSection& section,
|
210
|
+
const BlockIterator& cur,
|
211
|
+
BlueprintParserCore& parser,
|
212
|
+
ParameterCollection& parameters) {
|
213
|
+
Parameter parameter;
|
214
|
+
ParseSectionResult result = ParameterDefinitionParser::Parse(cur,
|
215
|
+
section.bounds.second,
|
216
|
+
section,
|
217
|
+
parser,
|
218
|
+
parameter);
|
219
|
+
if (result.first.error.code != Error::OK)
|
220
|
+
return result;
|
221
|
+
|
222
|
+
// Check duplicates
|
223
|
+
if (!parameters.empty()) {
|
224
|
+
ParameterCollection::iterator duplicate = FindParameter(parameters, parameter);
|
225
|
+
if (duplicate != parameters.end()) {
|
226
|
+
|
227
|
+
// WARN: Parameter already defined
|
228
|
+
std::stringstream ss;
|
229
|
+
ss << "overshadowing previous parameter '" << parameter.name << "' definition";
|
230
|
+
|
231
|
+
BlockIterator nameBlock = ListItemNameBlock(cur, section.bounds.second);
|
232
|
+
SourceCharactersBlock sourceBlock = CharacterMapForBlock(nameBlock, cur, section.bounds, parser.sourceData);
|
233
|
+
result.first.warnings.push_back(Warning(ss.str(),
|
234
|
+
RedefinitionWarning,
|
235
|
+
sourceBlock));
|
236
|
+
|
237
|
+
// Erase origan duplicate
|
238
|
+
parameters.erase(duplicate);
|
239
|
+
}
|
240
|
+
}
|
241
|
+
|
242
|
+
parameters.push_back(parameter);
|
243
|
+
|
244
|
+
return result;
|
245
|
+
}
|
246
|
+
};
|
247
|
+
|
248
|
+
typedef BlockParser<ParameterCollection, SectionParser<ParameterCollection> > ParametersParser;
|
249
|
+
}
|
250
|
+
|
251
|
+
|
252
|
+
#endif
|
@@ -0,0 +1,71 @@
|
|
1
|
+
//
|
2
|
+
// Parser.cpp
|
3
|
+
// snowcrash
|
4
|
+
//
|
5
|
+
// Created by Zdenek Nemec on 4/8/13.
|
6
|
+
// Copyright (c) 2013 Apiary Inc. All rights reserved.
|
7
|
+
//
|
8
|
+
|
9
|
+
#include <exception>
|
10
|
+
#include <sstream>
|
11
|
+
#include "Parser.h"
|
12
|
+
#include "MarkdownParser.h"
|
13
|
+
#include "BlueprintParser.h"
|
14
|
+
|
15
|
+
using namespace snowcrash;
|
16
|
+
|
17
|
+
const int SourceAnnotation::OK = 0;
|
18
|
+
|
19
|
+
// Check source for unsupported character \t & \r
|
20
|
+
// Returns true if passed (not found), false otherwise
|
21
|
+
static bool CheckSource(const SourceData& source, Result& result)
|
22
|
+
{
|
23
|
+
std::string::size_type pos = source.find("\t");
|
24
|
+
if (pos != std::string::npos) {
|
25
|
+
result.error = Error("the use of tab(s) '\\t' in source data isn't currently supported, please contact makers",
|
26
|
+
2,
|
27
|
+
MapSourceDataBlock(MakeSourceDataBlock(pos, 1), source));
|
28
|
+
return false;
|
29
|
+
}
|
30
|
+
|
31
|
+
pos = source.find("\r");
|
32
|
+
if (pos != std::string::npos) {
|
33
|
+
result.error = Error("the use of carriage return(s) '\\r' in source data isn't currently supported, please contact makers",
|
34
|
+
2,
|
35
|
+
MapSourceDataBlock(MakeSourceDataBlock(pos, 1), source));
|
36
|
+
return false;
|
37
|
+
}
|
38
|
+
|
39
|
+
return true;
|
40
|
+
}
|
41
|
+
|
42
|
+
void Parser::parse(const SourceData& source, BlueprintParserOptions options, Result& result, Blueprint& blueprint)
|
43
|
+
{
|
44
|
+
try {
|
45
|
+
|
46
|
+
// Sanity Check
|
47
|
+
if (!CheckSource(source, result))
|
48
|
+
return;
|
49
|
+
|
50
|
+
// Parse Markdown
|
51
|
+
MarkdownBlock::Stack markdown;
|
52
|
+
MarkdownParser markdownParser;
|
53
|
+
markdownParser.parse(source, result, markdown);
|
54
|
+
|
55
|
+
if (result.error.code != Error::OK)
|
56
|
+
return;
|
57
|
+
|
58
|
+
// Parse Blueprint
|
59
|
+
BlueprintParser::Parse(source, markdown, options, result, blueprint);
|
60
|
+
}
|
61
|
+
catch (const std::exception& e) {
|
62
|
+
|
63
|
+
std::stringstream ss;
|
64
|
+
ss << "parser exception: '" << e.what() << "'";
|
65
|
+
result.error = Error(ss.str(), 1);
|
66
|
+
}
|
67
|
+
catch (...) {
|
68
|
+
|
69
|
+
result.error = Error("parser exception has occured", 1);
|
70
|
+
}
|
71
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
//
|
2
|
+
// Parser.h
|
3
|
+
// snowcrash
|
4
|
+
//
|
5
|
+
// Created by Zdenek Nemec on 4/8/13.
|
6
|
+
// Copyright (c) 2013 Apiary Inc. All rights reserved.
|
7
|
+
//
|
8
|
+
|
9
|
+
#ifndef SNOWCRASH_PARSER_H
|
10
|
+
#define SNOWCRASH_PARSER_H
|
11
|
+
|
12
|
+
#include <functional>
|
13
|
+
#include "Blueprint.h"
|
14
|
+
#include "BlueprintParserCore.h"
|
15
|
+
|
16
|
+
namespace snowcrash {
|
17
|
+
|
18
|
+
//
|
19
|
+
// API Blueprint Parser
|
20
|
+
//
|
21
|
+
class Parser {
|
22
|
+
public:
|
23
|
+
|
24
|
+
// Parse source data into Blueprint AST
|
25
|
+
void parse(const SourceData& source, BlueprintParserOptions options, Result& result, Blueprint& blueprint);
|
26
|
+
};
|
27
|
+
}
|
28
|
+
|
29
|
+
#endif
|
@@ -0,0 +1,120 @@
|
|
1
|
+
//
|
2
|
+
// ParserCore.cc
|
3
|
+
// snowcrash
|
4
|
+
//
|
5
|
+
// Created by Zdenek Nemec on 5/4/13.
|
6
|
+
// Copyright (c) 2013 Apiary Inc. All rights reserved.
|
7
|
+
//
|
8
|
+
|
9
|
+
#include "ParserCore.h"
|
10
|
+
|
11
|
+
using namespace snowcrash;
|
12
|
+
|
13
|
+
SourceDataBlock snowcrash::MakeSourceDataBlock(size_t loc, size_t len)
|
14
|
+
{
|
15
|
+
SourceDataRange r;
|
16
|
+
r.location = loc;
|
17
|
+
r.length = len;
|
18
|
+
return SourceDataBlock(1, r);
|
19
|
+
}
|
20
|
+
|
21
|
+
void snowcrash::AppendSourceDataBlock(SourceDataBlock& destination, const SourceDataBlock& append)
|
22
|
+
{
|
23
|
+
if (append.empty())
|
24
|
+
return;
|
25
|
+
|
26
|
+
if (destination.empty() ||
|
27
|
+
append.front().location != destination.back().location + destination.back().length) {
|
28
|
+
destination.insert(destination.end(), append.begin(), append.end());
|
29
|
+
}
|
30
|
+
else {
|
31
|
+
// merge
|
32
|
+
destination.back().length += append.front().length;
|
33
|
+
|
34
|
+
if (append.size() > 1) {
|
35
|
+
destination.insert(destination.end(), ++append.begin(), append.end());
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
SourceDataBlockPair snowcrash::SplitSourceDataBlock(const SourceDataBlock& block, size_t len)
|
41
|
+
{
|
42
|
+
if (block.empty())
|
43
|
+
return std::make_pair(SourceDataBlock(), SourceDataBlock());
|
44
|
+
|
45
|
+
SourceDataBlock first;
|
46
|
+
SourceDataBlock second;
|
47
|
+
|
48
|
+
size_t remain = len;
|
49
|
+
for (SourceDataBlock::const_iterator it = block.begin(); it != block.end(); ++it) {
|
50
|
+
|
51
|
+
if (remain == 0) {
|
52
|
+
second.push_back(*it);
|
53
|
+
continue;
|
54
|
+
}
|
55
|
+
|
56
|
+
if (remain >= it->length) {
|
57
|
+
first.push_back(*it);
|
58
|
+
remain -= it->length;
|
59
|
+
continue;
|
60
|
+
}
|
61
|
+
|
62
|
+
if (remain < it->length) {
|
63
|
+
SourceDataRange left = *it;
|
64
|
+
left.length = remain;
|
65
|
+
first.push_back(left);
|
66
|
+
|
67
|
+
SourceDataRange right = *it;
|
68
|
+
right.location += remain;
|
69
|
+
right.length -= remain;
|
70
|
+
second.push_back(right);
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
return std::make_pair(first, second);
|
75
|
+
}
|
76
|
+
|
77
|
+
#define UTF8_CHAR_LEN( byte ) (( 0xE5000000 >> (( byte >> 3 ) & 0x1e )) & 3 ) + 1
|
78
|
+
|
79
|
+
/** \returns Number of UTF8 characters in byte buffer */
|
80
|
+
static size_t strnlen_utf8(const char* s, size_t len)
|
81
|
+
{
|
82
|
+
if (!s || !len)
|
83
|
+
return 0;
|
84
|
+
|
85
|
+
size_t i = 0, j = 0;
|
86
|
+
while (s[i] && i < len) {
|
87
|
+
i += UTF8_CHAR_LEN(s[i]);
|
88
|
+
j++;
|
89
|
+
}
|
90
|
+
return j;
|
91
|
+
}
|
92
|
+
|
93
|
+
SourceCharactersRange snowcrash::MapSourceDataRange(const SourceDataRange& range, const SourceData& data)
|
94
|
+
{
|
95
|
+
if (data.empty())
|
96
|
+
return SourceCharactersRange();
|
97
|
+
|
98
|
+
size_t charLocation = 0;
|
99
|
+
if (range.location > 0)
|
100
|
+
charLocation = strnlen_utf8(data.c_str(), range.location);
|
101
|
+
|
102
|
+
size_t charLength = 0;
|
103
|
+
if (range.length > 0)
|
104
|
+
charLength = strnlen_utf8(data.c_str() + range.location, range.length);
|
105
|
+
|
106
|
+
SourceCharactersRange characterRange = {charLocation, charLength };
|
107
|
+
return characterRange;
|
108
|
+
}
|
109
|
+
|
110
|
+
SourceCharactersBlock snowcrash::MapSourceDataBlock(const SourceDataBlock& block, const SourceData& data)
|
111
|
+
{
|
112
|
+
SourceCharactersBlock characterMap;
|
113
|
+
|
114
|
+
for (SourceDataBlock::const_iterator it = block.begin(); it != block.end(); ++it) {
|
115
|
+
SourceCharactersRange characterRange = MapSourceDataRange(*it, data);
|
116
|
+
characterMap.push_back(characterRange);
|
117
|
+
}
|
118
|
+
|
119
|
+
return characterMap;
|
120
|
+
}
|