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.
- checksums.yaml +7 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +21 -0
- data/README.md +26 -0
- data/chess_engine.gemspec +14 -0
- data/lib/chess_engine/board.rb +95 -0
- data/lib/chess_engine/cli.rb +105 -0
- data/lib/chess_engine/game.rb +148 -0
- data/lib/chess_engine/input.rb +19 -0
- data/lib/chess_engine/move.rb +35 -0
- data/lib/chess_engine/piece.rb +97 -0
- data/lib/chess_engine/validator.rb +87 -0
- data/lib/chess_engine.rb +1 -0
- data/spec/board_spec.rb +70 -0
- data/spec/game_helper.rb +5 -0
- data/spec/game_spec.rb +79 -0
- data/spec/spec_helper.rb +100 -0
- data/spec/validator_spec.rb +26 -0
- data/vendor/bundle/bin/coderay +27 -0
- data/vendor/bundle/bin/pry +27 -0
- data/vendor/bundle/cache/coderay-1.1.2.gem +0 -0
- data/vendor/bundle/cache/colorize-0.8.1.gem +0 -0
- data/vendor/bundle/cache/method_source-0.9.2.gem +0 -0
- data/vendor/bundle/cache/pry-0.12.2.gem +0 -0
- data/vendor/bundle/cache/rb-readline-0.5.5.gem +0 -0
- data/vendor/bundle/gems/coderay-1.1.2/MIT-LICENSE +22 -0
- data/vendor/bundle/gems/coderay-1.1.2/README_INDEX.rdoc +123 -0
- data/vendor/bundle/gems/coderay-1.1.2/bin/coderay +215 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/duo.rb +81 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/_map.rb +17 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/comment_filter.rb +25 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/count.rb +39 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/debug.rb +49 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/debug_lint.rb +63 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/div.rb +23 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/encoder.rb +190 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/filter.rb +58 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html/css.rb +65 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html/numbering.rb +108 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html/output.rb +166 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html.rb +333 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/json.rb +83 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb +45 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/lint.rb +59 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/null.rb +18 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/page.rb +24 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/span.rb +23 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/statistic.rb +95 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/terminal.rb +195 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/text.rb +46 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/token_kind_filter.rb +111 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/xml.rb +72 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/yaml.rb +50 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders.rb +18 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/for_redcloth.rb +95 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/file_type.rb +151 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/plugin.rb +55 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/plugin_host.rb +221 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/word_list.rb +72 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/_map.rb +24 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/c.rb +189 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/clojure.rb +217 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/cpp.rb +217 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/css.rb +196 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/debug.rb +75 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/delphi.rb +144 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/diff.rb +221 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/erb.rb +81 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/go.rb +208 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/groovy.rb +268 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/haml.rb +168 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/html.rb +275 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/java/builtin_types.rb +421 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/java.rb +174 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/java_script.rb +237 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/json.rb +98 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/lua.rb +280 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/php.rb +527 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/python.rb +287 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/raydebug.rb +75 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/ruby/patterns.rb +178 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/ruby/string_state.rb +79 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/ruby.rb +477 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/sass.rb +232 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/scanner.rb +337 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/sql.rb +169 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/taskpaper.rb +36 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/text.rb +26 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/xml.rb +17 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/yaml.rb +140 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners.rb +27 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles/_map.rb +7 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles/alpha.rb +153 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles/style.rb +18 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles.rb +15 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/token_kinds.rb +85 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/tokens.rb +161 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/tokens_proxy.rb +55 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/version.rb +3 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay.rb +284 -0
- data/vendor/bundle/gems/colorize-0.8.1/CHANGELOG +65 -0
- data/vendor/bundle/gems/colorize-0.8.1/LICENSE +339 -0
- data/vendor/bundle/gems/colorize-0.8.1/README.md +105 -0
- data/vendor/bundle/gems/colorize-0.8.1/Rakefile +13 -0
- data/vendor/bundle/gems/colorize-0.8.1/colorize.gemspec +36 -0
- data/vendor/bundle/gems/colorize-0.8.1/lib/colorize/class_methods.rb +120 -0
- data/vendor/bundle/gems/colorize-0.8.1/lib/colorize/instance_methods.rb +132 -0
- data/vendor/bundle/gems/colorize-0.8.1/lib/colorize.rb +12 -0
- data/vendor/bundle/gems/colorize-0.8.1/lib/colorized_string.rb +19 -0
- data/vendor/bundle/gems/colorize-0.8.1/test/test_colorize.rb +164 -0
- data/vendor/bundle/gems/method_source-0.9.2/Gemfile +2 -0
- data/vendor/bundle/gems/method_source-0.9.2/LICENSE +25 -0
- data/vendor/bundle/gems/method_source-0.9.2/README.markdown +91 -0
- data/vendor/bundle/gems/method_source-0.9.2/Rakefile +81 -0
- data/vendor/bundle/gems/method_source-0.9.2/lib/method_source/code_helpers.rb +154 -0
- data/vendor/bundle/gems/method_source-0.9.2/lib/method_source/source_location.rb +138 -0
- data/vendor/bundle/gems/method_source-0.9.2/lib/method_source/version.rb +3 -0
- data/vendor/bundle/gems/method_source-0.9.2/lib/method_source.rb +141 -0
- data/vendor/bundle/gems/method_source-0.9.2/method_source.gemspec +35 -0
- data/vendor/bundle/gems/method_source-0.9.2/spec/method_source/code_helpers_spec.rb +43 -0
- data/vendor/bundle/gems/method_source-0.9.2/spec/method_source_spec.rb +143 -0
- data/vendor/bundle/gems/method_source-0.9.2/spec/spec_helper.rb +101 -0
- data/vendor/bundle/gems/pry-0.12.2/CHANGELOG.md +953 -0
- data/vendor/bundle/gems/pry-0.12.2/LICENSE +25 -0
- data/vendor/bundle/gems/pry-0.12.2/README.md +390 -0
- data/vendor/bundle/gems/pry-0.12.2/bin/pry +8 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/basic_object.rb +6 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/cli.rb +218 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/code/code_file.rb +110 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/code/code_range.rb +71 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/code/loc.rb +98 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/code.rb +353 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/code_object.rb +195 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/color_printer.rb +65 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/command.rb +723 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/command_set.rb +415 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/amend_line.rb +98 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/bang.rb +20 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/bang_pry.rb +17 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/abstract_formatter.rb +27 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/exception_formatter.rb +79 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/file_formatter.rb +71 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat.rb +63 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cd.rb +41 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/change_inspector.rb +27 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/change_prompt.rb +46 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/clear_screen.rb +14 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/code_collector.rb +167 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/disable_pry.rb +27 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/disabled_commands.rb +2 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/easter_eggs.rb +112 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/edit/exception_patcher.rb +25 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/edit/file_and_line_locator.rb +36 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/edit.rb +200 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/exit.rb +43 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/exit_all.rb +29 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/exit_program.rb +23 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/find_method.rb +191 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/fix_indent.rb +19 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_cd.rb +26 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_install.rb +32 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_list.rb +33 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_open.rb +29 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_readme.rb +25 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_search.rb +40 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_stats.rb +83 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gist.rb +102 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/help.rb +164 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/hist.rb +181 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/import_set.rb +23 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/install_command.rb +54 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/jump_to.rb +29 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/list_inspectors.rb +35 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/constants.rb +58 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/formatter.rb +51 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/globals.rb +46 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/grep.rb +19 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/instance_vars.rb +38 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/interrogatable.rb +18 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/jruby_hacks.rb +49 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/local_names.rb +33 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/local_vars.rb +37 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/ls_entity.rb +69 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/methods.rb +54 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/methods_helper.rb +46 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/self_methods.rb +33 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls.rb +113 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/nesting.rb +25 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/play.rb +102 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/pry_backtrace.rb +25 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/pry_version.rb +17 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/raise_up.rb +33 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/reload_code.rb +62 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/reset.rb +18 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ri.rb +65 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/save_file.rb +61 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/shell_command.rb +75 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/shell_mode.rb +25 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_doc.rb +81 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_info.rb +216 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_input.rb +17 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_source.rb +53 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/stat.rb +40 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/switch_to.rb +23 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/toggle_color.rb +24 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/watch_expression/expression.rb +38 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/watch_expression.rb +107 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/whereami.rb +197 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/wtf.rb +70 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands.rb +6 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/behavior.rb +255 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/convenience.rb +28 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/default.rb +159 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/memoization.rb +48 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/config.rb +35 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/core_extensions.rb +142 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/editor.rb +128 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/exceptions.rb +76 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/forwardable.rb +23 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/base_helpers.rb +200 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/command_helpers.rb +157 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/documentation_helpers.rb +76 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/options_helpers.rb +27 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/platform.rb +58 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/table.rb +114 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/text.rb +115 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers.rb +6 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/history.rb +161 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/hooks.rb +171 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/indent.rb +408 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/input_completer.rb +265 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/input_lock.rb +130 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/inspector.rb +27 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/last_exception.rb +61 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/method/disowned.rb +55 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/method/patcher.rb +122 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/method/weird_method_locator.rb +198 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/method.rb +552 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/object_path.rb +83 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/output.rb +50 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/pager.rb +250 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/platform.rb +91 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/plugins.rb +122 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/prompt.rb +145 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/pry_class.rb +425 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/pry_instance.rb +699 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/repl.rb +261 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/repl_file_loader.rb +73 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/ring.rb +84 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/rubygem.rb +84 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop/LICENSE +20 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop/commands.rb +195 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop/option.rb +206 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop.rb +661 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/terminal.rb +91 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/evalable.rb +15 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/mockable.rb +14 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/pry_tester.rb +73 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/utility.rb +26 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/variables.rb +46 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable.rb +70 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/version.rb +3 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/wrapped_module/candidate.rb +131 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/wrapped_module.rb +378 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry.rb +132 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/CHANGES +94 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/LICENSE +25 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/README.md +81 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/Rakefile +25 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/bench/_rl_adjust_point.rb +26 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/examples/example_readline.rb +8 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/examples/example_readline_with_completion.rb +18 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/examples/tinyirb.rb +11 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/lib/rb-readline.rb +18 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/lib/rbreadline/version.rb +3 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/lib/rbreadline.rb +8920 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/lib/readline.rb +539 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/rb-readline.gemspec +51 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/setup.rb +1585 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/test/support/filesystem_completion_helper.rb +53 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/test/test_completion.rb +100 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/test/test_filename_completion_proc.rb +88 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/test/test_history.rb +29 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/test/test_rbreadline.rb +23 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/test/test_readline.rb +221 -0
- data/vendor/bundle/specifications/coderay-1.1.2.gemspec +26 -0
- data/vendor/bundle/specifications/colorize-0.8.1.gemspec +38 -0
- data/vendor/bundle/specifications/method_source-0.9.2.gemspec +35 -0
- data/vendor/bundle/specifications/pry-0.12.2.gemspec +38 -0
- data/vendor/bundle/specifications/rb-readline-0.5.5.gemspec +39 -0
- metadata +363 -0
@@ -0,0 +1,232 @@
|
|
1
|
+
module CodeRay
|
2
|
+
module Scanners
|
3
|
+
|
4
|
+
# A scanner for Sass.
|
5
|
+
class Sass < CSS
|
6
|
+
|
7
|
+
register_for :sass
|
8
|
+
file_extension 'sass'
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@state = :initial
|
14
|
+
end
|
15
|
+
|
16
|
+
def scan_tokens encoder, options
|
17
|
+
states = Array(options[:state] || @state).dup
|
18
|
+
|
19
|
+
encoder.begin_group :string if states.last == :sqstring || states.last == :dqstring
|
20
|
+
|
21
|
+
until eos?
|
22
|
+
|
23
|
+
if bol? && (match = scan(/(?>( +)?(\/[\*\/])(.+)?)(?=\n)/))
|
24
|
+
encoder.text_token self[1], :space if self[1]
|
25
|
+
encoder.begin_group :comment
|
26
|
+
encoder.text_token self[2], :delimiter
|
27
|
+
encoder.text_token self[3], :content if self[3]
|
28
|
+
if match = scan(/(?:\n+#{self[1]} .*)+/)
|
29
|
+
encoder.text_token match, :content
|
30
|
+
end
|
31
|
+
encoder.end_group :comment
|
32
|
+
elsif match = scan(/\n|[^\n\S]+\n?/)
|
33
|
+
encoder.text_token match, :space
|
34
|
+
if match.index(/\n/)
|
35
|
+
value_expected = false
|
36
|
+
states.pop if states.last == :include
|
37
|
+
end
|
38
|
+
|
39
|
+
elsif states.last == :sass_inline && (match = scan(/\}/))
|
40
|
+
encoder.text_token match, :inline_delimiter
|
41
|
+
encoder.end_group :inline
|
42
|
+
states.pop
|
43
|
+
|
44
|
+
elsif case states.last
|
45
|
+
when :initial, :media, :sass_inline
|
46
|
+
if match = scan(/(?>#{RE::Ident})(?!\()/ox)
|
47
|
+
encoder.text_token match, value_expected ? :value : (check(/.*:(?![a-z])/) ? :key : :tag)
|
48
|
+
next
|
49
|
+
elsif !value_expected && (match = scan(/\*/))
|
50
|
+
encoder.text_token match, :tag
|
51
|
+
next
|
52
|
+
elsif match = scan(RE::Class)
|
53
|
+
encoder.text_token match, :class
|
54
|
+
next
|
55
|
+
elsif match = scan(RE::Id)
|
56
|
+
encoder.text_token match, :id
|
57
|
+
next
|
58
|
+
elsif match = scan(RE::PseudoClass)
|
59
|
+
encoder.text_token match, :pseudo_class
|
60
|
+
next
|
61
|
+
elsif match = scan(RE::AttributeSelector)
|
62
|
+
# TODO: Improve highlighting inside of attribute selectors.
|
63
|
+
encoder.text_token match[0,1], :operator
|
64
|
+
encoder.text_token match[1..-2], :attribute_name if match.size > 2
|
65
|
+
encoder.text_token match[-1,1], :operator if match[-1] == ?]
|
66
|
+
next
|
67
|
+
elsif match = scan(/(\=|@mixin +)#{RE::Ident}/o)
|
68
|
+
encoder.text_token match, :function
|
69
|
+
next
|
70
|
+
elsif match = scan(/@import\b/)
|
71
|
+
encoder.text_token match, :directive
|
72
|
+
states << :include
|
73
|
+
next
|
74
|
+
elsif match = scan(/@media\b/)
|
75
|
+
encoder.text_token match, :directive
|
76
|
+
# states.push :media_before_name
|
77
|
+
next
|
78
|
+
end
|
79
|
+
|
80
|
+
when :block
|
81
|
+
if match = scan(/(?>#{RE::Ident})(?!\()/ox)
|
82
|
+
if value_expected
|
83
|
+
encoder.text_token match, :value
|
84
|
+
else
|
85
|
+
encoder.text_token match, :key
|
86
|
+
end
|
87
|
+
next
|
88
|
+
end
|
89
|
+
|
90
|
+
when :sqstring, :dqstring
|
91
|
+
if match = scan(states.last == :sqstring ? /(?:[^\n\'\#]+|\\\n|#{RE::Escape}|#(?!\{))+/o : /(?:[^\n\"\#]+|\\\n|#{RE::Escape}|#(?!\{))+/o)
|
92
|
+
encoder.text_token match, :content
|
93
|
+
elsif match = scan(/['"]/)
|
94
|
+
encoder.text_token match, :delimiter
|
95
|
+
encoder.end_group :string
|
96
|
+
states.pop
|
97
|
+
elsif match = scan(/#\{/)
|
98
|
+
encoder.begin_group :inline
|
99
|
+
encoder.text_token match, :inline_delimiter
|
100
|
+
states.push :sass_inline
|
101
|
+
elsif match = scan(/ \\ | $ /x)
|
102
|
+
encoder.end_group states.last
|
103
|
+
encoder.text_token match, :error unless match.empty?
|
104
|
+
states.pop
|
105
|
+
else
|
106
|
+
raise_inspect "else case #{states.last} reached; %p not handled." % peek(1), encoder
|
107
|
+
end
|
108
|
+
|
109
|
+
when :include
|
110
|
+
if match = scan(/[^\s'",]+/)
|
111
|
+
encoder.text_token match, :include
|
112
|
+
next
|
113
|
+
end
|
114
|
+
|
115
|
+
else
|
116
|
+
#:nocov:
|
117
|
+
raise_inspect 'Unknown state: %p' % [states.last], encoder
|
118
|
+
#:nocov:
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
elsif match = scan(/\$#{RE::Ident}/o)
|
123
|
+
encoder.text_token match, :variable
|
124
|
+
next
|
125
|
+
|
126
|
+
elsif match = scan(/&/)
|
127
|
+
encoder.text_token match, :local_variable
|
128
|
+
|
129
|
+
elsif match = scan(/\+#{RE::Ident}/o)
|
130
|
+
encoder.text_token match, :include
|
131
|
+
value_expected = true
|
132
|
+
|
133
|
+
elsif match = scan(/\/\*(?:.*?\*\/|.*)|\/\/.*/)
|
134
|
+
encoder.text_token match, :comment
|
135
|
+
|
136
|
+
elsif match = scan(/#\{/)
|
137
|
+
encoder.begin_group :inline
|
138
|
+
encoder.text_token match, :inline_delimiter
|
139
|
+
states.push :sass_inline
|
140
|
+
|
141
|
+
elsif match = scan(/\{/)
|
142
|
+
value_expected = false
|
143
|
+
encoder.text_token match, :operator
|
144
|
+
states.push :block
|
145
|
+
|
146
|
+
elsif match = scan(/\}/)
|
147
|
+
value_expected = false
|
148
|
+
encoder.text_token match, :operator
|
149
|
+
if states.last == :block || states.last == :media
|
150
|
+
states.pop
|
151
|
+
end
|
152
|
+
|
153
|
+
elsif match = scan(/['"]/)
|
154
|
+
encoder.begin_group :string
|
155
|
+
encoder.text_token match, :delimiter
|
156
|
+
if states.include? :sass_inline
|
157
|
+
# no nesting, just scan the string until delimiter
|
158
|
+
content = scan_until(/(?=#{match}|\}|\z)/)
|
159
|
+
encoder.text_token content, :content unless content.empty?
|
160
|
+
encoder.text_token match, :delimiter if scan(/#{match}/)
|
161
|
+
encoder.end_group :string
|
162
|
+
else
|
163
|
+
states.push match == "'" ? :sqstring : :dqstring
|
164
|
+
end
|
165
|
+
|
166
|
+
elsif match = scan(/#{RE::Function}/o)
|
167
|
+
encoder.begin_group :function
|
168
|
+
start = match[/^[-\w]+\(/]
|
169
|
+
encoder.text_token start, :delimiter
|
170
|
+
if match[-1] == ?)
|
171
|
+
encoder.text_token match[start.size..-2], :content
|
172
|
+
encoder.text_token ')', :delimiter
|
173
|
+
else
|
174
|
+
encoder.text_token match[start.size..-1], :content if start.size < match.size
|
175
|
+
end
|
176
|
+
encoder.end_group :function
|
177
|
+
|
178
|
+
elsif match = scan(/[a-z][-a-z_]*(?=\()/o)
|
179
|
+
encoder.text_token match, :predefined
|
180
|
+
|
181
|
+
elsif match = scan(/(?: #{RE::Dimension} | #{RE::Percentage} | #{RE::Num} )/ox)
|
182
|
+
encoder.text_token match, :float
|
183
|
+
|
184
|
+
elsif match = scan(/#{RE::HexColor}/o)
|
185
|
+
encoder.text_token match, :color
|
186
|
+
|
187
|
+
elsif match = scan(/! *(?:important|optional)/)
|
188
|
+
encoder.text_token match, :important
|
189
|
+
|
190
|
+
elsif match = scan(/(?:rgb|hsl)a?\([^()\n]*\)?/)
|
191
|
+
encoder.text_token match, :color
|
192
|
+
|
193
|
+
elsif match = scan(/@else if\b|#{RE::AtKeyword}/o)
|
194
|
+
encoder.text_token match, :directive
|
195
|
+
value_expected = true
|
196
|
+
|
197
|
+
elsif match = scan(/ == | != | [-+*\/>~:;,.=()] /x)
|
198
|
+
if match == ':'
|
199
|
+
value_expected = true
|
200
|
+
elsif match == ';'
|
201
|
+
value_expected = false
|
202
|
+
end
|
203
|
+
encoder.text_token match, :operator
|
204
|
+
|
205
|
+
else
|
206
|
+
encoder.text_token getch, :error
|
207
|
+
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
211
|
+
|
212
|
+
states.pop if states.last == :include
|
213
|
+
|
214
|
+
if options[:keep_state]
|
215
|
+
@state = states.dup
|
216
|
+
end
|
217
|
+
|
218
|
+
while state = states.pop
|
219
|
+
if state == :sass_inline
|
220
|
+
encoder.end_group :inline
|
221
|
+
elsif state == :sqstring || state == :dqstring
|
222
|
+
encoder.end_group :string
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
encoder
|
227
|
+
end
|
228
|
+
|
229
|
+
end
|
230
|
+
|
231
|
+
end
|
232
|
+
end
|
@@ -0,0 +1,337 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module CodeRay
|
4
|
+
module Scanners
|
5
|
+
|
6
|
+
# = Scanner
|
7
|
+
#
|
8
|
+
# The base class for all Scanners.
|
9
|
+
#
|
10
|
+
# It is a subclass of Ruby's great +StringScanner+, which
|
11
|
+
# makes it easy to access the scanning methods inside.
|
12
|
+
#
|
13
|
+
# It is also +Enumerable+, so you can use it like an Array of
|
14
|
+
# Tokens:
|
15
|
+
#
|
16
|
+
# require 'coderay'
|
17
|
+
#
|
18
|
+
# c_scanner = CodeRay::Scanners[:c].new "if (*p == '{') nest++;"
|
19
|
+
#
|
20
|
+
# for text, kind in c_scanner
|
21
|
+
# puts text if kind == :operator
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# # prints: (*==)++;
|
25
|
+
#
|
26
|
+
# OK, this is a very simple example :)
|
27
|
+
# You can also use +map+, +any?+, +find+ and even +sort_by+,
|
28
|
+
# if you want.
|
29
|
+
class Scanner < StringScanner
|
30
|
+
|
31
|
+
extend Plugin
|
32
|
+
plugin_host Scanners
|
33
|
+
|
34
|
+
# Raised if a Scanner fails while scanning
|
35
|
+
ScanError = Class.new StandardError
|
36
|
+
|
37
|
+
# The default options for all scanner classes.
|
38
|
+
#
|
39
|
+
# Define @default_options for subclasses.
|
40
|
+
DEFAULT_OPTIONS = { }
|
41
|
+
|
42
|
+
KINDS_NOT_LOC = [:comment, :doctype, :docstring]
|
43
|
+
|
44
|
+
attr_accessor :state
|
45
|
+
|
46
|
+
class << self
|
47
|
+
|
48
|
+
# Normalizes the given code into a string with UNIX newlines, in the
|
49
|
+
# scanner's internal encoding, with invalid and undefined charachters
|
50
|
+
# replaced by placeholders. Always returns a new object.
|
51
|
+
def normalize code
|
52
|
+
# original = code
|
53
|
+
code = code.to_s unless code.is_a? ::String
|
54
|
+
return code if code.empty?
|
55
|
+
|
56
|
+
if code.respond_to? :encoding
|
57
|
+
code = encode_with_encoding code, self.encoding
|
58
|
+
else
|
59
|
+
code = to_unix code
|
60
|
+
end
|
61
|
+
# code = code.dup if code.eql? original
|
62
|
+
code
|
63
|
+
end
|
64
|
+
|
65
|
+
# The typical filename suffix for this scanner's language.
|
66
|
+
def file_extension extension = lang
|
67
|
+
@file_extension ||= extension.to_s
|
68
|
+
end
|
69
|
+
|
70
|
+
# The encoding used internally by this scanner.
|
71
|
+
def encoding name = 'UTF-8'
|
72
|
+
@encoding ||= defined?(Encoding.find) && Encoding.find(name)
|
73
|
+
end
|
74
|
+
|
75
|
+
# The lang of this Scanner class, which is equal to its Plugin ID.
|
76
|
+
def lang
|
77
|
+
@plugin_id
|
78
|
+
end
|
79
|
+
|
80
|
+
protected
|
81
|
+
|
82
|
+
def encode_with_encoding code, target_encoding
|
83
|
+
if code.encoding == target_encoding
|
84
|
+
if code.valid_encoding?
|
85
|
+
return to_unix(code)
|
86
|
+
else
|
87
|
+
source_encoding = guess_encoding code
|
88
|
+
end
|
89
|
+
else
|
90
|
+
source_encoding = code.encoding
|
91
|
+
end
|
92
|
+
# print "encode_with_encoding from #{source_encoding} to #{target_encoding}"
|
93
|
+
code.encode target_encoding, source_encoding, :universal_newline => true, :undef => :replace, :invalid => :replace
|
94
|
+
end
|
95
|
+
|
96
|
+
def to_unix code
|
97
|
+
code.index(?\r) ? code.gsub(/\r\n?/, "\n") : code
|
98
|
+
end
|
99
|
+
|
100
|
+
def guess_encoding s
|
101
|
+
#:nocov:
|
102
|
+
IO.popen("file -b --mime -", "w+") do |file|
|
103
|
+
file.write s[0, 1024]
|
104
|
+
file.close_write
|
105
|
+
begin
|
106
|
+
Encoding.find file.gets[/charset=([-\w]+)/, 1]
|
107
|
+
rescue ArgumentError
|
108
|
+
Encoding::BINARY
|
109
|
+
end
|
110
|
+
end
|
111
|
+
#:nocov:
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
# Create a new Scanner.
|
117
|
+
#
|
118
|
+
# * +code+ is the input String and is handled by the superclass
|
119
|
+
# StringScanner.
|
120
|
+
# * +options+ is a Hash with Symbols as keys.
|
121
|
+
# It is merged with the default options of the class (you can
|
122
|
+
# overwrite default options here.)
|
123
|
+
#
|
124
|
+
# Else, a Tokens object is used.
|
125
|
+
def initialize code = '', options = {}
|
126
|
+
if self.class == Scanner
|
127
|
+
raise NotImplementedError, "I am only the basic Scanner class. I can't scan anything. :( Use my subclasses."
|
128
|
+
end
|
129
|
+
|
130
|
+
@options = self.class::DEFAULT_OPTIONS.merge options
|
131
|
+
|
132
|
+
super self.class.normalize(code)
|
133
|
+
|
134
|
+
@tokens = options[:tokens] || Tokens.new
|
135
|
+
@tokens.scanner = self if @tokens.respond_to? :scanner=
|
136
|
+
|
137
|
+
setup
|
138
|
+
end
|
139
|
+
|
140
|
+
# Sets back the scanner. Subclasses should redefine the reset_instance
|
141
|
+
# method instead of this one.
|
142
|
+
def reset
|
143
|
+
super
|
144
|
+
reset_instance
|
145
|
+
end
|
146
|
+
|
147
|
+
# Set a new string to be scanned.
|
148
|
+
def string= code
|
149
|
+
code = self.class.normalize(code)
|
150
|
+
super code
|
151
|
+
reset_instance
|
152
|
+
end
|
153
|
+
|
154
|
+
# the Plugin ID for this scanner
|
155
|
+
def lang
|
156
|
+
self.class.lang
|
157
|
+
end
|
158
|
+
|
159
|
+
# the default file extension for this scanner
|
160
|
+
def file_extension
|
161
|
+
self.class.file_extension
|
162
|
+
end
|
163
|
+
|
164
|
+
# Scan the code and returns all tokens in a Tokens object.
|
165
|
+
def tokenize source = nil, options = {}
|
166
|
+
options = @options.merge(options)
|
167
|
+
|
168
|
+
set_tokens_from_options options
|
169
|
+
set_string_from_source source
|
170
|
+
|
171
|
+
begin
|
172
|
+
scan_tokens @tokens, options
|
173
|
+
rescue => e
|
174
|
+
message = "Error in %s#scan_tokens, initial state was: %p" % [self.class, defined?(state) && state]
|
175
|
+
raise_inspect e.message, @tokens, message, 30, e.backtrace
|
176
|
+
end
|
177
|
+
|
178
|
+
@cached_tokens = @tokens
|
179
|
+
if source.is_a? Array
|
180
|
+
@tokens.split_into_parts(*source.map { |part| part.size })
|
181
|
+
else
|
182
|
+
@tokens
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
# Cache the result of tokenize.
|
187
|
+
def tokens
|
188
|
+
@cached_tokens ||= tokenize
|
189
|
+
end
|
190
|
+
|
191
|
+
# Traverse the tokens.
|
192
|
+
def each &block
|
193
|
+
tokens.each(&block)
|
194
|
+
end
|
195
|
+
include Enumerable
|
196
|
+
|
197
|
+
# The current line position of the scanner, starting with 1.
|
198
|
+
# See also: #column.
|
199
|
+
#
|
200
|
+
# Beware, this is implemented inefficiently. It should be used
|
201
|
+
# for debugging only.
|
202
|
+
def line pos = self.pos
|
203
|
+
return 1 if pos <= 0
|
204
|
+
binary_string[0...pos].count("\n") + 1
|
205
|
+
end
|
206
|
+
|
207
|
+
# The current column position of the scanner, starting with 1.
|
208
|
+
# See also: #line.
|
209
|
+
def column pos = self.pos
|
210
|
+
return 1 if pos <= 0
|
211
|
+
pos - (binary_string.rindex(?\n, pos - 1) || -1)
|
212
|
+
end
|
213
|
+
|
214
|
+
# The string in binary encoding.
|
215
|
+
#
|
216
|
+
# To be used with #pos, which is the index of the byte the scanner
|
217
|
+
# will scan next.
|
218
|
+
def binary_string
|
219
|
+
@binary_string ||=
|
220
|
+
if string.respond_to?(:bytesize) && string.bytesize != string.size
|
221
|
+
#:nocov:
|
222
|
+
string.dup.force_encoding('binary')
|
223
|
+
#:nocov:
|
224
|
+
else
|
225
|
+
string
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
protected
|
230
|
+
|
231
|
+
# Can be implemented by subclasses to do some initialization
|
232
|
+
# that has to be done once per instance.
|
233
|
+
#
|
234
|
+
# Use reset for initialization that has to be done once per
|
235
|
+
# scan.
|
236
|
+
def setup # :doc:
|
237
|
+
end
|
238
|
+
|
239
|
+
def set_string_from_source source
|
240
|
+
case source
|
241
|
+
when Array
|
242
|
+
self.string = self.class.normalize(source.join)
|
243
|
+
when nil
|
244
|
+
reset
|
245
|
+
else
|
246
|
+
self.string = self.class.normalize(source)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
def set_tokens_from_options options
|
251
|
+
@tokens = options[:tokens] || @tokens || Tokens.new
|
252
|
+
@tokens.scanner = self if @tokens.respond_to? :scanner=
|
253
|
+
end
|
254
|
+
|
255
|
+
# This is the central method, and commonly the only one a
|
256
|
+
# subclass implements.
|
257
|
+
#
|
258
|
+
# Subclasses must implement this method; it must return +tokens+
|
259
|
+
# and must only use Tokens#<< for storing scanned tokens!
|
260
|
+
def scan_tokens tokens, options # :doc:
|
261
|
+
raise NotImplementedError, "#{self.class}#scan_tokens not implemented."
|
262
|
+
end
|
263
|
+
|
264
|
+
# Resets the scanner.
|
265
|
+
def reset_instance
|
266
|
+
@tokens.clear if @tokens.respond_to?(:clear) && !@options[:keep_tokens]
|
267
|
+
@cached_tokens = nil
|
268
|
+
@binary_string = nil if defined? @binary_string
|
269
|
+
end
|
270
|
+
|
271
|
+
SCAN_ERROR_MESSAGE = <<-MESSAGE
|
272
|
+
|
273
|
+
|
274
|
+
***ERROR in %s: %s (after %s tokens)
|
275
|
+
|
276
|
+
tokens:
|
277
|
+
%s
|
278
|
+
|
279
|
+
%s
|
280
|
+
|
281
|
+
surrounding code:
|
282
|
+
%p ~~ %p
|
283
|
+
|
284
|
+
|
285
|
+
***ERROR***
|
286
|
+
|
287
|
+
MESSAGE
|
288
|
+
|
289
|
+
def raise_inspect_arguments message, tokens, state, ambit
|
290
|
+
return File.basename(caller[0]),
|
291
|
+
message,
|
292
|
+
tokens_size(tokens),
|
293
|
+
tokens_last(tokens, 10).map(&:inspect).join("\n"),
|
294
|
+
scanner_state_info(state),
|
295
|
+
binary_string[pos - ambit, ambit],
|
296
|
+
binary_string[pos, ambit]
|
297
|
+
end
|
298
|
+
|
299
|
+
SCANNER_STATE_INFO = <<-INFO
|
300
|
+
current line: %d column: %d pos: %d
|
301
|
+
matched: %p state: %p
|
302
|
+
bol?: %p, eos?: %p
|
303
|
+
INFO
|
304
|
+
|
305
|
+
def scanner_state_info state
|
306
|
+
SCANNER_STATE_INFO % [
|
307
|
+
line, column, pos,
|
308
|
+
matched, state || 'No state given!',
|
309
|
+
bol?, eos?,
|
310
|
+
]
|
311
|
+
end
|
312
|
+
|
313
|
+
# Scanner error with additional status information
|
314
|
+
def raise_inspect message, tokens, state = self.state, ambit = 30, backtrace = caller
|
315
|
+
raise ScanError, SCAN_ERROR_MESSAGE % raise_inspect_arguments(message, tokens, state, ambit), backtrace
|
316
|
+
end
|
317
|
+
|
318
|
+
def tokens_size tokens
|
319
|
+
tokens.size if tokens.respond_to?(:size)
|
320
|
+
end
|
321
|
+
|
322
|
+
def tokens_last tokens, n
|
323
|
+
tokens.respond_to?(:last) ? tokens.last(n) : []
|
324
|
+
end
|
325
|
+
|
326
|
+
# Shorthand for scan_until(/\z/).
|
327
|
+
# This method also avoids a JRuby 1.9 mode bug.
|
328
|
+
def scan_rest
|
329
|
+
rest = self.rest
|
330
|
+
terminate
|
331
|
+
rest
|
332
|
+
end
|
333
|
+
|
334
|
+
end
|
335
|
+
|
336
|
+
end
|
337
|
+
end
|