llm-shell 0.9.2 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +61 -66
- data/lib/llm/shell/command.rb +40 -40
- data/lib/llm/shell/commands/clear_screen.rb +4 -18
- data/lib/llm/shell/commands/debug_mode.rb +12 -0
- data/lib/llm/shell/commands/dir_import.rb +4 -20
- data/lib/llm/shell/commands/disable_tool.rb +33 -0
- data/lib/llm/shell/commands/enable_tool.rb +33 -0
- data/lib/llm/shell/commands/file_import.rb +4 -20
- data/lib/llm/shell/commands/help.rb +23 -36
- data/lib/llm/shell/commands/show_chat.rb +4 -19
- data/lib/llm/shell/commands/show_version.rb +4 -20
- data/lib/llm/shell/commands/system_prompt.rb +4 -18
- data/lib/llm/shell/completion.rb +5 -5
- data/lib/llm/shell/config.rb +4 -5
- data/lib/llm/shell/formatter.rb +1 -2
- data/lib/llm/shell/internal/coderay/lib/coderay/duo.rb +81 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/_map.rb +17 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/comment_filter.rb +25 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/count.rb +39 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/debug.rb +49 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/debug_lint.rb +63 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/div.rb +23 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/encoder.rb +190 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/filter.rb +58 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/html/css.rb +65 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/html/numbering.rb +108 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/html/output.rb +164 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/html.rb +333 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/json.rb +83 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/lines_of_code.rb +45 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/lint.rb +59 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/null.rb +18 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/page.rb +24 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/span.rb +23 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/statistic.rb +95 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/terminal.rb +195 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/text.rb +46 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/token_kind_filter.rb +111 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/xml.rb +72 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/yaml.rb +50 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders.rb +18 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/for_redcloth.rb +95 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/helpers/file_type.rb +151 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/helpers/plugin.rb +55 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/helpers/plugin_host.rb +221 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/helpers/word_list.rb +72 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/_map.rb +24 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/c.rb +189 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/clojure.rb +217 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/cpp.rb +217 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/css.rb +196 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/debug.rb +75 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/delphi.rb +144 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/diff.rb +221 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/erb.rb +81 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/go.rb +208 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/groovy.rb +268 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/haml.rb +168 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/html.rb +275 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/java/builtin_types.rb +421 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/java.rb +174 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/java_script.rb +236 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/json.rb +98 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/lua.rb +280 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/php.rb +527 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/python.rb +287 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/raydebug.rb +75 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/ruby/patterns.rb +178 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/ruby/string_state.rb +79 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/ruby.rb +477 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/sass.rb +232 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/scanner.rb +337 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/sql.rb +169 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/taskpaper.rb +36 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/text.rb +26 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/xml.rb +17 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/yaml.rb +140 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners.rb +27 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/styles/_map.rb +7 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/styles/alpha.rb +153 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/styles/style.rb +18 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/styles.rb +15 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/token_kinds.rb +85 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/tokens.rb +164 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/tokens_proxy.rb +55 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/version.rb +3 -0
- data/lib/llm/shell/internal/coderay/lib/coderay.rb +284 -0
- data/lib/llm/shell/internal/io-line/lib/io/line/multiple.rb +19 -0
- data/lib/{io → llm/shell/internal/io-line/lib/io}/line.rb +2 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/bot/builder.rb +31 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/bot/conversable.rb +37 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/bot/prompt/completion.rb +49 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/bot/prompt/respond.rb +49 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/bot.rb +150 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/buffer.rb +162 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/client.rb +36 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/error.rb +49 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/eventhandler.rb +44 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/eventstream/event.rb +69 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/eventstream/parser.rb +88 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/eventstream.rb +8 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/file.rb +91 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/function.rb +177 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/message.rb +178 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/mime.rb +140 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/multipart.rb +101 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/object/builder.rb +38 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/object/kernel.rb +53 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/object.rb +89 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/provider.rb +352 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/error_handler.rb +36 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/files.rb +155 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/format/completion_format.rb +88 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/format.rb +29 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/models.rb +54 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/response/completion.rb +39 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/response/enumerable.rb +11 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/response/file.rb +23 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/response/web_search.rb +21 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/stream_parser.rb +66 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic.rb +138 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/deepseek/format/completion_format.rb +68 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/deepseek/format.rb +27 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/deepseek.rb +75 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/audio.rb +73 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/error_handler.rb +47 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/files.rb +146 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/format/completion_format.rb +69 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/format.rb +39 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/images.rb +133 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/models.rb +60 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/completion.rb +35 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/embedding.rb +8 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/file.rb +11 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/files.rb +15 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/image.rb +31 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/models.rb +15 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/web_search.rb +22 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/stream_parser.rb +86 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini.rb +173 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/llamacpp.rb +74 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/error_handler.rb +36 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/format/completion_format.rb +77 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/format.rb +29 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/models.rb +56 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/response/completion.rb +28 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/response/embedding.rb +9 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/stream_parser.rb +44 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama.rb +116 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/audio.rb +91 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/error_handler.rb +46 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/files.rb +134 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/format/completion_format.rb +90 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/format/moderation_format.rb +35 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/format/respond_format.rb +72 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/format.rb +54 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/images.rb +109 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/models.rb +55 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/moderations.rb +65 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/audio.rb +7 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/completion.rb +40 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/embedding.rb +9 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/enumerable.rb +23 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/file.rb +7 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/image.rb +16 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/moderations.rb +34 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/responds.rb +48 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/web_search.rb +21 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/responses/stream_parser.rb +76 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/responses.rb +99 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/stream_parser.rb +86 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/vector_stores.rb +228 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai.rb +206 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/xai/images.rb +58 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/xai.rb +72 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/zai.rb +74 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/response.rb +67 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/array.rb +26 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/boolean.rb +13 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/integer.rb +43 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/leaf.rb +78 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/null.rb +13 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/number.rb +43 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/object.rb +41 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/string.rb +34 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/version.rb +8 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema.rb +81 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/server_tool.rb +32 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/tool/param.rb +75 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/tool.rb +78 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/utils.rb +19 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/version.rb +5 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm.rb +121 -0
- data/lib/llm/shell/internal/optparse/lib/optionparser.rb +2 -0
- data/lib/llm/shell/internal/optparse/lib/optparse/ac.rb +70 -0
- data/lib/llm/shell/internal/optparse/lib/optparse/date.rb +18 -0
- data/lib/llm/shell/internal/optparse/lib/optparse/kwargs.rb +27 -0
- data/lib/llm/shell/internal/optparse/lib/optparse/shellwords.rb +7 -0
- data/lib/llm/shell/internal/optparse/lib/optparse/time.rb +11 -0
- data/lib/llm/shell/internal/optparse/lib/optparse/uri.rb +7 -0
- data/lib/llm/shell/internal/optparse/lib/optparse/version.rb +80 -0
- data/lib/llm/shell/internal/optparse/lib/optparse.rb +2469 -0
- data/lib/llm/shell/internal/paint/lib/paint/constants.rb +104 -0
- data/lib/llm/shell/internal/paint/lib/paint/pa.rb +13 -0
- data/lib/llm/shell/internal/paint/lib/paint/rgb_colors.rb +14 -0
- data/lib/llm/shell/internal/paint/lib/paint/shortcuts.rb +100 -0
- data/lib/llm/shell/internal/paint/lib/paint/shortcuts_version.rb +5 -0
- data/lib/llm/shell/internal/paint/lib/paint/util.rb +16 -0
- data/lib/llm/shell/internal/paint/lib/paint/version.rb +5 -0
- data/lib/llm/shell/internal/paint/lib/paint.rb +261 -0
- data/lib/llm/shell/internal/reline/lib/reline/config.rb +378 -0
- data/lib/llm/shell/internal/reline/lib/reline/face.rb +199 -0
- data/lib/llm/shell/internal/reline/lib/reline/history.rb +76 -0
- data/lib/llm/shell/internal/reline/lib/reline/io/ansi.rb +322 -0
- data/lib/llm/shell/internal/reline/lib/reline/io/dumb.rb +120 -0
- data/lib/llm/shell/internal/reline/lib/reline/io/windows.rb +530 -0
- data/lib/llm/shell/internal/reline/lib/reline/io.rb +55 -0
- data/lib/llm/shell/internal/reline/lib/reline/key_actor/base.rb +37 -0
- data/lib/llm/shell/internal/reline/lib/reline/key_actor/composite.rb +17 -0
- data/lib/llm/shell/internal/reline/lib/reline/key_actor/emacs.rb +517 -0
- data/lib/llm/shell/internal/reline/lib/reline/key_actor/vi_command.rb +518 -0
- data/lib/llm/shell/internal/reline/lib/reline/key_actor/vi_insert.rb +517 -0
- data/lib/llm/shell/internal/reline/lib/reline/key_actor.rb +8 -0
- data/lib/llm/shell/internal/reline/lib/reline/key_stroke.rb +119 -0
- data/lib/llm/shell/internal/reline/lib/reline/kill_ring.rb +125 -0
- data/lib/llm/shell/internal/reline/lib/reline/line_editor.rb +2356 -0
- data/lib/llm/shell/internal/reline/lib/reline/unicode/east_asian_width.rb +1292 -0
- data/lib/llm/shell/internal/reline/lib/reline/unicode.rb +421 -0
- data/lib/llm/shell/internal/reline/lib/reline/version.rb +3 -0
- data/lib/llm/shell/internal/reline/lib/reline.rb +527 -0
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/generated_parser.rb +712 -0
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/handler.rb +268 -0
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/local_date.rb +35 -0
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/local_date_time.rb +42 -0
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/local_time.rb +40 -0
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/parser.rb +21 -0
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/scanner.rb +92 -0
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/string_utils.rb +40 -0
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/version.rb +5 -0
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb.rb +49 -0
- data/lib/llm/shell/options.rb +1 -1
- data/lib/llm/shell/renderer.rb +2 -3
- data/lib/llm/shell/repl.rb +21 -16
- data/lib/llm/shell/tool.rb +42 -0
- data/lib/llm/shell/tools/read_file.rb +15 -0
- data/lib/llm/shell/tools/system.rb +17 -0
- data/lib/llm/shell/tools/write_file.rb +16 -0
- data/lib/llm/shell/version.rb +1 -1
- data/lib/llm/shell.rb +83 -39
- data/libexec/llm-shell/shell +4 -6
- data/llm-shell.gemspec +0 -4
- metadata +233 -63
- data/lib/llm/function.rb +0 -17
- data/lib/llm/shell/command/extension.rb +0 -42
- data/lib/llm/shell/commands/utils.rb +0 -21
- data/lib/llm/shell/functions/read_file.rb +0 -22
- data/lib/llm/shell/functions/write_file.rb +0 -22
|
@@ -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
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
module CodeRay
|
|
2
|
+
module Scanners
|
|
3
|
+
|
|
4
|
+
# by Josh Goebel
|
|
5
|
+
class SQL < Scanner
|
|
6
|
+
|
|
7
|
+
register_for :sql
|
|
8
|
+
|
|
9
|
+
KEYWORDS = %w(
|
|
10
|
+
all and any as before begin between by case check collate
|
|
11
|
+
each else end exists
|
|
12
|
+
for foreign from full group having if in inner is join
|
|
13
|
+
like not of on or order outer over references
|
|
14
|
+
then to union using values when where
|
|
15
|
+
left right distinct
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
OBJECTS = %w(
|
|
19
|
+
database databases table tables column columns fields index constraint
|
|
20
|
+
constraints transaction function procedure row key view trigger
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
COMMANDS = %w(
|
|
24
|
+
add alter comment create delete drop grant insert into select update set
|
|
25
|
+
show prompt begin commit rollback replace truncate
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
PREDEFINED_TYPES = %w(
|
|
29
|
+
char varchar varchar2 enum binary text tinytext mediumtext
|
|
30
|
+
longtext blob tinyblob mediumblob longblob timestamp
|
|
31
|
+
date time datetime year double decimal float int
|
|
32
|
+
integer tinyint mediumint bigint smallint unsigned bit numeric
|
|
33
|
+
bool boolean hex bin oct
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
PREDEFINED_FUNCTIONS = %w( sum cast substring abs pi count min max avg now )
|
|
37
|
+
|
|
38
|
+
DIRECTIVES = %w(
|
|
39
|
+
auto_increment unique default charset initially deferred
|
|
40
|
+
deferrable cascade immediate read write asc desc after
|
|
41
|
+
primary foreign return engine
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
PREDEFINED_CONSTANTS = %w( null true false )
|
|
45
|
+
|
|
46
|
+
IDENT_KIND = WordList::CaseIgnoring.new(:ident).
|
|
47
|
+
add(KEYWORDS, :keyword).
|
|
48
|
+
add(OBJECTS, :type).
|
|
49
|
+
add(COMMANDS, :class).
|
|
50
|
+
add(PREDEFINED_TYPES, :predefined_type).
|
|
51
|
+
add(PREDEFINED_CONSTANTS, :predefined_constant).
|
|
52
|
+
add(PREDEFINED_FUNCTIONS, :predefined).
|
|
53
|
+
add(DIRECTIVES, :directive)
|
|
54
|
+
|
|
55
|
+
ESCAPE = / [rbfntv\n\\\/'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} | . /mx
|
|
56
|
+
UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x
|
|
57
|
+
|
|
58
|
+
STRING_PREFIXES = /[xnb]|_\w+/i
|
|
59
|
+
|
|
60
|
+
STRING_CONTENT_PATTERN = {
|
|
61
|
+
'"' => / (?: [^\\"] | "" )+ /x,
|
|
62
|
+
"'" => / (?: [^\\'] | '' )+ /x,
|
|
63
|
+
'`' => / (?: [^\\`] | `` )+ /x,
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
def scan_tokens encoder, options
|
|
67
|
+
|
|
68
|
+
state = :initial
|
|
69
|
+
string_type = nil
|
|
70
|
+
string_content = ''
|
|
71
|
+
name_expected = false
|
|
72
|
+
|
|
73
|
+
until eos?
|
|
74
|
+
|
|
75
|
+
if state == :initial
|
|
76
|
+
|
|
77
|
+
if match = scan(/ \s+ | \\\n /x)
|
|
78
|
+
encoder.text_token match, :space
|
|
79
|
+
|
|
80
|
+
elsif match = scan(/(?:--\s?|#).*/)
|
|
81
|
+
encoder.text_token match, :comment
|
|
82
|
+
|
|
83
|
+
elsif match = scan(%r( /\* (!)? (?: .*? \*/ | .* ) )mx)
|
|
84
|
+
encoder.text_token match, self[1] ? :directive : :comment
|
|
85
|
+
|
|
86
|
+
elsif match = scan(/ [*\/=<>:;,!&^|()\[\]{}~%] | [-+\.](?!\d) /x)
|
|
87
|
+
name_expected = true if match == '.' && check(/[A-Za-z_]/)
|
|
88
|
+
encoder.text_token match, :operator
|
|
89
|
+
|
|
90
|
+
elsif match = scan(/(#{STRING_PREFIXES})?([`"'])/o)
|
|
91
|
+
prefix = self[1]
|
|
92
|
+
string_type = self[2]
|
|
93
|
+
encoder.begin_group :string
|
|
94
|
+
encoder.text_token prefix, :modifier if prefix
|
|
95
|
+
match = string_type
|
|
96
|
+
state = :string
|
|
97
|
+
encoder.text_token match, :delimiter
|
|
98
|
+
|
|
99
|
+
elsif match = scan(/ @? [A-Za-z_][A-Za-z_0-9\$]* /x)
|
|
100
|
+
encoder.text_token match, name_expected ? :ident : (match[0] == ?@ ? :variable : IDENT_KIND[match])
|
|
101
|
+
name_expected = false
|
|
102
|
+
|
|
103
|
+
elsif match = scan(/0[xX][0-9A-Fa-f]+/)
|
|
104
|
+
encoder.text_token match, :hex
|
|
105
|
+
|
|
106
|
+
elsif match = scan(/0[0-7]+(?![89.eEfF])/)
|
|
107
|
+
encoder.text_token match, :octal
|
|
108
|
+
|
|
109
|
+
elsif match = scan(/[-+]?(?>\d+)(?![.eEfF])/)
|
|
110
|
+
encoder.text_token match, :integer
|
|
111
|
+
|
|
112
|
+
elsif match = scan(/[-+]?(?:\d[fF]|\d*\.\d+(?:[eE][+-]?\d+)?|\d+[eE][+-]?\d+)/)
|
|
113
|
+
encoder.text_token match, :float
|
|
114
|
+
|
|
115
|
+
elsif match = scan(/\\N/)
|
|
116
|
+
encoder.text_token match, :predefined_constant
|
|
117
|
+
|
|
118
|
+
else
|
|
119
|
+
encoder.text_token getch, :error
|
|
120
|
+
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
elsif state == :string
|
|
124
|
+
if match = scan(STRING_CONTENT_PATTERN[string_type])
|
|
125
|
+
encoder.text_token match, :content
|
|
126
|
+
elsif match = scan(/["'`]/)
|
|
127
|
+
if string_type == match
|
|
128
|
+
if peek(1) == string_type # doubling means escape
|
|
129
|
+
encoder.text_token match + getch, :content
|
|
130
|
+
else
|
|
131
|
+
encoder.text_token match, :delimiter
|
|
132
|
+
encoder.end_group :string
|
|
133
|
+
state = :initial
|
|
134
|
+
string_type = nil
|
|
135
|
+
end
|
|
136
|
+
else
|
|
137
|
+
encoder.text_token match, :content
|
|
138
|
+
end
|
|
139
|
+
elsif match = scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox)
|
|
140
|
+
encoder.text_token match, :char
|
|
141
|
+
elsif match = scan(/ \\ . /mox)
|
|
142
|
+
encoder.text_token match, :content
|
|
143
|
+
elsif match = scan(/ \\ | $ /x)
|
|
144
|
+
encoder.text_token match, :error unless match.empty?
|
|
145
|
+
encoder.end_group :string
|
|
146
|
+
state = :initial
|
|
147
|
+
else
|
|
148
|
+
raise "else case \" reached; %p not handled." % peek(1), encoder
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
else
|
|
152
|
+
raise 'else-case reached', encoder
|
|
153
|
+
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
if state == :string
|
|
159
|
+
encoder.end_group state
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
encoder
|
|
163
|
+
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
end
|
|
169
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module CodeRay
|
|
2
|
+
module Scanners
|
|
3
|
+
|
|
4
|
+
class Taskpaper < Scanner
|
|
5
|
+
|
|
6
|
+
register_for :taskpaper
|
|
7
|
+
file_extension 'taskpaper'
|
|
8
|
+
|
|
9
|
+
protected
|
|
10
|
+
|
|
11
|
+
def scan_tokens encoder, options
|
|
12
|
+
until eos?
|
|
13
|
+
if match = scan(/\S.*:.*$/) # project
|
|
14
|
+
encoder.text_token(match, :namespace)
|
|
15
|
+
elsif match = scan(/-.+@done.*/) # completed task
|
|
16
|
+
encoder.text_token(match, :done)
|
|
17
|
+
elsif match = scan(/-(?:[^@\n]+|@(?!due))*/) # task
|
|
18
|
+
encoder.text_token(match, :plain)
|
|
19
|
+
elsif match = scan(/@due.*/) # comment
|
|
20
|
+
encoder.text_token(match, :important)
|
|
21
|
+
elsif match = scan(/.+/) # comment
|
|
22
|
+
encoder.text_token(match, :comment)
|
|
23
|
+
elsif match = scan(/\s+/) # space
|
|
24
|
+
encoder.text_token(match, :space)
|
|
25
|
+
else # other
|
|
26
|
+
encoder.text_token getch, :error
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
encoder
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module CodeRay
|
|
2
|
+
module Scanners
|
|
3
|
+
|
|
4
|
+
# Scanner for plain text.
|
|
5
|
+
#
|
|
6
|
+
# Yields just one token of the kind :plain.
|
|
7
|
+
#
|
|
8
|
+
# Alias: +plaintext+, +plain+
|
|
9
|
+
class Text < Scanner
|
|
10
|
+
|
|
11
|
+
register_for :text
|
|
12
|
+
title 'Plain text'
|
|
13
|
+
|
|
14
|
+
KINDS_NOT_LOC = [:plain] # :nodoc:
|
|
15
|
+
|
|
16
|
+
protected
|
|
17
|
+
|
|
18
|
+
def scan_tokens encoder, options
|
|
19
|
+
encoder.text_token string, :plain
|
|
20
|
+
encoder
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
end
|