lounge_lizard 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (348) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.gitmodules +3 -0
  4. data/.rspec +2 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +4 -0
  7. data/Guardfile +33 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +50 -0
  10. data/Rakefile +43 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/circle.yml +14 -0
  14. data/ext/drafter/CHANGELOG.md +278 -0
  15. data/ext/drafter/Dockerfile +17 -0
  16. data/ext/drafter/Makefile +62 -0
  17. data/ext/drafter/appveyor.yml +17 -0
  18. data/ext/drafter/bin/drafter +0 -0
  19. data/ext/drafter/build/Makefile +387 -0
  20. data/ext/drafter/build/drafter.Makefile +6 -0
  21. data/ext/drafter/build/drafter.target.mk +159 -0
  22. data/ext/drafter/build/ext/snowcrash/libmarkdownparser.target.mk +141 -0
  23. data/ext/drafter/build/ext/snowcrash/libsnowcrash.target.mk +154 -0
  24. data/ext/drafter/build/ext/snowcrash/libsundown.target.mk +149 -0
  25. data/ext/drafter/build/ext/snowcrash/perf-libsnowcrash.target.mk +147 -0
  26. data/ext/drafter/build/ext/snowcrash/snowcrash.Makefile +6 -0
  27. data/ext/drafter/build/gyp-mac-tool +606 -0
  28. data/ext/drafter/build/libdrafter.target.mk +186 -0
  29. data/ext/drafter/build/libsos.target.mk +137 -0
  30. data/ext/drafter/build/out/Release/drafter +0 -0
  31. data/ext/drafter/build/out/Release/libdrafter.dylib +0 -0
  32. data/ext/drafter/build/out/Release/libmarkdownparser.a +0 -0
  33. data/ext/drafter/build/out/Release/libsnowcrash.a +0 -0
  34. data/ext/drafter/build/out/Release/libsos.a +0 -0
  35. data/ext/drafter/build/out/Release/libsundown.a +0 -0
  36. data/ext/drafter/build/out/Release/obj.target/drafter/src/config.o +0 -0
  37. data/ext/drafter/build/out/Release/obj.target/drafter/src/main.o +0 -0
  38. data/ext/drafter/build/out/Release/obj.target/drafter/src/reporting.o +0 -0
  39. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/ConversionContext.o +0 -0
  40. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/NamedTypesRegistry.o +0 -0
  41. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/RefractAPI.o +0 -0
  42. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/RefractDataStructure.o +0 -0
  43. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/RefractElementFactory.o +0 -0
  44. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/RefractSourceMap.o +0 -0
  45. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/Render.o +0 -0
  46. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/Serialize.o +0 -0
  47. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/SerializeAST.o +0 -0
  48. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/SerializeResult.o +0 -0
  49. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/SerializeSourcemap.o +0 -0
  50. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/drafter.o +0 -0
  51. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/drafter_private.o +0 -0
  52. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/ComparableVisitor.o +0 -0
  53. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/Element.o +0 -0
  54. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/ExpandVisitor.o +0 -0
  55. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/IsExpandableVisitor.o +0 -0
  56. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/JSONSchemaVisitor.o +0 -0
  57. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/PrintVisitor.o +0 -0
  58. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/Query.o +0 -0
  59. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/Registry.o +0 -0
  60. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/RenderJSONVisitor.o +0 -0
  61. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/SerializeCompactVisitor.o +0 -0
  62. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/SerializeVisitor.o +0 -0
  63. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/TypeQueryVisitor.o +0 -0
  64. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/VisitorUtils.o +0 -0
  65. data/ext/drafter/build/out/Release/obj.target/libmarkdownparser/ext/snowcrash/ext/markdown-parser/src/ByteBuffer.o +0 -0
  66. data/ext/drafter/build/out/Release/obj.target/libmarkdownparser/ext/snowcrash/ext/markdown-parser/src/MarkdownNode.o +0 -0
  67. data/ext/drafter/build/out/Release/obj.target/libmarkdownparser/ext/snowcrash/ext/markdown-parser/src/MarkdownParser.o +0 -0
  68. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/Blueprint.o +0 -0
  69. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/BlueprintSourcemap.o +0 -0
  70. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/HTTP.o +0 -0
  71. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/HeadersParser.o +0 -0
  72. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/MSON.o +0 -0
  73. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/MSONOneOfParser.o +0 -0
  74. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/MSONSourcemap.o +0 -0
  75. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/MSONTypeSectionParser.o +0 -0
  76. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/MSONValueMemberParser.o +0 -0
  77. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/Section.o +0 -0
  78. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/Signature.o +0 -0
  79. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/UriTemplateParser.o +0 -0
  80. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/posix/RegexMatch.o +0 -0
  81. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/snowcrash.o +0 -0
  82. data/ext/drafter/build/out/Release/obj.target/libsos/ext/sos/src/sos.o +0 -0
  83. data/ext/drafter/build/out/Release/obj.target/libsundown/ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini_href_e.o +0 -0
  84. data/ext/drafter/build/out/Release/obj.target/libsundown/ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini_html_e.o +0 -0
  85. data/ext/drafter/build/out/Release/obj.target/libsundown/ext/snowcrash/ext/markdown-parser/ext/sundown/html/html.o +0 -0
  86. data/ext/drafter/build/out/Release/obj.target/libsundown/ext/snowcrash/ext/markdown-parser/ext/sundown/html/html_smartypants.o +0 -0
  87. data/ext/drafter/build/out/Release/obj.target/libsundown/ext/snowcrash/ext/markdown-parser/ext/sundown/src/autolink.o +0 -0
  88. data/ext/drafter/build/out/Release/obj.target/libsundown/ext/snowcrash/ext/markdown-parser/ext/sundown/src/buffer.o +0 -0
  89. data/ext/drafter/build/out/Release/obj.target/libsundown/ext/snowcrash/ext/markdown-parser/ext/sundown/src/markdown.o +0 -0
  90. data/ext/drafter/build/out/Release/obj.target/libsundown/ext/snowcrash/ext/markdown-parser/ext/sundown/src/src_map.o +0 -0
  91. data/ext/drafter/build/out/Release/obj.target/libsundown/ext/snowcrash/ext/markdown-parser/ext/sundown/src/stack.o +0 -0
  92. data/ext/drafter/circle.yml +32 -0
  93. data/ext/drafter/config.gypi +10 -0
  94. data/ext/drafter/config.mk +5 -0
  95. data/ext/drafter/configure +224 -0
  96. data/ext/drafter/drafter.gyp +189 -0
  97. data/ext/drafter/drafter.xcworkspace/contents.xcworkspacedata +13 -0
  98. data/ext/drafter/ext/snowcrash/Makefile +58 -0
  99. data/ext/drafter/ext/snowcrash/appveyor.yml +7 -0
  100. data/ext/drafter/ext/snowcrash/common.gypi +165 -0
  101. data/ext/drafter/ext/snowcrash/configure +197 -0
  102. data/ext/drafter/ext/snowcrash/ext/markdown-parser/Makefile +90 -0
  103. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/CONTRIBUTING.md +10 -0
  104. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/Makefile +84 -0
  105. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/Makefile.win +33 -0
  106. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/examples/smartypants.c +72 -0
  107. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/examples/sundown.c +80 -0
  108. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini.h +37 -0
  109. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini_href_e.c +108 -0
  110. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini_html_e.c +84 -0
  111. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html/html.c +647 -0
  112. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html/html.h +77 -0
  113. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html/html_smartypants.c +389 -0
  114. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html_block_names.txt +25 -0
  115. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/autolink.c +297 -0
  116. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/autolink.h +51 -0
  117. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/buffer.c +225 -0
  118. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/buffer.h +96 -0
  119. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/html_blocks.h +206 -0
  120. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/markdown.c +2726 -0
  121. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/markdown.h +147 -0
  122. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/src_map.c +204 -0
  123. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/src_map.h +58 -0
  124. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/stack.c +81 -0
  125. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/stack.h +29 -0
  126. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/sundown.def +20 -0
  127. data/ext/drafter/ext/snowcrash/ext/markdown-parser/msvc/markdown/markdown.vcproj +188 -0
  128. data/ext/drafter/ext/snowcrash/ext/markdown-parser/msvc/msvc.sln +38 -0
  129. data/ext/drafter/ext/snowcrash/ext/markdown-parser/msvc/sundown/sundown.vcproj +206 -0
  130. data/ext/drafter/ext/snowcrash/ext/markdown-parser/src/ByteBuffer.cc +160 -0
  131. data/ext/drafter/ext/snowcrash/ext/markdown-parser/src/ByteBuffer.h +90 -0
  132. data/ext/drafter/ext/snowcrash/ext/markdown-parser/src/MarkdownNode.cc +152 -0
  133. data/ext/drafter/ext/snowcrash/ext/markdown-parser/src/MarkdownNode.h +103 -0
  134. data/ext/drafter/ext/snowcrash/ext/markdown-parser/src/MarkdownParser.cc +388 -0
  135. data/ext/drafter/ext/snowcrash/ext/markdown-parser/src/MarkdownParser.h +106 -0
  136. data/ext/drafter/ext/snowcrash/snowcrash.gyp +196 -0
  137. data/ext/drafter/ext/snowcrash/src/ActionParser.h +560 -0
  138. data/ext/drafter/ext/snowcrash/src/AssetParser.h +123 -0
  139. data/ext/drafter/ext/snowcrash/src/AttributesParser.h +123 -0
  140. data/ext/drafter/ext/snowcrash/src/Blueprint.cc +90 -0
  141. data/ext/drafter/ext/snowcrash/src/Blueprint.h +489 -0
  142. data/ext/drafter/ext/snowcrash/src/BlueprintParser.h +845 -0
  143. data/ext/drafter/ext/snowcrash/src/BlueprintSourcemap.cc +81 -0
  144. data/ext/drafter/ext/snowcrash/src/BlueprintSourcemap.h +345 -0
  145. data/ext/drafter/ext/snowcrash/src/BlueprintUtility.h +111 -0
  146. data/ext/drafter/ext/snowcrash/src/CodeBlockUtility.h +276 -0
  147. data/ext/drafter/ext/snowcrash/src/DataStructureGroupParser.h +157 -0
  148. data/ext/drafter/ext/snowcrash/src/HTTP.cc +49 -0
  149. data/ext/drafter/ext/snowcrash/src/HTTP.h +108 -0
  150. data/ext/drafter/ext/snowcrash/src/HeadersParser.cc +117 -0
  151. data/ext/drafter/ext/snowcrash/src/HeadersParser.h +377 -0
  152. data/ext/drafter/ext/snowcrash/src/MSON.cc +272 -0
  153. data/ext/drafter/ext/snowcrash/src/MSON.h +405 -0
  154. data/ext/drafter/ext/snowcrash/src/MSONMixinParser.h +103 -0
  155. data/ext/drafter/ext/snowcrash/src/MSONNamedTypeParser.h +135 -0
  156. data/ext/drafter/ext/snowcrash/src/MSONOneOfParser.cc +132 -0
  157. data/ext/drafter/ext/snowcrash/src/MSONOneOfParser.h +80 -0
  158. data/ext/drafter/ext/snowcrash/src/MSONParameterParser.h +166 -0
  159. data/ext/drafter/ext/snowcrash/src/MSONPropertyMemberParser.h +106 -0
  160. data/ext/drafter/ext/snowcrash/src/MSONSourcemap.cc +141 -0
  161. data/ext/drafter/ext/snowcrash/src/MSONSourcemap.h +181 -0
  162. data/ext/drafter/ext/snowcrash/src/MSONTypeSectionParser.cc +209 -0
  163. data/ext/drafter/ext/snowcrash/src/MSONTypeSectionParser.h +213 -0
  164. data/ext/drafter/ext/snowcrash/src/MSONUtility.h +506 -0
  165. data/ext/drafter/ext/snowcrash/src/MSONValueMemberParser.cc +214 -0
  166. data/ext/drafter/ext/snowcrash/src/MSONValueMemberParser.h +390 -0
  167. data/ext/drafter/ext/snowcrash/src/ModelTable.h +87 -0
  168. data/ext/drafter/ext/snowcrash/src/ParameterParser.h +516 -0
  169. data/ext/drafter/ext/snowcrash/src/ParametersParser.h +222 -0
  170. data/ext/drafter/ext/snowcrash/src/PayloadParser.h +733 -0
  171. data/ext/drafter/ext/snowcrash/src/Platform.h +33 -0
  172. data/ext/drafter/ext/snowcrash/src/RegexMatch.h +32 -0
  173. data/ext/drafter/ext/snowcrash/src/RelationParser.h +87 -0
  174. data/ext/drafter/ext/snowcrash/src/ResourceGroupParser.h +297 -0
  175. data/ext/drafter/ext/snowcrash/src/ResourceParser.h +536 -0
  176. data/ext/drafter/ext/snowcrash/src/Section.cc +48 -0
  177. data/ext/drafter/ext/snowcrash/src/Section.h +60 -0
  178. data/ext/drafter/ext/snowcrash/src/SectionParser.h +246 -0
  179. data/ext/drafter/ext/snowcrash/src/SectionParserData.h +109 -0
  180. data/ext/drafter/ext/snowcrash/src/SectionProcessor.h +299 -0
  181. data/ext/drafter/ext/snowcrash/src/Signature.cc +75 -0
  182. data/ext/drafter/ext/snowcrash/src/Signature.h +103 -0
  183. data/ext/drafter/ext/snowcrash/src/SignatureSectionProcessor.h +442 -0
  184. data/ext/drafter/ext/snowcrash/src/SourceAnnotation.h +166 -0
  185. data/ext/drafter/ext/snowcrash/src/StringUtility.h +323 -0
  186. data/ext/drafter/ext/snowcrash/src/UriTemplateParser.cc +195 -0
  187. data/ext/drafter/ext/snowcrash/src/UriTemplateParser.h +240 -0
  188. data/ext/drafter/ext/snowcrash/src/ValuesParser.h +111 -0
  189. data/ext/drafter/ext/snowcrash/src/posix/RegexMatch.cc +99 -0
  190. data/ext/drafter/ext/snowcrash/src/snowcrash.cc +90 -0
  191. data/ext/drafter/ext/snowcrash/src/snowcrash.h +44 -0
  192. data/ext/drafter/ext/snowcrash/src/win/RegexMatch.cc +78 -0
  193. data/ext/drafter/ext/snowcrash/tools/gyp/AUTHORS +12 -0
  194. data/ext/drafter/ext/snowcrash/tools/gyp/DEPS +23 -0
  195. data/ext/drafter/ext/snowcrash/tools/gyp/OWNERS +1 -0
  196. data/ext/drafter/ext/snowcrash/tools/gyp/PRESUBMIT.py +137 -0
  197. data/ext/drafter/ext/snowcrash/tools/gyp/buildbot/buildbot_run.py +136 -0
  198. data/ext/drafter/ext/snowcrash/tools/gyp/buildbot/commit_queue/OWNERS +6 -0
  199. data/ext/drafter/ext/snowcrash/tools/gyp/buildbot/commit_queue/cq_config.json +15 -0
  200. data/ext/drafter/ext/snowcrash/tools/gyp/codereview.settings +10 -0
  201. data/ext/drafter/ext/snowcrash/tools/gyp/data/win/large-pdb-shim.cc +12 -0
  202. data/ext/drafter/ext/snowcrash/tools/gyp/gyp +8 -0
  203. data/ext/drafter/ext/snowcrash/tools/gyp/gyp.bat +5 -0
  204. data/ext/drafter/ext/snowcrash/tools/gyp/gyp_main.py +16 -0
  205. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/MSVSNew.py +340 -0
  206. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/MSVSProject.py +208 -0
  207. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/MSVSSettings.py +1096 -0
  208. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/MSVSToolFile.py +58 -0
  209. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/MSVSUserFile.py +147 -0
  210. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/MSVSUtil.py +270 -0
  211. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/MSVSUtil.pyc +0 -0
  212. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/MSVSVersion.py +445 -0
  213. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/MSVSVersion.pyc +0 -0
  214. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/__init__.py +548 -0
  215. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/__init__.pyc +0 -0
  216. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/common.py +608 -0
  217. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/common.pyc +0 -0
  218. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/easy_xml.py +157 -0
  219. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/flock_tool.py +54 -0
  220. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/__init__.py +0 -0
  221. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/__init__.pyc +0 -0
  222. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/analyzer.py +741 -0
  223. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/android.py +1069 -0
  224. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/cmake.py +1248 -0
  225. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/dump_dependency_json.py +99 -0
  226. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/eclipse.py +425 -0
  227. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/gypd.py +94 -0
  228. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/gypsh.py +56 -0
  229. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/make.py +2218 -0
  230. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/make.pyc +0 -0
  231. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/msvs.py +3467 -0
  232. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/ninja.py +2427 -0
  233. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/ninja.pyc +0 -0
  234. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/xcode.py +1300 -0
  235. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/xcode.pyc +0 -0
  236. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/input.py +2899 -0
  237. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/input.pyc +0 -0
  238. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/mac_tool.py +605 -0
  239. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/msvs_emulation.py +1093 -0
  240. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/msvs_emulation.pyc +0 -0
  241. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/ninja_syntax.py +160 -0
  242. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/ninja_syntax.pyc +0 -0
  243. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/ordered_dict.py +289 -0
  244. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/simple_copy.py +46 -0
  245. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/simple_copy.pyc +0 -0
  246. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/win_tool.py +314 -0
  247. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.py +1664 -0
  248. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyc +0 -0
  249. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/xcode_ninja.py +276 -0
  250. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/xcode_ninja.pyc +0 -0
  251. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/xcodeproj_file.py +2927 -0
  252. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/xcodeproj_file.pyc +0 -0
  253. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/xml_fix.py +69 -0
  254. data/ext/drafter/ext/snowcrash/tools/gyp/pylintrc +307 -0
  255. data/ext/drafter/ext/snowcrash/tools/gyp/samples/samples +81 -0
  256. data/ext/drafter/ext/snowcrash/tools/gyp/samples/samples.bat +5 -0
  257. data/ext/drafter/ext/snowcrash/tools/gyp/setup.py +19 -0
  258. data/ext/drafter/ext/snowcrash/tools/gyp/tools/Xcode/Specifications/gyp.pbfilespec +27 -0
  259. data/ext/drafter/ext/snowcrash/tools/gyp/tools/Xcode/Specifications/gyp.xclangspec +226 -0
  260. data/ext/drafter/ext/snowcrash/tools/gyp/tools/emacs/gyp.el +275 -0
  261. data/ext/drafter/ext/snowcrash/tools/gyp/tools/graphviz.py +100 -0
  262. data/ext/drafter/ext/snowcrash/tools/gyp/tools/pretty_gyp.py +155 -0
  263. data/ext/drafter/ext/snowcrash/tools/gyp/tools/pretty_sln.py +169 -0
  264. data/ext/drafter/ext/snowcrash/tools/gyp/tools/pretty_vcproj.py +329 -0
  265. data/ext/drafter/ext/snowcrash/vcbuild.bat +139 -0
  266. data/ext/drafter/ext/sos/Makefile +62 -0
  267. data/ext/drafter/ext/sos/src/sos.cc +235 -0
  268. data/ext/drafter/ext/sos/src/sos.h +188 -0
  269. data/ext/drafter/ext/sos/src/sosJSON.h +121 -0
  270. data/ext/drafter/ext/sos/src/sosYAML.h +105 -0
  271. data/ext/drafter/src/ConversionContext.cc +39 -0
  272. data/ext/drafter/src/ConversionContext.h +34 -0
  273. data/ext/drafter/src/NamedTypesRegistry.cc +405 -0
  274. data/ext/drafter/src/NamedTypesRegistry.h +28 -0
  275. data/ext/drafter/src/NodeInfo.h +143 -0
  276. data/ext/drafter/src/RefractAPI.cc +579 -0
  277. data/ext/drafter/src/RefractAPI.h +28 -0
  278. data/ext/drafter/src/RefractDataStructure.cc +1199 -0
  279. data/ext/drafter/src/RefractDataStructure.h +26 -0
  280. data/ext/drafter/src/RefractElementFactory.cc +107 -0
  281. data/ext/drafter/src/RefractElementFactory.h +67 -0
  282. data/ext/drafter/src/RefractSourceMap.cc +29 -0
  283. data/ext/drafter/src/RefractSourceMap.h +57 -0
  284. data/ext/drafter/src/Render.cc +157 -0
  285. data/ext/drafter/src/Render.h +40 -0
  286. data/ext/drafter/src/Serialize.cc +160 -0
  287. data/ext/drafter/src/Serialize.h +289 -0
  288. data/ext/drafter/src/SerializeAST.cc +507 -0
  289. data/ext/drafter/src/SerializeAST.h +29 -0
  290. data/ext/drafter/src/SerializeResult.cc +170 -0
  291. data/ext/drafter/src/SerializeResult.h +34 -0
  292. data/ext/drafter/src/SerializeSourcemap.cc +331 -0
  293. data/ext/drafter/src/SerializeSourcemap.h +21 -0
  294. data/ext/drafter/src/Version.h +40 -0
  295. data/ext/drafter/src/config.cc +91 -0
  296. data/ext/drafter/src/config.h +38 -0
  297. data/ext/drafter/src/drafter.cc +137 -0
  298. data/ext/drafter/src/drafter.h +102 -0
  299. data/ext/drafter/src/drafter_private.cc +85 -0
  300. data/ext/drafter/src/drafter_private.h +34 -0
  301. data/ext/drafter/src/main.cc +137 -0
  302. data/ext/drafter/src/refract/AppendDecorator.h +58 -0
  303. data/ext/drafter/src/refract/Build.h +67 -0
  304. data/ext/drafter/src/refract/ComparableVisitor.cc +43 -0
  305. data/ext/drafter/src/refract/ComparableVisitor.h +62 -0
  306. data/ext/drafter/src/refract/Element.cc +409 -0
  307. data/ext/drafter/src/refract/Element.h +656 -0
  308. data/ext/drafter/src/refract/ElementFwd.h +37 -0
  309. data/ext/drafter/src/refract/ElementInserter.h +59 -0
  310. data/ext/drafter/src/refract/Exception.h +31 -0
  311. data/ext/drafter/src/refract/ExpandVisitor.cc +359 -0
  312. data/ext/drafter/src/refract/ExpandVisitor.h +58 -0
  313. data/ext/drafter/src/refract/FilterVisitor.h +52 -0
  314. data/ext/drafter/src/refract/IsExpandableVisitor.cc +140 -0
  315. data/ext/drafter/src/refract/IsExpandableVisitor.h +31 -0
  316. data/ext/drafter/src/refract/Iterate.h +160 -0
  317. data/ext/drafter/src/refract/JSONSchemaVisitor.cc +675 -0
  318. data/ext/drafter/src/refract/JSONSchemaVisitor.h +73 -0
  319. data/ext/drafter/src/refract/PrintVisitor.cc +164 -0
  320. data/ext/drafter/src/refract/PrintVisitor.h +50 -0
  321. data/ext/drafter/src/refract/Query.cc +13 -0
  322. data/ext/drafter/src/refract/Query.h +38 -0
  323. data/ext/drafter/src/refract/Registry.cc +114 -0
  324. data/ext/drafter/src/refract/Registry.h +43 -0
  325. data/ext/drafter/src/refract/RenderJSONVisitor.cc +255 -0
  326. data/ext/drafter/src/refract/RenderJSONVisitor.h +51 -0
  327. data/ext/drafter/src/refract/SerializeCompactVisitor.cc +167 -0
  328. data/ext/drafter/src/refract/SerializeCompactVisitor.h +56 -0
  329. data/ext/drafter/src/refract/SerializeVisitor.cc +214 -0
  330. data/ext/drafter/src/refract/SerializeVisitor.h +55 -0
  331. data/ext/drafter/src/refract/TypeQueryVisitor.cc +46 -0
  332. data/ext/drafter/src/refract/TypeQueryVisitor.h +110 -0
  333. data/ext/drafter/src/refract/Visitor.h +126 -0
  334. data/ext/drafter/src/refract/VisitorUtils.cc +63 -0
  335. data/ext/drafter/src/refract/VisitorUtils.h +231 -0
  336. data/ext/drafter/src/reporting.cc +263 -0
  337. data/ext/drafter/src/reporting.h +39 -0
  338. data/ext/drafter/src/stream.h +148 -0
  339. data/ext/drafter/tools/homebrew/drafter.rb +18 -0
  340. data/ext/drafter/tools/make-tarball.sh +39 -0
  341. data/ext/drafter/tools/refract-filter.py +96 -0
  342. data/ext/drafter/tools/release.sh +17 -0
  343. data/ext/drafter/vcbuild.bat +203 -0
  344. data/lib/lounge_lizard/binding.rb +29 -0
  345. data/lib/lounge_lizard/version.rb +3 -0
  346. data/lib/lounge_lizard.rb +18 -0
  347. data/lounge_lizard.gemspec +37 -0
  348. metadata +547 -0
@@ -0,0 +1,1199 @@
1
+ //
2
+ // RefractDataStructure.cc
3
+ // drafter
4
+ //
5
+ // Created by Jiri Kratochvil on 18/05/15.
6
+ // Copyright (c) 2015 Apiary Inc. All rights reserved.
7
+ //
8
+
9
+ #include "SourceAnnotation.h"
10
+ #include "RefractDataStructure.h"
11
+ #include "refract/AppendDecorator.h"
12
+
13
+ #include "RefractSourceMap.h"
14
+ #include "refract/VisitorUtils.h"
15
+ #include "refract/ExpandVisitor.h"
16
+ #include "refract/SerializeVisitor.h"
17
+
18
+ #include "NamedTypesRegistry.h"
19
+ #include "RefractElementFactory.h"
20
+ #include "ConversionContext.h"
21
+
22
+ namespace drafter {
23
+
24
+ template <typename T>
25
+ struct ElementData {
26
+ typedef T ElementType;
27
+
28
+ typedef typename T::ValueType ValueType;
29
+ typedef snowcrash::SourceMap<ValueType> ValueSourceMapType;
30
+
31
+ typedef std::tuple<ValueType, ValueSourceMapType, bool> ValueInfo; // [value, sourceMap, validity(by LiteralTo<>)]
32
+
33
+ std::vector<ValueInfo> values;
34
+ std::vector<ValueInfo> defaults;
35
+ std::vector<ValueInfo> samples;
36
+
37
+ std::vector<std::string> descriptions;
38
+ std::vector<snowcrash::SourceMap<std::string> > descriptionsSourceMap;
39
+ };
40
+
41
+ template <typename U>
42
+ struct FetchSourceMap {
43
+
44
+ snowcrash::SourceMap<U> operator()(const NodeInfo<mson::ValueMember>& valueMember) {
45
+ snowcrash::SourceMap<U> sourceMap = *NodeInfo<U>::NullSourceMap();
46
+ sourceMap.sourceMap = valueMember.sourceMap->valueDefinition.sourceMap;
47
+ return sourceMap;
48
+ }
49
+
50
+ snowcrash::SourceMap<U> operator()(const NodeInfo<mson::TypeSection>& typeSection) {
51
+ snowcrash::SourceMap<U> sourceMap = *NodeInfo<U>::NullSourceMap();
52
+ sourceMap.sourceMap = typeSection.sourceMap->value.sourceMap;
53
+ return sourceMap;
54
+ }
55
+ };
56
+
57
+
58
+ template <typename T, typename V = typename T::ValueType>
59
+ struct Append {
60
+ typedef T ElementType;
61
+ typedef V ValueType;
62
+ ElementType*& element;
63
+ typedef typename ElementData<T>::ValueInfo ValueInfo;
64
+
65
+ Append(ElementType*& e) : element(e)
66
+ {
67
+ }
68
+
69
+ void operator()(const NodeInfo<ValueType>& value)
70
+ {
71
+ // FIXME: snowcrash warn about "Primitive type can not have member"
72
+ // but in real it create "empty" member
73
+ //
74
+ // solution for now: set if element has no already value, otherwise silently ignore
75
+ //
76
+ //throw snowcrash::Error("can not append to primitive type", snowcrash::MSONError);
77
+
78
+ if (element->empty()) {
79
+ element->set(*value.node);
80
+ AttachSourceMap(element, value);
81
+ }
82
+ }
83
+
84
+ void operator()(const ValueInfo& value)
85
+ {
86
+ const NodeInfo<ValueType> nodeInfo = MakeNodeInfo(std::get<0>(value), std::get<1>(value));
87
+ (*this)(nodeInfo);
88
+ }
89
+ };
90
+
91
+ template <typename T>
92
+ struct Append<T, std::vector<refract::IElement*> > {
93
+ typedef T ElementType;
94
+ typedef typename T::ValueType ValueType;
95
+ ElementType*& element;
96
+ typedef typename ElementData<T>::ValueInfo ValueInfo;
97
+
98
+ Append(ElementType*& e) : element(e)
99
+ {
100
+ }
101
+
102
+ void operator()(const NodeInfo<ValueType>& value)
103
+ {
104
+ std::for_each(value.node->begin(), value.node->end(), std::bind(&ElementType::push_back, element, std::placeholders::_1));
105
+ }
106
+
107
+ void operator()(const ValueInfo& value)
108
+ {
109
+ const NodeInfo<ValueType> nodeInfo = MakeNodeInfo(std::get<0>(value), std::get<1>(value));
110
+ (*this)(nodeInfo);
111
+ }
112
+ };
113
+
114
+ template <typename V, bool dummy = true>
115
+ struct CheckValueValidity {
116
+
117
+ typedef typename ElementData<V>::ValueInfo ValueInfo;
118
+
119
+ void operator()(const ValueInfo&, ConversionContext&) {
120
+ // do nothing
121
+ }
122
+ };
123
+
124
+ template <bool dummy>
125
+ struct CheckValueValidity<refract::NumberElement, dummy> {
126
+
127
+ typedef typename ElementData<refract::NumberElement>::ValueInfo ValueInfo;
128
+
129
+ void operator()(const ValueInfo& value, ConversionContext& context) {
130
+
131
+ if (!std::get<2>(value)) {
132
+ context.warn(snowcrash::Warning("invalid value format for 'number' type. please check mson specification for valid format", snowcrash::MSONError, std::get<1>(value).sourceMap));
133
+ }
134
+ }
135
+ };
136
+
137
+ template <bool dummy>
138
+ struct CheckValueValidity<refract::BooleanElement, dummy> {
139
+
140
+ typedef typename ElementData<refract::BooleanElement>::ValueInfo ValueInfo;
141
+
142
+ void operator()(const ValueInfo& value, ConversionContext& context) {
143
+ if (!std::get<2>(value)) {
144
+ context.warn(snowcrash::Warning("invalid value for 'boolean' type. allowed values are 'true' or 'false'", snowcrash::MSONError, std::get<1>(value).sourceMap));
145
+ }
146
+ }
147
+ };
148
+
149
+ using refract::RefractElements;
150
+
151
+ static void SetElementType(refract::IElement* element, const mson::TypeDefinition& td)
152
+ {
153
+ if (!td.typeSpecification.name.symbol.literal.empty()) {
154
+ element->element(td.typeSpecification.name.symbol.literal);
155
+ }
156
+ }
157
+
158
+ static mson::BaseTypeName NamedTypeFromElement(const refract::IElement* element) {
159
+ refract::TypeQueryVisitor type;
160
+ refract::Visit(type, *element);
161
+
162
+ switch (type.get()) {
163
+ case refract::TypeQueryVisitor::Boolean:
164
+ return mson::BooleanTypeName;
165
+
166
+ case refract::TypeQueryVisitor::Number:
167
+ return mson::NumberTypeName;
168
+
169
+ case refract::TypeQueryVisitor::String:
170
+ return mson::StringTypeName;
171
+
172
+ case refract::TypeQueryVisitor::Array:
173
+ return mson::ArrayTypeName;
174
+
175
+ case refract::TypeQueryVisitor::Enum:
176
+ return mson::EnumTypeName;
177
+
178
+ case refract::TypeQueryVisitor::Object:
179
+ return mson::ObjectTypeName;
180
+
181
+ default:
182
+ return mson::UndefinedTypeName;
183
+ }
184
+
185
+ return mson::UndefinedTypeName;
186
+ }
187
+
188
+ template<typename T>
189
+ static mson::BaseTypeName GetType(const T& type, ConversionContext& context) {
190
+ mson::BaseTypeName nameType = type.typeDefinition.typeSpecification.name.base;
191
+ const std::string& parent = type.typeDefinition.typeSpecification.name.symbol.literal;
192
+
193
+ if (nameType == mson::UndefinedTypeName && !parent.empty()) {
194
+ refract::IElement* base = FindRootAncestor(parent, context.GetNamedTypesRegistry());
195
+ if (base) {
196
+ nameType = NamedTypeFromElement(base);
197
+ }
198
+ }
199
+
200
+ return nameType;
201
+ }
202
+
203
+ static refract::ArrayElement* MsonTypeAttributesToRefract(const mson::TypeAttributes& ta)
204
+ {
205
+ if (ta == 0) {
206
+ return NULL;
207
+ }
208
+
209
+ refract::ArrayElement* attr = new refract::ArrayElement;
210
+
211
+ if (ta & mson::RequiredTypeAttribute) {
212
+ attr->push_back(refract::IElement::Create(SerializeKey::Required));
213
+ }
214
+ if (ta & mson::OptionalTypeAttribute) {
215
+ attr->push_back(refract::IElement::Create(SerializeKey::Optional));
216
+ }
217
+ if (ta & mson::FixedTypeAttribute) {
218
+ attr->push_back(refract::IElement::Create(SerializeKey::Fixed));
219
+ }
220
+ if (ta & mson::FixedTypeTypeAttribute) {
221
+ attr->push_back(refract::IElement::Create(SerializeKey::FixedType));
222
+ }
223
+ if (ta & mson::NullableTypeAttribute) {
224
+ attr->push_back(refract::IElement::Create(SerializeKey::Nullable));
225
+ }
226
+
227
+ if (attr->value.empty()) {
228
+ delete attr;
229
+ attr = NULL;
230
+ }
231
+
232
+ return attr;
233
+ }
234
+
235
+ static refract::IElement* MsonElementToRefract(const NodeInfo<mson::Element>& mse, ConversionContext& context, mson::BaseTypeName defaultNestedType = mson::StringTypeName);
236
+
237
+ RefractElements MsonElementsToRefract(const NodeInfo<mson::Elements>& elements, ConversionContext& context, mson::BaseTypeName defaultNestedType = mson::StringTypeName)
238
+ {
239
+ RefractElements result;
240
+ NodeInfoCollection<mson::Elements> elementsNodeInfo(elements);
241
+
242
+ std::transform(elementsNodeInfo.begin(), elementsNodeInfo.end(),
243
+ std::back_inserter(result),
244
+ std::bind(MsonElementToRefract, std::placeholders::_1, std::ref(context), defaultNestedType));
245
+
246
+ return result;
247
+ }
248
+
249
+ static mson::BaseTypeName SelectNestedTypeSpecification(const mson::TypeNames& nestedTypes, const mson::BaseTypeName defaultNestedType = mson::StringTypeName) {
250
+ mson::BaseTypeName type = defaultNestedType;
251
+ // Found if type of element is specified.
252
+ // if more types is used - fallback to "StringType"
253
+ if (nestedTypes.size() == 1) {
254
+ type = nestedTypes.begin()->base;
255
+ }
256
+ return type;
257
+ }
258
+
259
+
260
+ template <typename T>
261
+ class ExtractTypeSection
262
+ {
263
+ typedef typename T::ValueType ValueType;
264
+ typedef typename ElementData<T>::ValueInfo ValueInfo;
265
+
266
+ ElementData<T>& data;
267
+ ConversionContext& context;
268
+
269
+ mson::BaseTypeName elementTypeName;
270
+ mson::BaseTypeName defaultNestedType;
271
+
272
+ /**
273
+ * Fetch<> is intended to extract value from TypeSection.
274
+ * Generalized type is for primitive types
275
+ * Specialized is for (Array|Object)Element because of underlying type.
276
+ * `dummy` param is used because of specialization inside another struct
277
+ */
278
+ template <typename U, bool dummy = true>
279
+ struct Fetch {
280
+ ValueInfo operator()(const NodeInfo<mson::TypeSection>& typeSection, ConversionContext& context, const mson::BaseTypeName& defaultNestedType) {
281
+
282
+ std::pair<bool, U> val = LiteralTo<U>(typeSection.node->content.value);
283
+ snowcrash::SourceMap<U> sourceMap = FetchSourceMap<U>()(typeSection);
284
+
285
+ ValueInfo result = std::make_tuple(val.second, sourceMap, val.first);
286
+
287
+ CheckValueValidity<T>()(result, context);
288
+
289
+ return result;
290
+ }
291
+ };
292
+
293
+ template<bool dummy>
294
+ struct Fetch<RefractElements, dummy> {
295
+ ValueInfo operator()(const NodeInfo<mson::TypeSection>& typeSection, ConversionContext& context, const mson::BaseTypeName& defaultNestedType) {
296
+ return std::make_tuple(MsonElementsToRefract(MakeNodeInfo(typeSection.node->content.elements(),
297
+ typeSection.sourceMap->elements()),
298
+ context,
299
+ defaultNestedType),
300
+ FetchSourceMap<RefractElements>()(typeSection),
301
+ true
302
+ );
303
+ }
304
+ };
305
+
306
+ template <typename U, bool dummy = true>
307
+ struct TypeDefinition;
308
+
309
+ template<bool dummy>
310
+ struct TypeDefinition<snowcrash::DataStructure, dummy> {
311
+ const mson::TypeDefinition& operator()(const snowcrash::DataStructure& dataStructure) {
312
+ return dataStructure.typeDefinition;
313
+ }
314
+ };
315
+
316
+ template<bool dummy>
317
+ struct TypeDefinition<mson::ValueMember, dummy> {
318
+ const mson::TypeDefinition& operator()(const mson::ValueMember& valueMember) {
319
+ return valueMember.valueDefinition.typeDefinition;
320
+ }
321
+ };
322
+
323
+ public:
324
+
325
+ template<typename U>
326
+ ExtractTypeSection(ElementData<T>& data, ConversionContext& context, const NodeInfo<U>& sectionHolder)
327
+ : data(data),
328
+ context(context),
329
+ elementTypeName(TypeDefinition<U>()(*sectionHolder.node).typeSpecification.name.base),
330
+ defaultNestedType(SelectNestedTypeSpecification(TypeDefinition<U>()(*sectionHolder.node).typeSpecification.nestedTypes))
331
+ {}
332
+
333
+ void operator()(const NodeInfo<mson::TypeSection>& typeSection) {
334
+ Fetch<ValueType> fetch;
335
+
336
+ switch (typeSection.node->klass) {
337
+
338
+ case mson::TypeSection::MemberTypeClass:
339
+ // Primitives should not contain members
340
+ // this is to avoid push "empty" elements to primitives
341
+ // it is related to test/fixtures/mson/primitive-with-members.apib
342
+
343
+ if (!typeSection.node->content.elements().empty()) {
344
+ data.values.push_back(fetch(typeSection, context, defaultNestedType));
345
+ }
346
+ break;
347
+
348
+ case mson::TypeSection::SampleClass:
349
+ data.samples.push_back(fetch(typeSection, context, defaultNestedType));
350
+ break;
351
+
352
+ case mson::TypeSection::DefaultClass:
353
+ data.defaults.push_back(fetch(typeSection, context, defaultNestedType));
354
+ break;
355
+
356
+ case mson::TypeSection::BlockDescriptionClass:
357
+ data.descriptions.push_back(typeSection.node->content.description);
358
+ data.descriptionsSourceMap.push_back(typeSection.sourceMap->description);
359
+ break;
360
+
361
+ default:
362
+ // we are not able to get sourcemap info there
363
+ // It is strongly dependent on type of section.
364
+ // For unknown type of Element we are not able to locate SourceMap
365
+ // with adequate effort we do not provide it to upper level
366
+ throw snowcrash::Error("unknown section type", snowcrash::ApplicationError);
367
+ }
368
+ }
369
+ };
370
+
371
+ static mson::BaseTypeName RefractElementTypeToMsonType(refract::TypeQueryVisitor::ElementType type) {
372
+ switch (type) {
373
+ case refract::TypeQueryVisitor::String:
374
+ return mson::StringTypeName;
375
+
376
+ case refract::TypeQueryVisitor::Number:
377
+ return mson::NumberTypeName;
378
+
379
+ case refract::TypeQueryVisitor::Boolean:
380
+ return mson::BooleanTypeName;
381
+
382
+ case refract::TypeQueryVisitor::Array:
383
+ return mson::ArrayTypeName;
384
+
385
+ case refract::TypeQueryVisitor::Object:
386
+ return mson::ObjectTypeName;
387
+
388
+ case refract::TypeQueryVisitor::Enum:
389
+ return mson::EnumTypeName;
390
+
391
+ case refract::TypeQueryVisitor::Null:
392
+ case refract::TypeQueryVisitor::Member:
393
+ case refract::TypeQueryVisitor::Extend:
394
+ case refract::TypeQueryVisitor::Option:
395
+ case refract::TypeQueryVisitor::Select:
396
+ ;
397
+ };
398
+ return mson::UndefinedTypeName;
399
+ }
400
+
401
+ static mson::BaseTypeName GetMsonTypeFromName(const std::string& name, ConversionContext& context) {
402
+ refract::IElement* e = FindRootAncestor(name, context.GetNamedTypesRegistry());
403
+ if (!e) {
404
+ return mson::UndefinedTypeName;
405
+ }
406
+
407
+ refract::TypeQueryVisitor query;
408
+ refract::VisitBy(*e, query);
409
+ return RefractElementTypeToMsonType(query.get());
410
+ }
411
+
412
+ template <typename T>
413
+ struct ExtractTypeDefinition {
414
+
415
+ typedef T ElementType;
416
+ typedef typename ElementData<T>::ValueInfo ValueInfo;
417
+
418
+ ElementData<ElementType>& data;
419
+ ConversionContext& context;
420
+
421
+ template<typename X, bool dummy = true>
422
+ struct Fetch {
423
+ ValueInfo operator()(const mson::TypeNames&, ConversionContext&) {
424
+ typename T::ValueType val;
425
+ return std::make_tuple(val, *NodeInfo<typename T::ValueType>::NullSourceMap(), false);
426
+ }
427
+ };
428
+
429
+ template<bool dummy>
430
+ struct Fetch<RefractElements, dummy> {
431
+ ValueInfo operator()(const mson::TypeNames& typeNames, ConversionContext& context) {
432
+ RefractElements types;
433
+
434
+ for (mson::TypeNames::const_iterator it = typeNames.begin(); it != typeNames.end(); ++it) {
435
+ mson::BaseTypeName typeName = it->base;
436
+ FactoryCreateMethod method = eValue;
437
+
438
+ if (typeName == mson::UndefinedTypeName && !it->symbol.literal.empty()) {
439
+ typeName = GetMsonTypeFromName(it->symbol.literal, context);
440
+ method = it->symbol.variable ? eSample : eElement;
441
+ }
442
+
443
+ const RefractElementFactory& f = FactoryFromType(typeName);
444
+ types.push_back(f.Create(it->symbol.literal, method));
445
+ }
446
+
447
+ return std::make_tuple(types, *NodeInfo<typename T::ValueType>::NullSourceMap(), true);
448
+ }
449
+ };
450
+
451
+ ExtractTypeDefinition(ElementData<ElementType>& data, ConversionContext& context) : data(data), context(context) {}
452
+
453
+ void operator()(const NodeInfo<mson::TypeDefinition>& typeDefinition) {
454
+ ValueInfo value = Fetch<typename T::ValueType>()(typeDefinition.node->typeSpecification.nestedTypes, context);
455
+
456
+ if (std::get<2>(value)) {
457
+ data.values.push_back(value);
458
+ }
459
+ }
460
+ };
461
+
462
+ template <typename T, typename V = typename T::ValueType>
463
+ struct ExtractValueMember
464
+ {
465
+ typedef T ElementType;
466
+ typedef typename ElementData<T>::ValueInfo ValueInfo;
467
+
468
+ ElementData<T>& data;
469
+ ConversionContext& context;
470
+
471
+ template <typename U, bool dummy = true>
472
+ struct Fetch { // primitive values
473
+
474
+ ValueInfo operator()(const NodeInfo<mson::ValueMember>& valueMember, ConversionContext& context) {
475
+ if (valueMember.node->valueDefinition.values.size() > 1) {
476
+ throw snowcrash::Error("only one value is supported for primitive types", snowcrash::MSONError, valueMember.sourceMap->sourceMap);
477
+ }
478
+
479
+ const mson::Value& value = *valueMember.node->valueDefinition.values.begin();
480
+
481
+ std::pair<bool, U> val = LiteralTo<U>(value.literal);
482
+ snowcrash::SourceMap<U> sourceMap = FetchSourceMap<U>()(valueMember);
483
+
484
+ ValueInfo result = std::make_tuple(val.second, sourceMap, val.first);
485
+
486
+ CheckValueValidity<T>()(result, context);
487
+
488
+ return result;
489
+ }
490
+ };
491
+
492
+ template<bool dummy>
493
+ struct Fetch<RefractElements, dummy> { // Array|Object
494
+
495
+ ValueInfo operator()(const NodeInfo<mson::ValueMember>& valueMember, ConversionContext& context) {
496
+
497
+ const mson::BaseTypeName type = SelectNestedTypeSpecification(valueMember.node->valueDefinition.typeDefinition.typeSpecification.nestedTypes);
498
+
499
+ const RefractElementFactory& f = FactoryFromType(type);
500
+ const mson::Values& values = valueMember.node->valueDefinition.values;
501
+
502
+ RefractElements elements;
503
+
504
+ for (mson::Values::const_iterator it = values.begin(); it != values.end(); ++it) {
505
+ elements.push_back(f.Create(it->literal, it->variable ? eSample : eValue));
506
+ }
507
+
508
+ return std::make_tuple(elements, FetchSourceMap<RefractElements>()(valueMember), true);
509
+ }
510
+ };
511
+
512
+ template<typename Y, bool dummy = true>
513
+ struct IsValueVariable {
514
+
515
+ bool operator()(const mson::Value& value) {
516
+ return value.variable;
517
+ }
518
+ };
519
+
520
+ template<bool dummy>
521
+ struct IsValueVariable<RefractElements, dummy>{
522
+
523
+ bool operator()(const mson::Value&) {
524
+ return false;
525
+ }
526
+ };
527
+
528
+ ExtractValueMember(ElementData<T>& data, ConversionContext& context, const mson::BaseTypeName) : data(data), context(context) {}
529
+
530
+ void operator ()(const NodeInfo<mson::ValueMember>& valueMember)
531
+ {
532
+ // silently ignore "value" for ObjectElement e.g.
533
+ // # A (array)
534
+ // - key (object)
535
+ // warning is attached while creating ValueMember in snowcrash
536
+ if (valueMember.node->valueDefinition.typeDefinition.baseType == mson::ImplicitObjectBaseType ||
537
+ valueMember.node->valueDefinition.typeDefinition.baseType == mson::ObjectBaseType) {
538
+ return;
539
+ }
540
+
541
+ Fetch<typename T::ValueType> fetch;
542
+ mson::TypeAttributes attrs = valueMember.node->valueDefinition.typeDefinition.attributes;
543
+
544
+ if (!valueMember.node->valueDefinition.values.empty()) {
545
+ const mson::Value& value = *valueMember.node->valueDefinition.values.begin();
546
+
547
+ ValueInfo parsed = fetch(valueMember, context);
548
+
549
+ if (attrs & mson::DefaultTypeAttribute) {
550
+ data.defaults.push_back(parsed);
551
+ }
552
+ else if ((attrs & mson::SampleTypeAttribute) || IsValueVariable<typename T::ValueType>()(value)) {
553
+ data.samples.push_back(parsed);
554
+ }
555
+ else {
556
+ data.values.push_back(parsed);
557
+ }
558
+ }
559
+ else {
560
+ if (attrs & mson::DefaultTypeAttribute) {
561
+ context.warn(snowcrash::Warning("no value present when 'default' is specified"));
562
+ }
563
+
564
+ if (attrs & mson::SampleTypeAttribute) {
565
+ context.warn(snowcrash::Warning("no value present when 'sample' is specified"));
566
+ }
567
+ }
568
+
569
+ if (!valueMember.node->description.empty()) {
570
+ data.descriptions.push_back(valueMember.node->description);
571
+ data.descriptionsSourceMap.push_back(valueMember.sourceMap->description);
572
+ }
573
+
574
+ if ((valueMember.node->valueDefinition.values.empty() ||
575
+ (valueMember.node->valueDefinition.typeDefinition.typeSpecification.nestedTypes.size() > 1)) &&
576
+ (GetType(valueMember.node->valueDefinition, context) != mson::EnumTypeName)) {
577
+
578
+ ExtractTypeDefinition<T> extd(data, context);
579
+ extd(MakeNodeInfoWithoutSourceMap(valueMember.node->valueDefinition.typeDefinition));
580
+ }
581
+ }
582
+ };
583
+
584
+ namespace
585
+ {
586
+ template<typename T> void Deleter(T* ptr) { delete ptr; }
587
+
588
+ struct Join {
589
+ std::string& base;
590
+ Join(std::string& str) : base(str)
591
+ {
592
+ }
593
+
594
+ void operator()(const std::string& append, const std::string separator = "\n")
595
+ {
596
+ if (append.empty()) {
597
+ return;
598
+ }
599
+
600
+ if (!base.empty()) {
601
+ base.append(separator);
602
+ }
603
+
604
+ base.append(append);
605
+ }
606
+ };
607
+
608
+ refract::IElement* SetSerializeFlag(refract::IElement* element) {
609
+ refract::TypeQueryVisitor query;
610
+ refract::VisitBy(*element, query);
611
+
612
+ RefractElements* children = NULL;
613
+
614
+ if (query.get() == refract::TypeQueryVisitor::Array) {
615
+ children = &static_cast<refract::ArrayElement*>(element)->value;
616
+ }
617
+ else if (query.get() == refract::TypeQueryVisitor::Enum) {
618
+ children = &static_cast<refract::EnumElement*>(element)->value;
619
+
620
+ }
621
+ else if (query.get() == refract::TypeQueryVisitor::Object) {
622
+ children = &static_cast<refract::ObjectElement*>(element)->value;
623
+
624
+ }
625
+
626
+ if (children) {
627
+ refract::SetRenderFlag(*children, refract::IElement::rFull);
628
+ }
629
+
630
+ return element;
631
+ }
632
+
633
+ template <typename T>
634
+ struct SaveSamples {
635
+
636
+ template <typename U>
637
+ void operator()(const U& samples, refract::IElement* element) {
638
+ if (samples.empty()) {
639
+ return;
640
+ }
641
+
642
+ refract::ArrayElement* a = new refract::ArrayElement;
643
+
644
+ for (auto sample : samples) {
645
+ T* sampleElement = new T;
646
+ sampleElement->set(std::get<0>(sample));
647
+ SetSerializeFlag(sampleElement);
648
+ a->push_back(sampleElement);
649
+ }
650
+
651
+ element->attributes[SerializeKey::Samples] = a;
652
+ }
653
+
654
+ };
655
+
656
+ template <typename T>
657
+ struct SaveDefault {
658
+
659
+ template <typename U>
660
+ void operator()(const U& defaults, refract::IElement* element) {
661
+ if (defaults.empty()) {
662
+ return;
663
+ }
664
+
665
+ T* defaultElement = new T;
666
+ defaultElement->set(std::get<0>(*defaults.rbegin()));
667
+ SetSerializeFlag(defaultElement);
668
+ element->attributes[SerializeKey::Default] = defaultElement;
669
+ }
670
+
671
+ };
672
+
673
+
674
+ template <typename T>
675
+ struct MakeNodeInfoFunctor {
676
+ NodeInfo<T> operator()(std::pair<bool, const T&> v, const snowcrash::SourceMap<T>& sm) {
677
+ return MakeNodeInfo<T>(v.second, sm);
678
+ }
679
+ };
680
+
681
+ template<typename T>
682
+ void TransformElementData(T* element, ElementData<T>& data) {
683
+ std::for_each(data.values.begin(), data.values.end(), Append<T>(element));
684
+ SaveSamples<T>()(data.samples, element);
685
+ SaveDefault<T>()(data.defaults, element);
686
+ }
687
+ }
688
+
689
+ template<typename T>
690
+ refract::IElement* DescriptionToRefract(const ElementData<T>& data)
691
+ {
692
+ if (data.descriptions.empty()) {
693
+ return NULL;
694
+ }
695
+
696
+ std::string description;
697
+ Join join(description);
698
+
699
+ for_each(data.descriptions.begin(), data.descriptions.end(), join);
700
+
701
+ snowcrash::SourceMap<std::string> sourceMap;
702
+ typedef typename std::vector<snowcrash::SourceMap<std::string> >::const_iterator Iterator;
703
+
704
+ for (Iterator it = data.descriptionsSourceMap.begin(); it != data.descriptionsSourceMap.end(); ++it) {
705
+ sourceMap.sourceMap.append(it->sourceMap);
706
+ }
707
+
708
+ return PrimitiveToRefract(NodeInfo<std::string>(&description, &sourceMap));
709
+ }
710
+
711
+ template <typename T>
712
+ struct MoveFirstValueToSample {
713
+ void operator() (const NodeInfo<mson::ValueMember>& value, ElementData<T>& data)
714
+ {
715
+ }
716
+ };
717
+
718
+ template <>
719
+ struct MoveFirstValueToSample<refract::EnumElement> {
720
+ typedef refract::EnumElement T;
721
+ void operator()(const NodeInfo<mson::ValueMember>& value, ElementData<T>& data) {
722
+ if (value.node->valueDefinition.values.empty() || data.values.empty()) {
723
+ return;
724
+ }
725
+
726
+ data.samples.insert(data.samples.begin(), data.values.front());
727
+ data.values.erase(data.values.begin());
728
+ }
729
+ };
730
+
731
+ template <typename T>
732
+ refract::IElement* RefractElementFromValue(const NodeInfo<mson::ValueMember>& value, ConversionContext& context, const mson::BaseTypeName defaultNestedType, bool generateAttributes = true)
733
+ {
734
+ using namespace refract;
735
+ typedef T ElementType;
736
+
737
+ ElementData<ElementType> data;
738
+ ElementType* element = new ElementType;
739
+
740
+ if (generateAttributes) {
741
+ mson::TypeAttributes attrs = value.node->valueDefinition.typeDefinition.attributes;
742
+
743
+ // there is no source map for attributes
744
+ if (refract::IElement* attributes = MsonTypeAttributesToRefract(attrs)) {
745
+ element->attributes[SerializeKey::TypeAttributes] = attributes;
746
+ }
747
+ }
748
+
749
+ ExtractValueMember<ElementType>(data, context, defaultNestedType)(value);
750
+
751
+ size_t valuesCount = data.values.size();
752
+
753
+ if (!data.descriptions.empty()) {
754
+ element->meta[SerializeKey::Description] = DescriptionToRefract(data);
755
+ }
756
+
757
+ SetElementType(element, value.node->valueDefinition.typeDefinition);
758
+ AttachSourceMap(element, MakeNodeInfo(value.node, value.sourceMap));
759
+
760
+ NodeInfoCollection<mson::TypeSections> typeSections(MAKE_NODE_INFO(value, sections));
761
+
762
+ std::for_each(typeSections.begin(), typeSections.end(), ExtractTypeSection<T>(data, context, value));
763
+
764
+ if (valuesCount != data.values.size()) {
765
+ // there are some values coming from TypeSections -> move first value into examples
766
+ MoveFirstValueToSample<T>()(value, data);
767
+ }
768
+
769
+ TransformElementData(element, data);
770
+
771
+ return element;
772
+ }
773
+
774
+ static bool VariablePropertyIsString(const mson::ValueDefinition& variable, ConversionContext& context)
775
+ {
776
+ if (variable.typeDefinition.typeSpecification.name.base == mson::StringTypeName) {
777
+ return true;
778
+ }
779
+
780
+ if (refract::TypeQueryVisitor::as<refract::StringElement>(FindRootAncestor(variable.typeDefinition.typeSpecification.name.symbol.literal, context.GetNamedTypesRegistry()))) {
781
+ return true;
782
+ }
783
+
784
+ return false;
785
+ }
786
+
787
+ refract::IElement* GetPropertyKey(const NodeInfo<mson::PropertyMember>& property, ConversionContext& context)
788
+ {
789
+
790
+ refract::StringElement* key = new refract::StringElement;
791
+ snowcrash::SourceMap<mson::Literal> sourceMap;
792
+ sourceMap.sourceMap.append(property.sourceMap->name.sourceMap);
793
+
794
+ if (!property.node->name.variable.empty()) {
795
+
796
+ if (property.node->name.variable.values.size() > 1) {
797
+ // FIXME: is there example for multiple variables?
798
+ context.warn(
799
+ snowcrash::Warning(
800
+ "multiple variables in property definition is not implemented",
801
+ snowcrash::MSONError,
802
+ sourceMap.sourceMap));
803
+ }
804
+
805
+ // variable containt type definition
806
+ if (!property.node->name.variable.typeDefinition.empty()) {
807
+ if (!VariablePropertyIsString(property.node->name.variable, context)) {
808
+ delete key;
809
+ throw snowcrash::Error("'variable named property' must be string or its sub-type", snowcrash::MSONError, sourceMap.sourceMap);
810
+ }
811
+
812
+ SetElementType(key, property.node->name.variable.typeDefinition);
813
+
814
+ }
815
+
816
+ key->attributes[SerializeKey::Variable] = refract::IElement::Create(true);
817
+
818
+ if (!property.node->name.variable.values.empty()) {
819
+ key->set(property.node->name.variable.values.begin()->literal);
820
+ }
821
+ }
822
+
823
+ if (!property.node->name.literal.empty()) {
824
+ key->set(property.node->name.literal);
825
+ }
826
+
827
+ AttachSourceMap(key, MakeNodeInfo(property.node->name.literal, sourceMap));
828
+
829
+ return key;
830
+ }
831
+
832
+ template <typename T>
833
+ refract::MemberElement* RefractElementFromProperty(const NodeInfo<mson::PropertyMember>& property, ConversionContext& context, const mson::BaseTypeName defaultNestedType)
834
+ {
835
+ refract::IElement* key = GetPropertyKey(property, context);
836
+ refract::IElement* value = RefractElementFromValue<T>(NodeInfo<mson::ValueMember>(property.node, property.sourceMap), context, defaultNestedType, false);
837
+ refract::MemberElement* element = new refract::MemberElement(key, value);
838
+
839
+ mson::TypeAttributes attrs = property.node->valueDefinition.typeDefinition.attributes;
840
+
841
+ // there is no source map for attributes
842
+ if (refract::IElement* attributes = MsonTypeAttributesToRefract(attrs)) {
843
+ element->attributes[SerializeKey::TypeAttributes] = attributes;
844
+ }
845
+
846
+ std::string description;
847
+ std::string& descriptionRef = description;
848
+ Join join(descriptionRef);
849
+ snowcrash::SourceMap<std::string> sourceMap;
850
+
851
+ refract::IElement::MemberElementCollection::iterator iterator = value->meta.find(SerializeKey::Description);
852
+ if (iterator != value->meta.end()) {
853
+ // There is already setted description to "value" as result of `RefractElementFromValue()`
854
+ // so we need to move this atribute from "value" up to MemberElement
855
+ //
856
+ // NOTE: potentionaly unsafe, but we set it already to StringElement
857
+ // most safe is check it via refract::TypeQueryVisitor
858
+ descriptionRef = (static_cast<refract::StringElement*>((*iterator)->value.second)->value);
859
+ element->meta.push_back(*iterator);
860
+ value->meta.std::vector<refract::MemberElement*>::erase(iterator);
861
+ // FIXME: extract source map
862
+ }
863
+ else {
864
+ join(property.node->description);
865
+ sourceMap.sourceMap.append(property.sourceMap->description.sourceMap);
866
+ }
867
+
868
+ bool addNewLine = false;
869
+ if (!descriptionRef.empty()) {
870
+ addNewLine = true;
871
+ }
872
+
873
+ NodeInfoCollection<mson::TypeSections> typeSections(MAKE_NODE_INFO(property, sections));
874
+
875
+ for (NodeInfoCollection<mson::TypeSections>::const_iterator it = typeSections.begin(); it != typeSections.end(); ++it) {
876
+ if (it->node->klass == mson::TypeSection::BlockDescriptionClass) {
877
+ if (addNewLine) {
878
+ descriptionRef.append("\n");
879
+ addNewLine = false;
880
+ }
881
+
882
+ join(it->node->content.description);
883
+ sourceMap.sourceMap.append(it->sourceMap->description.sourceMap);
884
+ }
885
+ }
886
+
887
+ if (!description.empty()) {
888
+ element->meta[SerializeKey::Description] = PrimitiveToRefract(MakeNodeInfo(description, sourceMap));
889
+ }
890
+
891
+ return element;
892
+ }
893
+
894
+ static bool ValueHasMembers(const mson::ValueMember* value)
895
+ {
896
+ for (mson::TypeSections::const_iterator it = value->sections.begin(); it != value->sections.end(); ++it) {
897
+ if (it->klass == mson::TypeSection::MemberTypeClass) {
898
+ return true;
899
+ }
900
+ }
901
+ return false;
902
+ }
903
+
904
+ static bool ValueHasChildren(const mson::ValueMember* value)
905
+ {
906
+ return value->valueDefinition.values.size() > 1;
907
+ }
908
+
909
+ static bool ValueHasName(const mson::ValueMember* value)
910
+ {
911
+ return !value->valueDefinition.typeDefinition.typeSpecification.name.symbol.literal.empty();
912
+ }
913
+
914
+ struct PropertyTrait {
915
+ typedef refract::MemberElement ElementType;
916
+ typedef NodeInfo<mson::PropertyMember> InputType;
917
+
918
+ template<typename T> static ElementType* Invoke(const InputType& prop, ConversionContext& context, const mson::BaseTypeName defaultNestedType) {
919
+ return RefractElementFromProperty<T>(prop, context, defaultNestedType);
920
+ }
921
+ };
922
+
923
+ struct ValueTrait {
924
+ typedef refract::IElement ElementType;
925
+ typedef NodeInfo<mson::ValueMember> InputType;
926
+
927
+ template<typename T> static ElementType* Invoke (const InputType& val, ConversionContext& context, const mson::BaseTypeName defaultNestedType) {
928
+ return RefractElementFromValue<T>(val, context, defaultNestedType);
929
+ }
930
+ };
931
+
932
+ static void CheckTypeAttributesClash(const mson::TypeAttributes& attributes,
933
+ const snowcrash::SourceMap<mson::ValueDefinition>& sourceMap,
934
+ ConversionContext& context) {
935
+
936
+ if ((attributes & mson::FixedTypeAttribute) != 0 &&
937
+ (attributes & mson::OptionalTypeAttribute) != 0) {
938
+
939
+ context.warn(snowcrash::Warning("cannot use 'fixed' and 'optional' together",
940
+ snowcrash::MSONError, sourceMap.sourceMap));
941
+ }
942
+
943
+ if ((attributes & mson::RequiredTypeAttribute) != 0 &&
944
+ (attributes & mson::OptionalTypeAttribute) != 0) {
945
+
946
+ context.warn(snowcrash::Warning("cannot use 'required' and 'optional' together",
947
+ snowcrash::MSONError, sourceMap.sourceMap));
948
+ }
949
+
950
+ if ((attributes & mson::DefaultTypeAttribute) != 0 &&
951
+ (attributes & mson::SampleTypeAttribute) != 0) {
952
+
953
+ context.warn(snowcrash::Warning("cannot use 'default' and 'sample' together",
954
+ snowcrash::MSONError, sourceMap.sourceMap));
955
+ }
956
+
957
+ if ((attributes & mson::FixedTypeAttribute) != 0 &&
958
+ (attributes & mson::FixedTypeTypeAttribute) != 0) {
959
+
960
+ context.warn(snowcrash::Warning("cannot use 'fixed' and 'fixed-type' together",
961
+ snowcrash::MSONError, sourceMap.sourceMap));
962
+ }
963
+ }
964
+
965
+ template <typename Trait>
966
+ static refract::IElement* MsonMemberToRefract(const typename Trait::InputType& input,
967
+ ConversionContext& context,
968
+ const mson::BaseTypeName nameType,
969
+ const mson::BaseTypeName defaultNestedType,
970
+ bool checkTypeAttributes = true) {
971
+
972
+ if (checkTypeAttributes) {
973
+ CheckTypeAttributesClash(input.node->valueDefinition.typeDefinition.attributes, input.sourceMap->valueDefinition, context);
974
+ }
975
+
976
+ switch (nameType) {
977
+ case mson::BooleanTypeName:
978
+ return Trait::template Invoke<refract::BooleanElement>(input, context, defaultNestedType);
979
+
980
+ case mson::NumberTypeName:
981
+ return Trait::template Invoke<refract::NumberElement>(input, context, defaultNestedType);
982
+
983
+ case mson::StringTypeName:
984
+ return Trait::template Invoke<refract::StringElement>(input, context, defaultNestedType);
985
+
986
+ case mson::EnumTypeName:
987
+ return Trait::template Invoke<refract::EnumElement>(input, context, defaultNestedType);
988
+
989
+ case mson::ArrayTypeName:
990
+ return Trait::template Invoke<refract::ArrayElement>(input, context, defaultNestedType);
991
+
992
+ case mson::ObjectTypeName:
993
+ return Trait::template Invoke<refract::ObjectElement>(input, context, defaultNestedType);
994
+
995
+ case mson::UndefinedTypeName:
996
+ {
997
+ if (ValueHasChildren(input.node)) {
998
+ // FIXME: what about EnumElement
999
+ return Trait::template Invoke<refract::ArrayElement>(input, context, defaultNestedType);
1000
+ }
1001
+ else if (ValueHasName(input.node) || ValueHasMembers(input.node)) {
1002
+ return Trait::template Invoke<refract::ObjectElement>(input, context, defaultNestedType);
1003
+ }
1004
+ else if (nameType != defaultNestedType) {
1005
+ return MsonMemberToRefract<Trait>(input, context, defaultNestedType, defaultNestedType, false);
1006
+ }
1007
+
1008
+ return MsonMemberToRefract<Trait>(input, context, mson::StringTypeName, defaultNestedType, false);
1009
+ }
1010
+ }
1011
+
1012
+ throw snowcrash::Error("unknown type of mson member", snowcrash::MSONError, input.sourceMap->sourceMap);
1013
+ }
1014
+
1015
+ static refract::IElement* MsonOneofToRefract(const NodeInfo<mson::OneOf>& oneOf, ConversionContext& context)
1016
+ {
1017
+ refract::SelectElement* select = new refract::SelectElement;
1018
+
1019
+ NodeInfoCollection<mson::OneOf> oneOfNodeInfo(oneOf);
1020
+
1021
+ for (NodeInfoCollection<mson::OneOf>::const_iterator it = oneOfNodeInfo.begin(); it != oneOfNodeInfo.end(); ++it) {
1022
+
1023
+ refract::OptionElement* option = new refract::OptionElement;
1024
+
1025
+ // we can not use MsonElementToRefract() for groups,
1026
+ // "option" element handles directly all elements in group
1027
+ if (it->node->klass == mson::Element::GroupClass) {
1028
+ option->set(MsonElementsToRefract(MakeNodeInfo(it->node->content.elements(), it->sourceMap->elements()), context));
1029
+ }
1030
+ else {
1031
+ option->push_back(MsonElementToRefract(*it, context, mson::StringTypeName));
1032
+ }
1033
+
1034
+ select->push_back(option);
1035
+ }
1036
+
1037
+ return select;
1038
+ }
1039
+
1040
+ static refract::IElement* MsonMixinToRefract(const NodeInfo<mson::Mixin>& mixin)
1041
+ {
1042
+ refract::ObjectElement* ref = new refract::ObjectElement;
1043
+ ref->element(SerializeKey::Ref);
1044
+ ref->renderType(refract::IElement::rCompact);
1045
+
1046
+ refract::MemberElement* href = new refract::MemberElement;
1047
+ href->set(SerializeKey::Href, refract::IElement::Create(mixin.node->typeSpecification.name.symbol.literal));
1048
+ ref->push_back(href);
1049
+
1050
+ refract::MemberElement* path = new refract::MemberElement;
1051
+ path->set(SerializeKey::Path,refract::IElement::Create(SerializeKey::Content));
1052
+ ref->push_back(path);
1053
+
1054
+ return ref;
1055
+ }
1056
+
1057
+ static refract::IElement* MsonElementToRefract(const NodeInfo<mson::Element>& mse, ConversionContext& context, const mson::BaseTypeName defaultNestedType/* = mson::StringTypeName */)
1058
+ {
1059
+ switch (mse.node->klass) {
1060
+ case mson::Element::PropertyClass:
1061
+ return MsonMemberToRefract<PropertyTrait>(MakeNodeInfo(mse.node->content.property, mse.sourceMap->property),
1062
+ context,
1063
+ GetType(mse.node->content.property.valueDefinition, context),
1064
+ defaultNestedType);
1065
+
1066
+ case mson::Element::ValueClass:
1067
+ return MsonMemberToRefract<ValueTrait>(MakeNodeInfo(mse.node->content.value, mse.sourceMap->value),
1068
+ context,
1069
+ GetType(mse.node->content.value.valueDefinition, context),
1070
+ defaultNestedType);
1071
+
1072
+ case mson::Element::MixinClass:
1073
+ return MsonMixinToRefract(MakeNodeInfo(mse.node->content.mixin, mse.sourceMap->mixin));
1074
+
1075
+ case mson::Element::OneOfClass:
1076
+ return MsonOneofToRefract(MakeNodeInfo(mse.node->content.oneOf(), mse.sourceMap->oneOf()), context);
1077
+
1078
+ case mson::Element::GroupClass:
1079
+ throw snowcrash::Error("unable to handle element group", snowcrash::ApplicationError);
1080
+
1081
+ default:
1082
+ throw snowcrash::Error("unknown type of mson element", snowcrash::ApplicationError);
1083
+ }
1084
+ }
1085
+
1086
+ template<typename T>
1087
+ refract::IElement* RefractElementFromMSON(const NodeInfo<snowcrash::DataStructure>& ds, ConversionContext& context)
1088
+ {
1089
+ using namespace refract;
1090
+ typedef T ElementType;
1091
+
1092
+ ElementType* element = new ElementType;
1093
+ SetElementType(element, ds.node->typeDefinition);
1094
+
1095
+ if (!ds.node->name.symbol.literal.empty()) {
1096
+ snowcrash::SourceMap<mson::Literal> sourceMap = *NodeInfo<mson::Literal>::NullSourceMap();
1097
+ sourceMap.sourceMap.append(ds.sourceMap->name.sourceMap);
1098
+ element->meta[SerializeKey::Id] = PrimitiveToRefract(MakeNodeInfo(ds.node->name.symbol.literal, sourceMap));
1099
+ }
1100
+
1101
+ AttachSourceMap(element, MakeNodeInfo(ds.node, ds.sourceMap));
1102
+
1103
+ // there is no source map for attributes
1104
+ if (refract::IElement* attributes = MsonTypeAttributesToRefract(ds.node->typeDefinition.attributes)) {
1105
+ element->attributes[SerializeKey::TypeAttributes] = attributes;
1106
+ }
1107
+
1108
+ ElementData<T> data;
1109
+
1110
+ ExtractTypeDefinition<ElementType> extd(data, context);
1111
+ extd(MAKE_NODE_INFO(ds, typeDefinition));
1112
+
1113
+ NodeInfoCollection<mson::TypeSections> typeSections(MAKE_NODE_INFO(ds, sections));
1114
+
1115
+ std::for_each(typeSections.begin(), typeSections.end(), ExtractTypeSection<T>(data, context, ds));
1116
+
1117
+ TransformElementData<T>(element, data);
1118
+
1119
+ if (refract::IElement* description = DescriptionToRefract(data)) {
1120
+ element->meta[SerializeKey::Description] = description;
1121
+ }
1122
+
1123
+ return element;
1124
+ }
1125
+
1126
+ refract::IElement* MSONToRefract(const NodeInfo<snowcrash::DataStructure>& dataStructure, ConversionContext& context)
1127
+ {
1128
+ if (dataStructure.node->empty()) {
1129
+ return NULL;
1130
+ }
1131
+
1132
+ using namespace refract;
1133
+ IElement* element = NULL;
1134
+
1135
+ mson::BaseTypeName nameType = GetType(*dataStructure.node, context);
1136
+
1137
+ switch (nameType) {
1138
+ case mson::BooleanTypeName:
1139
+ element = RefractElementFromMSON<refract::BooleanElement>(dataStructure, context);
1140
+ break;
1141
+
1142
+ case mson::NumberTypeName:
1143
+ element = RefractElementFromMSON<refract::NumberElement>(dataStructure, context);
1144
+ break;
1145
+
1146
+ case mson::StringTypeName:
1147
+ element = RefractElementFromMSON<refract::StringElement>(dataStructure, context);
1148
+ break;
1149
+
1150
+ case mson::EnumTypeName:
1151
+ element = RefractElementFromMSON<refract::EnumElement>(dataStructure, context);
1152
+ break;
1153
+
1154
+ case mson::ArrayTypeName:
1155
+ element = RefractElementFromMSON<refract::ArrayElement>(dataStructure, context);
1156
+ break;
1157
+
1158
+ case mson::ObjectTypeName:
1159
+ case mson::UndefinedTypeName:
1160
+ element = RefractElementFromMSON<refract::ObjectElement>(dataStructure, context);
1161
+ break;
1162
+
1163
+ default:
1164
+ throw snowcrash::Error("unknown type of data structure", snowcrash::ApplicationError);
1165
+ }
1166
+
1167
+ return element;
1168
+ }
1169
+
1170
+ refract::IElement* ExpandRefract(refract::IElement* element, ConversionContext& context)
1171
+ {
1172
+ if (!element) {
1173
+ return element;
1174
+ }
1175
+
1176
+ refract::ExpandVisitor expander(context.GetNamedTypesRegistry());
1177
+ refract::Visit(expander, *element);
1178
+
1179
+ if (refract::IElement* expanded = expander.get()) {
1180
+ delete element;
1181
+ element = expanded;
1182
+ }
1183
+
1184
+ return element;
1185
+ }
1186
+
1187
+ sos::Object SerializeRefract(refract::IElement* element, ConversionContext& context)
1188
+ {
1189
+ if (!element) {
1190
+ return sos::Object();
1191
+ }
1192
+
1193
+ refract::SosSerializeVisitor serializer(context.options.generateSourceMap);
1194
+ refract::Visit(serializer, *element);
1195
+
1196
+ return serializer.get();
1197
+ }
1198
+
1199
+ } // namespace drafter