redsnow 0.2.1 → 0.3.0

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.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +2 -0
  3. data/ext/snowcrash/bin/snowcrash +0 -0
  4. data/ext/snowcrash/snowcrash.xcworkspace/contents.xcworkspacedata +10 -0
  5. data/ext/snowcrash/src/ActionParser.h +35 -33
  6. data/ext/snowcrash/src/AssetParser.h +17 -17
  7. data/ext/snowcrash/src/Blueprint.h +101 -66
  8. data/ext/snowcrash/src/BlueprintParser.h +219 -10
  9. data/ext/snowcrash/src/BlueprintSourcemap.h +1 -1
  10. data/ext/snowcrash/src/BlueprintUtility.h +14 -14
  11. data/ext/snowcrash/src/CBlueprint.cc +29 -10
  12. data/ext/snowcrash/src/CBlueprint.h +19 -3
  13. data/ext/snowcrash/src/CBlueprintSourcemap.cc +20 -10
  14. data/ext/snowcrash/src/CBlueprintSourcemap.h +12 -3
  15. data/ext/snowcrash/src/CodeBlockUtility.h +25 -25
  16. data/ext/snowcrash/src/HTTP.cc +3 -0
  17. data/ext/snowcrash/src/HTTP.h +9 -6
  18. data/ext/snowcrash/src/HeadersParser.h +34 -14
  19. data/ext/snowcrash/src/ParameterParser.h +21 -21
  20. data/ext/snowcrash/src/ParametersParser.h +6 -5
  21. data/ext/snowcrash/src/PayloadParser.h +174 -129
  22. data/ext/snowcrash/src/RegexMatch.h +3 -3
  23. data/ext/snowcrash/src/ResourceGroupParser.h +5 -4
  24. data/ext/snowcrash/src/ResourceParser.h +30 -26
  25. data/ext/snowcrash/src/Section.cc +6 -6
  26. data/ext/snowcrash/src/Section.h +2 -2
  27. data/ext/snowcrash/src/SectionParser.h +41 -41
  28. data/ext/snowcrash/src/SectionParserData.h +10 -10
  29. data/ext/snowcrash/src/SectionProcessor.h +70 -30
  30. data/ext/snowcrash/src/Serialize.h +3 -3
  31. data/ext/snowcrash/src/SerializeJSON.cc +124 -96
  32. data/ext/snowcrash/src/SerializeJSON.h +1 -1
  33. data/ext/snowcrash/src/SerializeYAML.cc +71 -53
  34. data/ext/snowcrash/src/SerializeYAML.h +1 -1
  35. data/ext/snowcrash/src/Signature.cc +2 -2
  36. data/ext/snowcrash/src/Signature.h +1 -1
  37. data/ext/snowcrash/src/SourceAnnotation.h +23 -23
  38. data/ext/snowcrash/src/StringUtility.h +71 -9
  39. data/ext/snowcrash/src/SymbolTable.h +17 -17
  40. data/ext/snowcrash/src/UriTemplateParser.cc +5 -5
  41. data/ext/snowcrash/src/UriTemplateParser.h +9 -9
  42. data/ext/snowcrash/src/ValuesParser.h +2 -2
  43. data/ext/snowcrash/src/Version.h +1 -1
  44. data/ext/snowcrash/src/csnowcrash.cc +10 -8
  45. data/ext/snowcrash/src/snowcrash.cc +9 -9
  46. data/ext/snowcrash/src/snowcrash.h +6 -8
  47. data/ext/snowcrash/src/snowcrash/snowcrash.cc +14 -14
  48. data/ext/snowcrash/src/win/RegexMatch.cc +7 -7
  49. data/ext/snowcrash/tools/gyp/pylib/gyp/__init__.pyc +0 -0
  50. data/ext/snowcrash/tools/gyp/pylib/gyp/common.pyc +0 -0
  51. data/ext/snowcrash/tools/gyp/pylib/gyp/generator/__init__.pyc +0 -0
  52. data/ext/snowcrash/tools/gyp/pylib/gyp/generator/make.pyc +0 -0
  53. data/ext/snowcrash/tools/gyp/pylib/gyp/generator/xcode.pyc +0 -0
  54. data/ext/snowcrash/tools/gyp/pylib/gyp/input.pyc +0 -0
  55. data/ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyc +0 -0
  56. data/ext/snowcrash/tools/gyp/pylib/gyp/xcodeproj_file.pyc +0 -0
  57. data/ext/snowcrash/tools/homebrew/snowcrash.rb +1 -1
  58. data/lib/redsnow/binding.rb +8 -2
  59. data/lib/redsnow/blueprint.rb +4 -3
  60. data/lib/redsnow/sourcemap.rb +6 -4
  61. data/lib/redsnow/version.rb +1 -1
  62. metadata +4 -17
@@ -21,4 +21,4 @@ namespace snowcrash {
21
21
  void SerializeSourceMapJSON(const snowcrash::SourceMap<snowcrash::Blueprint>& blueprint, std::ostream &os);
22
22
  }
23
23
 
24
- #endif
24
+ #endif
@@ -17,13 +17,13 @@ static std::string ReservedCharacters = "#-[]:|>!*&%@`,{}?\'";
17
17
  static std::string NormalizeStringValue(const std::string& value, bool& needsQuotation)
18
18
  {
19
19
  std::string normalizedValue = value;
20
-
20
+
21
21
  if (normalizedValue.find("\"") != std::string::npos)
22
22
  normalizedValue = EscapeDoubleQuotes(normalizedValue);
23
-
23
+
24
24
  if (value.find("\n") != std::string::npos)
25
25
  normalizedValue = EscapeNewlines(normalizedValue);
26
-
26
+
27
27
  needsQuotation = (normalizedValue != value);
28
28
 
29
29
  if (!needsQuotation) {
@@ -33,7 +33,7 @@ static std::string NormalizeStringValue(const std::string& value, bool& needsQuo
33
33
  break;
34
34
  }
35
35
  }
36
-
36
+
37
37
  return normalizedValue;
38
38
  }
39
39
 
@@ -43,7 +43,7 @@ static void ArrayItemLeadIn(size_t level, std::ostream &os, bool withTrailingSpa
43
43
  {
44
44
  if (level < 1)
45
45
  return;
46
-
46
+
47
47
  for (size_t i = 0; i < level - 1; ++i)
48
48
  os << " ";
49
49
 
@@ -59,17 +59,17 @@ static void serialize(const std::string& key, const std::string& value, size_t l
59
59
  {
60
60
  if (key.empty())
61
61
  return;
62
-
62
+
63
63
  for (size_t i = 0; i < level; ++i)
64
64
  os << " ";
65
-
65
+
66
66
  if (!value.empty()) {
67
-
67
+
68
68
  os << key << ": ";
69
69
 
70
70
  bool needsQuotation = false;
71
71
  std::string normalizedValue = NormalizeStringValue(value, needsQuotation);
72
-
72
+
73
73
  if (implicitQuotation) {
74
74
  // Always use quotation
75
75
  os << "\"" << normalizedValue << "\"";
@@ -80,7 +80,7 @@ static void serialize(const std::string& key, const std::string& value, size_t l
80
80
  else
81
81
  os << value;
82
82
  }
83
-
83
+
84
84
  os << std::endl;
85
85
  }
86
86
  else
@@ -160,7 +160,7 @@ static void serializeKeyValueCollection(const Collection<KeyValuePair>::type& co
160
160
  static void serialize(const Collection<Metadata>::type& metadata, std::ostream &os)
161
161
  {
162
162
  serialize(SerializeKey::Metadata, std::string(), 0, os);
163
-
163
+
164
164
  if (metadata.empty())
165
165
  return;
166
166
 
@@ -204,28 +204,28 @@ static void serialize(const Parameters& parameters, size_t level, std::ostream &
204
204
 
205
205
  // Description
206
206
  serialize(SerializeKey::Description, it->description, level + 1, os);
207
-
207
+
208
208
  // Type
209
209
  serialize(SerializeKey::Type, it->type, level + 1, os);
210
-
210
+
211
211
  // Required
212
212
  serialize(SerializeKey::Required, (it->use == OptionalParameterUse) ? "false" : "true", level + 1, os, false);
213
-
213
+
214
214
  // Default
215
215
  serialize(SerializeKey::Default, it->defaultValue, level + 1, os);
216
-
216
+
217
217
  // Example
218
218
  serialize(SerializeKey::Example, it->exampleValue, level + 1, os);
219
-
219
+
220
220
  // Values
221
221
  serialize(SerializeKey::Values, std::string(), level + 1, os);
222
-
222
+
223
223
  for (Collection<Value>::const_iterator val_it = it->values.begin();
224
224
  val_it != it->values.end();
225
225
  ++val_it) {
226
226
 
227
227
  ArrayItemLeadIn(level + 2, os);
228
-
228
+
229
229
  serialize(SerializeKey::Value, *val_it, 0, os);
230
230
  }
231
231
  }
@@ -275,13 +275,36 @@ static void serialize(const Collection<SourceMap<Parameter> >::type& parameters,
275
275
  }
276
276
  }
277
277
 
278
+ /** Serialize Reference */
279
+ static void serialize(const Reference& reference, size_t level, std::ostream &os)
280
+ {
281
+ if (reference.id.empty()) {
282
+ return;
283
+ }
284
+
285
+ serialize(SerializeKey::Reference, "", level - 1, os);
286
+
287
+ // ID
288
+ serialize(SerializeKey::Id, reference.id, level, os);
289
+ }
290
+
291
+ /** Serialize Reference source map */
292
+ static void serialize(const SourceMap<Reference>& reference, size_t level, std::ostream &os)
293
+ {
294
+ if (reference.sourceMap.empty()) {
295
+ return;
296
+ }
297
+
298
+ serialize(SerializeKey::Reference, reference, level - 1, os);
299
+ }
300
+
278
301
  /** Serialize Payload */
279
302
  static void serialize(const Payload& payload, size_t level, bool array, std::ostream &os)
280
303
  {
281
304
  for (size_t i = 0; i < level - 1; i++) {
282
305
  os << " ";
283
306
  }
284
-
307
+
285
308
  if (array)
286
309
  os << "- ";
287
310
  else
@@ -290,25 +313,22 @@ static void serialize(const Payload& payload, size_t level, bool array, std::ost
290
313
  // Name
291
314
  serialize(SerializeKey::Name, payload.name, 0, os);
292
315
 
293
- // Symbol Reference
294
- if (!payload.symbol.empty()) {
295
- serialize(SerializeKey::Reference, "", level, os);
296
- serialize(SerializeKey::Id, payload.symbol, level + 1, os);
297
- }
316
+ // Reference
317
+ serialize(payload.reference, level + 1, os);
298
318
 
299
319
  // Description
300
320
  serialize(SerializeKey::Description, payload.description, level, os);
301
-
321
+
302
322
  // Headers
303
323
  serialize(SerializeKey::Headers, std::string(), level, os);
304
324
 
305
325
  if (!payload.headers.empty()) {
306
326
  serialize(payload.headers, level, os);
307
327
  }
308
-
328
+
309
329
  // Body
310
330
  serialize(SerializeKey::Body, payload.body, level, os);
311
-
331
+
312
332
  // Schema
313
333
  serialize(SerializeKey::Schema, payload.schema, level, os);
314
334
  }
@@ -328,10 +348,8 @@ static void serialize(const SourceMap<Payload>& payload, size_t level, bool arra
328
348
  // Name
329
349
  serialize(SerializeKey::Name, payload.name, level, os, true);
330
350
 
331
- // Symbol Reference
332
- if (!payload.symbol.sourceMap.empty()) {
333
- serialize(SerializeKey::Reference, payload.symbol, level, os);
334
- }
351
+ // Reference
352
+ serialize(payload.reference, level + 1, os);
335
353
 
336
354
  // Description
337
355
  serialize(SerializeKey::Description, payload.description, level, os);
@@ -357,10 +375,10 @@ static void serialize(const TransactionExample& example, std::ostream &os)
357
375
 
358
376
  // Name
359
377
  serialize(SerializeKey::Name, example.name, 0, os);
360
-
378
+
361
379
  // Description
362
380
  serialize(SerializeKey::Description, example.description, 4, os);
363
-
381
+
364
382
  // Requests
365
383
  serialize(SerializeKey::Requests, std::string(), 4, os);
366
384
 
@@ -372,7 +390,7 @@ static void serialize(const TransactionExample& example, std::ostream &os)
372
390
  serialize(*it, 5, true, os);
373
391
  }
374
392
  }
375
-
393
+
376
394
  // Responses
377
395
  serialize(SerializeKey::Responses, std::string(), 4, os);
378
396
 
@@ -426,22 +444,22 @@ static void serialize(const SourceMap<TransactionExample>& example, std::ostream
426
444
  static void serialize(const Action& action, std::ostream &os)
427
445
  {
428
446
  os << " - "; // indent 3
429
-
447
+
430
448
  // Name
431
449
  serialize(SerializeKey::Name, action.name, 0, os);
432
-
450
+
433
451
  // Description
434
452
  serialize(SerializeKey::Description, action.description, 3, os);
435
453
 
436
454
  // HTTP method
437
455
  serialize(SerializeKey::Method, action.method, 3, os);
438
-
456
+
439
457
  // Parameters
440
458
  serialize(SerializeKey::Parameters, std::string(), 3, os);
441
459
 
442
460
  if (!action.parameters.empty())
443
461
  serialize(action.parameters, 3, os);
444
-
462
+
445
463
  // Examples
446
464
  serialize(SerializeKey::Examples, std::string(), 3, os);
447
465
 
@@ -492,34 +510,34 @@ static void serialize(const SourceMap<Action>& action, std::ostream &os)
492
510
  static void serialize(const Resource& resource, std::ostream &os)
493
511
  {
494
512
  os << " - "; // indent 2
495
-
513
+
496
514
  // Name
497
515
  serialize(SerializeKey::Name, resource.name, 0, os);
498
-
516
+
499
517
  // Description
500
518
  serialize(SerializeKey::Description, resource.description, 2, os);
501
-
519
+
502
520
  // URI Template
503
521
  serialize(SerializeKey::URITemplate, resource.uriTemplate, 2, os);
504
-
522
+
505
523
  // Model
506
524
  serialize(SerializeKey::Model, std::string(), 2, os);
507
525
 
508
526
  if (!resource.model.name.empty())
509
527
  serialize(resource.model, 3, false, os);
510
-
528
+
511
529
  // Parameters
512
530
  serialize(SerializeKey::Parameters, std::string(), 2, os);
513
531
 
514
532
  if (!resource.parameters.empty())
515
533
  serialize(resource.parameters, 2, os);
516
-
534
+
517
535
  // Actions
518
536
  serialize(SerializeKey::Actions, std::string(), 2, os);
519
-
537
+
520
538
  if (resource.actions.empty())
521
539
  return;
522
-
540
+
523
541
  for (Collection<Action>::const_iterator it = resource.actions.begin();
524
542
  it != resource.actions.end();
525
543
  ++it) {
@@ -575,13 +593,13 @@ static void serialize(const ResourceGroup& group, std::ostream &os)
575
593
 
576
594
  // Name
577
595
  serialize(SerializeKey::Name, group.name, 0, os);
578
-
596
+
579
597
  // Description
580
598
  serialize(SerializeKey::Description, group.description, 1, os);
581
599
 
582
600
  // Resources
583
601
  serialize(SerializeKey::Resources, std::string(), 1, os);
584
-
602
+
585
603
  if (group.resources.empty())
586
604
  return;
587
605
 
@@ -623,16 +641,16 @@ static void serialize(const Blueprint& blueprint, std::ostream &os)
623
641
  {
624
642
  // AST Version
625
643
  serialize(SerializeKey::ASTVersion, AST_SERIALIZATION_VERSION, 0, os, false);
626
-
644
+
627
645
  // Metadata
628
646
  serialize(blueprint.metadata, os);
629
-
647
+
630
648
  // API Name
631
649
  serialize(SerializeKey::Name, blueprint.name, 0, os);
632
-
650
+
633
651
  // API Description
634
652
  serialize(SerializeKey::Description, blueprint.description, 0, os);
635
-
653
+
636
654
  // Resource Groups
637
655
  serialize(SerializeKey::ResourceGroups, std::string(), 0, os);
638
656
 
@@ -642,7 +660,7 @@ static void serialize(const Blueprint& blueprint, std::ostream &os)
642
660
  for (Collection<ResourceGroup>::type::const_iterator it = blueprint.resourceGroups.begin();
643
661
  it != blueprint.resourceGroups.end();
644
662
  ++it) {
645
-
663
+
646
664
  serialize(*it, os);
647
665
  }
648
666
  }
@@ -13,7 +13,7 @@
13
13
  #include "BlueprintSourcemap.h"
14
14
 
15
15
  namespace snowcrash {
16
-
16
+
17
17
  // Naive YAML serialization to ostream
18
18
  void SerializeYAML(const snowcrash::Blueprint& blueprint, std::ostream &os);
19
19
 
@@ -38,7 +38,7 @@ SectionType snowcrash::SectionKeywordSignature(const mdp::MarkdownNodeIterator&
38
38
  if ((type = SectionProcessor<Parameters>::sectionType(node)) != UndefinedSectionType)
39
39
  return type;
40
40
 
41
- /*
41
+ /*
42
42
  * NOTE: Order is important. Resource MUST preceed the Action.
43
43
  *
44
44
  * This is because an HTTP Request Method + URI is recognized as both %ActionSectionType and %ResourceSectionType.
@@ -46,7 +46,7 @@ SectionType snowcrash::SectionKeywordSignature(const mdp::MarkdownNodeIterator&
46
46
  */
47
47
  if ((type = SectionProcessor<Resource>::sectionType(node)) != UndefinedSectionType)
48
48
  return type;
49
-
49
+
50
50
  if ((type = SectionProcessor<Action>::sectionType(node)) != UndefinedSectionType)
51
51
  return type;
52
52
 
@@ -14,7 +14,7 @@
14
14
 
15
15
  namespace snowcrash {
16
16
 
17
- /**
17
+ /**
18
18
  * \brief Query whether a node has keyword-defined signature.
19
19
  * \param node A Markdown AST node to check.
20
20
  * \return Type of the node if it has a recognized keyword signature, UndefinedType otherwise
@@ -14,8 +14,8 @@
14
14
  #include "ByteBuffer.h"
15
15
 
16
16
  namespace snowcrash {
17
-
18
-
17
+
18
+
19
19
  /**
20
20
  * \brief A source data annotation.
21
21
  *
@@ -23,30 +23,30 @@ namespace snowcrash {
23
23
  * annotation code and an optional message.
24
24
  */
25
25
  struct SourceAnnotation {
26
-
26
+
27
27
  /**
28
28
  * \brief Default annotation code representing success.
29
29
  */
30
30
  static const int OK;
31
-
31
+
32
32
  /**
33
33
  * \brief %SourceAnnotation default constructor.
34
34
  *
35
35
  * Creates an empty annotation with the default annotation code.
36
36
  */
37
37
  SourceAnnotation() : code(OK) {}
38
-
38
+
39
39
  /**
40
40
  * \brief %SourceAnnotation copy constructor.
41
41
  * \param rhs An annotation to be copied.
42
42
  */
43
43
  SourceAnnotation(const SourceAnnotation& rhs) {
44
-
44
+
45
45
  this->message = rhs.message;
46
46
  this->code = rhs.code;
47
47
  this->location = rhs.location;
48
48
  }
49
-
49
+
50
50
  /**
51
51
  * \brief %SourceAnnotation constructor.
52
52
  * \param message An annotation message.
@@ -56,18 +56,18 @@ namespace snowcrash {
56
56
  SourceAnnotation(const std::string& message,
57
57
  int code = OK,
58
58
  const mdp::CharactersRangeSet& location = mdp::CharactersRangeSet()) {
59
-
59
+
60
60
  this->message = message;
61
61
  this->code = code;
62
-
62
+
63
63
  this->location.clear();
64
64
  if (!location.empty())
65
65
  this->location.assign(location.begin(), location.end());
66
66
  }
67
-
67
+
68
68
  /** \brief %SourceAnnotation destructor. */
69
69
  ~SourceAnnotation() {}
70
-
70
+
71
71
  /**
72
72
  * \brief %SourceAnnotation assignment operator
73
73
  * \param rhs An annotation to be assigned to this annotation.
@@ -78,22 +78,22 @@ namespace snowcrash {
78
78
  this->location = rhs.location;
79
79
  return *this;
80
80
  }
81
-
81
+
82
82
  /** The location of this annotation within the source data buffer. */
83
83
  mdp::CharactersRangeSet location;
84
-
84
+
85
85
  /** An annotation code. */
86
86
  int code;
87
-
87
+
88
88
  /** A annotation message. */
89
89
  std::string message;
90
90
  };
91
-
91
+
92
92
  /**
93
93
  * Error source annotation.
94
94
  */
95
95
  typedef SourceAnnotation Error;
96
-
96
+
97
97
  /**
98
98
  * Error codes
99
99
  */
@@ -103,12 +103,12 @@ namespace snowcrash {
103
103
  BusinessError = 2,
104
104
  SymbolError = 3
105
105
  };
106
-
106
+
107
107
  /**
108
108
  * Warning source annotation.
109
109
  */
110
110
  typedef SourceAnnotation Warning;
111
-
111
+
112
112
  /**
113
113
  * Warning codes
114
114
  */
@@ -127,12 +127,12 @@ namespace snowcrash {
127
127
  AmbiguityWarning = 11,
128
128
  URIWarning = 12
129
129
  };
130
-
130
+
131
131
  /**
132
132
  * A set of warning source annotations.
133
133
  */
134
134
  typedef std::vector<Warning> Warnings;
135
-
135
+
136
136
  /**
137
137
  * \brief A parsing report Report.
138
138
  *
@@ -141,7 +141,7 @@ namespace snowcrash {
141
141
  * and a set of warning source annotations.
142
142
  */
143
143
  struct Report {
144
-
144
+
145
145
  /**
146
146
  * \brief Append a report to this one, replacing the error source annotation.
147
147
  *
@@ -152,10 +152,10 @@ namespace snowcrash {
152
152
  warnings.insert(warnings.end(), rhs.warnings.begin(), rhs.warnings.end());
153
153
  return *this;
154
154
  }
155
-
155
+
156
156
  /** Result error source annotation */
157
157
  Error error;
158
-
158
+
159
159
  /** Result warning source annotations */
160
160
  Warnings warnings;
161
161
  };