chess_engine 0.0.1

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 (292) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +5 -0
  3. data/Gemfile.lock +21 -0
  4. data/README.md +26 -0
  5. data/chess_engine.gemspec +14 -0
  6. data/lib/chess_engine/board.rb +95 -0
  7. data/lib/chess_engine/cli.rb +105 -0
  8. data/lib/chess_engine/game.rb +148 -0
  9. data/lib/chess_engine/input.rb +19 -0
  10. data/lib/chess_engine/move.rb +35 -0
  11. data/lib/chess_engine/piece.rb +97 -0
  12. data/lib/chess_engine/validator.rb +87 -0
  13. data/lib/chess_engine.rb +1 -0
  14. data/spec/board_spec.rb +70 -0
  15. data/spec/game_helper.rb +5 -0
  16. data/spec/game_spec.rb +79 -0
  17. data/spec/spec_helper.rb +100 -0
  18. data/spec/validator_spec.rb +26 -0
  19. data/vendor/bundle/bin/coderay +27 -0
  20. data/vendor/bundle/bin/pry +27 -0
  21. data/vendor/bundle/cache/coderay-1.1.2.gem +0 -0
  22. data/vendor/bundle/cache/colorize-0.8.1.gem +0 -0
  23. data/vendor/bundle/cache/method_source-0.9.2.gem +0 -0
  24. data/vendor/bundle/cache/pry-0.12.2.gem +0 -0
  25. data/vendor/bundle/cache/rb-readline-0.5.5.gem +0 -0
  26. data/vendor/bundle/gems/coderay-1.1.2/MIT-LICENSE +22 -0
  27. data/vendor/bundle/gems/coderay-1.1.2/README_INDEX.rdoc +123 -0
  28. data/vendor/bundle/gems/coderay-1.1.2/bin/coderay +215 -0
  29. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/duo.rb +81 -0
  30. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/_map.rb +17 -0
  31. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/comment_filter.rb +25 -0
  32. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/count.rb +39 -0
  33. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/debug.rb +49 -0
  34. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/debug_lint.rb +63 -0
  35. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/div.rb +23 -0
  36. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/encoder.rb +190 -0
  37. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/filter.rb +58 -0
  38. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html/css.rb +65 -0
  39. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html/numbering.rb +108 -0
  40. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html/output.rb +166 -0
  41. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html.rb +333 -0
  42. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/json.rb +83 -0
  43. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb +45 -0
  44. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/lint.rb +59 -0
  45. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/null.rb +18 -0
  46. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/page.rb +24 -0
  47. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/span.rb +23 -0
  48. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/statistic.rb +95 -0
  49. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/terminal.rb +195 -0
  50. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/text.rb +46 -0
  51. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/token_kind_filter.rb +111 -0
  52. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/xml.rb +72 -0
  53. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/yaml.rb +50 -0
  54. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders.rb +18 -0
  55. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/for_redcloth.rb +95 -0
  56. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/file_type.rb +151 -0
  57. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/plugin.rb +55 -0
  58. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/plugin_host.rb +221 -0
  59. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/word_list.rb +72 -0
  60. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/_map.rb +24 -0
  61. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/c.rb +189 -0
  62. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/clojure.rb +217 -0
  63. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/cpp.rb +217 -0
  64. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/css.rb +196 -0
  65. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/debug.rb +75 -0
  66. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/delphi.rb +144 -0
  67. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/diff.rb +221 -0
  68. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/erb.rb +81 -0
  69. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/go.rb +208 -0
  70. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/groovy.rb +268 -0
  71. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/haml.rb +168 -0
  72. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/html.rb +275 -0
  73. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/java/builtin_types.rb +421 -0
  74. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/java.rb +174 -0
  75. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/java_script.rb +237 -0
  76. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/json.rb +98 -0
  77. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/lua.rb +280 -0
  78. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/php.rb +527 -0
  79. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/python.rb +287 -0
  80. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/raydebug.rb +75 -0
  81. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/ruby/patterns.rb +178 -0
  82. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/ruby/string_state.rb +79 -0
  83. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/ruby.rb +477 -0
  84. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/sass.rb +232 -0
  85. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/scanner.rb +337 -0
  86. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/sql.rb +169 -0
  87. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/taskpaper.rb +36 -0
  88. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/text.rb +26 -0
  89. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/xml.rb +17 -0
  90. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/yaml.rb +140 -0
  91. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners.rb +27 -0
  92. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles/_map.rb +7 -0
  93. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles/alpha.rb +153 -0
  94. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles/style.rb +18 -0
  95. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles.rb +15 -0
  96. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/token_kinds.rb +85 -0
  97. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/tokens.rb +161 -0
  98. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/tokens_proxy.rb +55 -0
  99. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/version.rb +3 -0
  100. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay.rb +284 -0
  101. data/vendor/bundle/gems/colorize-0.8.1/CHANGELOG +65 -0
  102. data/vendor/bundle/gems/colorize-0.8.1/LICENSE +339 -0
  103. data/vendor/bundle/gems/colorize-0.8.1/README.md +105 -0
  104. data/vendor/bundle/gems/colorize-0.8.1/Rakefile +13 -0
  105. data/vendor/bundle/gems/colorize-0.8.1/colorize.gemspec +36 -0
  106. data/vendor/bundle/gems/colorize-0.8.1/lib/colorize/class_methods.rb +120 -0
  107. data/vendor/bundle/gems/colorize-0.8.1/lib/colorize/instance_methods.rb +132 -0
  108. data/vendor/bundle/gems/colorize-0.8.1/lib/colorize.rb +12 -0
  109. data/vendor/bundle/gems/colorize-0.8.1/lib/colorized_string.rb +19 -0
  110. data/vendor/bundle/gems/colorize-0.8.1/test/test_colorize.rb +164 -0
  111. data/vendor/bundle/gems/method_source-0.9.2/Gemfile +2 -0
  112. data/vendor/bundle/gems/method_source-0.9.2/LICENSE +25 -0
  113. data/vendor/bundle/gems/method_source-0.9.2/README.markdown +91 -0
  114. data/vendor/bundle/gems/method_source-0.9.2/Rakefile +81 -0
  115. data/vendor/bundle/gems/method_source-0.9.2/lib/method_source/code_helpers.rb +154 -0
  116. data/vendor/bundle/gems/method_source-0.9.2/lib/method_source/source_location.rb +138 -0
  117. data/vendor/bundle/gems/method_source-0.9.2/lib/method_source/version.rb +3 -0
  118. data/vendor/bundle/gems/method_source-0.9.2/lib/method_source.rb +141 -0
  119. data/vendor/bundle/gems/method_source-0.9.2/method_source.gemspec +35 -0
  120. data/vendor/bundle/gems/method_source-0.9.2/spec/method_source/code_helpers_spec.rb +43 -0
  121. data/vendor/bundle/gems/method_source-0.9.2/spec/method_source_spec.rb +143 -0
  122. data/vendor/bundle/gems/method_source-0.9.2/spec/spec_helper.rb +101 -0
  123. data/vendor/bundle/gems/pry-0.12.2/CHANGELOG.md +953 -0
  124. data/vendor/bundle/gems/pry-0.12.2/LICENSE +25 -0
  125. data/vendor/bundle/gems/pry-0.12.2/README.md +390 -0
  126. data/vendor/bundle/gems/pry-0.12.2/bin/pry +8 -0
  127. data/vendor/bundle/gems/pry-0.12.2/lib/pry/basic_object.rb +6 -0
  128. data/vendor/bundle/gems/pry-0.12.2/lib/pry/cli.rb +218 -0
  129. data/vendor/bundle/gems/pry-0.12.2/lib/pry/code/code_file.rb +110 -0
  130. data/vendor/bundle/gems/pry-0.12.2/lib/pry/code/code_range.rb +71 -0
  131. data/vendor/bundle/gems/pry-0.12.2/lib/pry/code/loc.rb +98 -0
  132. data/vendor/bundle/gems/pry-0.12.2/lib/pry/code.rb +353 -0
  133. data/vendor/bundle/gems/pry-0.12.2/lib/pry/code_object.rb +195 -0
  134. data/vendor/bundle/gems/pry-0.12.2/lib/pry/color_printer.rb +65 -0
  135. data/vendor/bundle/gems/pry-0.12.2/lib/pry/command.rb +723 -0
  136. data/vendor/bundle/gems/pry-0.12.2/lib/pry/command_set.rb +415 -0
  137. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/amend_line.rb +98 -0
  138. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/bang.rb +20 -0
  139. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/bang_pry.rb +17 -0
  140. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/abstract_formatter.rb +27 -0
  141. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/exception_formatter.rb +79 -0
  142. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/file_formatter.rb +71 -0
  143. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
  144. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat.rb +63 -0
  145. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cd.rb +41 -0
  146. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/change_inspector.rb +27 -0
  147. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/change_prompt.rb +46 -0
  148. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/clear_screen.rb +14 -0
  149. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/code_collector.rb +167 -0
  150. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/disable_pry.rb +27 -0
  151. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/disabled_commands.rb +2 -0
  152. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/easter_eggs.rb +112 -0
  153. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/edit/exception_patcher.rb +25 -0
  154. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/edit/file_and_line_locator.rb +36 -0
  155. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/edit.rb +200 -0
  156. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/exit.rb +43 -0
  157. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/exit_all.rb +29 -0
  158. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/exit_program.rb +23 -0
  159. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/find_method.rb +191 -0
  160. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/fix_indent.rb +19 -0
  161. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_cd.rb +26 -0
  162. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_install.rb +32 -0
  163. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_list.rb +33 -0
  164. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_open.rb +29 -0
  165. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_readme.rb +25 -0
  166. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_search.rb +40 -0
  167. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_stats.rb +83 -0
  168. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gist.rb +102 -0
  169. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/help.rb +164 -0
  170. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/hist.rb +181 -0
  171. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/import_set.rb +23 -0
  172. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/install_command.rb +54 -0
  173. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/jump_to.rb +29 -0
  174. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/list_inspectors.rb +35 -0
  175. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/constants.rb +58 -0
  176. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/formatter.rb +51 -0
  177. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/globals.rb +46 -0
  178. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/grep.rb +19 -0
  179. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/instance_vars.rb +38 -0
  180. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/interrogatable.rb +18 -0
  181. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/jruby_hacks.rb +49 -0
  182. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/local_names.rb +33 -0
  183. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/local_vars.rb +37 -0
  184. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/ls_entity.rb +69 -0
  185. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/methods.rb +54 -0
  186. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/methods_helper.rb +46 -0
  187. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/self_methods.rb +33 -0
  188. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls.rb +113 -0
  189. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/nesting.rb +25 -0
  190. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/play.rb +102 -0
  191. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/pry_backtrace.rb +25 -0
  192. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/pry_version.rb +17 -0
  193. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/raise_up.rb +33 -0
  194. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/reload_code.rb +62 -0
  195. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/reset.rb +18 -0
  196. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ri.rb +65 -0
  197. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/save_file.rb +61 -0
  198. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/shell_command.rb +75 -0
  199. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/shell_mode.rb +25 -0
  200. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_doc.rb +81 -0
  201. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_info.rb +216 -0
  202. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_input.rb +17 -0
  203. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_source.rb +53 -0
  204. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/stat.rb +40 -0
  205. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/switch_to.rb +23 -0
  206. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/toggle_color.rb +24 -0
  207. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/watch_expression/expression.rb +38 -0
  208. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/watch_expression.rb +107 -0
  209. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/whereami.rb +197 -0
  210. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/wtf.rb +70 -0
  211. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands.rb +6 -0
  212. data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/behavior.rb +255 -0
  213. data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/convenience.rb +28 -0
  214. data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/default.rb +159 -0
  215. data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/memoization.rb +48 -0
  216. data/vendor/bundle/gems/pry-0.12.2/lib/pry/config.rb +35 -0
  217. data/vendor/bundle/gems/pry-0.12.2/lib/pry/core_extensions.rb +142 -0
  218. data/vendor/bundle/gems/pry-0.12.2/lib/pry/editor.rb +128 -0
  219. data/vendor/bundle/gems/pry-0.12.2/lib/pry/exceptions.rb +76 -0
  220. data/vendor/bundle/gems/pry-0.12.2/lib/pry/forwardable.rb +23 -0
  221. data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/base_helpers.rb +200 -0
  222. data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/command_helpers.rb +157 -0
  223. data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/documentation_helpers.rb +76 -0
  224. data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/options_helpers.rb +27 -0
  225. data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/platform.rb +58 -0
  226. data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/table.rb +114 -0
  227. data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/text.rb +115 -0
  228. data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers.rb +6 -0
  229. data/vendor/bundle/gems/pry-0.12.2/lib/pry/history.rb +161 -0
  230. data/vendor/bundle/gems/pry-0.12.2/lib/pry/hooks.rb +171 -0
  231. data/vendor/bundle/gems/pry-0.12.2/lib/pry/indent.rb +408 -0
  232. data/vendor/bundle/gems/pry-0.12.2/lib/pry/input_completer.rb +265 -0
  233. data/vendor/bundle/gems/pry-0.12.2/lib/pry/input_lock.rb +130 -0
  234. data/vendor/bundle/gems/pry-0.12.2/lib/pry/inspector.rb +27 -0
  235. data/vendor/bundle/gems/pry-0.12.2/lib/pry/last_exception.rb +61 -0
  236. data/vendor/bundle/gems/pry-0.12.2/lib/pry/method/disowned.rb +55 -0
  237. data/vendor/bundle/gems/pry-0.12.2/lib/pry/method/patcher.rb +122 -0
  238. data/vendor/bundle/gems/pry-0.12.2/lib/pry/method/weird_method_locator.rb +198 -0
  239. data/vendor/bundle/gems/pry-0.12.2/lib/pry/method.rb +552 -0
  240. data/vendor/bundle/gems/pry-0.12.2/lib/pry/object_path.rb +83 -0
  241. data/vendor/bundle/gems/pry-0.12.2/lib/pry/output.rb +50 -0
  242. data/vendor/bundle/gems/pry-0.12.2/lib/pry/pager.rb +250 -0
  243. data/vendor/bundle/gems/pry-0.12.2/lib/pry/platform.rb +91 -0
  244. data/vendor/bundle/gems/pry-0.12.2/lib/pry/plugins.rb +122 -0
  245. data/vendor/bundle/gems/pry-0.12.2/lib/pry/prompt.rb +145 -0
  246. data/vendor/bundle/gems/pry-0.12.2/lib/pry/pry_class.rb +425 -0
  247. data/vendor/bundle/gems/pry-0.12.2/lib/pry/pry_instance.rb +699 -0
  248. data/vendor/bundle/gems/pry-0.12.2/lib/pry/repl.rb +261 -0
  249. data/vendor/bundle/gems/pry-0.12.2/lib/pry/repl_file_loader.rb +73 -0
  250. data/vendor/bundle/gems/pry-0.12.2/lib/pry/ring.rb +84 -0
  251. data/vendor/bundle/gems/pry-0.12.2/lib/pry/rubygem.rb +84 -0
  252. data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop/LICENSE +20 -0
  253. data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop/commands.rb +195 -0
  254. data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop/option.rb +206 -0
  255. data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop.rb +661 -0
  256. data/vendor/bundle/gems/pry-0.12.2/lib/pry/terminal.rb +91 -0
  257. data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/evalable.rb +15 -0
  258. data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/mockable.rb +14 -0
  259. data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/pry_tester.rb +73 -0
  260. data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/utility.rb +26 -0
  261. data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/variables.rb +46 -0
  262. data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable.rb +70 -0
  263. data/vendor/bundle/gems/pry-0.12.2/lib/pry/version.rb +3 -0
  264. data/vendor/bundle/gems/pry-0.12.2/lib/pry/wrapped_module/candidate.rb +131 -0
  265. data/vendor/bundle/gems/pry-0.12.2/lib/pry/wrapped_module.rb +378 -0
  266. data/vendor/bundle/gems/pry-0.12.2/lib/pry.rb +132 -0
  267. data/vendor/bundle/gems/rb-readline-0.5.5/CHANGES +94 -0
  268. data/vendor/bundle/gems/rb-readline-0.5.5/LICENSE +25 -0
  269. data/vendor/bundle/gems/rb-readline-0.5.5/README.md +81 -0
  270. data/vendor/bundle/gems/rb-readline-0.5.5/Rakefile +25 -0
  271. data/vendor/bundle/gems/rb-readline-0.5.5/bench/_rl_adjust_point.rb +26 -0
  272. data/vendor/bundle/gems/rb-readline-0.5.5/examples/example_readline.rb +8 -0
  273. data/vendor/bundle/gems/rb-readline-0.5.5/examples/example_readline_with_completion.rb +18 -0
  274. data/vendor/bundle/gems/rb-readline-0.5.5/examples/tinyirb.rb +11 -0
  275. data/vendor/bundle/gems/rb-readline-0.5.5/lib/rb-readline.rb +18 -0
  276. data/vendor/bundle/gems/rb-readline-0.5.5/lib/rbreadline/version.rb +3 -0
  277. data/vendor/bundle/gems/rb-readline-0.5.5/lib/rbreadline.rb +8920 -0
  278. data/vendor/bundle/gems/rb-readline-0.5.5/lib/readline.rb +539 -0
  279. data/vendor/bundle/gems/rb-readline-0.5.5/rb-readline.gemspec +51 -0
  280. data/vendor/bundle/gems/rb-readline-0.5.5/setup.rb +1585 -0
  281. data/vendor/bundle/gems/rb-readline-0.5.5/test/support/filesystem_completion_helper.rb +53 -0
  282. data/vendor/bundle/gems/rb-readline-0.5.5/test/test_completion.rb +100 -0
  283. data/vendor/bundle/gems/rb-readline-0.5.5/test/test_filename_completion_proc.rb +88 -0
  284. data/vendor/bundle/gems/rb-readline-0.5.5/test/test_history.rb +29 -0
  285. data/vendor/bundle/gems/rb-readline-0.5.5/test/test_rbreadline.rb +23 -0
  286. data/vendor/bundle/gems/rb-readline-0.5.5/test/test_readline.rb +221 -0
  287. data/vendor/bundle/specifications/coderay-1.1.2.gemspec +26 -0
  288. data/vendor/bundle/specifications/colorize-0.8.1.gemspec +38 -0
  289. data/vendor/bundle/specifications/method_source-0.9.2.gemspec +35 -0
  290. data/vendor/bundle/specifications/pry-0.12.2.gemspec +38 -0
  291. data/vendor/bundle/specifications/rb-readline-0.5.5.gemspec +39 -0
  292. metadata +363 -0
@@ -0,0 +1,171 @@
1
+ class Pry
2
+ # Implements a hooks system for Pry. A hook is a callable that is associated
3
+ # with an event. A number of events are currently provided by Pry, these
4
+ # include: `:when_started`, `:before_session`, `:after_session`. A hook must
5
+ # have a name, and is connected with an event by the `Pry::Hooks#add_hook`
6
+ # method.
7
+ #
8
+ # @example Adding a hook for the `:before_session` event.
9
+ # Pry.config.hooks.add_hook(:before_session, :say_hi) do
10
+ # puts "hello"
11
+ # end
12
+ class Hooks
13
+ def initialize
14
+ @hooks = Hash.new { |h, k| h[k] = [] }
15
+ end
16
+
17
+ # Ensure that duplicates have their @hooks object.
18
+ def initialize_copy(_orig)
19
+ hooks_dup = @hooks.dup
20
+ @hooks.each do |k, v|
21
+ hooks_dup[k] = v.dup
22
+ end
23
+
24
+ @hooks = hooks_dup
25
+ end
26
+
27
+ def errors
28
+ @errors ||= []
29
+ end
30
+
31
+ # Destructively merge the contents of two `Pry:Hooks` instances.
32
+ #
33
+ # @param [Pry::Hooks] other The `Pry::Hooks` instance to merge
34
+ # @return [Pry:Hooks] The receiver.
35
+ # @see #merge
36
+ def merge!(other)
37
+ @hooks.merge!(other.dup.hooks) do |key, array, other_array|
38
+ temp_hash, output = {}, []
39
+
40
+ (array + other_array).reverse_each do |pair|
41
+ temp_hash[pair.first] ||= output.unshift(pair)
42
+ end
43
+
44
+ output
45
+ end
46
+
47
+ self
48
+ end
49
+
50
+ # @example
51
+ # hooks = Pry::Hooks.new.add_hook(:before_session, :say_hi) { puts "hi!" }
52
+ # Pry::Hooks.new.merge(hooks)
53
+ # @param [Pry::Hooks] other The `Pry::Hooks` instance to merge
54
+ # @return [Pry::Hooks] a new `Pry::Hooks` instance containing a merge of the
55
+ # contents of two `Pry:Hooks` instances.
56
+ def merge(other)
57
+ self.dup.tap do |v|
58
+ v.merge!(other)
59
+ end
60
+ end
61
+
62
+ # Add a new hook to be executed for the `event_name` event.
63
+ # @param [Symbol] event_name The name of the event.
64
+ # @param [Symbol] hook_name The name of the hook.
65
+ # @param [#call] callable The callable.
66
+ # @yield The block to use as the callable (if no `callable` provided).
67
+ # @return [Pry:Hooks] The receiver.
68
+ def add_hook(event_name, hook_name, callable = nil, &block)
69
+ event_name = event_name.to_s
70
+
71
+ # do not allow duplicates, but allow multiple `nil` hooks
72
+ # (anonymous hooks)
73
+ if hook_exists?(event_name, hook_name) && !hook_name.nil?
74
+ raise ArgumentError, "Hook with name '#{hook_name}' already defined!"
75
+ end
76
+
77
+ if !block && !callable
78
+ raise ArgumentError, "Must provide a block or callable."
79
+ end
80
+
81
+ # ensure we only have one anonymous hook
82
+ @hooks[event_name].delete_if { |h, k| h.nil? } if hook_name.nil?
83
+
84
+ if block
85
+ @hooks[event_name] << [hook_name, block]
86
+ elsif callable
87
+ @hooks[event_name] << [hook_name, callable]
88
+ end
89
+
90
+ self
91
+ end
92
+
93
+ # Execute the list of hooks for the `event_name` event.
94
+ # @param [Symbol] event_name The name of the event.
95
+ # @param [Array] args The arguments to pass to each hook function.
96
+ # @return [Object] The return value of the last executed hook.
97
+ def exec_hook(event_name, *args, &block)
98
+ @hooks[event_name.to_s].map do |hook_name, callable|
99
+ begin
100
+ callable.call(*args, &block)
101
+ rescue RescuableException => e
102
+ errors << e
103
+ e
104
+ end
105
+ end.last
106
+ end
107
+
108
+ # @param [Symbol] event_name The name of the event.
109
+ # @return [Fixnum] The number of hook functions for `event_name`.
110
+ def hook_count(event_name)
111
+ @hooks[event_name.to_s].size
112
+ end
113
+
114
+ # @param [Symbol] event_name The name of the event.
115
+ # @param [Symbol] hook_name The name of the hook
116
+ # @return [#call] a specific hook for a given event.
117
+ def get_hook(event_name, hook_name)
118
+ hook = @hooks[event_name.to_s].find do |current_hook_name, callable|
119
+ current_hook_name == hook_name
120
+ end
121
+ hook.last if hook
122
+ end
123
+
124
+ # @param [Symbol] event_name The name of the event.
125
+ # @return [Hash] The hash of hook names / hook functions.
126
+ # @note Modifying the returned hash does not alter the hooks, use
127
+ # `add_hook`/`delete_hook` for that.
128
+ def get_hooks(event_name)
129
+ Hash[@hooks[event_name.to_s]]
130
+ end
131
+
132
+ # @param [Symbol] event_name The name of the event.
133
+ # @param [Symbol] hook_name The name of the hook.
134
+ # to delete.
135
+ # @return [#call] The deleted hook.
136
+ def delete_hook(event_name, hook_name)
137
+ deleted_callable = nil
138
+
139
+ @hooks[event_name.to_s].delete_if do |current_hook_name, callable|
140
+ if current_hook_name == hook_name
141
+ deleted_callable = callable
142
+ true
143
+ else
144
+ false
145
+ end
146
+ end
147
+ deleted_callable
148
+ end
149
+
150
+ # Clear all hooks functions for a given event.
151
+ #
152
+ # @param [String] event_name The name of the event.
153
+ # @return [void]
154
+ def clear_event_hooks(event_name)
155
+ @hooks[event_name.to_s] = []
156
+ end
157
+
158
+ # @param [Symbol] event_name Name of the event.
159
+ # @param [Symbol] hook_name Name of the hook.
160
+ # @return [Boolean] Whether the hook by the name `hook_name`.
161
+ def hook_exists?(event_name, hook_name)
162
+ @hooks[event_name.to_s].map(&:first).include?(hook_name)
163
+ end
164
+
165
+ protected
166
+
167
+ def hooks
168
+ @hooks
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,408 @@
1
+ require 'coderay'
2
+
3
+ class Pry
4
+ ##
5
+ # Pry::Indent is a class that can be used to indent a number of lines
6
+ # containing Ruby code similar as to how IRB does it (but better). The class
7
+ # works by tokenizing a string using CodeRay and then looping over those
8
+ # tokens. Based on the tokens in a line of code that line (or the next one)
9
+ # will be indented or un-indented by correctly.
10
+ #
11
+ class Indent
12
+ include Helpers::BaseHelpers
13
+
14
+ # Raised if {#module_nesting} would not work.
15
+ class UnparseableNestingError < StandardError; end
16
+
17
+ # @return [String] String containing the spaces to be inserted before the next line.
18
+ attr_reader :indent_level
19
+
20
+ # @return [Array<String>] The stack of open tokens.
21
+ attr_reader :stack
22
+
23
+ # The amount of spaces to insert for each indent level.
24
+ SPACES = ' '
25
+
26
+ # Hash containing all the tokens that should increase the indentation
27
+ # level. The keys of this hash are open tokens, the values the matching
28
+ # tokens that should prevent a line from being indented if they appear on
29
+ # the same line.
30
+ OPEN_TOKENS = {
31
+ 'def' => 'end',
32
+ 'class' => 'end',
33
+ 'module' => 'end',
34
+ 'do' => 'end',
35
+ 'if' => 'end',
36
+ 'unless' => 'end',
37
+ 'while' => 'end',
38
+ 'until' => 'end',
39
+ 'for' => 'end',
40
+ 'case' => 'end',
41
+ 'begin' => 'end',
42
+ '[' => ']',
43
+ '{' => '}',
44
+ '(' => ')'
45
+ }
46
+
47
+ # Which tokens can either be open tokens, or appear as modifiers on
48
+ # a single-line.
49
+ SINGLELINE_TOKENS = %w(if while until unless rescue)
50
+
51
+ # Which tokens can be followed by an optional "do" keyword.
52
+ OPTIONAL_DO_TOKENS = %w(for while until)
53
+
54
+ # Collection of token types that should be ignored. Without this list
55
+ # keywords such as "class" inside strings would cause the code to be
56
+ # indented incorrectly.
57
+ #
58
+ # :pre_constant and :preserved_constant are the CodeRay 0.9.8 and 1.0.0
59
+ # classifications of "true", "false", and "nil".
60
+ IGNORE_TOKENS = [:space, :content, :string, :method, :ident,
61
+ :constant, :pre_constant, :predefined_constant]
62
+
63
+ # Tokens that indicate the end of a statement (i.e. that, if they appear
64
+ # directly before an "if" indicates that that if applies to the same line,
65
+ # not the next line)
66
+ #
67
+ # :reserved and :keywords are the CodeRay 0.9.8 and 1.0.0 respectively
68
+ # classifications of "super", "next", "return", etc.
69
+ STATEMENT_END_TOKENS = IGNORE_TOKENS + [:regexp, :integer, :float,
70
+ :keyword, :delimiter, :reserved,
71
+ :instance_variable,
72
+ :class_variable, :global_variable]
73
+
74
+ # Collection of tokens that should appear dedented even though they
75
+ # don't affect the surrounding code.
76
+ MIDWAY_TOKENS = %w(when else elsif ensure rescue)
77
+
78
+ # Clean the indentation of a fragment of ruby.
79
+ #
80
+ # @param [String] str
81
+ # @return [String]
82
+ def self.indent(str)
83
+ new.indent(str)
84
+ end
85
+
86
+ # Get the module nesting at the given point in the given string.
87
+ #
88
+ # NOTE If the line specified contains a method definition, then the nesting
89
+ # at the start of the method definition is used. Otherwise the nesting from
90
+ # the end of the line is used.
91
+ #
92
+ # @param [String] str The ruby code to analyze
93
+ # @param [Fixnum] line_number The line number (starting from 1)
94
+ # @return [Array<String>]
95
+ def self.nesting_at(str, line_number)
96
+ indent = new
97
+ lines = str.split("\n")
98
+ n = line_number - 1
99
+ to_indent = lines[0...n] << (lines[n] || "").split("def").first(1)
100
+ indent.indent(to_indent.join("\n") << "\n")
101
+ indent.module_nesting
102
+ end
103
+
104
+ def initialize
105
+ reset
106
+ end
107
+
108
+ # reset internal state
109
+ def reset
110
+ @stack = []
111
+ @indent_level = ''
112
+ @heredoc_queue = []
113
+ @close_heredocs = {}
114
+ @string_start = nil
115
+ @awaiting_class = false
116
+ @module_nesting = []
117
+ self
118
+ end
119
+
120
+ # Indents a string and returns it. This string can either be a single line
121
+ # or multiple ones.
122
+ #
123
+ # @example
124
+ # str = <<TXT
125
+ # class User
126
+ # attr_accessor :name
127
+ # end
128
+ # TXT
129
+ #
130
+ # # This would result in the following being displayed:
131
+ # #
132
+ # # class User
133
+ # # attr_accessor :name
134
+ # # end
135
+ # #
136
+ # puts Pry::Indent.new.indent(str)
137
+ #
138
+ # @param [String] input The input string to indent.
139
+ # @return [String] The indented version of +input+.
140
+ #
141
+ def indent(input)
142
+ output = ''
143
+ prefix = indent_level
144
+
145
+ input.lines.each do |line|
146
+ if in_string?
147
+ tokens = tokenize("#{open_delimiters_line}\n#{line}")
148
+ tokens = tokens.drop_while { |token, type| !(String === token && token.include?("\n")) }
149
+ previously_in_string = true
150
+ else
151
+ tokens = tokenize(line)
152
+ previously_in_string = false
153
+ end
154
+
155
+ before, after = indentation_delta(tokens)
156
+
157
+ before.times { prefix.sub! SPACES, '' }
158
+ new_prefix = prefix + SPACES * after
159
+
160
+ line = prefix + line.lstrip unless previously_in_string
161
+
162
+ output += line
163
+
164
+ prefix = new_prefix
165
+ end
166
+
167
+ @indent_level = prefix
168
+
169
+ return output
170
+ end
171
+
172
+ # Get the indentation for the start of the next line.
173
+ #
174
+ # This is what's used between the prompt and the cursor in pry.
175
+ #
176
+ # @return String The correct number of spaces
177
+ #
178
+ def current_prefix
179
+ in_string? ? '' : indent_level
180
+ end
181
+
182
+ # Get the change in indentation indicated by the line.
183
+ #
184
+ # By convention, you remove indent from the line containing end tokens,
185
+ # but add indent to the line *after* that which contains the start tokens.
186
+ #
187
+ # This method returns a pair, where the first number is the number of closings
188
+ # on this line (i.e. the number of indents to remove before the line) and the
189
+ # second is the number of openings (i.e. the number of indents to add after
190
+ # this line)
191
+ #
192
+ # @param [Array] tokens A list of tokens to scan.
193
+ # @return [Array[Integer]]
194
+ #
195
+ def indentation_delta(tokens)
196
+
197
+ # We need to keep track of whether we've seen a "for" on this line because
198
+ # if the line ends with "do" then that "do" should be discounted (i.e. we're
199
+ # only opening one level not two) To do this robustly we want to keep track
200
+ # of the indent level at which we saw the for, so we can differentiate
201
+ # between "for x in [1,2,3] do" and "for x in ([1,2,3].map do" properly
202
+ seen_for_at = []
203
+
204
+ # When deciding whether an "if" token is the start of a multiline statement,
205
+ # or just the middle of a single-line if statement, we just look at the
206
+ # preceding token, which is tracked here.
207
+ last_token, last_kind = [nil, nil]
208
+
209
+ # delta keeps track of the total difference from the start of each line after
210
+ # the given token, 0 is just the level at which the current line started for
211
+ # reference.
212
+ remove_before, add_after = [0, 0]
213
+
214
+ # If the list of tokens contains a matching closing token the line should
215
+ # not be indented (and thus we should return true).
216
+ tokens.each do |token, kind|
217
+ is_singleline_if = (SINGLELINE_TOKENS.include?(token)) && end_of_statement?(last_token, last_kind)
218
+ is_optional_do = (token == "do" && seen_for_at.include?(add_after - 1))
219
+
220
+ last_token, last_kind = token, kind unless kind == :space
221
+ next if IGNORE_TOKENS.include?(kind)
222
+
223
+ track_module_nesting(token, kind)
224
+
225
+ seen_for_at << add_after if OPTIONAL_DO_TOKENS.include?(token)
226
+
227
+ next if is_singleline_if
228
+
229
+ if kind == :delimiter
230
+ track_delimiter(token)
231
+ elsif OPEN_TOKENS.keys.include?(token) && !is_optional_do && !is_singleline_if
232
+ @stack << token
233
+ add_after += 1
234
+ elsif token == OPEN_TOKENS[@stack.last]
235
+ popped = @stack.pop
236
+ track_module_nesting_end(popped)
237
+ if add_after == 0
238
+ remove_before += 1
239
+ else
240
+ add_after -= 1
241
+ end
242
+ elsif MIDWAY_TOKENS.include?(token)
243
+ if add_after == 0
244
+ remove_before += 1
245
+ add_after += 1
246
+ end
247
+ end
248
+ end
249
+
250
+ return [remove_before, add_after]
251
+ end
252
+
253
+ # If the code just before an "if" or "while" token on a line looks like the end of a statement,
254
+ # then we want to treat that "if" as a singleline, not multiline statement.
255
+ def end_of_statement?(last_token, last_kind)
256
+ (last_token =~ /^[)\]}\/]$/ || STATEMENT_END_TOKENS.include?(last_kind))
257
+ end
258
+
259
+ # Are we currently in the middle of a string literal.
260
+ #
261
+ # This is used to determine whether to re-indent a given line, we mustn't re-indent
262
+ # within string literals because to do so would actually change the value of the
263
+ # String!
264
+ #
265
+ # @return Boolean
266
+ def in_string?
267
+ !open_delimiters.empty?
268
+ end
269
+
270
+ # Given a string of Ruby code, use CodeRay to export the tokens.
271
+ #
272
+ # @param [String] string The Ruby to lex
273
+ # @return [Array] An Array of pairs of [token_value, token_type]
274
+ def tokenize(string)
275
+ tokens = CodeRay.scan(string, :ruby)
276
+ tokens = tokens.tokens.each_slice(2) if tokens.respond_to?(:tokens) # Coderay 1.0.0
277
+ tokens.to_a
278
+ end
279
+
280
+ # Update the internal state about what kind of strings are open.
281
+ #
282
+ # Most of the complication here comes from the fact that HEREDOCs can be nested. For
283
+ # normal strings (which can't be nested) we assume that CodeRay correctly pairs
284
+ # open-and-close delimiters so we don't bother checking what they are.
285
+ #
286
+ # @param [String] token The token (of type :delimiter)
287
+ def track_delimiter(token)
288
+ case token
289
+ when /^<<-(["'`]?)(.*)\\1/
290
+ @heredoc_queue << token
291
+ @close_heredocs[token] = /^\s*$2/
292
+ when @close_heredocs[@heredoc_queue.first]
293
+ @heredoc_queue.shift
294
+ else
295
+ if @string_start
296
+ @string_start = nil
297
+ else
298
+ @string_start = token
299
+ end
300
+ end
301
+ end
302
+
303
+ # All the open delimiters, in the order that they first appeared.
304
+ #
305
+ # @return [String]
306
+ def open_delimiters
307
+ @heredoc_queue + [@string_start].compact
308
+ end
309
+
310
+ # Return a string which restores the CodeRay string status to the correct value by
311
+ # opening HEREDOCs and strings.
312
+ #
313
+ # @return String
314
+ def open_delimiters_line
315
+ "puts #{open_delimiters.join(", ")}"
316
+ end
317
+
318
+ # Update the internal state relating to module nesting.
319
+ #
320
+ # It's responsible for adding to the @module_nesting array, which looks
321
+ # something like:
322
+ #
323
+ # [ ["class", "Foo"], ["module", "Bar::Baz"], ["class <<", "self"] ]
324
+ #
325
+ # A nil value in the @module_nesting array happens in two places: either
326
+ # when @awaiting_class is true and we're still waiting for the string to
327
+ # fill that space, or when a parse was rejected.
328
+ #
329
+ # At the moment this function is quite restricted about what formats it will
330
+ # parse, for example we disallow expressions after the class keyword. This
331
+ # could maybe be improved in the future.
332
+ #
333
+ # @param [String] token a token from Coderay
334
+ # @param [Symbol] kind the kind of that token
335
+ def track_module_nesting(token, kind)
336
+ if kind == :keyword && (token == "class" || token == "module")
337
+ @module_nesting << [token, nil]
338
+ @awaiting_class = true
339
+ elsif @awaiting_class
340
+ if kind == :operator && token == "<<" && @module_nesting.last[0] == "class"
341
+ @module_nesting.last[0] = "class <<"
342
+ @awaiting_class = true
343
+ elsif kind == :class && token =~ /\A(self|[A-Z:][A-Za-z0-9_:]*)\z/
344
+ @module_nesting.last[1] = token if kind == :class
345
+ @awaiting_class = false
346
+ else
347
+ # leave @module_nesting[-1]
348
+ @awaiting_class = false
349
+ end
350
+ end
351
+ end
352
+
353
+ # Update the internal state relating to module nesting on 'end'.
354
+ #
355
+ # If the current 'end' pairs up with a class or a module then we should
356
+ # pop an array off of @module_nesting
357
+ #
358
+ # @param [String] token a token from Coderay
359
+ # @param [Symbol] kind the kind of that token
360
+ def track_module_nesting_end(token, kind = :keyword)
361
+ if kind == :keyword && (token == "class" || token == "module")
362
+ @module_nesting.pop
363
+ end
364
+ end
365
+
366
+ # Return a list of strings which can be used to re-construct the Module.nesting at
367
+ # the current point in the file.
368
+ #
369
+ # Returns nil if the syntax of the file was not recognizable.
370
+ #
371
+ # @return [Array<String>]
372
+ def module_nesting
373
+ @module_nesting.map do |(kind, token)|
374
+ raise UnparseableNestingError, @module_nesting.inspect if token.nil?
375
+
376
+ "#{kind} #{token}"
377
+ end
378
+ end
379
+
380
+ # Return a string which, when printed, will rewrite the previous line with
381
+ # the correct indentation. Mostly useful for fixing 'end'.
382
+ #
383
+ # @param [String] prompt The user's prompt
384
+ # @param [String] code The code the user just typed in
385
+ # @param [Integer] overhang The number of characters to erase afterwards (the
386
+ # the difference in length between the old line and the new one)
387
+ #
388
+ # @return [String] correctly indented line
389
+ def correct_indentation(prompt, code, overhang = 0)
390
+ prompt = prompt.delete("\001\002")
391
+ line_to_measure = Pry::Helpers::Text.strip_color(prompt) << code
392
+ whitespace = ' ' * overhang
393
+
394
+ cols = Terminal.width!
395
+ lines = cols == 0 ? 1 : (line_to_measure.length / cols + 1).to_i
396
+
397
+ if Helpers::Platform.windows_ansi?
398
+ move_up = "\e[#{lines}F"
399
+ move_down = "\e[#{lines}E"
400
+ else
401
+ move_up = "\e[#{lines}A\e[0G"
402
+ move_down = "\e[#{lines}B\e[0G"
403
+ end
404
+
405
+ "#{move_up}#{prompt}#{colorize_code(code)}#{whitespace}#{move_down}"
406
+ end
407
+ end
408
+ end