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
@@ -0,0 +1,42 @@
|
|
1
|
+
//
|
2
|
+
// Section.cc
|
3
|
+
// snowcrash
|
4
|
+
//
|
5
|
+
// Created by Zdenek Nemec on 5/14/14.
|
6
|
+
// Copyright (c) 2014 Apiary Inc. All rights reserved.
|
7
|
+
//
|
8
|
+
|
9
|
+
#include "Section.h"
|
10
|
+
|
11
|
+
using namespace snowcrash;
|
12
|
+
|
13
|
+
std::string snowcrash::SectionName(const SectionType& section) {
|
14
|
+
|
15
|
+
switch (section) {
|
16
|
+
case ModelSectionType:
|
17
|
+
case ModelBodySectionType:
|
18
|
+
return "model";
|
19
|
+
|
20
|
+
case RequestSectionType:
|
21
|
+
case RequestBodySectionType:
|
22
|
+
return "request";
|
23
|
+
|
24
|
+
case ResponseSectionType:
|
25
|
+
case ResponseBodySectionType:
|
26
|
+
return "response";
|
27
|
+
|
28
|
+
case BodySectionType:
|
29
|
+
case DanglingBodySectionType:
|
30
|
+
return "message-body";
|
31
|
+
|
32
|
+
case SchemaSectionType:
|
33
|
+
case DanglingSchemaSectionType:
|
34
|
+
return "message-schema";
|
35
|
+
|
36
|
+
case HeadersSectionType:
|
37
|
+
return "headers";
|
38
|
+
|
39
|
+
default:
|
40
|
+
return "section";
|
41
|
+
}
|
42
|
+
}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
//
|
2
|
+
// Section.h
|
3
|
+
// snowcrash
|
4
|
+
//
|
5
|
+
// Created by Zdenek Nemec on 11/1/13.
|
6
|
+
// Copyright (c) 2013 Apiary Inc. All rights reserved.
|
7
|
+
//
|
8
|
+
|
9
|
+
#ifndef SNOWCRASH_SECTION_H
|
10
|
+
#define SNOWCRASH_SECTION_H
|
11
|
+
|
12
|
+
#include <string>
|
13
|
+
|
14
|
+
namespace snowcrash {
|
15
|
+
|
16
|
+
/**
|
17
|
+
* API Blueprint Sections Types.
|
18
|
+
*/
|
19
|
+
enum SectionType {
|
20
|
+
UndefinedSectionType, /// < Undefined section
|
21
|
+
BlueprintSectionType, /// < Blueprint overview
|
22
|
+
ResourceGroupSectionType, /// < Resource group
|
23
|
+
ResourceSectionType, /// < Resource
|
24
|
+
ActionSectionType, /// < Action
|
25
|
+
RequestSectionType, /// < Request
|
26
|
+
RequestBodySectionType, /// < Request & Payload body combined (abbrev)
|
27
|
+
ResponseSectionType, /// < Response
|
28
|
+
ResponseBodySectionType, /// < Response & Body combined (abbrev)
|
29
|
+
ModelSectionType, /// < Model
|
30
|
+
ModelBodySectionType, /// < Model & Body combined (abbrev)
|
31
|
+
BodySectionType, /// < Payload Body
|
32
|
+
DanglingBodySectionType, /// < Dangling Body (unrecognised section considered to be Body)
|
33
|
+
SchemaSectionType, /// < Payload Schema
|
34
|
+
DanglingSchemaSectionType, /// < Dangling Schema (unrecognised section considered to be Schema)
|
35
|
+
HeadersSectionType, /// < Headers
|
36
|
+
ForeignSectionType, /// < Foreign, unexpected section
|
37
|
+
ParametersSectionType, /// < Parameters
|
38
|
+
ParameterSectionType, /// < One Parameter definition
|
39
|
+
ValuesSectionType, /// < Value enumeration
|
40
|
+
ValueSectionType /// < One Value
|
41
|
+
};
|
42
|
+
|
43
|
+
/** \return Human readable name for given %SectionType */
|
44
|
+
extern std::string SectionName(const SectionType& section);
|
45
|
+
}
|
46
|
+
|
47
|
+
#endif
|
@@ -0,0 +1,229 @@
|
|
1
|
+
//
|
2
|
+
// SectionParser.h
|
3
|
+
// snowcrash
|
4
|
+
//
|
5
|
+
// Created by Zdenek Nemec on 5/4/13.
|
6
|
+
// Copyright (c) 2013 Apiary Inc. All rights reserved.
|
7
|
+
//
|
8
|
+
|
9
|
+
#ifndef SNOWCRASH_SECTIONPARSER_H
|
10
|
+
#define SNOWCRASH_SECTIONPARSER_H
|
11
|
+
|
12
|
+
#include <stdexcept>
|
13
|
+
#include "SectionProcessor.h"
|
14
|
+
|
15
|
+
#define ADAPTER_MISMATCH_ERR std::logic_error("mismatched adapter and node type")
|
16
|
+
|
17
|
+
namespace snowcrash {
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Blueprint section parser
|
21
|
+
*/
|
22
|
+
template<typename T, typename Adapter>
|
23
|
+
struct SectionParser {
|
24
|
+
|
25
|
+
|
26
|
+
/**
|
27
|
+
* \brief Parse a section of blueprint
|
28
|
+
* \param node Initial node to start parsing at
|
29
|
+
* \param siblings Siblings of the initial node
|
30
|
+
* \param pd Parser data
|
31
|
+
* \param T Parsed output
|
32
|
+
* \return Iterator to the first unparsed block
|
33
|
+
*/
|
34
|
+
static MarkdownNodeIterator parse(const MarkdownNodeIterator& node,
|
35
|
+
const MarkdownNodes& siblings,
|
36
|
+
SectionParserData& pd,
|
37
|
+
Report& report,
|
38
|
+
T& out) {
|
39
|
+
|
40
|
+
SectionLayout layout = DefaultSectionLayout;
|
41
|
+
MarkdownNodeIterator cur = Adapter::startingNode(node);
|
42
|
+
const MarkdownNodes& collection = Adapter::startingNodeSiblings(node, siblings);
|
43
|
+
|
44
|
+
// Signature node
|
45
|
+
MarkdownNodeIterator lastCur = cur;
|
46
|
+
cur = SectionProcessor<T>::processSignature(cur, collection, pd, layout, report, out);
|
47
|
+
|
48
|
+
// Exclusive Nested Sections Layout
|
49
|
+
if (layout == ExclusiveNestedSectionLayout) {
|
50
|
+
|
51
|
+
cur = parseNestedSections(cur, collection, pd, report, out);
|
52
|
+
|
53
|
+
SectionProcessor<T>::finalize(node, pd, report, out);
|
54
|
+
|
55
|
+
return Adapter::nextStartingNode(node, siblings, cur);
|
56
|
+
}
|
57
|
+
|
58
|
+
// Parser redirect layout
|
59
|
+
if (layout == RedirectSectionLayout) {
|
60
|
+
SectionProcessor<T>::finalize(node, pd, report, out);
|
61
|
+
|
62
|
+
return Adapter::nextStartingNode(node, siblings, cur);
|
63
|
+
}
|
64
|
+
|
65
|
+
// Default layout
|
66
|
+
if (lastCur == cur)
|
67
|
+
return Adapter::nextStartingNode(node, siblings, cur);
|
68
|
+
|
69
|
+
// Description nodes
|
70
|
+
while(cur != collection.end() &&
|
71
|
+
SectionProcessor<T>::isDescriptionNode(cur, pd.sectionContext())) {
|
72
|
+
|
73
|
+
lastCur = cur;
|
74
|
+
cur = SectionProcessor<T>::processDescription(cur, collection, pd, report, out);
|
75
|
+
if (lastCur == cur)
|
76
|
+
return Adapter::nextStartingNode(node, siblings, cur);
|
77
|
+
}
|
78
|
+
|
79
|
+
// Content nodes
|
80
|
+
while(cur != collection.end() &&
|
81
|
+
SectionProcessor<T>::isContentNode(cur, pd.sectionContext())) {
|
82
|
+
|
83
|
+
lastCur = cur;
|
84
|
+
cur = SectionProcessor<T>::processContent(cur, collection, pd, report, out);
|
85
|
+
if (lastCur == cur)
|
86
|
+
return Adapter::nextStartingNode(node, siblings, cur);
|
87
|
+
}
|
88
|
+
|
89
|
+
// Nested Sections
|
90
|
+
cur = parseNestedSections(cur, collection, pd, report, out);
|
91
|
+
|
92
|
+
SectionProcessor<T>::finalize(node, pd, report, out);
|
93
|
+
|
94
|
+
return Adapter::nextStartingNode(node, siblings, cur);
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
/** Parse nested sections */
|
99
|
+
static MarkdownNodeIterator parseNestedSections(const MarkdownNodeIterator& node,
|
100
|
+
const MarkdownNodes& collection,
|
101
|
+
SectionParserData& pd,
|
102
|
+
Report& report,
|
103
|
+
T& out) {
|
104
|
+
|
105
|
+
MarkdownNodeIterator cur = node;
|
106
|
+
MarkdownNodeIterator lastCur = cur;
|
107
|
+
|
108
|
+
SectionType lastSectionType = UndefinedSectionType;
|
109
|
+
|
110
|
+
// Nested sections
|
111
|
+
while(cur != collection.end()) {
|
112
|
+
|
113
|
+
lastCur = cur;
|
114
|
+
SectionType nestedType = SectionProcessor<T>::nestedSectionType(cur);
|
115
|
+
|
116
|
+
pd.sectionsContext.push_back(nestedType);
|
117
|
+
|
118
|
+
if (nestedType != UndefinedSectionType) {
|
119
|
+
cur = SectionProcessor<T>::processNestedSection(cur, collection, pd, report, out);
|
120
|
+
}
|
121
|
+
else if (Adapter::nextSkipsUnexpected ||
|
122
|
+
SectionProcessor<T>::isUnexpectedNode(cur, pd.sectionContext())) {
|
123
|
+
cur = SectionProcessor<T>::processUnexpectedNode(cur, collection, pd, lastSectionType, report, out);
|
124
|
+
}
|
125
|
+
|
126
|
+
if (cur != collection.end() &&
|
127
|
+
(pd.sectionContext() != UndefinedSectionType ||
|
128
|
+
(cur->type != mdp::ParagraphMarkdownNodeType &&
|
129
|
+
cur->type != mdp::CodeMarkdownNodeType))) {
|
130
|
+
|
131
|
+
lastSectionType = pd.sectionContext();
|
132
|
+
}
|
133
|
+
|
134
|
+
pd.sectionsContext.pop_back();
|
135
|
+
|
136
|
+
if (lastCur == cur)
|
137
|
+
break;
|
138
|
+
}
|
139
|
+
|
140
|
+
return cur;
|
141
|
+
}
|
142
|
+
};
|
143
|
+
|
144
|
+
/** Parser Adapter for parsing header-defined sections */
|
145
|
+
struct HeaderSectionAdapter {
|
146
|
+
|
147
|
+
/** \return Node to start parsing with */
|
148
|
+
static const MarkdownNodeIterator startingNode(const MarkdownNodeIterator& seed) {
|
149
|
+
if (seed->type != mdp::HeaderMarkdownNodeType)
|
150
|
+
throw ADAPTER_MISMATCH_ERR;
|
151
|
+
|
152
|
+
return seed;
|
153
|
+
}
|
154
|
+
|
155
|
+
/** \return Collection of siblings to starting Node */
|
156
|
+
static const MarkdownNodes& startingNodeSiblings(const MarkdownNodeIterator& seed,
|
157
|
+
const MarkdownNodes& siblings) {
|
158
|
+
return siblings;
|
159
|
+
}
|
160
|
+
|
161
|
+
/** \return Starting node for next parsing */
|
162
|
+
static const MarkdownNodeIterator nextStartingNode(const MarkdownNodeIterator& seed,
|
163
|
+
const MarkdownNodes& siblings,
|
164
|
+
const MarkdownNodeIterator& cur) {
|
165
|
+
return cur;
|
166
|
+
}
|
167
|
+
|
168
|
+
/**
|
169
|
+
* \brief Adapter Markdown node skipping behavior trait.
|
170
|
+
*
|
171
|
+
* Adapter trait signalizing that the adapter can possibly skip some Markdown nodes on a nextStartingNode() call.
|
172
|
+
* If set to true, a call to nextStartingNode() can skip some nodes causing some information loss. False otherwise.
|
173
|
+
*/
|
174
|
+
static const bool nextSkipsUnexpected = false;
|
175
|
+
};
|
176
|
+
|
177
|
+
/** Parser Adapter for parsing list-defined sections */
|
178
|
+
struct ListSectionAdapter {
|
179
|
+
|
180
|
+
static const MarkdownNodeIterator startingNode(const MarkdownNodeIterator& seed) {
|
181
|
+
if (seed->type != mdp::ListItemMarkdownNodeType)
|
182
|
+
throw ADAPTER_MISMATCH_ERR;
|
183
|
+
|
184
|
+
return seed->children().begin();
|
185
|
+
}
|
186
|
+
|
187
|
+
static const MarkdownNodes& startingNodeSiblings(const MarkdownNodeIterator& seed,
|
188
|
+
const MarkdownNodes& siblings) {
|
189
|
+
return seed->children();
|
190
|
+
}
|
191
|
+
|
192
|
+
static const MarkdownNodeIterator nextStartingNode(const MarkdownNodeIterator& seed,
|
193
|
+
const MarkdownNodes& siblings,
|
194
|
+
const MarkdownNodeIterator& cur) {
|
195
|
+
if (seed == siblings.end())
|
196
|
+
return seed;
|
197
|
+
|
198
|
+
return ++MarkdownNodeIterator(seed);
|
199
|
+
}
|
200
|
+
|
201
|
+
static const bool nextSkipsUnexpected = true;
|
202
|
+
};
|
203
|
+
|
204
|
+
/** Parser Adapter for parsing blueprint sections */
|
205
|
+
struct BlueprintSectionAdapter {
|
206
|
+
|
207
|
+
/** \return Node to start parsing with */
|
208
|
+
static const MarkdownNodeIterator startingNode(const MarkdownNodeIterator& seed) {
|
209
|
+
return seed;
|
210
|
+
}
|
211
|
+
|
212
|
+
/** \return Collection of siblings to starting Node */
|
213
|
+
static const MarkdownNodes& startingNodeSiblings(const MarkdownNodeIterator& seed,
|
214
|
+
const MarkdownNodes& siblings) {
|
215
|
+
return siblings;
|
216
|
+
}
|
217
|
+
|
218
|
+
/** \return Starting node for next parsing */
|
219
|
+
static const MarkdownNodeIterator nextStartingNode(const MarkdownNodeIterator& seed,
|
220
|
+
const MarkdownNodes& siblings,
|
221
|
+
const MarkdownNodeIterator& cur) {
|
222
|
+
return cur;
|
223
|
+
}
|
224
|
+
|
225
|
+
static const bool nextSkipsUnexpected = false;
|
226
|
+
};
|
227
|
+
}
|
228
|
+
|
229
|
+
#endif
|
@@ -0,0 +1,81 @@
|
|
1
|
+
//
|
2
|
+
// SectionParserData.h
|
3
|
+
// snowcrash
|
4
|
+
//
|
5
|
+
// Created by Zdenek Nemec on 5/21/14.
|
6
|
+
// Copyright (c) 2014 Apiary Inc. All rights reserved.
|
7
|
+
//
|
8
|
+
|
9
|
+
#ifndef SNOWCRASH_SECTIONPARSERDATA_H
|
10
|
+
#define SNOWCRASH_SECTIONPARSERDATA_H
|
11
|
+
|
12
|
+
#include "Blueprint.h"
|
13
|
+
#include "Section.h"
|
14
|
+
#include "SymbolTable.h"
|
15
|
+
|
16
|
+
namespace snowcrash {
|
17
|
+
|
18
|
+
/**
|
19
|
+
* \brief Blueprint Parser Options.
|
20
|
+
*
|
21
|
+
* Controls blueprint parser behavior.
|
22
|
+
*/
|
23
|
+
enum BlueprintParserOption {
|
24
|
+
RenderDescriptionsOption = (1 << 0), /// < Render Markdown in description.
|
25
|
+
RequireBlueprintNameOption = (1 << 1) /// < Treat missing blueprint name as error
|
26
|
+
};
|
27
|
+
|
28
|
+
typedef unsigned int BlueprintParserOptions;
|
29
|
+
|
30
|
+
/**
|
31
|
+
* \brief Section Parser Data
|
32
|
+
*
|
33
|
+
* State of the parser.
|
34
|
+
*/
|
35
|
+
struct SectionParserData {
|
36
|
+
SectionParserData(BlueprintParserOptions opts,
|
37
|
+
const mdp::ByteBuffer& src,
|
38
|
+
const Blueprint& bp)
|
39
|
+
: options(opts), sourceData(src), blueprint(bp) {}
|
40
|
+
|
41
|
+
/** Parser Options */
|
42
|
+
BlueprintParserOptions options;
|
43
|
+
|
44
|
+
/** Symbol Table */
|
45
|
+
SymbolTable symbolTable;
|
46
|
+
|
47
|
+
/** Source Data */
|
48
|
+
const mdp::ByteBuffer& sourceData;
|
49
|
+
|
50
|
+
/** AST being parsed **/
|
51
|
+
const Blueprint& blueprint;
|
52
|
+
|
53
|
+
/** Sections Context */
|
54
|
+
typedef std::vector<SectionType> SectionsStack;
|
55
|
+
SectionsStack sectionsContext;
|
56
|
+
|
57
|
+
/** \returns Actual Section Context */
|
58
|
+
SectionType sectionContext() const {
|
59
|
+
return (sectionsContext.empty()) ? UndefinedSectionType : sectionsContext.back();
|
60
|
+
}
|
61
|
+
|
62
|
+
/** \returns Parent Section Context */
|
63
|
+
SectionType parentSectionContext() const {
|
64
|
+
if (sectionsContext.empty())
|
65
|
+
return UndefinedSectionType;
|
66
|
+
|
67
|
+
size_t size = sectionsContext.size();
|
68
|
+
if (size == 1)
|
69
|
+
return sectionsContext.back();
|
70
|
+
else
|
71
|
+
return sectionsContext[size-2];
|
72
|
+
}
|
73
|
+
|
74
|
+
private:
|
75
|
+
SectionParserData();
|
76
|
+
SectionParserData(const SectionParserData&);
|
77
|
+
SectionParserData& operator=(const SectionParserData&);
|
78
|
+
};
|
79
|
+
}
|
80
|
+
|
81
|
+
#endif
|
@@ -0,0 +1,211 @@
|
|
1
|
+
//
|
2
|
+
// Processor.h
|
3
|
+
// snowcrash
|
4
|
+
//
|
5
|
+
// Created by Zdenek Nemec on 5/14/14.
|
6
|
+
// Copyright (c) 2014 Apiary Inc. All rights reserved.
|
7
|
+
//
|
8
|
+
|
9
|
+
#ifndef SNOWCRASH_SECTIONPROCESSOR_H
|
10
|
+
#define SNOWCRASH_SECTIONPROCESSOR_H
|
11
|
+
|
12
|
+
#include "SectionParserData.h"
|
13
|
+
#include "SourceAnnotation.h"
|
14
|
+
#include "Signature.h"
|
15
|
+
|
16
|
+
namespace snowcrash {
|
17
|
+
|
18
|
+
using mdp::MarkdownNode;
|
19
|
+
using mdp::MarkdownNodes;
|
20
|
+
using mdp::MarkdownNodeIterator;
|
21
|
+
|
22
|
+
typedef Collection<SectionType>::type SectionTypes;
|
23
|
+
|
24
|
+
/**
|
25
|
+
* Layout of the section being parsed
|
26
|
+
*/
|
27
|
+
enum SectionLayout {
|
28
|
+
DefaultSectionLayout, /// Default Section Layout: Signature > Description > Content > Nested
|
29
|
+
ExclusiveNestedSectionLayout, /// Section is composed of nested sections only
|
30
|
+
RedirectSectionLayout /// Section should be parsed by another parser as whole
|
31
|
+
};
|
32
|
+
|
33
|
+
/*
|
34
|
+
* Forward Declarations
|
35
|
+
*/
|
36
|
+
template<typename T>
|
37
|
+
struct SectionProcessor;
|
38
|
+
|
39
|
+
/**
|
40
|
+
* \brief Section Processor Base
|
41
|
+
*
|
42
|
+
* Defines section processor interface alongised with its default
|
43
|
+
* behavior.
|
44
|
+
*/
|
45
|
+
template<typename T>
|
46
|
+
struct SectionProcessorBase {
|
47
|
+
|
48
|
+
/**
|
49
|
+
* \brief Process section signature Markdown node
|
50
|
+
* \param node Node to process
|
51
|
+
* \param siblings Siblings of the node being processed
|
52
|
+
* \param pd Section parser state
|
53
|
+
* \param report Process log report
|
54
|
+
* \param out Processed output
|
55
|
+
* \return Result of the process operation
|
56
|
+
*/
|
57
|
+
static MarkdownNodeIterator processSignature(const MarkdownNodeIterator& node,
|
58
|
+
const MarkdownNodes& siblings,
|
59
|
+
SectionParserData& pd,
|
60
|
+
SectionLayout& layout,
|
61
|
+
Report& report,
|
62
|
+
T& out) {
|
63
|
+
return ++MarkdownNodeIterator(node);
|
64
|
+
}
|
65
|
+
|
66
|
+
/** Process section description Markdown node */
|
67
|
+
static MarkdownNodeIterator processDescription(const MarkdownNodeIterator& node,
|
68
|
+
const MarkdownNodes& siblings,
|
69
|
+
SectionParserData& pd,
|
70
|
+
Report& report,
|
71
|
+
T& out) {
|
72
|
+
|
73
|
+
if (!out.description.empty()) {
|
74
|
+
TwoNewLines(out.description);
|
75
|
+
}
|
76
|
+
|
77
|
+
out.description += mdp::MapBytesRangeSet(node->sourceMap, pd.sourceData);
|
78
|
+
|
79
|
+
return ++MarkdownNodeIterator(node);
|
80
|
+
}
|
81
|
+
|
82
|
+
/** Process section-specific content Markdown node */
|
83
|
+
static MarkdownNodeIterator processContent(const MarkdownNodeIterator& node,
|
84
|
+
const MarkdownNodes& siblings,
|
85
|
+
SectionParserData& pd,
|
86
|
+
Report& report,
|
87
|
+
T& out) {
|
88
|
+
return ++MarkdownNodeIterator(node);
|
89
|
+
}
|
90
|
+
|
91
|
+
/**
|
92
|
+
* \brief Process nested sections Markdown node(s)
|
93
|
+
* \param node Node to process
|
94
|
+
* \param siblings Siblings of the node being processed
|
95
|
+
* \param pd Section parser state
|
96
|
+
* \param report Process log report
|
97
|
+
* \param out Processed output
|
98
|
+
*/
|
99
|
+
static MarkdownNodeIterator processNestedSection(const MarkdownNodeIterator& node,
|
100
|
+
const MarkdownNodes& siblings,
|
101
|
+
SectionParserData& pd,
|
102
|
+
Report& report,
|
103
|
+
T& out) {
|
104
|
+
return node;
|
105
|
+
}
|
106
|
+
|
107
|
+
/** Process unexpected Markdown node */
|
108
|
+
static MarkdownNodeIterator processUnexpectedNode(const MarkdownNodeIterator& node,
|
109
|
+
const MarkdownNodes& siblings,
|
110
|
+
SectionParserData& pd,
|
111
|
+
SectionType& lastSectionType,
|
112
|
+
Report& report,
|
113
|
+
T& out) {
|
114
|
+
|
115
|
+
// WARN: Ignoring unexpected node
|
116
|
+
std::stringstream ss;
|
117
|
+
mdp::CharactersRangeSet sourceMap = mdp::BytesRangeSetToCharactersRangeSet(node->sourceMap, pd.sourceData);
|
118
|
+
|
119
|
+
if (node->type == mdp::HeaderMarkdownNodeType) {
|
120
|
+
ss << "unexpected header block, expected a group, resource or an action definition";
|
121
|
+
ss << ", e.g. '# Group <name>', '# <resource name> [<URI>]' or '# <HTTP method> <URI>'";
|
122
|
+
} else {
|
123
|
+
ss << "ignoring unrecognized block";
|
124
|
+
}
|
125
|
+
|
126
|
+
report.warnings.push_back(Warning(ss.str(),
|
127
|
+
IgnoringWarning,
|
128
|
+
sourceMap));
|
129
|
+
|
130
|
+
return ++MarkdownNodeIterator(node);
|
131
|
+
}
|
132
|
+
|
133
|
+
/** Final validation after processing */
|
134
|
+
static void finalize(const MarkdownNodeIterator& node,
|
135
|
+
SectionParserData& pd,
|
136
|
+
Report& report,
|
137
|
+
T& out) {
|
138
|
+
}
|
139
|
+
|
140
|
+
/** \return True if the node is a section description node */
|
141
|
+
static bool isDescriptionNode(const MarkdownNodeIterator& node,
|
142
|
+
SectionType sectionType) {
|
143
|
+
|
144
|
+
if (SectionProcessor<T>::isContentNode(node, sectionType) ||
|
145
|
+
SectionProcessor<T>::nestedSectionType(node) != UndefinedSectionType) {
|
146
|
+
|
147
|
+
return false;
|
148
|
+
}
|
149
|
+
|
150
|
+
SectionType keywordSectionType = SectionKeywordSignature(node);
|
151
|
+
|
152
|
+
if (keywordSectionType == UndefinedSectionType) {
|
153
|
+
return true;
|
154
|
+
}
|
155
|
+
|
156
|
+
SectionTypes nestedTypes = SectionProcessor<T>::nestedSectionTypes();
|
157
|
+
|
158
|
+
if (std::find(nestedTypes.begin(), nestedTypes.end(), keywordSectionType) != nestedTypes.end()) {
|
159
|
+
// Node is a keyword defined section defined in one of the nested sections
|
160
|
+
// Treat it as a description
|
161
|
+
return true;
|
162
|
+
}
|
163
|
+
|
164
|
+
return false;
|
165
|
+
}
|
166
|
+
|
167
|
+
/** \return True if the node is a section-specific content node */
|
168
|
+
static bool isContentNode(const MarkdownNodeIterator& node,
|
169
|
+
SectionType sectionType) {
|
170
|
+
return false;
|
171
|
+
}
|
172
|
+
|
173
|
+
/** \return True if the node is unexpected in the current context */
|
174
|
+
static bool isUnexpectedNode(const MarkdownNodeIterator& node,
|
175
|
+
SectionType sectionType) {
|
176
|
+
|
177
|
+
SectionType keywordSectionType = SectionKeywordSignature(node);
|
178
|
+
SectionTypes nestedTypes = SectionProcessor<T>::nestedSectionTypes();
|
179
|
+
|
180
|
+
if (std::find(nestedTypes.begin(), nestedTypes.end(), keywordSectionType) != nestedTypes.end()) {
|
181
|
+
return true;
|
182
|
+
}
|
183
|
+
|
184
|
+
return (keywordSectionType == UndefinedSectionType);
|
185
|
+
}
|
186
|
+
|
187
|
+
/** \return Nested sections of the section */
|
188
|
+
static SectionTypes nestedSectionTypes() {
|
189
|
+
return SectionTypes();
|
190
|
+
}
|
191
|
+
|
192
|
+
/** \return %SectionType of the node */
|
193
|
+
static SectionType sectionType(const MarkdownNodeIterator& node) {
|
194
|
+
return UndefinedSectionType;
|
195
|
+
}
|
196
|
+
|
197
|
+
/** \return Nested %SectionType of the node */
|
198
|
+
static SectionType nestedSectionType(const MarkdownNodeIterator& node) {
|
199
|
+
return UndefinedSectionType;
|
200
|
+
}
|
201
|
+
};
|
202
|
+
|
203
|
+
/**
|
204
|
+
* Default Section Processor
|
205
|
+
*/
|
206
|
+
template<typename T>
|
207
|
+
struct SectionProcessor : public SectionProcessorBase<T> {
|
208
|
+
};
|
209
|
+
}
|
210
|
+
|
211
|
+
#endif
|