redsnow 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +2 -0
  3. data/ext/snowcrash/Makefile +1 -1
  4. data/ext/snowcrash/bin/snowcrash +0 -0
  5. data/ext/snowcrash/configure +9 -9
  6. data/ext/snowcrash/ext/markdown-parser/Makefile +87 -0
  7. data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/CONTRIBUTING.md +0 -0
  8. data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/Makefile +2 -1
  9. data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/Makefile.win +0 -0
  10. data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/examples/smartypants.c +0 -0
  11. data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/examples/sundown.c +0 -0
  12. data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/html/houdini.h +0 -0
  13. data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/html/houdini_href_e.c +0 -0
  14. data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/html/houdini_html_e.c +0 -0
  15. data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/html/html.c +0 -0
  16. data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/html/html.h +0 -0
  17. data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/html/html_smartypants.c +0 -0
  18. data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/html_block_names.txt +0 -0
  19. data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/src/autolink.c +0 -0
  20. data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/src/autolink.h +0 -0
  21. data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/src/buffer.c +0 -0
  22. data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/src/buffer.h +1 -1
  23. data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/src/html_blocks.h +0 -0
  24. data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/src/markdown.c +9 -3
  25. data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/src/markdown.h +0 -0
  26. data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/src/src_map.c +11 -7
  27. data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/src/src_map.h +1 -1
  28. data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/src/stack.c +0 -0
  29. data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/src/stack.h +0 -0
  30. data/ext/snowcrash/{sundown → ext/markdown-parser/ext/sundown}/sundown.def +0 -0
  31. data/ext/snowcrash/ext/markdown-parser/msvc/markdown/markdown.vcproj +188 -0
  32. data/ext/snowcrash/ext/markdown-parser/msvc/msvc.sln +38 -0
  33. data/ext/snowcrash/ext/markdown-parser/msvc/sundown/sundown.vcproj +206 -0
  34. data/ext/snowcrash/ext/markdown-parser/src/ByteBuffer.cc +92 -0
  35. data/ext/snowcrash/ext/markdown-parser/src/ByteBuffer.h +82 -0
  36. data/ext/snowcrash/ext/markdown-parser/src/MarkdownNode.cc +152 -0
  37. data/ext/snowcrash/ext/markdown-parser/src/MarkdownNode.h +103 -0
  38. data/ext/snowcrash/ext/markdown-parser/src/MarkdownParser.cc +388 -0
  39. data/ext/snowcrash/{src → ext/markdown-parser/src}/MarkdownParser.h +43 -33
  40. data/ext/snowcrash/snowcrash.gyp +114 -63
  41. data/ext/snowcrash/src/ActionParser.h +334 -398
  42. data/ext/snowcrash/src/AssetParser.h +82 -171
  43. data/ext/snowcrash/src/Blueprint.h +7 -2
  44. data/ext/snowcrash/src/BlueprintParser.h +212 -286
  45. data/ext/snowcrash/src/BlueprintUtility.h +2 -2
  46. data/ext/snowcrash/src/CBlueprint.h +1 -1
  47. data/ext/snowcrash/src/CSourceAnnotation.cc +11 -11
  48. data/ext/snowcrash/src/CSourceAnnotation.h +9 -9
  49. data/ext/snowcrash/src/CodeBlockUtility.h +199 -149
  50. data/ext/snowcrash/src/HeadersParser.h +197 -0
  51. data/ext/snowcrash/src/ParameterParser.h +429 -0
  52. data/ext/snowcrash/src/ParametersParser.h +136 -211
  53. data/ext/snowcrash/src/PayloadParser.h +458 -562
  54. data/ext/snowcrash/src/Platform.h +0 -3
  55. data/ext/snowcrash/src/ResourceGroupParser.h +183 -164
  56. data/ext/snowcrash/src/ResourceParser.h +325 -493
  57. data/ext/snowcrash/src/Section.cc +42 -0
  58. data/ext/snowcrash/src/Section.h +47 -0
  59. data/ext/snowcrash/src/SectionParser.h +229 -0
  60. data/ext/snowcrash/src/SectionParserData.h +81 -0
  61. data/ext/snowcrash/src/SectionProcessor.h +211 -0
  62. data/ext/snowcrash/src/Signature.cc +74 -0
  63. data/ext/snowcrash/src/Signature.h +32 -0
  64. data/ext/snowcrash/src/SourceAnnotation.h +7 -20
  65. data/ext/snowcrash/src/StringUtility.h +30 -10
  66. data/ext/snowcrash/src/SymbolTable.h +7 -7
  67. data/ext/snowcrash/src/UriTemplateParser.cc +10 -10
  68. data/ext/snowcrash/src/UriTemplateParser.h +11 -14
  69. data/ext/snowcrash/src/ValuesParser.h +122 -0
  70. data/ext/snowcrash/src/Version.h +2 -2
  71. data/ext/snowcrash/src/csnowcrash.cc +5 -5
  72. data/ext/snowcrash/src/csnowcrash.h +3 -3
  73. data/ext/snowcrash/src/snowcrash.cc +74 -4
  74. data/ext/snowcrash/src/snowcrash.h +9 -4
  75. data/ext/snowcrash/src/snowcrash/snowcrash.cc +16 -16
  76. data/ext/snowcrash/tools/homebrew/snowcrash.rb +3 -2
  77. data/ext/snowcrash/vcbuild.bat +13 -4
  78. data/lib/redsnow.rb +5 -5
  79. data/lib/redsnow/binding.rb +1 -1
  80. data/lib/redsnow/blueprint.rb +33 -2
  81. data/lib/redsnow/parseresult.rb +7 -4
  82. data/lib/redsnow/version.rb +1 -1
  83. data/test/redsnow_binding_test.rb +6 -6
  84. data/test/redsnow_parseresult_test.rb +1 -1
  85. metadata +62 -42
  86. data/ext/snowcrash/src/BlockUtility.h +0 -186
  87. data/ext/snowcrash/src/BlueprintParserCore.h +0 -190
  88. data/ext/snowcrash/src/BlueprintSection.h +0 -140
  89. data/ext/snowcrash/src/DescriptionSectionUtility.h +0 -156
  90. data/ext/snowcrash/src/HeaderParser.h +0 -289
  91. data/ext/snowcrash/src/ListBlockUtility.h +0 -273
  92. data/ext/snowcrash/src/ListUtility.h +0 -95
  93. data/ext/snowcrash/src/MarkdownBlock.cc +0 -176
  94. data/ext/snowcrash/src/MarkdownBlock.h +0 -93
  95. data/ext/snowcrash/src/MarkdownParser.cc +0 -266
  96. data/ext/snowcrash/src/ParameterDefinitonParser.h +0 -645
  97. data/ext/snowcrash/src/Parser.cc +0 -71
  98. data/ext/snowcrash/src/Parser.h +0 -29
  99. data/ext/snowcrash/src/ParserCore.cc +0 -120
  100. data/ext/snowcrash/src/ParserCore.h +0 -82
  101. data/ext/snowcrash/src/SectionUtility.h +0 -142
@@ -0,0 +1,74 @@
1
+ //
2
+ // Signature.cc
3
+ // snowcrash
4
+ //
5
+ // Created by Zdenek Nemec on 6/20/14.
6
+ // Copyright (c) 2014 Apiary Inc. All rights reserved.
7
+ //
8
+
9
+ #include "Signature.h"
10
+ #include "SectionParser.h"
11
+ #include "ActionParser.h"
12
+ #include "AssetParser.h"
13
+ #include "HeadersParser.h"
14
+ #include "PayloadParser.h"
15
+ #include "ParametersParser.h"
16
+ #include "ResourceParser.h"
17
+ #include "ResourceGroupParser.h"
18
+
19
+ using namespace snowcrash;
20
+
21
+ SectionType snowcrash::SectionKeywordSignature(const mdp::MarkdownNodeIterator& node)
22
+ {
23
+ // Note: Every-keyword defined section should be listed here...
24
+ SectionType type = UndefinedSectionType;
25
+
26
+ if ((type = SectionProcessor<Headers>::sectionType(node)) != UndefinedSectionType)
27
+ return type;
28
+
29
+ if ((type = SectionProcessor<Asset>::sectionType(node)) != UndefinedSectionType)
30
+ return type;
31
+
32
+ if ((type = SectionProcessor<Payload>::sectionType(node)) != UndefinedSectionType)
33
+ return type;
34
+
35
+ if ((type = SectionProcessor<Values>::sectionType(node)) != UndefinedSectionType)
36
+ return type;
37
+
38
+ if ((type = SectionProcessor<Parameters>::sectionType(node)) != UndefinedSectionType)
39
+ return type;
40
+
41
+ /*
42
+ * NOTE: Order is important. Resource MUST preceed the Action.
43
+ *
44
+ * This is because an HTTP Request Method + URI is recognized as both %ActionSectionType and %ResourceSectionType.
45
+ * This is not optimal and should be addressed in the future.
46
+ */
47
+ if ((type = SectionProcessor<Resource>::sectionType(node)) != UndefinedSectionType)
48
+ return type;
49
+
50
+ if ((type = SectionProcessor<Action>::sectionType(node)) != UndefinedSectionType)
51
+ return type;
52
+
53
+ if ((type = SectionProcessor<ResourceGroup>::sectionType(node)) != UndefinedSectionType)
54
+ return type;
55
+
56
+ return type;
57
+ }
58
+
59
+ SectionType snowcrash::RecognizeCodeBlockFirstLine(const mdp::ByteBuffer& subject)
60
+ {
61
+ SectionType type = UndefinedSectionType;
62
+
63
+ if (RegexMatch(subject, HeadersRegex)) {
64
+ return HeadersSectionType;
65
+ }
66
+ else if (RegexMatch(subject, BodyRegex)) {
67
+ return BodySectionType;
68
+ }
69
+ else if (RegexMatch(subject, SchemaRegex)) {
70
+ return SchemaSectionType;
71
+ }
72
+
73
+ return type;
74
+ }
@@ -0,0 +1,32 @@
1
+ //
2
+ // Signature.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_SIGNATURE_H
10
+ #define SNOWCRASH_SIGNATURE_H
11
+
12
+ #include "MarkdownNode.h"
13
+ #include "Section.h"
14
+
15
+ namespace snowcrash {
16
+
17
+ /**
18
+ * \brief Query whether a node has keyword-defined signature.
19
+ * \param node A Markdown AST node to check.
20
+ * \return Type of the node if it has a recognized keyword signature, UndefinedType otherwise
21
+ */
22
+ extern SectionType SectionKeywordSignature(const mdp::MarkdownNodeIterator& node);
23
+
24
+ /**
25
+ * \brief Recognize the type of section given the first line from a code block
26
+ * \param subject The first line that needs to be recognized
27
+ * \return SectionType Type of the section if the line contains a keyword
28
+ */
29
+ extern SectionType RecognizeCodeBlockFirstLine(const mdp::ByteBuffer& subject);
30
+ }
31
+
32
+ #endif
@@ -11,23 +11,10 @@
11
11
 
12
12
  #include <string>
13
13
  #include <vector>
14
+ #include "ByteBuffer.h"
14
15
 
15
16
  namespace snowcrash {
16
17
 
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
18
 
32
19
  /**
33
20
  * \brief A source data annotation.
@@ -68,7 +55,7 @@ namespace snowcrash {
68
55
  */
69
56
  SourceAnnotation(const std::string& message,
70
57
  int code = OK,
71
- const SourceCharactersBlock& location = SourceCharactersBlock()) {
58
+ const mdp::CharactersRangeSet& location = mdp::CharactersRangeSet()) {
72
59
 
73
60
  this->message = message;
74
61
  this->code = code;
@@ -93,7 +80,7 @@ namespace snowcrash {
93
80
  }
94
81
 
95
82
  /** The location of this annotation within the source data buffer. */
96
- SourceCharactersBlock location;
83
+ mdp::CharactersRangeSet location;
97
84
 
98
85
  /** An annotation code. */
99
86
  int code;
@@ -147,20 +134,20 @@ namespace snowcrash {
147
134
  typedef std::vector<Warning> Warnings;
148
135
 
149
136
  /**
150
- * \brief A parsing result Report.
137
+ * \brief A parsing report Report.
151
138
  *
152
139
  * Result of a source data parsing operation.
153
140
  * Composed of ONE error source annotation
154
141
  * and a set of warning source annotations.
155
142
  */
156
- struct Result {
143
+ struct Report {
157
144
 
158
145
  /**
159
- * \brief Append a result to this one, replacing the error source annotation.
146
+ * \brief Append a report to this one, replacing the error source annotation.
160
147
  *
161
148
  * NOTE: A binding does not need to wrap this action.
162
149
  */
163
- Result& operator+=(const Result& rhs) {
150
+ Report& operator+=(const Report& rhs) {
164
151
  error = rhs.error;
165
152
  warnings.insert(warnings.end(), rhs.warnings.begin(), rhs.warnings.end());
166
153
  return *this;
@@ -45,15 +45,6 @@ namespace snowcrash {
45
45
  return TrimStringStart(TrimStringEnd(s));
46
46
  }
47
47
 
48
- // Retrieve first line of given string
49
- inline std::string GetFirstLine(const std::string& s) {
50
- std::string::size_type pos = s.find("\n");
51
- if (pos == std::string::npos)
52
- return s;
53
- else
54
- return s.substr(0, pos);
55
- }
56
-
57
48
  // Split string by delim
58
49
  inline std::vector<std::string>& Split(const std::string& s, char delim, std::vector<std::string>& elems) {
59
50
  std::stringstream ss(s);
@@ -85,7 +76,20 @@ namespace snowcrash {
85
76
  return elems;
86
77
  }
87
78
 
88
-
79
+ // Make sure last two characters are newlines
80
+ inline std::string& TwoNewLines(std::string& s) {
81
+
82
+ if (s[s.length() - 1] != '\n') {
83
+ s += "\n";
84
+ }
85
+
86
+ if (s[s.length() - 2] != '\n') {
87
+ s += "\n";
88
+ }
89
+
90
+ return s;
91
+ }
92
+
89
93
  /**
90
94
  * \brief Replace all occurrences of a string.
91
95
  * \param s A string to search in.
@@ -104,6 +108,22 @@ namespace snowcrash {
104
108
  }
105
109
  return target;
106
110
  }
111
+
112
+ /**
113
+ * \brief Extract the first line from a string.
114
+ *
115
+ * \param s Subject of the extraction
116
+ * \param r Remaining content aftert the extraction
117
+ * \return First line from the subject string
118
+ */
119
+ inline std::string GetFirstLine(const std::string& s, std::string& r){
120
+ std::vector<std::string> elem = SplitOnFirst(s, '\n');
121
+ if (elem.empty())
122
+ return std::string();
123
+ if (elem.size() > 1)
124
+ r = elem.back();
125
+ return elem.front();
126
+ }
107
127
  }
108
128
 
109
129
  #endif
@@ -11,6 +11,7 @@
11
11
 
12
12
  #include <string>
13
13
  #include <map>
14
+ #include "ByteBuffer.h"
14
15
  #include "RegexMatch.h"
15
16
 
16
17
  #ifdef DEBUG
@@ -31,13 +32,10 @@ namespace snowcrashconst {
31
32
  }
32
33
 
33
34
  namespace snowcrash {
34
-
35
- // Name of a symbol
36
- typedef SourceData SymbolName;
37
35
 
38
36
  // Resource Object Symbol
39
37
  typedef std::pair<SymbolName, ResourceModel> ResourceModelSymbol;
40
-
38
+
41
39
  // Resource Object Symbol Table
42
40
  typedef std::map<SymbolName, ResourceModel> ResourceModelSymbolTable;
43
41
 
@@ -50,21 +48,23 @@ namespace snowcrash {
50
48
 
51
49
  // Checks whether given source data represents reference to a symbol returning true if so,
52
50
  // false otherwise. If source data is represent reference referred symbol name is filled in.
53
- FORCEINLINE bool GetSymbolReference(const SourceData& sourceData,
54
- SymbolName& referredSymbol) {
51
+ inline bool GetSymbolReference(const mdp::ByteBuffer& sourceData,
52
+ SymbolName& referredSymbol) {
55
53
 
56
54
  CaptureGroups captureGroups;
55
+
57
56
  if (RegexCapture(sourceData, snowcrashconst::SymbolReferenceRegex, captureGroups, 3)) {
58
57
  referredSymbol = captureGroups[1];
59
58
  TrimString(referredSymbol);
60
59
  return true;
61
60
  }
61
+
62
62
  return false;
63
63
  }
64
64
 
65
65
  #ifdef DEBUG
66
66
  // Prints markdown block recursively to stdout
67
- FORCEINLINE void PrintSymbolTable(const SymbolTable& symbolTable) {
67
+ inline void PrintSymbolTable(const SymbolTable& symbolTable) {
68
68
 
69
69
  std::cout << "Resource Model Symbols:\n";
70
70
  for (ResourceModelSymbolTable::const_iterator it = symbolTable.resourceModels.begin();
@@ -114,7 +114,7 @@ static ClassifiedExpression ClassifyExpression(const Expression& expression) {
114
114
  return undefinedExpression;
115
115
  }
116
116
 
117
- void URITemplateParser::parse(const URITemplate& uri, const SourceCharactersBlock& sourceBlock, ParsedURITemplate& result)
117
+ void URITemplateParser::parse(const URITemplate& uri, const mdp::CharactersRangeSet& sourceBlock, ParsedURITemplate& result)
118
118
  {
119
119
  CaptureGroups groups;
120
120
  Expressions expressions;
@@ -128,17 +128,17 @@ void URITemplateParser::parse(const URITemplate& uri, const SourceCharactersBloc
128
128
  result.path = groups[4];
129
129
 
130
130
  if (HasMismatchedCurlyBrackets(result.path)) {
131
- result.result.warnings.push_back(Warning("The URI template contains mismatched expression brackets", URIWarning, sourceBlock));
131
+ result.report.warnings.push_back(Warning("The URI template contains mismatched expression brackets", URIWarning, sourceBlock));
132
132
  return;
133
133
  }
134
134
 
135
135
  if (HasNestedCurlyBrackets(result.path)) {
136
- result.result.warnings.push_back(Warning("The URI template contains nested expression brackets", URIWarning, sourceBlock));
136
+ result.report.warnings.push_back(Warning("The URI template contains nested expression brackets", URIWarning, sourceBlock));
137
137
  return;
138
138
  }
139
139
 
140
140
  if (PathContainsSquareBrackets(result.path)) {
141
- result.result.warnings.push_back(Warning("The URI template contains square brackets, please percent encode square brackets as %5B and %5D", URIWarning, sourceBlock));
141
+ result.report.warnings.push_back(Warning("The URI template contains square brackets, please percent encode square brackets as %5B and %5D", URIWarning, sourceBlock));
142
142
  }
143
143
 
144
144
  expressions = GetUriTemplateExpressions(result.path);
@@ -155,21 +155,21 @@ void URITemplateParser::parse(const URITemplate& uri, const SourceCharactersBloc
155
155
  if (classifiedExpression.ContainsSpaces()) {
156
156
  std::stringstream ss;
157
157
  ss << "URI template expression \"" << classifiedExpression.innerExpression << "\" contains spaces. Allowed characters for expressions are A-Z a-z 0-9 _ and percent encoded characters";
158
- result.result.warnings.push_back(Warning(ss.str(), URIWarning, sourceBlock));
158
+ result.report.warnings.push_back(Warning(ss.str(), URIWarning, sourceBlock));
159
159
  hasIllegalCharacters = true;
160
160
  }
161
161
 
162
162
  if (classifiedExpression.ContainsHyphens()) {
163
163
  std::stringstream ss;
164
164
  ss << "URI template expression \"" << classifiedExpression.innerExpression << "\" contains hyphens. Allowed characters for expressions are A-Z a-z 0-9 _ and percent encoded characters";
165
- result.result.warnings.push_back(Warning(ss.str(), URIWarning, sourceBlock));
165
+ result.report.warnings.push_back(Warning(ss.str(), URIWarning, sourceBlock));
166
166
  hasIllegalCharacters = true;
167
167
  }
168
168
 
169
169
  if (classifiedExpression.ContainsAssignment()) {
170
170
  std::stringstream ss;
171
171
  ss << "URI template expression \"" << classifiedExpression.innerExpression << "\" contains assignment. Allowed characters for expressions are A-Z a-z 0-9 _ and percent encoded characters";
172
- result.result.warnings.push_back(Warning(ss.str(), URIWarning, sourceBlock));
172
+ result.report.warnings.push_back(Warning(ss.str(), URIWarning, sourceBlock));
173
173
  hasIllegalCharacters = true;
174
174
  }
175
175
 
@@ -177,18 +177,18 @@ void URITemplateParser::parse(const URITemplate& uri, const SourceCharactersBloc
177
177
  if (classifiedExpression.IsInvalidExpressionName()) {
178
178
  std::stringstream ss;
179
179
  ss << "URI template expression \"" << classifiedExpression.innerExpression << "\" contains invalid characters. Allowed characters for expressions are A-Z a-z 0-9 _ and percent encoded characters";
180
- result.result.warnings.push_back(Warning(ss.str(), URIWarning, sourceBlock));
180
+ result.report.warnings.push_back(Warning(ss.str(), URIWarning, sourceBlock));
181
181
  }
182
182
  }
183
183
  }
184
184
  else{
185
- result.result.warnings.push_back(Warning(classifiedExpression.unsupportedWarningText, URIWarning, sourceBlock));
185
+ result.report.warnings.push_back(Warning(classifiedExpression.unsupportedWarningText, URIWarning, sourceBlock));
186
186
  }
187
187
  currentExpression++;
188
188
  }
189
189
  }
190
190
  else{
191
- result.result.error = Error("Failed to parse URI Template", URIWarning);
191
+ result.report.error = Error("Failed to parse URI Template", URIWarning);
192
192
  }
193
193
 
194
194
  }
@@ -6,20 +6,17 @@
6
6
  // Copyright (c) 2013 Apiary Inc. All rights reserved.
7
7
  //
8
8
 
9
- #ifndef SNOWCRASH_H
10
- #define SNOWCRASH_H
9
+ #ifndef SNOWCRASH_URITEMPLATEPARSER_H
10
+ #define SNOWCRASH_URITEMPLATEPARSER_H
11
11
 
12
- #include <string>
13
12
  #include "Blueprint.h"
14
- #include "Parser.h"
15
-
16
-
13
+ #include "SourceAnnotation.h"
14
+ #include "RegexMatch.h"
17
15
 
18
16
  #define URI_REGEX "^(http|https|ftp|file)?(://)?([^/]*)?(.*)$"
19
17
  #define URI_TEMPLATE_OPERATOR_REGEX "([+|#|.|/|;|?|&])"
20
18
  #define URI_TEMPLATE_EXPRESSION_REGEX "^([?|#|+|&]?(([A-Z|a-z|0-9|_|,])*|(%[A-F|a-f|0-9]{2})*)*\\*?)$"
21
19
 
22
-
23
20
  namespace snowcrash {
24
21
 
25
22
  /**
@@ -30,7 +27,7 @@ namespace snowcrash {
30
27
  std::string host;
31
28
  std::string path;
32
29
 
33
- Result result;
30
+ Report report;
34
31
  };
35
32
 
36
33
  /**
@@ -69,19 +66,19 @@ namespace snowcrash {
69
66
  return false;
70
67
  }
71
68
 
72
- FORCEINLINE bool ContainsSpaces() {
69
+ bool ContainsSpaces() {
73
70
  return innerExpression.find(" ") != std::string::npos;
74
71
  }
75
72
 
76
- FORCEINLINE bool ContainsAssignment() {
73
+ bool ContainsAssignment() {
77
74
  return innerExpression.find("=") != std::string::npos;
78
75
  }
79
76
 
80
- FORCEINLINE bool ContainsHyphens() {
77
+ bool ContainsHyphens() {
81
78
  return innerExpression.find("-") != std::string::npos;
82
79
  }
83
80
 
84
- FORCEINLINE bool IsInvalidExpressionName() {
81
+ bool IsInvalidExpressionName() {
85
82
  std::string tmpExpression = innerExpression;
86
83
  if (tmpExpression.find("..") != std::string::npos) return true;
87
84
 
@@ -94,7 +91,7 @@ namespace snowcrash {
94
91
  return !RegexMatch(tmpExpression, URI_TEMPLATE_EXPRESSION_REGEX);
95
92
  }
96
93
 
97
- FORCEINLINE bool IsSupportedExpressionType() {
94
+ bool IsSupportedExpressionType() {
98
95
  return isSupported;
99
96
  }
100
97
  };
@@ -236,7 +233,7 @@ namespace snowcrash {
236
233
  *
237
234
  * \param uri A uri to be parsed.
238
235
  */
239
- static void parse(const URITemplate& uri, const SourceCharactersBlock& sourceBlock, ParsedURITemplate& result);
236
+ static void parse(const URITemplate& uri, const mdp::CharactersRangeSet& sourceBlock, ParsedURITemplate& result);
240
237
  };
241
238
  }
242
239
 
@@ -0,0 +1,122 @@
1
+ //
2
+ // ValuesParser.h
3
+ // snowcrash
4
+ //
5
+ // Created by Pavan Kumar Sunkara on 6/12/14
6
+ // Copyright (c) 2014 Apiary Inc. All rights reserved.
7
+ //
8
+
9
+ #ifndef SNOWCRASH_VALUESPARSER_H
10
+ #define SNOWCRASH_VALUESPARSER_H
11
+
12
+ #include "SectionParser.h"
13
+ #include "RegexMatch.h"
14
+ #include "StringUtility.h"
15
+
16
+ /** Parameter Value regex */
17
+ #define PARAMETER_VALUE "`([^`]+)`"
18
+
19
+ namespace snowcrash {
20
+
21
+ /** Parameter Values */
22
+ typedef Collection<Value>::type Values; // TODO: Move this into core later
23
+
24
+ /** Parameter Values matching regex */
25
+ const char* const ValuesRegex = "^[[:blank:]]*[Vv]alues[[:blank:]]*$";
26
+
27
+ /**
28
+ * Values section processor
29
+ */
30
+ template<>
31
+ struct SectionProcessor<Values> : public SectionProcessorBase<Values> {
32
+
33
+ static MarkdownNodeIterator processNestedSection(const MarkdownNodeIterator& node,
34
+ const MarkdownNodes& siblings,
35
+ SectionParserData& pd,
36
+ Report& report,
37
+ Values& out) {
38
+
39
+ if (pd.sectionContext() == ValueSectionType) {
40
+
41
+ mdp::ByteBuffer content = node->children().front().text;
42
+ CaptureGroups captureGroups;
43
+
44
+ RegexCapture(content, PARAMETER_VALUE, captureGroups);
45
+
46
+ if (captureGroups.size() > 1) {
47
+ out.push_back(captureGroups[1]);
48
+ } else {
49
+ TrimString(content);
50
+
51
+ // WARN: Ignoring the unexpected param value
52
+ std::stringstream ss;
53
+ ss << "ignoring the '" << content << "' element";
54
+ ss << ", expected '`" << content << "`'";
55
+
56
+ mdp::CharactersRangeSet sourceMap = mdp::BytesRangeSetToCharactersRangeSet(node->sourceMap, pd.sourceData);
57
+ report.warnings.push_back(Warning(ss.str(),
58
+ IgnoringWarning,
59
+ sourceMap));
60
+ }
61
+
62
+ return ++MarkdownNodeIterator(node);
63
+ }
64
+
65
+ return node;
66
+ }
67
+
68
+ static MarkdownNodeIterator processDescription(const MarkdownNodeIterator& node,
69
+ const MarkdownNodes& siblings,
70
+ SectionParserData& pd,
71
+ Report& report,
72
+ Values& out) {
73
+
74
+ return node;
75
+ }
76
+
77
+ static bool isDescriptionNode(const MarkdownNodeIterator& node,
78
+ SectionType sectionType) {
79
+
80
+ return false;
81
+ }
82
+
83
+ static SectionType sectionType(const MarkdownNodeIterator& node) {
84
+
85
+ if (node->type == mdp::ListItemMarkdownNodeType
86
+ && !node->children().empty()) {
87
+
88
+ mdp::ByteBuffer subject = node->children().front().text;
89
+ TrimString(subject);
90
+
91
+ if (RegexMatch(subject, ValuesRegex)) {
92
+ return ValuesSectionType;
93
+ }
94
+ }
95
+
96
+ return UndefinedSectionType;
97
+ }
98
+
99
+ static SectionType nestedSectionType(const MarkdownNodeIterator& node) {
100
+
101
+ if (node->type == mdp::ListItemMarkdownNodeType
102
+ && !node->children().empty()) {
103
+
104
+ mdp::ByteBuffer subject = node->children().front().text;
105
+ TrimString(subject);
106
+
107
+ if (node->children().size() == 1 &&
108
+ !subject.empty()) {
109
+
110
+ return ValueSectionType;
111
+ }
112
+ }
113
+
114
+ return UndefinedSectionType;
115
+ }
116
+ };
117
+
118
+ /** Parameter Section Parser */
119
+ typedef SectionParser<Values, ListSectionAdapter> ValuesParser;
120
+ }
121
+
122
+ #endif