redsnow 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- 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,21 @@
|
|
1
|
+
//
|
2
|
+
// SerializeJSON.h
|
3
|
+
// snowcrash
|
4
|
+
//
|
5
|
+
// Created by Zdenek Nemec on 4/27/13.
|
6
|
+
// Copyright (c) 2013 Apiary Inc. All rights reserved.
|
7
|
+
//
|
8
|
+
|
9
|
+
#ifndef SNOWCRASH_SERIALIZE_JSON_H
|
10
|
+
#define SNOWCRASH_SERIALIZE_JSON_H
|
11
|
+
|
12
|
+
#include <ostream>
|
13
|
+
#include "Blueprint.h"
|
14
|
+
|
15
|
+
namespace snowcrash {
|
16
|
+
|
17
|
+
// Naive JSON serialization to ostream
|
18
|
+
void SerializeJSON(const snowcrash::Blueprint& blueprint, std::ostream &os);
|
19
|
+
}
|
20
|
+
|
21
|
+
#endif
|
@@ -0,0 +1,336 @@
|
|
1
|
+
//
|
2
|
+
// SerializeYAML.cc
|
3
|
+
// snowcrash
|
4
|
+
//
|
5
|
+
// Created by Zdenek Nemec on 5/3/13.
|
6
|
+
// Copyright (c) 2013 Apiary Inc. All rights reserved.
|
7
|
+
//
|
8
|
+
|
9
|
+
#include "Serialize.h"
|
10
|
+
#include "SerializeYAML.h"
|
11
|
+
|
12
|
+
using namespace snowcrash;
|
13
|
+
|
14
|
+
static std::string ReservedCharacters = "#-[]:|>!*&%@`,{}?\'";
|
15
|
+
|
16
|
+
/** Normalizes string value for use in YAML and checks whether quotation is need */
|
17
|
+
static std::string NormalizeStringValue(const std::string& value, bool& needsQuotation)
|
18
|
+
{
|
19
|
+
std::string normalizedValue = value;
|
20
|
+
if (normalizedValue.find("\"") != std::string::npos)
|
21
|
+
normalizedValue = EscapeDoubleQuotes(normalizedValue);
|
22
|
+
|
23
|
+
if (value.find("\n") != std::string::npos)
|
24
|
+
normalizedValue = EscapeNewlines(normalizedValue);
|
25
|
+
|
26
|
+
needsQuotation = (normalizedValue != value);
|
27
|
+
if (!needsQuotation) {
|
28
|
+
for (std::string::const_iterator it = value.begin() ; it < value.end() ; ++it){
|
29
|
+
needsQuotation = ReservedCharacters.find(*it) != std::string::npos;
|
30
|
+
if (needsQuotation)
|
31
|
+
break;
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
return normalizedValue;
|
36
|
+
}
|
37
|
+
|
38
|
+
|
39
|
+
/** Insert array item mark */
|
40
|
+
static void ArrayItemLeadIn(size_t level, std::ostream &os)
|
41
|
+
{
|
42
|
+
if (level < 1)
|
43
|
+
return;
|
44
|
+
|
45
|
+
for (size_t i = 0; i < level - 1; ++i)
|
46
|
+
os << " ";
|
47
|
+
|
48
|
+
os << "- ";
|
49
|
+
}
|
50
|
+
|
51
|
+
/** Serialize key value pair */
|
52
|
+
static void serialize(const std::string& key, const std::string& value, size_t level, std::ostream &os, bool implicitQuotation = true)
|
53
|
+
{
|
54
|
+
if (key.empty())
|
55
|
+
return;
|
56
|
+
|
57
|
+
for (size_t i = 0; i < level; ++i)
|
58
|
+
os << " ";
|
59
|
+
|
60
|
+
if (!value.empty()) {
|
61
|
+
|
62
|
+
os << key << ": ";
|
63
|
+
|
64
|
+
bool needsQuotation = false;
|
65
|
+
std::string normalizedValue = NormalizeStringValue(value, needsQuotation);
|
66
|
+
|
67
|
+
if (implicitQuotation) {
|
68
|
+
// Always use quotation
|
69
|
+
os << "\"" << normalizedValue << "\"";
|
70
|
+
}
|
71
|
+
else {
|
72
|
+
if (needsQuotation)
|
73
|
+
os << "\"" << normalizedValue << "\"";
|
74
|
+
else
|
75
|
+
os << value;
|
76
|
+
}
|
77
|
+
|
78
|
+
os << std::endl;
|
79
|
+
}
|
80
|
+
else
|
81
|
+
os << key << ":\n";
|
82
|
+
}
|
83
|
+
|
84
|
+
/** Serializes key value collection */
|
85
|
+
static void serializeKeyValueCollection(const Collection<KeyValuePair>::type& collection, size_t level, std::ostream &os)
|
86
|
+
{
|
87
|
+
for (Collection<KeyValuePair>::const_iterator it = collection.begin(); it != collection.end(); ++it) {
|
88
|
+
|
89
|
+
// Array item
|
90
|
+
ArrayItemLeadIn(level + 1, os);
|
91
|
+
|
92
|
+
// Name
|
93
|
+
serialize(SerializeKey::Name, it->first, 0, os);
|
94
|
+
|
95
|
+
// Value
|
96
|
+
serialize(SerializeKey::Value, it->second, level + 1, os);
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
/** Serialize Metadata */
|
101
|
+
static void serialize(const Collection<Metadata>::type& metadata, std::ostream &os)
|
102
|
+
{
|
103
|
+
serialize(SerializeKey::Metadata, std::string(), 0, os);
|
104
|
+
|
105
|
+
if (metadata.empty())
|
106
|
+
return;
|
107
|
+
|
108
|
+
serializeKeyValueCollection(metadata, 0, os);
|
109
|
+
}
|
110
|
+
|
111
|
+
/** Serialize Headers */
|
112
|
+
static void serialize(const Collection<Header>::type& headers, size_t level, std::ostream &os)
|
113
|
+
{
|
114
|
+
serializeKeyValueCollection(headers, level, os);
|
115
|
+
}
|
116
|
+
|
117
|
+
/** Serialize Parameters */
|
118
|
+
static void serialize(const Collection<Parameter>::type& parameters, size_t level, std::ostream &os)
|
119
|
+
{
|
120
|
+
for (Collection<Parameter>::const_iterator it = parameters.begin(); it != parameters.end(); ++it) {
|
121
|
+
|
122
|
+
// Array item
|
123
|
+
ArrayItemLeadIn(level + 1, os);
|
124
|
+
|
125
|
+
// Key / name
|
126
|
+
serialize(SerializeKey::Name, it->name, 0, os);
|
127
|
+
|
128
|
+
// Description
|
129
|
+
serialize(SerializeKey::Description, it->description, level + 1, os);
|
130
|
+
|
131
|
+
// Type
|
132
|
+
serialize(SerializeKey::Type, it->type, level + 1, os);
|
133
|
+
|
134
|
+
// Required
|
135
|
+
serialize(SerializeKey::Required, (it->use == OptionalParameterUse) ? "false" : "true", level + 1, os, false);
|
136
|
+
|
137
|
+
// Default
|
138
|
+
serialize(SerializeKey::Default, it->defaultValue, level + 1, os);
|
139
|
+
|
140
|
+
// Example
|
141
|
+
serialize(SerializeKey::Example, it->exampleValue, level + 1, os);
|
142
|
+
|
143
|
+
// Values
|
144
|
+
serialize(SerializeKey::Values, std::string(), level + 1, os);
|
145
|
+
|
146
|
+
if (!it->values.empty()) {
|
147
|
+
for (Collection<Value>::const_iterator val_it = it->values.begin();
|
148
|
+
val_it != it->values.end();
|
149
|
+
++val_it) {
|
150
|
+
|
151
|
+
ArrayItemLeadIn(level + 2, os);
|
152
|
+
|
153
|
+
serialize(SerializeKey::Value, *val_it, 0, os);
|
154
|
+
}
|
155
|
+
}
|
156
|
+
}
|
157
|
+
}
|
158
|
+
|
159
|
+
/** Serialize Payload */
|
160
|
+
static void serialize(const Payload& payload, size_t level, bool array, std::ostream &os)
|
161
|
+
{
|
162
|
+
for (size_t i = 0; i < level - 1; i++) {
|
163
|
+
os << " ";
|
164
|
+
}
|
165
|
+
|
166
|
+
if (array)
|
167
|
+
os << "- ";
|
168
|
+
else
|
169
|
+
os << " ";
|
170
|
+
|
171
|
+
// Name
|
172
|
+
serialize(SerializeKey::Name, payload.name, 0, os);
|
173
|
+
|
174
|
+
// Description
|
175
|
+
serialize(SerializeKey::Description, payload.description, level, os);
|
176
|
+
|
177
|
+
// Headers
|
178
|
+
serialize(SerializeKey::Headers, std::string(), level, os);
|
179
|
+
if (!payload.headers.empty()) {
|
180
|
+
serialize(payload.headers, level, os);
|
181
|
+
}
|
182
|
+
|
183
|
+
// Body
|
184
|
+
serialize(SerializeKey::Body, payload.body, level, os);
|
185
|
+
|
186
|
+
// Schema
|
187
|
+
serialize(SerializeKey::Schema, payload.schema, level, os);
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
// Serialize Transaction Example
|
192
|
+
static void serialize(const TransactionExample& example, std::ostream &os)
|
193
|
+
{
|
194
|
+
os << " - "; // indent 4
|
195
|
+
// Name
|
196
|
+
serialize(SerializeKey::Name, example.name, 0, os);
|
197
|
+
|
198
|
+
// Description
|
199
|
+
serialize(SerializeKey::Description, example.description, 4, os);
|
200
|
+
|
201
|
+
// Requests
|
202
|
+
serialize(SerializeKey::Requests, std::string(), 4, os);
|
203
|
+
if (!example.requests.empty()) {
|
204
|
+
for (Collection<Request>::const_iterator it = example.requests.begin(); it != example.requests.end(); ++it) {
|
205
|
+
serialize(*it, 5, true, os);
|
206
|
+
}
|
207
|
+
}
|
208
|
+
|
209
|
+
// Responses
|
210
|
+
serialize(SerializeKey::Responses, std::string(), 4, os);
|
211
|
+
if (!example.responses.empty()) {
|
212
|
+
for (Collection<Response>::const_iterator it = example.responses.begin(); it != example.responses.end(); ++it) {
|
213
|
+
serialize(*it, 5, true, os);
|
214
|
+
}
|
215
|
+
}
|
216
|
+
}
|
217
|
+
|
218
|
+
/** Serialize Action */
|
219
|
+
static void serialize(const Action& action, std::ostream &os)
|
220
|
+
{
|
221
|
+
os << " - "; // indent 3
|
222
|
+
|
223
|
+
// Name
|
224
|
+
serialize(SerializeKey::Name, action.name, 0, os);
|
225
|
+
|
226
|
+
// Description
|
227
|
+
serialize(SerializeKey::Description, action.description, 3, os);
|
228
|
+
|
229
|
+
// HTTP method
|
230
|
+
serialize(SerializeKey::Method, action.method, 3, os);
|
231
|
+
|
232
|
+
// Parameters
|
233
|
+
serialize(SerializeKey::Parameters, std::string(), 3, os);
|
234
|
+
if (!action.parameters.empty())
|
235
|
+
serialize(action.parameters, 3, os);
|
236
|
+
|
237
|
+
// Examples
|
238
|
+
serialize(SerializeKey::Examples, std::string(), 3, os);
|
239
|
+
if (!action.examples.empty()) {
|
240
|
+
for (Collection<TransactionExample>::const_iterator it = action.examples.begin();
|
241
|
+
it != action.examples.end();
|
242
|
+
++it) {
|
243
|
+
serialize(*it, os);
|
244
|
+
}
|
245
|
+
}
|
246
|
+
}
|
247
|
+
|
248
|
+
/** Serialize Resource */
|
249
|
+
static void serialize(const Resource& resource, std::ostream &os)
|
250
|
+
{
|
251
|
+
os << " - "; // indent 2
|
252
|
+
|
253
|
+
// Name
|
254
|
+
serialize(SerializeKey::Name, resource.name, 0, os);
|
255
|
+
|
256
|
+
// Description
|
257
|
+
serialize(SerializeKey::Description, resource.description, 2, os);
|
258
|
+
|
259
|
+
// URI Template
|
260
|
+
serialize(SerializeKey::URITemplate, resource.uriTemplate, 2, os);
|
261
|
+
|
262
|
+
// Model
|
263
|
+
serialize(SerializeKey::Model, std::string(), 2, os);
|
264
|
+
if (!resource.model.name.empty())
|
265
|
+
serialize(resource.model, 3, false, os);
|
266
|
+
|
267
|
+
// Parameters
|
268
|
+
serialize(SerializeKey::Parameters, std::string(), 2, os);
|
269
|
+
if (!resource.parameters.empty())
|
270
|
+
serialize(resource.parameters, 2, os);
|
271
|
+
|
272
|
+
// Actions
|
273
|
+
serialize(SerializeKey::Actions, std::string(), 2, os);
|
274
|
+
|
275
|
+
if (resource.actions.empty())
|
276
|
+
return;
|
277
|
+
|
278
|
+
for (Collection<Action>::const_iterator it = resource.actions.begin(); it != resource.actions.end(); ++it) {
|
279
|
+
serialize(*it, os);
|
280
|
+
}
|
281
|
+
}
|
282
|
+
|
283
|
+
/** Serialize Resource Group */
|
284
|
+
static void serialize(const ResourceGroup& group, std::ostream &os)
|
285
|
+
{
|
286
|
+
os << "- "; // indent 1
|
287
|
+
|
288
|
+
// Name
|
289
|
+
serialize(SerializeKey::Name, group.name, 0, os);
|
290
|
+
|
291
|
+
// Description
|
292
|
+
serialize(SerializeKey::Description, group.description, 1, os);
|
293
|
+
|
294
|
+
// Resources
|
295
|
+
serialize(SerializeKey::Resources, std::string(), 1, os);
|
296
|
+
|
297
|
+
if (group.resources.empty())
|
298
|
+
return;
|
299
|
+
|
300
|
+
for (Collection<Resource>::const_iterator it = group.resources.begin(); it != group.resources.end(); ++it) {
|
301
|
+
serialize(*it, os);
|
302
|
+
}
|
303
|
+
}
|
304
|
+
|
305
|
+
/** Serialize Blueprint */
|
306
|
+
static void serialize(const Blueprint& blueprint, std::ostream &os)
|
307
|
+
{
|
308
|
+
// AST Version
|
309
|
+
serialize(SerializeKey::ASTVersion, AST_SERIALIZATION_VERSION, 0, os, false);
|
310
|
+
|
311
|
+
// Metadata
|
312
|
+
serialize(blueprint.metadata, os);
|
313
|
+
|
314
|
+
// API Name
|
315
|
+
serialize(SerializeKey::Name, blueprint.name, 0, os);
|
316
|
+
|
317
|
+
// API Description
|
318
|
+
serialize(SerializeKey::Description, blueprint.description, 0, os);
|
319
|
+
|
320
|
+
// Resource Groups
|
321
|
+
serialize(SerializeKey::ResourceGroups, std::string(), 0, os);
|
322
|
+
if (blueprint.resourceGroups.empty())
|
323
|
+
return;
|
324
|
+
|
325
|
+
for (Collection<ResourceGroup>::type::const_iterator it = blueprint.resourceGroups.begin();
|
326
|
+
it != blueprint.resourceGroups.end();
|
327
|
+
++it) {
|
328
|
+
|
329
|
+
serialize(*it, os);
|
330
|
+
}
|
331
|
+
}
|
332
|
+
|
333
|
+
void snowcrash::SerializeYAML(const snowcrash::Blueprint& blueprint, std::ostream &os)
|
334
|
+
{
|
335
|
+
serialize(blueprint, os);
|
336
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
//
|
2
|
+
// SerializeYAML.h
|
3
|
+
// snowcrash
|
4
|
+
//
|
5
|
+
// Created by Zdenek Nemec on 5/3/13.
|
6
|
+
// Copyright (c) 2013 Apiary Inc. All rights reserved.
|
7
|
+
//
|
8
|
+
|
9
|
+
#ifndef SNOWCRASH_SERIALIZE_YAML_H
|
10
|
+
#define SNOWCRASH_SERIALIZE_YAML_H
|
11
|
+
|
12
|
+
#include <ostream>
|
13
|
+
#include "Blueprint.h"
|
14
|
+
|
15
|
+
namespace snowcrash {
|
16
|
+
|
17
|
+
// Naive YAML serialization to ostream
|
18
|
+
void SerializeYAML(const snowcrash::Blueprint& blueprint, std::ostream &os);
|
19
|
+
}
|
20
|
+
|
21
|
+
#endif
|
@@ -0,0 +1,177 @@
|
|
1
|
+
//
|
2
|
+
// SourceAnnotation.h
|
3
|
+
// snowcrash
|
4
|
+
//
|
5
|
+
// Created by Zdenek Nemec on 7/12/13.
|
6
|
+
// Copyright (c) 2013 Apiary Inc. All rights reserved.
|
7
|
+
//
|
8
|
+
|
9
|
+
#ifndef SNOWCRASH_SOURCEANNOTATION_H
|
10
|
+
#define SNOWCRASH_SOURCEANNOTATION_H
|
11
|
+
|
12
|
+
#include <string>
|
13
|
+
#include <vector>
|
14
|
+
|
15
|
+
namespace snowcrash {
|
16
|
+
|
17
|
+
/**
|
18
|
+
* \brief A character range within the source code string.
|
19
|
+
*/
|
20
|
+
struct SourceCharactersRange {
|
21
|
+
size_t location;
|
22
|
+
size_t length;
|
23
|
+
};
|
24
|
+
|
25
|
+
/**
|
26
|
+
* \brief A block (set of ranges) of source code characters. A character map.
|
27
|
+
*
|
28
|
+
* NOTE: The block does not have to be continuous.
|
29
|
+
*/
|
30
|
+
typedef std::vector<SourceCharactersRange> SourceCharactersBlock;
|
31
|
+
|
32
|
+
/**
|
33
|
+
* \brief A source data annotation.
|
34
|
+
*
|
35
|
+
* Annotation bound to a source data block. Includes an
|
36
|
+
* annotation code and an optional message.
|
37
|
+
*/
|
38
|
+
struct SourceAnnotation {
|
39
|
+
|
40
|
+
/**
|
41
|
+
* \brief Default annotation code representing success.
|
42
|
+
*/
|
43
|
+
static const int OK;
|
44
|
+
|
45
|
+
/**
|
46
|
+
* \brief %SourceAnnotation default constructor.
|
47
|
+
*
|
48
|
+
* Creates an empty annotation with the default annotation code.
|
49
|
+
*/
|
50
|
+
SourceAnnotation() : code(OK) {}
|
51
|
+
|
52
|
+
/**
|
53
|
+
* \brief %SourceAnnotation copy constructor.
|
54
|
+
* \param rhs An annotation to be copied.
|
55
|
+
*/
|
56
|
+
SourceAnnotation(const SourceAnnotation& rhs) {
|
57
|
+
|
58
|
+
this->message = rhs.message;
|
59
|
+
this->code = rhs.code;
|
60
|
+
this->location = rhs.location;
|
61
|
+
}
|
62
|
+
|
63
|
+
/**
|
64
|
+
* \brief %SourceAnnotation constructor.
|
65
|
+
* \param message An annotation message.
|
66
|
+
* \param code Annotation code.
|
67
|
+
* \param location A location of the annotation.
|
68
|
+
*/
|
69
|
+
SourceAnnotation(const std::string& message,
|
70
|
+
int code = OK,
|
71
|
+
const SourceCharactersBlock& location = SourceCharactersBlock()) {
|
72
|
+
|
73
|
+
this->message = message;
|
74
|
+
this->code = code;
|
75
|
+
|
76
|
+
this->location.clear();
|
77
|
+
if (!location.empty())
|
78
|
+
this->location.assign(location.begin(), location.end());
|
79
|
+
}
|
80
|
+
|
81
|
+
/** \brief %SourceAnnotation destructor. */
|
82
|
+
~SourceAnnotation() {}
|
83
|
+
|
84
|
+
/**
|
85
|
+
* \brief %SourceAnnotation assignment operator
|
86
|
+
* \param rhs An annotation to be assigned to this annotation.
|
87
|
+
*/
|
88
|
+
SourceAnnotation& operator=(const SourceAnnotation& rhs) {
|
89
|
+
this->message = rhs.message;
|
90
|
+
this->code = rhs.code;
|
91
|
+
this->location = rhs.location;
|
92
|
+
return *this;
|
93
|
+
}
|
94
|
+
|
95
|
+
/** The location of this annotation within the source data buffer. */
|
96
|
+
SourceCharactersBlock location;
|
97
|
+
|
98
|
+
/** An annotation code. */
|
99
|
+
int code;
|
100
|
+
|
101
|
+
/** A annotation message. */
|
102
|
+
std::string message;
|
103
|
+
};
|
104
|
+
|
105
|
+
/**
|
106
|
+
* Error source annotation.
|
107
|
+
*/
|
108
|
+
typedef SourceAnnotation Error;
|
109
|
+
|
110
|
+
/**
|
111
|
+
* Error codes
|
112
|
+
*/
|
113
|
+
enum ErrorCode {
|
114
|
+
NoError = 0,
|
115
|
+
ApplicationError = 1,
|
116
|
+
BusinessError = 2,
|
117
|
+
SymbolError = 3
|
118
|
+
};
|
119
|
+
|
120
|
+
/**
|
121
|
+
* Warning source annotation.
|
122
|
+
*/
|
123
|
+
typedef SourceAnnotation Warning;
|
124
|
+
|
125
|
+
/**
|
126
|
+
* Warning codes
|
127
|
+
*/
|
128
|
+
enum WarningCode {
|
129
|
+
NoWarning = 0,
|
130
|
+
APINameWarning = 1,
|
131
|
+
DuplicateWarning = 2,
|
132
|
+
FormattingWarning = 3,
|
133
|
+
RedefinitionWarning = 4,
|
134
|
+
IgnoringWarning = 5,
|
135
|
+
EmptyDefinitionWarning = 6,
|
136
|
+
NotEmptyDefinitionWarning = 7,
|
137
|
+
LogicalErrorWarning = 8,
|
138
|
+
DeprecatedWarning = 9,
|
139
|
+
IndentationWarning = 10,
|
140
|
+
AmbiguityWarning = 11,
|
141
|
+
URIWarning = 12
|
142
|
+
};
|
143
|
+
|
144
|
+
/**
|
145
|
+
* A set of warning source annotations.
|
146
|
+
*/
|
147
|
+
typedef std::vector<Warning> Warnings;
|
148
|
+
|
149
|
+
/**
|
150
|
+
* \brief A parsing result Report.
|
151
|
+
*
|
152
|
+
* Result of a source data parsing operation.
|
153
|
+
* Composed of ONE error source annotation
|
154
|
+
* and a set of warning source annotations.
|
155
|
+
*/
|
156
|
+
struct Result {
|
157
|
+
|
158
|
+
/**
|
159
|
+
* \brief Append a result to this one, replacing the error source annotation.
|
160
|
+
*
|
161
|
+
* NOTE: A binding does not need to wrap this action.
|
162
|
+
*/
|
163
|
+
Result& operator+=(const Result& rhs) {
|
164
|
+
error = rhs.error;
|
165
|
+
warnings.insert(warnings.end(), rhs.warnings.begin(), rhs.warnings.end());
|
166
|
+
return *this;
|
167
|
+
}
|
168
|
+
|
169
|
+
/** Result error source annotation */
|
170
|
+
Error error;
|
171
|
+
|
172
|
+
/** Result warning source annotations */
|
173
|
+
Warnings warnings;
|
174
|
+
};
|
175
|
+
}
|
176
|
+
|
177
|
+
#endif
|