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,72 @@
|
|
|
1
|
+
module CodeRay
|
|
2
|
+
|
|
3
|
+
# = WordList
|
|
4
|
+
#
|
|
5
|
+
# <b>A Hash subclass designed for mapping word lists to token types.</b>
|
|
6
|
+
#
|
|
7
|
+
# A WordList is a Hash with some additional features.
|
|
8
|
+
# It is intended to be used for keyword recognition.
|
|
9
|
+
#
|
|
10
|
+
# WordList is optimized to be used in Scanners,
|
|
11
|
+
# typically to decide whether a given ident is a special token.
|
|
12
|
+
#
|
|
13
|
+
# For case insensitive words use WordList::CaseIgnoring.
|
|
14
|
+
#
|
|
15
|
+
# Example:
|
|
16
|
+
#
|
|
17
|
+
# # define word arrays
|
|
18
|
+
# RESERVED_WORDS = %w[
|
|
19
|
+
# asm break case continue default do else
|
|
20
|
+
# ]
|
|
21
|
+
#
|
|
22
|
+
# PREDEFINED_TYPES = %w[
|
|
23
|
+
# int long short char void
|
|
24
|
+
# ]
|
|
25
|
+
#
|
|
26
|
+
# # make a WordList
|
|
27
|
+
# IDENT_KIND = WordList.new(:ident).
|
|
28
|
+
# add(RESERVED_WORDS, :reserved).
|
|
29
|
+
# add(PREDEFINED_TYPES, :predefined_type)
|
|
30
|
+
#
|
|
31
|
+
# ...
|
|
32
|
+
#
|
|
33
|
+
# def scan_tokens tokens, options
|
|
34
|
+
# ...
|
|
35
|
+
#
|
|
36
|
+
# elsif scan(/[A-Za-z_][A-Za-z_0-9]*/)
|
|
37
|
+
# # use it
|
|
38
|
+
# kind = IDENT_KIND[match]
|
|
39
|
+
# ...
|
|
40
|
+
class WordList < Hash
|
|
41
|
+
|
|
42
|
+
# Create a new WordList with +default+ as default value.
|
|
43
|
+
def initialize default = false
|
|
44
|
+
super default
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Add words to the list and associate them with +value+.
|
|
48
|
+
#
|
|
49
|
+
# Returns +self+, so you can concat add calls.
|
|
50
|
+
def add words, value = true
|
|
51
|
+
words.each { |word| self[word] = value }
|
|
52
|
+
self
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
# A CaseIgnoring WordList is like a WordList, only that
|
|
59
|
+
# keys are compared case-insensitively (normalizing keys using +downcase+).
|
|
60
|
+
class WordList::CaseIgnoring < WordList
|
|
61
|
+
|
|
62
|
+
def [] key
|
|
63
|
+
super key.downcase
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def []= key, value
|
|
67
|
+
super key.downcase, value
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module CodeRay
|
|
2
|
+
module Scanners
|
|
3
|
+
|
|
4
|
+
map \
|
|
5
|
+
:'c++' => :cpp,
|
|
6
|
+
:cplusplus => :cpp,
|
|
7
|
+
:ecmascript => :java_script,
|
|
8
|
+
:ecma_script => :java_script,
|
|
9
|
+
:rhtml => :erb,
|
|
10
|
+
:eruby => :erb,
|
|
11
|
+
:irb => :ruby,
|
|
12
|
+
:javascript => :java_script,
|
|
13
|
+
:js => :java_script,
|
|
14
|
+
:pascal => :delphi,
|
|
15
|
+
:patch => :diff,
|
|
16
|
+
:plain => :text,
|
|
17
|
+
:plaintext => :text,
|
|
18
|
+
:xhtml => :html,
|
|
19
|
+
:yml => :yaml
|
|
20
|
+
|
|
21
|
+
default :text
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
module CodeRay
|
|
2
|
+
module Scanners
|
|
3
|
+
|
|
4
|
+
# Scanner for C.
|
|
5
|
+
class C < Scanner
|
|
6
|
+
|
|
7
|
+
register_for :c
|
|
8
|
+
file_extension 'c'
|
|
9
|
+
|
|
10
|
+
KEYWORDS = [
|
|
11
|
+
'asm', 'break', 'case', 'continue', 'default', 'do',
|
|
12
|
+
'else', 'enum', 'for', 'goto', 'if', 'return',
|
|
13
|
+
'sizeof', 'struct', 'switch', 'typedef', 'union', 'while',
|
|
14
|
+
'restrict', # added in C99
|
|
15
|
+
] # :nodoc:
|
|
16
|
+
|
|
17
|
+
PREDEFINED_TYPES = [
|
|
18
|
+
'int', 'long', 'short', 'char',
|
|
19
|
+
'signed', 'unsigned', 'float', 'double',
|
|
20
|
+
'bool', 'complex', # added in C99
|
|
21
|
+
] # :nodoc:
|
|
22
|
+
|
|
23
|
+
PREDEFINED_CONSTANTS = [
|
|
24
|
+
'EOF', 'NULL',
|
|
25
|
+
'true', 'false', # added in C99
|
|
26
|
+
] # :nodoc:
|
|
27
|
+
DIRECTIVES = [
|
|
28
|
+
'auto', 'extern', 'register', 'static', 'void',
|
|
29
|
+
'const', 'volatile', # added in C89
|
|
30
|
+
'inline', # added in C99
|
|
31
|
+
] # :nodoc:
|
|
32
|
+
|
|
33
|
+
IDENT_KIND = WordList.new(:ident).
|
|
34
|
+
add(KEYWORDS, :keyword).
|
|
35
|
+
add(PREDEFINED_TYPES, :predefined_type).
|
|
36
|
+
add(DIRECTIVES, :directive).
|
|
37
|
+
add(PREDEFINED_CONSTANTS, :predefined_constant) # :nodoc:
|
|
38
|
+
|
|
39
|
+
ESCAPE = / [rbfntv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x # :nodoc:
|
|
40
|
+
UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x # :nodoc:
|
|
41
|
+
|
|
42
|
+
protected
|
|
43
|
+
|
|
44
|
+
def scan_tokens encoder, options
|
|
45
|
+
|
|
46
|
+
state = :initial
|
|
47
|
+
label_expected = true
|
|
48
|
+
case_expected = false
|
|
49
|
+
label_expected_before_preproc_line = nil
|
|
50
|
+
in_preproc_line = false
|
|
51
|
+
|
|
52
|
+
until eos?
|
|
53
|
+
|
|
54
|
+
case state
|
|
55
|
+
|
|
56
|
+
when :initial
|
|
57
|
+
|
|
58
|
+
if match = scan(/ \s+ | \\\n /x)
|
|
59
|
+
if in_preproc_line && match != "\\\n" && match.index(?\n)
|
|
60
|
+
in_preproc_line = false
|
|
61
|
+
label_expected = label_expected_before_preproc_line
|
|
62
|
+
end
|
|
63
|
+
encoder.text_token match, :space
|
|
64
|
+
|
|
65
|
+
elsif match = scan(%r! // [^\n\\]* (?: \\. [^\n\\]* )* | /\* (?: .*? \*/ | .* ) !mx)
|
|
66
|
+
encoder.text_token match, :comment
|
|
67
|
+
|
|
68
|
+
elsif match = scan(/ [-+*=<>?:;,!&^|()\[\]{}~%]+ | \/=? | \.(?!\d) /x)
|
|
69
|
+
label_expected = match =~ /[;\{\}]/
|
|
70
|
+
if case_expected
|
|
71
|
+
label_expected = true if match == ':'
|
|
72
|
+
case_expected = false
|
|
73
|
+
end
|
|
74
|
+
encoder.text_token match, :operator
|
|
75
|
+
|
|
76
|
+
elsif match = scan(/ [A-Za-z_][A-Za-z_0-9]* /x)
|
|
77
|
+
kind = IDENT_KIND[match]
|
|
78
|
+
if kind == :ident && label_expected && !in_preproc_line && scan(/:(?!:)/)
|
|
79
|
+
kind = :label
|
|
80
|
+
match << matched
|
|
81
|
+
else
|
|
82
|
+
label_expected = false
|
|
83
|
+
if kind == :keyword
|
|
84
|
+
case match
|
|
85
|
+
when 'case', 'default'
|
|
86
|
+
case_expected = true
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
encoder.text_token match, kind
|
|
91
|
+
|
|
92
|
+
elsif match = scan(/L?"/)
|
|
93
|
+
encoder.begin_group :string
|
|
94
|
+
if match[0] == ?L
|
|
95
|
+
encoder.text_token 'L', :modifier
|
|
96
|
+
match = '"'
|
|
97
|
+
end
|
|
98
|
+
encoder.text_token match, :delimiter
|
|
99
|
+
state = :string
|
|
100
|
+
|
|
101
|
+
elsif match = scan(/ \# \s* if \s* 0 /x)
|
|
102
|
+
match << scan_until(/ ^\# (?:elif|else|endif) .*? $ | \z /xm) unless eos?
|
|
103
|
+
encoder.text_token match, :comment
|
|
104
|
+
|
|
105
|
+
elsif match = scan(/#[ \t]*(\w*)/)
|
|
106
|
+
encoder.text_token match, :preprocessor
|
|
107
|
+
in_preproc_line = true
|
|
108
|
+
label_expected_before_preproc_line = label_expected
|
|
109
|
+
state = :include_expected if self[1] == 'include'
|
|
110
|
+
|
|
111
|
+
elsif match = scan(/ L?' (?: [^\'\n\\] | \\ #{ESCAPE} )? '? /ox)
|
|
112
|
+
label_expected = false
|
|
113
|
+
encoder.text_token match, :char
|
|
114
|
+
|
|
115
|
+
elsif match = scan(/\$/)
|
|
116
|
+
encoder.text_token match, :ident
|
|
117
|
+
|
|
118
|
+
elsif match = scan(/0[xX][0-9A-Fa-f]+/)
|
|
119
|
+
label_expected = false
|
|
120
|
+
encoder.text_token match, :hex
|
|
121
|
+
|
|
122
|
+
elsif match = scan(/(?:0[0-7]+)(?![89.eEfF])/)
|
|
123
|
+
label_expected = false
|
|
124
|
+
encoder.text_token match, :octal
|
|
125
|
+
|
|
126
|
+
elsif match = scan(/(?:\d+)(?![.eEfF])L?L?/)
|
|
127
|
+
label_expected = false
|
|
128
|
+
encoder.text_token match, :integer
|
|
129
|
+
|
|
130
|
+
elsif match = scan(/\d[fF]?|\d*\.\d+(?:[eE][+-]?\d+)?[fF]?|\d+[eE][+-]?\d+[fF]?/)
|
|
131
|
+
label_expected = false
|
|
132
|
+
encoder.text_token match, :float
|
|
133
|
+
|
|
134
|
+
else
|
|
135
|
+
encoder.text_token getch, :error
|
|
136
|
+
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
when :string
|
|
140
|
+
if match = scan(/[^\\\n"]+/)
|
|
141
|
+
encoder.text_token match, :content
|
|
142
|
+
elsif match = scan(/"/)
|
|
143
|
+
encoder.text_token match, :delimiter
|
|
144
|
+
encoder.end_group :string
|
|
145
|
+
state = :initial
|
|
146
|
+
label_expected = false
|
|
147
|
+
elsif match = scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox)
|
|
148
|
+
encoder.text_token match, :char
|
|
149
|
+
elsif match = scan(/ \\ | $ /x)
|
|
150
|
+
encoder.end_group :string
|
|
151
|
+
encoder.text_token match, :error unless match.empty?
|
|
152
|
+
state = :initial
|
|
153
|
+
label_expected = false
|
|
154
|
+
else
|
|
155
|
+
raise_inspect "else case \" reached; %p not handled." % peek(1), encoder
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
when :include_expected
|
|
159
|
+
if match = scan(/<[^>\n]+>?|"[^"\n\\]*(?:\\.[^"\n\\]*)*"?/)
|
|
160
|
+
encoder.text_token match, :include
|
|
161
|
+
state = :initial
|
|
162
|
+
|
|
163
|
+
elsif match = scan(/\s+/)
|
|
164
|
+
encoder.text_token match, :space
|
|
165
|
+
state = :initial if match.index ?\n
|
|
166
|
+
|
|
167
|
+
else
|
|
168
|
+
state = :initial
|
|
169
|
+
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
else
|
|
173
|
+
raise_inspect 'Unknown state', encoder
|
|
174
|
+
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
if state == :string
|
|
180
|
+
encoder.end_group :string
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
encoder
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
end
|
|
189
|
+
end
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
module CodeRay
|
|
3
|
+
module Scanners
|
|
4
|
+
|
|
5
|
+
# Clojure scanner by Licenser.
|
|
6
|
+
class Clojure < Scanner
|
|
7
|
+
|
|
8
|
+
register_for :clojure
|
|
9
|
+
file_extension 'clj'
|
|
10
|
+
|
|
11
|
+
SPECIAL_FORMS = %w[
|
|
12
|
+
def if do let quote var fn loop recur throw try catch monitor-enter monitor-exit .
|
|
13
|
+
new
|
|
14
|
+
] # :nodoc:
|
|
15
|
+
|
|
16
|
+
CORE_FORMS = %w[
|
|
17
|
+
+ - -> ->> .. / * <= < = == >= > accessor aclone add-classpath add-watch
|
|
18
|
+
agent agent-error agent-errors aget alength alias all-ns alter alter-meta!
|
|
19
|
+
alter-var-root amap ancestors and apply areduce array-map aset aset-boolean
|
|
20
|
+
aset-byte aset-char aset-double aset-float aset-int aset-long aset-short
|
|
21
|
+
assert assoc assoc! assoc-in associative? atom await await-for bases bean
|
|
22
|
+
bigdec bigint binding bit-and bit-and-not bit-clear bit-flip bit-not bit-or
|
|
23
|
+
bit-set bit-shift-left bit-shift-right bit-test bit-xor boolean boolean-array
|
|
24
|
+
booleans bound-fn bound-fn* bound? butlast byte byte-array bytes case cast char
|
|
25
|
+
char-array char-escape-string char-name-string char? chars class class?
|
|
26
|
+
clear-agent-errors clojure-version coll? comment commute comp comparator
|
|
27
|
+
compare compare-and-set! compile complement concat cond condp conj conj!
|
|
28
|
+
cons constantly construct-proxy contains? count counted? create-ns
|
|
29
|
+
create-struct cycle dec decimal? declare definline defmacro defmethod defmulti
|
|
30
|
+
defn defn- defonce defprotocol defrecord defstruct deftype delay delay?
|
|
31
|
+
deliver denominator deref derive descendants disj disj! dissoc dissoc!
|
|
32
|
+
distinct distinct? doall doc dorun doseq dosync dotimes doto double
|
|
33
|
+
double-array doubles drop drop-last drop-while empty empty? ensure
|
|
34
|
+
enumeration-seq error-handler error-mode eval even? every? extend
|
|
35
|
+
extend-protocol extend-type extenders extends? false? ffirst file-seq
|
|
36
|
+
filter find find-doc find-ns find-var first float float-array float?
|
|
37
|
+
floats flush fn fn? fnext for force format future future-call future-cancel
|
|
38
|
+
future-cancelled? future-done? future? gen-class gen-interface gensym get
|
|
39
|
+
get-in get-method get-proxy-class get-thread-bindings get-validator hash
|
|
40
|
+
hash-map hash-set identical? identity if-let if-not ifn? import in-ns
|
|
41
|
+
inc init-proxy instance? int int-array integer? interleave intern
|
|
42
|
+
interpose into into-array ints io! isa? iterate iterator-seq juxt key
|
|
43
|
+
keys keyword keyword? last lazy-cat lazy-seq let letfn line-seq list list*
|
|
44
|
+
list? load load-file load-reader load-string loaded-libs locking long
|
|
45
|
+
long-array longs loop macroexpand macroexpand-1 make-array make-hierarchy
|
|
46
|
+
map map? mapcat max max-key memfn memoize merge merge-with meta methods
|
|
47
|
+
min min-key mod name namespace neg? newline next nfirst nil? nnext not
|
|
48
|
+
not-any? not-empty not-every? not= ns ns-aliases ns-imports ns-interns
|
|
49
|
+
ns-map ns-name ns-publics ns-refers ns-resolve ns-unalias ns-unmap nth
|
|
50
|
+
nthnext num number? numerator object-array odd? or parents partial
|
|
51
|
+
partition pcalls peek persistent! pmap pop pop! pop-thread-bindings
|
|
52
|
+
pos? pr pr-str prefer-method prefers print print-namespace-doc
|
|
53
|
+
print-str printf println println-str prn prn-str promise proxy
|
|
54
|
+
proxy-mappings proxy-super push-thread-bindings pvalues quot rand
|
|
55
|
+
rand-int range ratio? rationalize re-find re-groups re-matcher
|
|
56
|
+
re-matches re-pattern re-seq read read-line read-string reduce ref
|
|
57
|
+
ref-history-count ref-max-history ref-min-history ref-set refer
|
|
58
|
+
refer-clojure reify release-pending-sends rem remove remove-all-methods
|
|
59
|
+
remove-method remove-ns remove-watch repeat repeatedly replace replicate
|
|
60
|
+
require reset! reset-meta! resolve rest restart-agent resultset-seq
|
|
61
|
+
reverse reversible? rseq rsubseq satisfies? second select-keys send
|
|
62
|
+
send-off seq seq? seque sequence sequential? set set-error-handler!
|
|
63
|
+
set-error-mode! set-validator! set? short short-array shorts
|
|
64
|
+
shutdown-agents slurp some sort sort-by sorted-map sorted-map-by
|
|
65
|
+
sorted-set sorted-set-by sorted? special-form-anchor special-symbol?
|
|
66
|
+
split-at split-with str string? struct struct-map subs subseq subvec
|
|
67
|
+
supers swap! symbol symbol? sync syntax-symbol-anchor take take-last
|
|
68
|
+
take-nth take-while test the-ns thread-bound? time to-array to-array-2d
|
|
69
|
+
trampoline transient tree-seq true? type unchecked-add unchecked-dec
|
|
70
|
+
unchecked-divide unchecked-inc unchecked-multiply unchecked-negate
|
|
71
|
+
unchecked-remainder unchecked-subtract underive update-in update-proxy
|
|
72
|
+
use val vals var-get var-set var? vary-meta vec vector vector-of vector?
|
|
73
|
+
when when-first when-let when-not while with-bindings with-bindings*
|
|
74
|
+
with-in-str with-local-vars with-meta with-open with-out-str
|
|
75
|
+
with-precision xml-seq zero? zipmap
|
|
76
|
+
] # :nodoc:
|
|
77
|
+
|
|
78
|
+
PREDEFINED_CONSTANTS = %w[
|
|
79
|
+
true false nil *1 *2 *3 *agent* *clojure-version* *command-line-args*
|
|
80
|
+
*compile-files* *compile-path* *e *err* *file* *flush-on-newline*
|
|
81
|
+
*in* *ns* *out* *print-dup* *print-length* *print-level* *print-meta*
|
|
82
|
+
*print-readably* *read-eval* *warn-on-reflection*
|
|
83
|
+
] # :nodoc:
|
|
84
|
+
|
|
85
|
+
IDENT_KIND = WordList.new(:ident).
|
|
86
|
+
add(SPECIAL_FORMS, :keyword).
|
|
87
|
+
add(CORE_FORMS, :keyword).
|
|
88
|
+
add(PREDEFINED_CONSTANTS, :predefined_constant)
|
|
89
|
+
|
|
90
|
+
KEYWORD_NEXT_TOKEN_KIND = WordList.new(nil).
|
|
91
|
+
add(%w[ def defn defn- definline defmacro defmulti defmethod defstruct defonce declare ], :function).
|
|
92
|
+
add(%w[ ns ], :namespace).
|
|
93
|
+
add(%w[ defprotocol defrecord ], :class)
|
|
94
|
+
|
|
95
|
+
BASIC_IDENTIFIER = /[a-zA-Z$%*\/_+!?&<>\-=]=?[a-zA-Z0-9$&*+!\/_?<>\-\#]*/
|
|
96
|
+
IDENTIFIER = /(?!-\d)(?:(?:#{BASIC_IDENTIFIER}\.)*#{BASIC_IDENTIFIER}(?:\/#{BASIC_IDENTIFIER})?\.?)|\.\.?/
|
|
97
|
+
SYMBOL = /::?#{IDENTIFIER}/o
|
|
98
|
+
DIGIT = /\d/
|
|
99
|
+
DIGIT10 = DIGIT
|
|
100
|
+
DIGIT16 = /[0-9a-f]/i
|
|
101
|
+
DIGIT8 = /[0-7]/
|
|
102
|
+
DIGIT2 = /[01]/
|
|
103
|
+
RADIX16 = /\#x/i
|
|
104
|
+
RADIX8 = /\#o/i
|
|
105
|
+
RADIX2 = /\#b/i
|
|
106
|
+
RADIX10 = /\#d/i
|
|
107
|
+
EXACTNESS = /#i|#e/i
|
|
108
|
+
SIGN = /[\+-]?/
|
|
109
|
+
EXP_MARK = /[esfdl]/i
|
|
110
|
+
EXP = /#{EXP_MARK}#{SIGN}#{DIGIT}+/
|
|
111
|
+
SUFFIX = /#{EXP}?/
|
|
112
|
+
PREFIX10 = /#{RADIX10}?#{EXACTNESS}?|#{EXACTNESS}?#{RADIX10}?/
|
|
113
|
+
PREFIX16 = /#{RADIX16}#{EXACTNESS}?|#{EXACTNESS}?#{RADIX16}/
|
|
114
|
+
PREFIX8 = /#{RADIX8}#{EXACTNESS}?|#{EXACTNESS}?#{RADIX8}/
|
|
115
|
+
PREFIX2 = /#{RADIX2}#{EXACTNESS}?|#{EXACTNESS}?#{RADIX2}/
|
|
116
|
+
UINT10 = /#{DIGIT10}+#*/
|
|
117
|
+
UINT16 = /#{DIGIT16}+#*/
|
|
118
|
+
UINT8 = /#{DIGIT8}+#*/
|
|
119
|
+
UINT2 = /#{DIGIT2}+#*/
|
|
120
|
+
DECIMAL = /#{DIGIT10}+#+\.#*#{SUFFIX}|#{DIGIT10}+\.#{DIGIT10}*#*#{SUFFIX}|\.#{DIGIT10}+#*#{SUFFIX}|#{UINT10}#{EXP}/
|
|
121
|
+
UREAL10 = /#{UINT10}\/#{UINT10}|#{DECIMAL}|#{UINT10}/
|
|
122
|
+
UREAL16 = /#{UINT16}\/#{UINT16}|#{UINT16}/
|
|
123
|
+
UREAL8 = /#{UINT8}\/#{UINT8}|#{UINT8}/
|
|
124
|
+
UREAL2 = /#{UINT2}\/#{UINT2}|#{UINT2}/
|
|
125
|
+
REAL10 = /#{SIGN}#{UREAL10}/
|
|
126
|
+
REAL16 = /#{SIGN}#{UREAL16}/
|
|
127
|
+
REAL8 = /#{SIGN}#{UREAL8}/
|
|
128
|
+
REAL2 = /#{SIGN}#{UREAL2}/
|
|
129
|
+
IMAG10 = /i|#{UREAL10}i/
|
|
130
|
+
IMAG16 = /i|#{UREAL16}i/
|
|
131
|
+
IMAG8 = /i|#{UREAL8}i/
|
|
132
|
+
IMAG2 = /i|#{UREAL2}i/
|
|
133
|
+
COMPLEX10 = /#{REAL10}@#{REAL10}|#{REAL10}\+#{IMAG10}|#{REAL10}-#{IMAG10}|\+#{IMAG10}|-#{IMAG10}|#{REAL10}/
|
|
134
|
+
COMPLEX16 = /#{REAL16}@#{REAL16}|#{REAL16}\+#{IMAG16}|#{REAL16}-#{IMAG16}|\+#{IMAG16}|-#{IMAG16}|#{REAL16}/
|
|
135
|
+
COMPLEX8 = /#{REAL8}@#{REAL8}|#{REAL8}\+#{IMAG8}|#{REAL8}-#{IMAG8}|\+#{IMAG8}|-#{IMAG8}|#{REAL8}/
|
|
136
|
+
COMPLEX2 = /#{REAL2}@#{REAL2}|#{REAL2}\+#{IMAG2}|#{REAL2}-#{IMAG2}|\+#{IMAG2}|-#{IMAG2}|#{REAL2}/
|
|
137
|
+
NUM10 = /#{PREFIX10}?#{COMPLEX10}/
|
|
138
|
+
NUM16 = /#{PREFIX16}#{COMPLEX16}/
|
|
139
|
+
NUM8 = /#{PREFIX8}#{COMPLEX8}/
|
|
140
|
+
NUM2 = /#{PREFIX2}#{COMPLEX2}/
|
|
141
|
+
NUM = /#{NUM10}|#{NUM16}|#{NUM8}|#{NUM2}/
|
|
142
|
+
|
|
143
|
+
protected
|
|
144
|
+
|
|
145
|
+
def scan_tokens encoder, options
|
|
146
|
+
|
|
147
|
+
state = :initial
|
|
148
|
+
kind = nil
|
|
149
|
+
|
|
150
|
+
until eos?
|
|
151
|
+
|
|
152
|
+
case state
|
|
153
|
+
when :initial
|
|
154
|
+
if match = scan(/ \s+ | \\\n | , /x)
|
|
155
|
+
encoder.text_token match, :space
|
|
156
|
+
elsif match = scan(/['`\(\[\)\]\{\}]|\#[({]|~@?|[@\^]/)
|
|
157
|
+
encoder.text_token match, :operator
|
|
158
|
+
elsif match = scan(/;.*/)
|
|
159
|
+
encoder.text_token match, :comment # TODO: recognize (comment ...) too
|
|
160
|
+
elsif match = scan(/\#?\\(?:newline|space|.?)/)
|
|
161
|
+
encoder.text_token match, :char
|
|
162
|
+
elsif match = scan(/\#[ft]/)
|
|
163
|
+
encoder.text_token match, :predefined_constant
|
|
164
|
+
elsif match = scan(/#{IDENTIFIER}/o)
|
|
165
|
+
kind = IDENT_KIND[match]
|
|
166
|
+
encoder.text_token match, kind
|
|
167
|
+
if rest? && kind == :keyword
|
|
168
|
+
if kind = KEYWORD_NEXT_TOKEN_KIND[match]
|
|
169
|
+
encoder.text_token match, :space if match = scan(/\s+/o)
|
|
170
|
+
encoder.text_token match, kind if match = scan(/#{IDENTIFIER}/o)
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
elsif match = scan(/#{SYMBOL}/o)
|
|
174
|
+
encoder.text_token match, :symbol
|
|
175
|
+
elsif match = scan(/\./)
|
|
176
|
+
encoder.text_token match, :operator
|
|
177
|
+
elsif match = scan(/ \# \^ #{IDENTIFIER} /ox)
|
|
178
|
+
encoder.text_token match, :type
|
|
179
|
+
elsif match = scan(/ (\#)? " /x)
|
|
180
|
+
state = self[1] ? :regexp : :string
|
|
181
|
+
encoder.begin_group state
|
|
182
|
+
encoder.text_token match, :delimiter
|
|
183
|
+
elsif match = scan(/#{NUM}/o) and not matched.empty?
|
|
184
|
+
encoder.text_token match, match[/[.e\/]/i] ? :float : :integer
|
|
185
|
+
else
|
|
186
|
+
encoder.text_token getch, :error
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
when :string, :regexp
|
|
190
|
+
if match = scan(/[^"\\]+|\\.?/)
|
|
191
|
+
encoder.text_token match, :content
|
|
192
|
+
elsif match = scan(/"/)
|
|
193
|
+
encoder.text_token match, :delimiter
|
|
194
|
+
encoder.end_group state
|
|
195
|
+
state = :initial
|
|
196
|
+
else
|
|
197
|
+
raise_inspect "else case \" reached; %p not handled." % peek(1),
|
|
198
|
+
encoder, state
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
else
|
|
202
|
+
raise 'else case reached'
|
|
203
|
+
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
if [:string, :regexp].include? state
|
|
209
|
+
encoder.end_group state
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
encoder
|
|
213
|
+
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
end
|