redsnow 0.1.6 → 0.2.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 (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,38 @@
1
+ 
2
+ Microsoft Visual Studio Solution File, Format Version 10.00
3
+ # Visual Studio 2008
4
+ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "markdown", "markdown\markdown.vcproj", "{288550BA-B6D6-4254-B5E3-9E8CE20970AE}"
5
+ ProjectSection(ProjectDependencies) = postProject
6
+ {08CAEF5D-9ED7-4CB1-844D-D39AA17D3AD6} = {08CAEF5D-9ED7-4CB1-844D-D39AA17D3AD6}
7
+ EndProjectSection
8
+ EndProject
9
+ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sundown", "sundown\sundown.vcproj", "{08CAEF5D-9ED7-4CB1-844D-D39AA17D3AD6}"
10
+ EndProject
11
+ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test-markdown", "test-markdown\test-markdown.vcproj", "{DB045416-DCDB-45D3-904C-C1F15D608FC3}"
12
+ ProjectSection(ProjectDependencies) = postProject
13
+ {288550BA-B6D6-4254-B5E3-9E8CE20970AE} = {288550BA-B6D6-4254-B5E3-9E8CE20970AE}
14
+ EndProjectSection
15
+ EndProject
16
+ Global
17
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
18
+ Debug|Win32 = Debug|Win32
19
+ Release|Win32 = Release|Win32
20
+ EndGlobalSection
21
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
22
+ {288550BA-B6D6-4254-B5E3-9E8CE20970AE}.Debug|Win32.ActiveCfg = Debug|Win32
23
+ {288550BA-B6D6-4254-B5E3-9E8CE20970AE}.Debug|Win32.Build.0 = Debug|Win32
24
+ {288550BA-B6D6-4254-B5E3-9E8CE20970AE}.Release|Win32.ActiveCfg = Release|Win32
25
+ {288550BA-B6D6-4254-B5E3-9E8CE20970AE}.Release|Win32.Build.0 = Release|Win32
26
+ {08CAEF5D-9ED7-4CB1-844D-D39AA17D3AD6}.Debug|Win32.ActiveCfg = Debug|Win32
27
+ {08CAEF5D-9ED7-4CB1-844D-D39AA17D3AD6}.Debug|Win32.Build.0 = Debug|Win32
28
+ {08CAEF5D-9ED7-4CB1-844D-D39AA17D3AD6}.Release|Win32.ActiveCfg = Release|Win32
29
+ {08CAEF5D-9ED7-4CB1-844D-D39AA17D3AD6}.Release|Win32.Build.0 = Release|Win32
30
+ {DB045416-DCDB-45D3-904C-C1F15D608FC3}.Debug|Win32.ActiveCfg = Debug|Win32
31
+ {DB045416-DCDB-45D3-904C-C1F15D608FC3}.Debug|Win32.Build.0 = Debug|Win32
32
+ {DB045416-DCDB-45D3-904C-C1F15D608FC3}.Release|Win32.ActiveCfg = Release|Win32
33
+ {DB045416-DCDB-45D3-904C-C1F15D608FC3}.Release|Win32.Build.0 = Release|Win32
34
+ EndGlobalSection
35
+ GlobalSection(SolutionProperties) = preSolution
36
+ HideSolutionNode = FALSE
37
+ EndGlobalSection
38
+ EndGlobal
@@ -0,0 +1,206 @@
1
+ <?xml version="1.0" encoding="Windows-1252"?>
2
+ <VisualStudioProject
3
+ ProjectType="Visual C++"
4
+ Version="9.00"
5
+ Name="sundown"
6
+ ProjectGUID="{08CAEF5D-9ED7-4CB1-844D-D39AA17D3AD6}"
7
+ RootNamespace="sundown"
8
+ TargetFrameworkVersion="196613"
9
+ >
10
+ <Platforms>
11
+ <Platform
12
+ Name="Win32"
13
+ />
14
+ </Platforms>
15
+ <ToolFiles>
16
+ </ToolFiles>
17
+ <Configurations>
18
+ <Configuration
19
+ Name="Debug|Win32"
20
+ OutputDirectory="..\..\build\debug"
21
+ IntermediateDirectory="..\..\build\data\sundown\debug"
22
+ ConfigurationType="4"
23
+ CharacterSet="2"
24
+ >
25
+ <Tool
26
+ Name="VCPreBuildEventTool"
27
+ />
28
+ <Tool
29
+ Name="VCCustomBuildTool"
30
+ />
31
+ <Tool
32
+ Name="VCXMLDataGeneratorTool"
33
+ />
34
+ <Tool
35
+ Name="VCWebServiceProxyGeneratorTool"
36
+ />
37
+ <Tool
38
+ Name="VCMIDLTool"
39
+ />
40
+ <Tool
41
+ Name="VCCLCompilerTool"
42
+ Optimization="0"
43
+ MinimalRebuild="true"
44
+ BasicRuntimeChecks="3"
45
+ RuntimeLibrary="3"
46
+ WarningLevel="3"
47
+ DebugInformationFormat="4"
48
+ />
49
+ <Tool
50
+ Name="VCManagedResourceCompilerTool"
51
+ />
52
+ <Tool
53
+ Name="VCResourceCompilerTool"
54
+ />
55
+ <Tool
56
+ Name="VCPreLinkEventTool"
57
+ />
58
+ <Tool
59
+ Name="VCLibrarianTool"
60
+ />
61
+ <Tool
62
+ Name="VCALinkTool"
63
+ />
64
+ <Tool
65
+ Name="VCXDCMakeTool"
66
+ />
67
+ <Tool
68
+ Name="VCBscMakeTool"
69
+ />
70
+ <Tool
71
+ Name="VCFxCopTool"
72
+ />
73
+ <Tool
74
+ Name="VCPostBuildEventTool"
75
+ />
76
+ </Configuration>
77
+ <Configuration
78
+ Name="Release|Win32"
79
+ OutputDirectory="..\..\build\release"
80
+ IntermediateDirectory="..\..\build\data\sundown\release"
81
+ ConfigurationType="4"
82
+ CharacterSet="2"
83
+ WholeProgramOptimization="1"
84
+ >
85
+ <Tool
86
+ Name="VCPreBuildEventTool"
87
+ />
88
+ <Tool
89
+ Name="VCCustomBuildTool"
90
+ />
91
+ <Tool
92
+ Name="VCXMLDataGeneratorTool"
93
+ />
94
+ <Tool
95
+ Name="VCWebServiceProxyGeneratorTool"
96
+ />
97
+ <Tool
98
+ Name="VCMIDLTool"
99
+ />
100
+ <Tool
101
+ Name="VCCLCompilerTool"
102
+ Optimization="2"
103
+ EnableIntrinsicFunctions="true"
104
+ RuntimeLibrary="2"
105
+ EnableFunctionLevelLinking="true"
106
+ WarningLevel="3"
107
+ DebugInformationFormat="3"
108
+ />
109
+ <Tool
110
+ Name="VCManagedResourceCompilerTool"
111
+ />
112
+ <Tool
113
+ Name="VCResourceCompilerTool"
114
+ />
115
+ <Tool
116
+ Name="VCPreLinkEventTool"
117
+ />
118
+ <Tool
119
+ Name="VCLibrarianTool"
120
+ />
121
+ <Tool
122
+ Name="VCALinkTool"
123
+ />
124
+ <Tool
125
+ Name="VCXDCMakeTool"
126
+ />
127
+ <Tool
128
+ Name="VCBscMakeTool"
129
+ />
130
+ <Tool
131
+ Name="VCFxCopTool"
132
+ />
133
+ <Tool
134
+ Name="VCPostBuildEventTool"
135
+ />
136
+ </Configuration>
137
+ </Configurations>
138
+ <References>
139
+ </References>
140
+ <Files>
141
+ <Filter
142
+ Name="Source Files"
143
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
144
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
145
+ >
146
+ <File
147
+ RelativePath="..\..\ext\sundown\src\autolink.c"
148
+ >
149
+ </File>
150
+ <File
151
+ RelativePath="..\..\ext\sundown\src\buffer.c"
152
+ >
153
+ </File>
154
+ <File
155
+ RelativePath="..\..\ext\sundown\src\markdown.c"
156
+ >
157
+ </File>
158
+ <File
159
+ RelativePath="..\..\ext\sundown\src\src_map.c"
160
+ >
161
+ </File>
162
+ <File
163
+ RelativePath="..\..\ext\sundown\src\stack.c"
164
+ >
165
+ </File>
166
+ </Filter>
167
+ <Filter
168
+ Name="Header Files"
169
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
170
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
171
+ >
172
+ <File
173
+ RelativePath="..\..\ext\sundown\src\autolink.h"
174
+ >
175
+ </File>
176
+ <File
177
+ RelativePath="..\..\ext\sundown\src\buffer.h"
178
+ >
179
+ </File>
180
+ <File
181
+ RelativePath="..\..\ext\sundown\src\html_blocks.h"
182
+ >
183
+ </File>
184
+ <File
185
+ RelativePath="..\..\ext\sundown\src\markdown.h"
186
+ >
187
+ </File>
188
+ <File
189
+ RelativePath="..\..\ext\sundown\src\src_map.h"
190
+ >
191
+ </File>
192
+ <File
193
+ RelativePath="..\..\ext\sundown\src\stack.h"
194
+ >
195
+ </File>
196
+ </Filter>
197
+ <Filter
198
+ Name="Resource Files"
199
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
200
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
201
+ >
202
+ </Filter>
203
+ </Files>
204
+ <Globals>
205
+ </Globals>
206
+ </VisualStudioProject>
@@ -0,0 +1,92 @@
1
+ //
2
+ // ByteBuffer.cc
3
+ // markdownparser
4
+ //
5
+ // Created by Zdenek Nemec on 4/22/14.
6
+ // Copyright (c) 2014 Apiary Inc. All rights reserved.
7
+ //
8
+
9
+ #include "ByteBuffer.h"
10
+
11
+ using namespace mdp;
12
+
13
+ /* Byte lenght of an UTF8 character (based on first byte) */
14
+ #define UTF8_CHAR_LEN( byte ) (( 0xE5000000 >> (( byte >> 3 ) & 0x1e )) & 3 ) + 1
15
+
16
+ /* Number of UTF8 characters in byte buffer */
17
+ static size_t strnlen_utf8(const char* s, size_t len)
18
+ {
19
+ if (!s || !len)
20
+ return 0;
21
+
22
+ size_t i = 0, j = 0;
23
+ while (s[i] && i < len) {
24
+ i += UTF8_CHAR_LEN(s[i]);
25
+ j++;
26
+ }
27
+ return j;
28
+ }
29
+
30
+ /* Convert range of bytes to a range of characters */
31
+ static CharactersRange BytesRangeToCharactersRange(const BytesRange& bytesRange, const ByteBuffer& byteBuffer)
32
+ {
33
+ if (byteBuffer.empty()) {
34
+ return CharactersRange();
35
+ }
36
+
37
+ BytesRange workRange = bytesRange;
38
+ if (bytesRange.location + bytesRange.length > byteBuffer.length()) {
39
+ // Accomodate maximum possible length
40
+ workRange.length -= bytesRange.location + bytesRange.length - byteBuffer.length();
41
+ }
42
+
43
+ size_t charLocation = 0;
44
+ if (bytesRange.location > 0)
45
+ charLocation = strnlen_utf8(byteBuffer.c_str(), bytesRange.location);
46
+
47
+ size_t charLength = 0;
48
+ if (bytesRange.length > 0)
49
+ charLength = strnlen_utf8(byteBuffer.c_str() + bytesRange.location, bytesRange.length);
50
+
51
+ CharactersRange characterRange = CharactersRange(charLocation, charLength);
52
+ return characterRange;
53
+ }
54
+
55
+ CharactersRangeSet mdp::BytesRangeSetToCharactersRangeSet(const BytesRangeSet& rangeSet, const ByteBuffer& byteBuffer)
56
+ {
57
+ CharactersRangeSet characterMap;
58
+
59
+ for (BytesRangeSet::const_iterator it = rangeSet.begin(); it != rangeSet.end(); ++it) {
60
+ CharactersRange characterRange = BytesRangeToCharactersRange(*it, byteBuffer);
61
+ characterMap.push_back(characterRange);
62
+ }
63
+
64
+ return characterMap;
65
+ }
66
+
67
+ ByteBuffer mdp::MapBytesRangeSet(const BytesRangeSet& rangeSet, const ByteBuffer& byteBuffer)
68
+ {
69
+ if (byteBuffer.empty())
70
+ return ByteBuffer();
71
+
72
+ size_t length = byteBuffer.length();
73
+ ByteBufferStream s;
74
+ for (BytesRangeSet::const_iterator it = rangeSet.begin(); it != rangeSet.end(); ++it) {
75
+
76
+ if (it->location + it->length > length) {
77
+ // Sundown adds an extra newline on the source input if needed.
78
+ if (it->location + it->length - length == 1) {
79
+ s << byteBuffer.substr(it->location, length - it->location);
80
+ return s.str();
81
+ }
82
+ else {
83
+ // Wrong map
84
+ return ByteBuffer();
85
+ }
86
+ }
87
+
88
+ s << byteBuffer.substr(it->location, it->length);
89
+ }
90
+
91
+ return s.str();
92
+ }
@@ -0,0 +1,82 @@
1
+ //
2
+ // ByteBuffer.h
3
+ // markdownparser
4
+ //
5
+ // Created by Zdenek Nemec on 4/18/14.
6
+ // Copyright (c) 2014 Apiary Inc. All rights reserved.
7
+ //
8
+
9
+ #ifndef MARKDOWNPARSER_BYTEBUFFER_H
10
+ #define MARKDOWNPARSER_BYTEBUFFER_H
11
+
12
+ #include <string>
13
+ #include <vector>
14
+ #include <sstream>
15
+
16
+ namespace mdp {
17
+
18
+ /**
19
+ * \brief Source data byte buffer
20
+ *
21
+ * Note this is a byte buffer, a sequence of
22
+ * UTF8 bytes note necessarily characters.
23
+ */
24
+ typedef std::string ByteBuffer;
25
+
26
+ /** Byte buffer stream */
27
+ typedef std::stringstream ByteBufferStream;
28
+
29
+ /** A generic continuous range */
30
+ struct Range {
31
+ size_t location;
32
+ size_t length;
33
+
34
+ Range(size_t loc = 0, size_t len = 0)
35
+ : location(loc), length(len) {}
36
+ };
37
+
38
+ /** Range of bytes */
39
+ typedef Range BytesRange;
40
+
41
+ /** Range of characters */
42
+ typedef Range CharactersRange;
43
+
44
+ /** A generic set of non-continuous of ranges */
45
+ template<typename T>
46
+ class RangeSet : public std::vector<T> {
47
+ public:
48
+
49
+ /** Append another range set to this one, merging continuous blocks */
50
+ void append(const RangeSet& val)
51
+ {
52
+ if (val.empty())
53
+ return;
54
+ if (this->empty() ||
55
+ val.front().location != this->back().location + this->back().length) {
56
+ this->insert(this->end(), val.begin(), val.end());
57
+ }
58
+ else {
59
+ // merge
60
+ this->back().length += val.front().length;
61
+
62
+ if (val.size() > 1) {
63
+ this->insert(this->end(), ++val.begin(), val.end());
64
+ }
65
+ }
66
+ }
67
+ };
68
+
69
+ /** Set of non-continuous byte ranges */
70
+ typedef RangeSet<BytesRange> BytesRangeSet;
71
+
72
+ /** Set of non-continuous character ranges */
73
+ typedef RangeSet<CharactersRange> CharactersRangeSet;
74
+
75
+ /** Convert ranges of bytes to ranges of characters */
76
+ CharactersRangeSet BytesRangeSetToCharactersRangeSet(const BytesRangeSet& rangeSet, const ByteBuffer& byteBuffer);
77
+
78
+ /** Maps bytes range set to byte buffer */
79
+ ByteBuffer MapBytesRangeSet(const BytesRangeSet& rangeSet, const ByteBuffer& byteBuffer);
80
+ }
81
+
82
+ #endif
@@ -0,0 +1,152 @@
1
+ //
2
+ // MarkdownNode.cc
3
+ // markdownparser
4
+ //
5
+ // Created by Zdenek Nemec on 4/19/14.
6
+ // Copyright (c) 2014 Apiary Inc. All rights reserved.
7
+ //
8
+
9
+ #include "MarkdownNode.h"
10
+
11
+ using namespace mdp;
12
+
13
+ MarkdownNode::MarkdownNode(MarkdownNodeType type_, MarkdownNode *parent_, const ByteBuffer& text_, const Data& data_)
14
+ : type(type_), text(text_), data(data_), m_parent(parent_)
15
+ {
16
+ m_children.reset(::new MarkdownNodes);
17
+ }
18
+
19
+ MarkdownNode::MarkdownNode(const MarkdownNode& rhs)
20
+ {
21
+ this->type = rhs.type;
22
+ this->text = rhs.text;
23
+ this->data = rhs.data;
24
+ this->sourceMap = rhs.sourceMap;
25
+ this->m_children.reset(::new MarkdownNodes(*rhs.m_children.get()));
26
+ this->m_parent = rhs.m_parent;
27
+ }
28
+
29
+ MarkdownNode& MarkdownNode::operator=(const MarkdownNode& rhs)
30
+ {
31
+ this->type = rhs.type;
32
+ this->text = rhs.text;
33
+ this->data = rhs.data;
34
+ this->sourceMap = rhs.sourceMap;
35
+ this->m_children.reset(::new MarkdownNodes(*rhs.m_children.get()));
36
+ this->m_parent = rhs.m_parent;
37
+ return *this;
38
+ }
39
+
40
+ MarkdownNode::~MarkdownNode()
41
+ {
42
+ }
43
+
44
+ MarkdownNode& MarkdownNode::parent()
45
+ {
46
+ if (!hasParent())
47
+ throw "no parent set";
48
+ return *m_parent;
49
+ }
50
+
51
+ const MarkdownNode& MarkdownNode::parent() const
52
+ {
53
+ if (!hasParent())
54
+ throw "no parent set";
55
+ return *m_parent;
56
+ }
57
+
58
+ void MarkdownNode::setParent(MarkdownNode *parent)
59
+ {
60
+ m_parent = parent;
61
+ }
62
+
63
+ bool MarkdownNode::hasParent() const
64
+ {
65
+ return (m_parent != NULL);
66
+ }
67
+
68
+ MarkdownNodes& MarkdownNode::children()
69
+ {
70
+ if (!m_children.get())
71
+ throw "no children set";
72
+
73
+ return *m_children;
74
+ }
75
+
76
+ const MarkdownNodes& MarkdownNode::children() const
77
+ {
78
+ if (!m_children.get())
79
+ throw "no children set";
80
+
81
+ return *m_children;
82
+ }
83
+
84
+ void MarkdownNode::printNode(size_t level) const
85
+ {
86
+ using std::cout;
87
+ for (size_t i = 0; i < level; ++i)
88
+ std::cout << " ";
89
+
90
+ cout << "+ ";
91
+ switch (type) {
92
+ case RootMarkdownNodeType:
93
+ cout << "root";
94
+ break;
95
+
96
+ case CodeMarkdownNodeType:
97
+ cout << "code";
98
+ break;
99
+
100
+ case QuoteMarkdownNodeType:
101
+ cout << "quote";
102
+ break;
103
+
104
+ case HTMLMarkdownNodeType:
105
+ cout << "HTML";
106
+ break;
107
+
108
+ case HeaderMarkdownNodeType:
109
+ cout << "header";
110
+ break;
111
+
112
+ case HRuleMarkdownNodeType:
113
+ cout << "hrul";
114
+ break;
115
+
116
+ case ListItemMarkdownNodeType:
117
+ cout << "list item";
118
+ break;
119
+
120
+ case ParagraphMarkdownNodeType:
121
+ cout << "paragraph";
122
+ break;
123
+
124
+ default:
125
+ cout << "undefined";
126
+ break;
127
+ }
128
+
129
+ cout << " (type " << type << ", data " << data << ") - ";
130
+ cout << "`" << text << "`";
131
+
132
+ if (!sourceMap.empty()) {
133
+ for (mdp::BytesRangeSet::const_iterator it = sourceMap.begin();
134
+ it != sourceMap.end();
135
+ ++it) {
136
+ std::cout << ((it == sourceMap.begin()) ? " :" : ";");
137
+ std::cout << it->location << ":" << it->length;
138
+ }
139
+ }
140
+
141
+ cout << std::endl;
142
+
143
+ for (MarkdownNodeIterator it = m_children->begin();
144
+ it != m_children->end();
145
+ ++it) {
146
+ it->printNode(level + 1);
147
+ }
148
+
149
+ if (level == 0)
150
+ cout << std::endl << std::endl;
151
+ }
152
+