llm-shell 0.10.0 → 0.11.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/LICENSE +21 -0
- data/README.md +24 -160
- data/exe/llm-shell +7 -0
- data/llm-shell.gemspec +26 -32
- metadata +36 -372
- data/bin/llm-shell +0 -21
- data/lib/llm/shell/command.rb +0 -88
- data/lib/llm/shell/commands/clear_screen.rb +0 -18
- data/lib/llm/shell/commands/debug_mode.rb +0 -12
- data/lib/llm/shell/commands/dir_import.rb +0 -33
- data/lib/llm/shell/commands/disable_tool.rb +0 -33
- data/lib/llm/shell/commands/enable_tool.rb +0 -33
- data/lib/llm/shell/commands/file_import.rb +0 -25
- data/lib/llm/shell/commands/help.rb +0 -53
- data/lib/llm/shell/commands/show_chat.rb +0 -31
- data/lib/llm/shell/commands/show_version.rb +0 -17
- data/lib/llm/shell/commands/system_prompt.rb +0 -21
- data/lib/llm/shell/completion.rb +0 -40
- data/lib/llm/shell/config.rb +0 -34
- data/lib/llm/shell/default.rb +0 -23
- data/lib/llm/shell/formatter.rb +0 -41
- data/lib/llm/shell/internal/coderay/lib/coderay/duo.rb +0 -81
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/_map.rb +0 -17
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/comment_filter.rb +0 -25
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/count.rb +0 -39
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/debug.rb +0 -49
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/debug_lint.rb +0 -63
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/div.rb +0 -23
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/encoder.rb +0 -190
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/filter.rb +0 -58
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/html/css.rb +0 -65
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/html/numbering.rb +0 -108
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/html/output.rb +0 -164
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/html.rb +0 -333
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/json.rb +0 -83
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/lines_of_code.rb +0 -45
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/lint.rb +0 -59
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/null.rb +0 -18
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/page.rb +0 -24
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/span.rb +0 -23
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/statistic.rb +0 -95
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/terminal.rb +0 -195
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/text.rb +0 -46
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/token_kind_filter.rb +0 -111
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/xml.rb +0 -72
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/yaml.rb +0 -50
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders.rb +0 -18
- data/lib/llm/shell/internal/coderay/lib/coderay/for_redcloth.rb +0 -95
- data/lib/llm/shell/internal/coderay/lib/coderay/helpers/file_type.rb +0 -151
- data/lib/llm/shell/internal/coderay/lib/coderay/helpers/plugin.rb +0 -55
- data/lib/llm/shell/internal/coderay/lib/coderay/helpers/plugin_host.rb +0 -221
- data/lib/llm/shell/internal/coderay/lib/coderay/helpers/word_list.rb +0 -72
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/_map.rb +0 -24
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/c.rb +0 -189
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/clojure.rb +0 -217
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/cpp.rb +0 -217
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/css.rb +0 -196
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/debug.rb +0 -75
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/delphi.rb +0 -144
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/diff.rb +0 -221
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/erb.rb +0 -81
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/go.rb +0 -208
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/groovy.rb +0 -268
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/haml.rb +0 -168
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/html.rb +0 -275
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/java/builtin_types.rb +0 -421
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/java.rb +0 -174
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/java_script.rb +0 -236
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/json.rb +0 -98
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/lua.rb +0 -280
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/php.rb +0 -527
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/python.rb +0 -287
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/raydebug.rb +0 -75
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/ruby/patterns.rb +0 -178
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/ruby/string_state.rb +0 -79
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/ruby.rb +0 -477
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/sass.rb +0 -232
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/scanner.rb +0 -337
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/sql.rb +0 -169
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/taskpaper.rb +0 -36
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/text.rb +0 -26
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/xml.rb +0 -17
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/yaml.rb +0 -140
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners.rb +0 -27
- data/lib/llm/shell/internal/coderay/lib/coderay/styles/_map.rb +0 -7
- data/lib/llm/shell/internal/coderay/lib/coderay/styles/alpha.rb +0 -153
- data/lib/llm/shell/internal/coderay/lib/coderay/styles/style.rb +0 -18
- data/lib/llm/shell/internal/coderay/lib/coderay/styles.rb +0 -15
- data/lib/llm/shell/internal/coderay/lib/coderay/token_kinds.rb +0 -85
- data/lib/llm/shell/internal/coderay/lib/coderay/tokens.rb +0 -164
- data/lib/llm/shell/internal/coderay/lib/coderay/tokens_proxy.rb +0 -55
- data/lib/llm/shell/internal/coderay/lib/coderay/version.rb +0 -3
- data/lib/llm/shell/internal/coderay/lib/coderay.rb +0 -284
- data/lib/llm/shell/internal/io-line/lib/io/line/multiple.rb +0 -19
- data/lib/llm/shell/internal/io-line/lib/io/line.rb +0 -28
- data/lib/llm/shell/internal/llm.rb/lib/llm/bot/builder.rb +0 -31
- data/lib/llm/shell/internal/llm.rb/lib/llm/bot/conversable.rb +0 -37
- data/lib/llm/shell/internal/llm.rb/lib/llm/bot/prompt/completion.rb +0 -49
- data/lib/llm/shell/internal/llm.rb/lib/llm/bot/prompt/respond.rb +0 -49
- data/lib/llm/shell/internal/llm.rb/lib/llm/bot.rb +0 -150
- data/lib/llm/shell/internal/llm.rb/lib/llm/buffer.rb +0 -162
- data/lib/llm/shell/internal/llm.rb/lib/llm/client.rb +0 -36
- data/lib/llm/shell/internal/llm.rb/lib/llm/error.rb +0 -49
- data/lib/llm/shell/internal/llm.rb/lib/llm/eventhandler.rb +0 -44
- data/lib/llm/shell/internal/llm.rb/lib/llm/eventstream/event.rb +0 -69
- data/lib/llm/shell/internal/llm.rb/lib/llm/eventstream/parser.rb +0 -88
- data/lib/llm/shell/internal/llm.rb/lib/llm/eventstream.rb +0 -8
- data/lib/llm/shell/internal/llm.rb/lib/llm/file.rb +0 -91
- data/lib/llm/shell/internal/llm.rb/lib/llm/function.rb +0 -177
- data/lib/llm/shell/internal/llm.rb/lib/llm/message.rb +0 -178
- data/lib/llm/shell/internal/llm.rb/lib/llm/mime.rb +0 -140
- data/lib/llm/shell/internal/llm.rb/lib/llm/multipart.rb +0 -101
- data/lib/llm/shell/internal/llm.rb/lib/llm/object/builder.rb +0 -38
- data/lib/llm/shell/internal/llm.rb/lib/llm/object/kernel.rb +0 -53
- data/lib/llm/shell/internal/llm.rb/lib/llm/object.rb +0 -89
- data/lib/llm/shell/internal/llm.rb/lib/llm/provider.rb +0 -352
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/error_handler.rb +0 -36
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/files.rb +0 -155
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/format/completion_format.rb +0 -88
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/format.rb +0 -29
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/models.rb +0 -54
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/response/completion.rb +0 -39
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/response/enumerable.rb +0 -11
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/response/file.rb +0 -23
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/response/web_search.rb +0 -21
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/stream_parser.rb +0 -66
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic.rb +0 -138
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/deepseek/format/completion_format.rb +0 -68
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/deepseek/format.rb +0 -27
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/deepseek.rb +0 -75
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/audio.rb +0 -73
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/error_handler.rb +0 -47
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/files.rb +0 -146
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/format/completion_format.rb +0 -69
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/format.rb +0 -39
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/images.rb +0 -133
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/models.rb +0 -60
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/completion.rb +0 -35
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/embedding.rb +0 -8
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/file.rb +0 -11
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/files.rb +0 -15
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/image.rb +0 -31
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/models.rb +0 -15
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/web_search.rb +0 -22
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/stream_parser.rb +0 -86
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini.rb +0 -173
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/llamacpp.rb +0 -74
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/error_handler.rb +0 -36
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/format/completion_format.rb +0 -77
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/format.rb +0 -29
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/models.rb +0 -56
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/response/completion.rb +0 -28
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/response/embedding.rb +0 -9
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/stream_parser.rb +0 -44
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama.rb +0 -116
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/audio.rb +0 -91
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/error_handler.rb +0 -46
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/files.rb +0 -134
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/format/completion_format.rb +0 -90
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/format/moderation_format.rb +0 -35
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/format/respond_format.rb +0 -72
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/format.rb +0 -54
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/images.rb +0 -109
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/models.rb +0 -55
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/moderations.rb +0 -65
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/audio.rb +0 -7
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/completion.rb +0 -40
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/embedding.rb +0 -9
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/enumerable.rb +0 -23
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/file.rb +0 -7
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/image.rb +0 -16
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/moderations.rb +0 -34
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/responds.rb +0 -48
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/web_search.rb +0 -21
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/responses/stream_parser.rb +0 -76
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/responses.rb +0 -99
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/stream_parser.rb +0 -86
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/vector_stores.rb +0 -228
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai.rb +0 -206
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/xai/images.rb +0 -58
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/xai.rb +0 -72
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/zai.rb +0 -74
- data/lib/llm/shell/internal/llm.rb/lib/llm/response.rb +0 -67
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/array.rb +0 -26
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/boolean.rb +0 -13
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/integer.rb +0 -43
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/leaf.rb +0 -78
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/null.rb +0 -13
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/number.rb +0 -43
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/object.rb +0 -41
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/string.rb +0 -34
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/version.rb +0 -8
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema.rb +0 -81
- data/lib/llm/shell/internal/llm.rb/lib/llm/server_tool.rb +0 -32
- data/lib/llm/shell/internal/llm.rb/lib/llm/tool/param.rb +0 -75
- data/lib/llm/shell/internal/llm.rb/lib/llm/tool.rb +0 -78
- data/lib/llm/shell/internal/llm.rb/lib/llm/utils.rb +0 -19
- data/lib/llm/shell/internal/llm.rb/lib/llm/version.rb +0 -5
- data/lib/llm/shell/internal/llm.rb/lib/llm.rb +0 -121
- data/lib/llm/shell/internal/optparse/lib/optionparser.rb +0 -2
- data/lib/llm/shell/internal/optparse/lib/optparse/ac.rb +0 -70
- data/lib/llm/shell/internal/optparse/lib/optparse/date.rb +0 -18
- data/lib/llm/shell/internal/optparse/lib/optparse/kwargs.rb +0 -27
- data/lib/llm/shell/internal/optparse/lib/optparse/shellwords.rb +0 -7
- data/lib/llm/shell/internal/optparse/lib/optparse/time.rb +0 -11
- data/lib/llm/shell/internal/optparse/lib/optparse/uri.rb +0 -7
- data/lib/llm/shell/internal/optparse/lib/optparse/version.rb +0 -80
- data/lib/llm/shell/internal/optparse/lib/optparse.rb +0 -2469
- data/lib/llm/shell/internal/paint/lib/paint/constants.rb +0 -104
- data/lib/llm/shell/internal/paint/lib/paint/pa.rb +0 -13
- data/lib/llm/shell/internal/paint/lib/paint/rgb_colors.rb +0 -14
- data/lib/llm/shell/internal/paint/lib/paint/shortcuts.rb +0 -100
- data/lib/llm/shell/internal/paint/lib/paint/shortcuts_version.rb +0 -5
- data/lib/llm/shell/internal/paint/lib/paint/util.rb +0 -16
- data/lib/llm/shell/internal/paint/lib/paint/version.rb +0 -5
- data/lib/llm/shell/internal/paint/lib/paint.rb +0 -261
- data/lib/llm/shell/internal/reline/lib/reline/config.rb +0 -378
- data/lib/llm/shell/internal/reline/lib/reline/face.rb +0 -199
- data/lib/llm/shell/internal/reline/lib/reline/history.rb +0 -76
- data/lib/llm/shell/internal/reline/lib/reline/io/ansi.rb +0 -322
- data/lib/llm/shell/internal/reline/lib/reline/io/dumb.rb +0 -120
- data/lib/llm/shell/internal/reline/lib/reline/io/windows.rb +0 -530
- data/lib/llm/shell/internal/reline/lib/reline/io.rb +0 -55
- data/lib/llm/shell/internal/reline/lib/reline/key_actor/base.rb +0 -37
- data/lib/llm/shell/internal/reline/lib/reline/key_actor/composite.rb +0 -17
- data/lib/llm/shell/internal/reline/lib/reline/key_actor/emacs.rb +0 -517
- data/lib/llm/shell/internal/reline/lib/reline/key_actor/vi_command.rb +0 -518
- data/lib/llm/shell/internal/reline/lib/reline/key_actor/vi_insert.rb +0 -517
- data/lib/llm/shell/internal/reline/lib/reline/key_actor.rb +0 -8
- data/lib/llm/shell/internal/reline/lib/reline/key_stroke.rb +0 -119
- data/lib/llm/shell/internal/reline/lib/reline/kill_ring.rb +0 -125
- data/lib/llm/shell/internal/reline/lib/reline/line_editor.rb +0 -2356
- data/lib/llm/shell/internal/reline/lib/reline/unicode/east_asian_width.rb +0 -1292
- data/lib/llm/shell/internal/reline/lib/reline/unicode.rb +0 -421
- data/lib/llm/shell/internal/reline/lib/reline/version.rb +0 -3
- data/lib/llm/shell/internal/reline/lib/reline.rb +0 -527
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/generated_parser.rb +0 -712
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/handler.rb +0 -268
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/local_date.rb +0 -35
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/local_date_time.rb +0 -42
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/local_time.rb +0 -40
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/parser.rb +0 -21
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/scanner.rb +0 -92
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/string_utils.rb +0 -40
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/version.rb +0 -5
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb.rb +0 -49
- data/lib/llm/shell/markdown.rb +0 -83
- data/lib/llm/shell/options.rb +0 -39
- data/lib/llm/shell/renderer.rb +0 -51
- data/lib/llm/shell/repl.rb +0 -111
- data/lib/llm/shell/tool.rb +0 -42
- data/lib/llm/shell/tools/read_file.rb +0 -15
- data/lib/llm/shell/tools/system.rb +0 -17
- data/lib/llm/shell/tools/write_file.rb +0 -16
- data/lib/llm/shell/version.rb +0 -8
- data/lib/llm/shell.rb +0 -132
- data/lib/llm-shell.rb +0 -3
- data/libexec/llm-shell/shell +0 -43
- data/share/llm-shell/prompts/default.txt +0 -21
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
module CodeRay
|
|
2
|
-
module Scanners
|
|
3
|
-
|
|
4
|
-
class Go < Scanner
|
|
5
|
-
|
|
6
|
-
register_for :go
|
|
7
|
-
file_extension 'go'
|
|
8
|
-
|
|
9
|
-
# http://golang.org/ref/spec#Keywords
|
|
10
|
-
KEYWORDS = [
|
|
11
|
-
'break', 'default', 'func', 'interface', 'select',
|
|
12
|
-
'case', 'defer', 'go', 'map', 'struct',
|
|
13
|
-
'chan', 'else', 'goto', 'package', 'switch',
|
|
14
|
-
'const', 'fallthrough', 'if', 'range', 'type',
|
|
15
|
-
'continue', 'for', 'import', 'return', 'var',
|
|
16
|
-
] # :nodoc:
|
|
17
|
-
|
|
18
|
-
# http://golang.org/ref/spec#Types
|
|
19
|
-
PREDEFINED_TYPES = [
|
|
20
|
-
'bool',
|
|
21
|
-
'uint8', 'uint16', 'uint32', 'uint64',
|
|
22
|
-
'int8', 'int16', 'int32', 'int64',
|
|
23
|
-
'float32', 'float64',
|
|
24
|
-
'complex64', 'complex128',
|
|
25
|
-
'byte', 'rune', 'string', 'error',
|
|
26
|
-
'uint', 'int', 'uintptr',
|
|
27
|
-
] # :nodoc:
|
|
28
|
-
|
|
29
|
-
PREDEFINED_CONSTANTS = [
|
|
30
|
-
'nil', 'iota',
|
|
31
|
-
'true', 'false',
|
|
32
|
-
] # :nodoc:
|
|
33
|
-
|
|
34
|
-
PREDEFINED_FUNCTIONS = %w[
|
|
35
|
-
append cap close complex copy delete imag len
|
|
36
|
-
make new panic print println real recover
|
|
37
|
-
] # :nodoc:
|
|
38
|
-
|
|
39
|
-
IDENT_KIND = WordList.new(:ident).
|
|
40
|
-
add(KEYWORDS, :keyword).
|
|
41
|
-
add(PREDEFINED_TYPES, :predefined_type).
|
|
42
|
-
add(PREDEFINED_CONSTANTS, :predefined_constant).
|
|
43
|
-
add(PREDEFINED_FUNCTIONS, :predefined) # :nodoc:
|
|
44
|
-
|
|
45
|
-
ESCAPE = / [rbfntv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x # :nodoc:
|
|
46
|
-
UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x # :nodoc:
|
|
47
|
-
|
|
48
|
-
protected
|
|
49
|
-
|
|
50
|
-
def scan_tokens encoder, options
|
|
51
|
-
|
|
52
|
-
state = :initial
|
|
53
|
-
label_expected = true
|
|
54
|
-
case_expected = false
|
|
55
|
-
label_expected_before_preproc_line = nil
|
|
56
|
-
in_preproc_line = false
|
|
57
|
-
|
|
58
|
-
until eos?
|
|
59
|
-
|
|
60
|
-
case state
|
|
61
|
-
|
|
62
|
-
when :initial
|
|
63
|
-
|
|
64
|
-
if match = scan(/ \s+ | \\\n /x)
|
|
65
|
-
if in_preproc_line && match != "\\\n" && match.index(?\n)
|
|
66
|
-
in_preproc_line = false
|
|
67
|
-
case_expected = false
|
|
68
|
-
label_expected = label_expected_before_preproc_line
|
|
69
|
-
end
|
|
70
|
-
encoder.text_token match, :space
|
|
71
|
-
|
|
72
|
-
elsif match = scan(%r! // [^\n\\]* (?: \\. [^\n\\]* )* | /\* (?: .*? \*/ | .* ) !mx)
|
|
73
|
-
encoder.text_token match, :comment
|
|
74
|
-
|
|
75
|
-
elsif match = scan(/ <?- (?![\d.]) | [+*=<>?:;,!&^|()\[\]{}~%]+ | \/=? | \.(?!\d) /x)
|
|
76
|
-
if case_expected
|
|
77
|
-
label_expected = true if match == ':'
|
|
78
|
-
case_expected = false
|
|
79
|
-
end
|
|
80
|
-
encoder.text_token match, :operator
|
|
81
|
-
|
|
82
|
-
elsif match = scan(/ [A-Za-z_][A-Za-z_0-9]* /x)
|
|
83
|
-
kind = IDENT_KIND[match]
|
|
84
|
-
if kind == :ident && label_expected && !in_preproc_line && scan(/:(?!:)/)
|
|
85
|
-
kind = :label
|
|
86
|
-
label_expected = false
|
|
87
|
-
match << matched
|
|
88
|
-
else
|
|
89
|
-
label_expected = false
|
|
90
|
-
if kind == :keyword
|
|
91
|
-
case match
|
|
92
|
-
when 'case', 'default'
|
|
93
|
-
case_expected = true
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
encoder.text_token match, kind
|
|
98
|
-
|
|
99
|
-
elsif match = scan(/L?"/)
|
|
100
|
-
encoder.begin_group :string
|
|
101
|
-
if match[0] == ?L
|
|
102
|
-
encoder.text_token 'L', :modifier
|
|
103
|
-
match = '"'
|
|
104
|
-
end
|
|
105
|
-
encoder.text_token match, :delimiter
|
|
106
|
-
state = :string
|
|
107
|
-
|
|
108
|
-
elsif match = scan(/ ` ([^`]+)? (`)? /x)
|
|
109
|
-
encoder.begin_group :shell
|
|
110
|
-
encoder.text_token '`', :delimiter
|
|
111
|
-
encoder.text_token self[1], :content if self[1]
|
|
112
|
-
encoder.text_token self[2], :delimiter if self[2]
|
|
113
|
-
encoder.end_group :shell
|
|
114
|
-
|
|
115
|
-
elsif match = scan(/ \# \s* if \s* 0 /x)
|
|
116
|
-
match << scan_until(/ ^\# (?:elif|else|endif) .*? $ | \z /xm) unless eos?
|
|
117
|
-
encoder.text_token match, :comment
|
|
118
|
-
|
|
119
|
-
elsif match = scan(/#[ \t]*(\w*)/)
|
|
120
|
-
encoder.text_token match, :preprocessor
|
|
121
|
-
in_preproc_line = true
|
|
122
|
-
label_expected_before_preproc_line = label_expected
|
|
123
|
-
state = :include_expected if self[1] == 'include'
|
|
124
|
-
|
|
125
|
-
elsif match = scan(/ L?' (?: [^\'\n\\] | \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) )? '? /ox)
|
|
126
|
-
label_expected = false
|
|
127
|
-
encoder.text_token match, :char
|
|
128
|
-
|
|
129
|
-
elsif match = scan(/\$/)
|
|
130
|
-
encoder.text_token match, :ident
|
|
131
|
-
|
|
132
|
-
elsif match = scan(/-?\d*(\.\d*)?([eE][+-]?\d+)?i/)
|
|
133
|
-
label_expected = false
|
|
134
|
-
encoder.text_token match, :imaginary
|
|
135
|
-
|
|
136
|
-
elsif match = scan(/-?0[xX][0-9A-Fa-f]+/)
|
|
137
|
-
label_expected = false
|
|
138
|
-
encoder.text_token match, :hex
|
|
139
|
-
|
|
140
|
-
elsif match = scan(/-?(?:0[0-7]+)(?![89.eEfF])/)
|
|
141
|
-
label_expected = false
|
|
142
|
-
encoder.text_token match, :octal
|
|
143
|
-
|
|
144
|
-
elsif match = scan(/-?(?:\d*\.\d+|\d+\.)(?:[eE][+-]?\d+)?|\d+[eE][+-]?\d+/)
|
|
145
|
-
label_expected = false
|
|
146
|
-
encoder.text_token match, :float
|
|
147
|
-
|
|
148
|
-
elsif match = scan(/-?(?:\d+)(?![.eEfF])L?L?/)
|
|
149
|
-
label_expected = false
|
|
150
|
-
encoder.text_token match, :integer
|
|
151
|
-
|
|
152
|
-
else
|
|
153
|
-
encoder.text_token getch, :error
|
|
154
|
-
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
when :string
|
|
158
|
-
if match = scan(/[^\\\n"]+/)
|
|
159
|
-
encoder.text_token match, :content
|
|
160
|
-
elsif match = scan(/"/)
|
|
161
|
-
encoder.text_token match, :delimiter
|
|
162
|
-
encoder.end_group :string
|
|
163
|
-
state = :initial
|
|
164
|
-
label_expected = false
|
|
165
|
-
elsif match = scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox)
|
|
166
|
-
encoder.text_token match, :char
|
|
167
|
-
elsif match = scan(/ \\ /x)
|
|
168
|
-
encoder.text_token match, :error
|
|
169
|
-
elsif match = scan(/$/)
|
|
170
|
-
encoder.end_group :string
|
|
171
|
-
state = :initial
|
|
172
|
-
label_expected = false
|
|
173
|
-
else
|
|
174
|
-
raise_inspect "else case \" reached; %p not handled." % peek(1), encoder
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
when :include_expected
|
|
178
|
-
if match = scan(/<[^>\n]+>?|"[^"\n\\]*(?:\\.[^"\n\\]*)*"?/)
|
|
179
|
-
encoder.text_token match, :include
|
|
180
|
-
state = :initial
|
|
181
|
-
|
|
182
|
-
elsif match = scan(/\s+/)
|
|
183
|
-
encoder.text_token match, :space
|
|
184
|
-
state = :initial if match.index ?\n
|
|
185
|
-
|
|
186
|
-
else
|
|
187
|
-
state = :initial
|
|
188
|
-
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
else
|
|
192
|
-
raise_inspect 'Unknown state', encoder
|
|
193
|
-
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
if state == :string
|
|
199
|
-
encoder.end_group :string
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
encoder
|
|
203
|
-
end
|
|
204
|
-
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
end
|
|
208
|
-
end
|
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
module CodeRay
|
|
2
|
-
module Scanners
|
|
3
|
-
|
|
4
|
-
load :java
|
|
5
|
-
|
|
6
|
-
# Scanner for Groovy.
|
|
7
|
-
class Groovy < Java
|
|
8
|
-
|
|
9
|
-
register_for :groovy
|
|
10
|
-
|
|
11
|
-
# TODO: check list of keywords
|
|
12
|
-
GROOVY_KEYWORDS = %w[
|
|
13
|
-
as assert def in
|
|
14
|
-
] # :nodoc:
|
|
15
|
-
KEYWORDS_EXPECTING_VALUE = WordList.new.add %w[
|
|
16
|
-
case instanceof new return throw typeof while as assert in
|
|
17
|
-
] # :nodoc:
|
|
18
|
-
GROOVY_MAGIC_VARIABLES = %w[ it ] # :nodoc:
|
|
19
|
-
|
|
20
|
-
IDENT_KIND = Java::IDENT_KIND.dup.
|
|
21
|
-
add(GROOVY_KEYWORDS, :keyword).
|
|
22
|
-
add(GROOVY_MAGIC_VARIABLES, :local_variable) # :nodoc:
|
|
23
|
-
|
|
24
|
-
ESCAPE = / [bfnrtv$\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x # :nodoc:
|
|
25
|
-
UNICODE_ESCAPE = / u[a-fA-F0-9]{4} /x # :nodoc: no 4-byte unicode chars? U[a-fA-F0-9]{8}
|
|
26
|
-
REGEXP_ESCAPE = / [bfnrtv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} | \d | [bBdDsSwW\/] /x # :nodoc:
|
|
27
|
-
|
|
28
|
-
# TODO: interpretation inside ', ", /
|
|
29
|
-
STRING_CONTENT_PATTERN = {
|
|
30
|
-
"'" => /(?>\\[^\\'\n]+|[^\\'\n]+)+/,
|
|
31
|
-
'"' => /[^\\$"\n]+/,
|
|
32
|
-
"'''" => /(?>[^\\']+|'(?!''))+/,
|
|
33
|
-
'"""' => /(?>[^\\$"]+|"(?!""))+/,
|
|
34
|
-
'/' => /[^\\$\/\n]+/,
|
|
35
|
-
} # :nodoc:
|
|
36
|
-
|
|
37
|
-
protected
|
|
38
|
-
|
|
39
|
-
def setup
|
|
40
|
-
@state = :initial
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def scan_tokens encoder, options
|
|
44
|
-
state = options[:state] || @state
|
|
45
|
-
inline_block_stack = []
|
|
46
|
-
inline_block_paren_depth = nil
|
|
47
|
-
string_delimiter = nil
|
|
48
|
-
import_clause = class_name_follows = last_token = after_def = false
|
|
49
|
-
value_expected = true
|
|
50
|
-
|
|
51
|
-
until eos?
|
|
52
|
-
|
|
53
|
-
case state
|
|
54
|
-
|
|
55
|
-
when :initial
|
|
56
|
-
|
|
57
|
-
if match = scan(/ \s+ | \\\n /x)
|
|
58
|
-
encoder.text_token match, :space
|
|
59
|
-
if match.index ?\n
|
|
60
|
-
import_clause = after_def = false
|
|
61
|
-
value_expected = true unless value_expected
|
|
62
|
-
end
|
|
63
|
-
next
|
|
64
|
-
|
|
65
|
-
elsif match = scan(%r! // [^\n\\]* (?: \\. [^\n\\]* )* | /\* (?: .*? \*/ | .* ) !mx)
|
|
66
|
-
value_expected = true
|
|
67
|
-
after_def = false
|
|
68
|
-
encoder.text_token match, :comment
|
|
69
|
-
|
|
70
|
-
elsif bol? && match = scan(/ \#!.* /x)
|
|
71
|
-
encoder.text_token match, :doctype
|
|
72
|
-
|
|
73
|
-
elsif import_clause && match = scan(/ (?!as) #{IDENT} (?: \. #{IDENT} )* (?: \.\* )? /ox)
|
|
74
|
-
after_def = value_expected = false
|
|
75
|
-
encoder.text_token match, :include
|
|
76
|
-
|
|
77
|
-
elsif match = scan(/ #{IDENT} | \[\] /ox)
|
|
78
|
-
kind = IDENT_KIND[match]
|
|
79
|
-
value_expected = (kind == :keyword) && KEYWORDS_EXPECTING_VALUE[match]
|
|
80
|
-
if last_token == '.'
|
|
81
|
-
kind = :ident
|
|
82
|
-
elsif class_name_follows
|
|
83
|
-
kind = :class
|
|
84
|
-
class_name_follows = false
|
|
85
|
-
elsif after_def && check(/\s*[({]/)
|
|
86
|
-
kind = :method
|
|
87
|
-
after_def = false
|
|
88
|
-
elsif kind == :ident && last_token != '?' && check(/:/)
|
|
89
|
-
kind = :key
|
|
90
|
-
else
|
|
91
|
-
class_name_follows = true if match == 'class' || (import_clause && match == 'as')
|
|
92
|
-
import_clause = match == 'import'
|
|
93
|
-
after_def = true if match == 'def'
|
|
94
|
-
end
|
|
95
|
-
encoder.text_token match, kind
|
|
96
|
-
|
|
97
|
-
elsif match = scan(/;/)
|
|
98
|
-
import_clause = after_def = false
|
|
99
|
-
value_expected = true
|
|
100
|
-
encoder.text_token match, :operator
|
|
101
|
-
|
|
102
|
-
elsif match = scan(/\{/)
|
|
103
|
-
class_name_follows = after_def = false
|
|
104
|
-
value_expected = true
|
|
105
|
-
encoder.text_token match, :operator
|
|
106
|
-
if !inline_block_stack.empty?
|
|
107
|
-
inline_block_paren_depth += 1
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
# TODO: ~'...', ~"..." and ~/.../ style regexps
|
|
111
|
-
elsif match = scan(/ \.\.<? | \*?\.(?!\d)@? | \.& | \?:? | [,?:(\[] | -[->] | \+\+ |
|
|
112
|
-
&& | \|\| | \*\*=? | ==?~ | <=?>? | [-+*%^~&|>=!]=? | <<<?=? | >>>?=? /x)
|
|
113
|
-
value_expected = true
|
|
114
|
-
value_expected = :regexp if match == '~'
|
|
115
|
-
after_def = false
|
|
116
|
-
encoder.text_token match, :operator
|
|
117
|
-
|
|
118
|
-
elsif match = scan(/ [)\]}] /x)
|
|
119
|
-
value_expected = after_def = false
|
|
120
|
-
if !inline_block_stack.empty? && match == '}'
|
|
121
|
-
inline_block_paren_depth -= 1
|
|
122
|
-
if inline_block_paren_depth == 0 # closing brace of inline block reached
|
|
123
|
-
encoder.text_token match, :inline_delimiter
|
|
124
|
-
encoder.end_group :inline
|
|
125
|
-
state, string_delimiter, inline_block_paren_depth = inline_block_stack.pop
|
|
126
|
-
next
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
encoder.text_token match, :operator
|
|
130
|
-
|
|
131
|
-
elsif check(/[\d.]/)
|
|
132
|
-
after_def = value_expected = false
|
|
133
|
-
if match = scan(/0[xX][0-9A-Fa-f]+/)
|
|
134
|
-
encoder.text_token match, :hex
|
|
135
|
-
elsif match = scan(/(?>0[0-7]+)(?![89.eEfF])/)
|
|
136
|
-
encoder.text_token match, :octal
|
|
137
|
-
elsif match = scan(/\d+[fFdD]|\d*\.\d+(?:[eE][+-]?\d+)?[fFdD]?|\d+[eE][+-]?\d+[fFdD]?/)
|
|
138
|
-
encoder.text_token match, :float
|
|
139
|
-
elsif match = scan(/\d+[lLgG]?/)
|
|
140
|
-
encoder.text_token match, :integer
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
elsif match = scan(/'''|"""/)
|
|
144
|
-
after_def = value_expected = false
|
|
145
|
-
state = :multiline_string
|
|
146
|
-
encoder.begin_group :string
|
|
147
|
-
string_delimiter = match
|
|
148
|
-
encoder.text_token match, :delimiter
|
|
149
|
-
|
|
150
|
-
# TODO: record.'name' syntax
|
|
151
|
-
elsif match = scan(/["']/)
|
|
152
|
-
after_def = value_expected = false
|
|
153
|
-
state = match == '/' ? :regexp : :string
|
|
154
|
-
encoder.begin_group state
|
|
155
|
-
string_delimiter = match
|
|
156
|
-
encoder.text_token match, :delimiter
|
|
157
|
-
|
|
158
|
-
elsif value_expected && match = scan(/\//)
|
|
159
|
-
after_def = value_expected = false
|
|
160
|
-
encoder.begin_group :regexp
|
|
161
|
-
state = :regexp
|
|
162
|
-
string_delimiter = '/'
|
|
163
|
-
encoder.text_token match, :delimiter
|
|
164
|
-
|
|
165
|
-
elsif match = scan(/ @ #{IDENT} /ox)
|
|
166
|
-
after_def = value_expected = false
|
|
167
|
-
encoder.text_token match, :annotation
|
|
168
|
-
|
|
169
|
-
elsif match = scan(/\//)
|
|
170
|
-
after_def = false
|
|
171
|
-
value_expected = true
|
|
172
|
-
encoder.text_token match, :operator
|
|
173
|
-
|
|
174
|
-
else
|
|
175
|
-
encoder.text_token getch, :error
|
|
176
|
-
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
when :string, :regexp, :multiline_string
|
|
180
|
-
if match = scan(STRING_CONTENT_PATTERN[string_delimiter])
|
|
181
|
-
encoder.text_token match, :content
|
|
182
|
-
|
|
183
|
-
elsif match = scan(state == :multiline_string ? /'''|"""/ : /["'\/]/)
|
|
184
|
-
encoder.text_token match, :delimiter
|
|
185
|
-
if state == :regexp
|
|
186
|
-
# TODO: regexp modifiers? s, m, x, i?
|
|
187
|
-
modifiers = scan(/[ix]+/)
|
|
188
|
-
encoder.text_token modifiers, :modifier if modifiers && !modifiers.empty?
|
|
189
|
-
end
|
|
190
|
-
state = :string if state == :multiline_string
|
|
191
|
-
encoder.end_group state
|
|
192
|
-
string_delimiter = nil
|
|
193
|
-
after_def = value_expected = false
|
|
194
|
-
state = :initial
|
|
195
|
-
next
|
|
196
|
-
|
|
197
|
-
elsif (state == :string || state == :multiline_string) &&
|
|
198
|
-
(match = scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox))
|
|
199
|
-
if string_delimiter[0] == ?' && !(match == "\\\\" || match == "\\'")
|
|
200
|
-
encoder.text_token match, :content
|
|
201
|
-
else
|
|
202
|
-
encoder.text_token match, :char
|
|
203
|
-
end
|
|
204
|
-
elsif state == :regexp && match = scan(/ \\ (?: #{REGEXP_ESCAPE} | #{UNICODE_ESCAPE} ) /mox)
|
|
205
|
-
encoder.text_token match, :char
|
|
206
|
-
|
|
207
|
-
elsif match = scan(/ \$ #{IDENT} /mox)
|
|
208
|
-
encoder.begin_group :inline
|
|
209
|
-
encoder.text_token '$', :inline_delimiter
|
|
210
|
-
match = match[1..-1]
|
|
211
|
-
encoder.text_token match, IDENT_KIND[match]
|
|
212
|
-
encoder.end_group :inline
|
|
213
|
-
next
|
|
214
|
-
elsif match = scan(/ \$ \{ /x)
|
|
215
|
-
encoder.begin_group :inline
|
|
216
|
-
encoder.text_token match, :inline_delimiter
|
|
217
|
-
inline_block_stack << [state, string_delimiter, inline_block_paren_depth]
|
|
218
|
-
inline_block_paren_depth = 1
|
|
219
|
-
state = :initial
|
|
220
|
-
next
|
|
221
|
-
|
|
222
|
-
elsif match = scan(/ \$ /mx)
|
|
223
|
-
encoder.text_token match, :content
|
|
224
|
-
|
|
225
|
-
elsif match = scan(/ \\. /mx)
|
|
226
|
-
encoder.text_token match, :content # TODO: Shouldn't this be :error?
|
|
227
|
-
|
|
228
|
-
elsif match = scan(/ \\ | \n /x)
|
|
229
|
-
encoder.end_group state == :regexp ? :regexp : :string
|
|
230
|
-
encoder.text_token match, :error
|
|
231
|
-
after_def = value_expected = false
|
|
232
|
-
state = :initial
|
|
233
|
-
|
|
234
|
-
else
|
|
235
|
-
raise_inspect "else case \" reached; %p not handled." % peek(1), encoder
|
|
236
|
-
|
|
237
|
-
end
|
|
238
|
-
|
|
239
|
-
else
|
|
240
|
-
raise_inspect 'Unknown state', encoder
|
|
241
|
-
|
|
242
|
-
end
|
|
243
|
-
|
|
244
|
-
last_token = match unless [:space, :comment, :doctype].include? kind
|
|
245
|
-
|
|
246
|
-
end
|
|
247
|
-
|
|
248
|
-
if [:multiline_string, :string, :regexp].include? state
|
|
249
|
-
encoder.end_group state == :regexp ? :regexp : :string
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
if options[:keep_state]
|
|
253
|
-
@state = state
|
|
254
|
-
end
|
|
255
|
-
|
|
256
|
-
until inline_block_stack.empty?
|
|
257
|
-
state, = *inline_block_stack.pop
|
|
258
|
-
encoder.end_group :inline
|
|
259
|
-
encoder.end_group state == :regexp ? :regexp : :string
|
|
260
|
-
end
|
|
261
|
-
|
|
262
|
-
encoder
|
|
263
|
-
end
|
|
264
|
-
|
|
265
|
-
end
|
|
266
|
-
|
|
267
|
-
end
|
|
268
|
-
end
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
module CodeRay
|
|
2
|
-
module Scanners
|
|
3
|
-
|
|
4
|
-
load :ruby
|
|
5
|
-
load :html
|
|
6
|
-
load :java_script
|
|
7
|
-
|
|
8
|
-
class HAML < Scanner
|
|
9
|
-
|
|
10
|
-
register_for :haml
|
|
11
|
-
title 'HAML Template'
|
|
12
|
-
|
|
13
|
-
KINDS_NOT_LOC = HTML::KINDS_NOT_LOC
|
|
14
|
-
|
|
15
|
-
protected
|
|
16
|
-
|
|
17
|
-
def setup
|
|
18
|
-
super
|
|
19
|
-
@ruby_scanner = CodeRay.scanner :ruby, :tokens => @tokens, :keep_tokens => true
|
|
20
|
-
@embedded_ruby_scanner = CodeRay.scanner :ruby, :tokens => @tokens, :keep_tokens => true, :state => @ruby_scanner.interpreted_string_state
|
|
21
|
-
@html_scanner = CodeRay.scanner :html, :tokens => @tokens, :keep_tokens => true
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def scan_tokens encoder, options
|
|
25
|
-
|
|
26
|
-
match = nil
|
|
27
|
-
code = ''
|
|
28
|
-
|
|
29
|
-
until eos?
|
|
30
|
-
|
|
31
|
-
if bol?
|
|
32
|
-
if match = scan(/!!!.*/)
|
|
33
|
-
encoder.text_token match, :doctype
|
|
34
|
-
next
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
if match = scan(/(?>( *)(\/(?!\[if)|-\#|:javascript|:ruby|:\w+) *)(?=\n)/)
|
|
38
|
-
encoder.text_token match, :comment
|
|
39
|
-
|
|
40
|
-
code = self[2]
|
|
41
|
-
if match = scan(/(?:\n+#{self[1]} .*)+/)
|
|
42
|
-
case code
|
|
43
|
-
when '/', '-#'
|
|
44
|
-
encoder.text_token match, :comment
|
|
45
|
-
when ':javascript'
|
|
46
|
-
# TODO: recognize #{...} snippets inside JavaScript
|
|
47
|
-
@java_script_scanner ||= CodeRay.scanner :java_script, :tokens => @tokens, :keep_tokens => true
|
|
48
|
-
@java_script_scanner.tokenize match, :tokens => encoder
|
|
49
|
-
when ':ruby'
|
|
50
|
-
@ruby_scanner.tokenize match, :tokens => encoder
|
|
51
|
-
when /:\w+/
|
|
52
|
-
encoder.text_token match, :comment
|
|
53
|
-
else
|
|
54
|
-
raise 'else-case reached: %p' % [code]
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
if match = scan(/ +/)
|
|
60
|
-
encoder.text_token match, :space
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
if match = scan(/\/.*/)
|
|
64
|
-
encoder.text_token match, :comment
|
|
65
|
-
next
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
if match = scan(/\\/)
|
|
69
|
-
encoder.text_token match, :plain
|
|
70
|
-
if match = scan(/.+/)
|
|
71
|
-
@html_scanner.tokenize match, :tokens => encoder
|
|
72
|
-
end
|
|
73
|
-
next
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
tag = false
|
|
77
|
-
|
|
78
|
-
if match = scan(/%[-\w:]+\/?/)
|
|
79
|
-
encoder.text_token match, :tag
|
|
80
|
-
# if match = scan(/( +)(.+)/)
|
|
81
|
-
# encoder.text_token self[1], :space
|
|
82
|
-
# @embedded_ruby_scanner.tokenize self[2], :tokens => encoder
|
|
83
|
-
# end
|
|
84
|
-
tag = true
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
while match = scan(/([.#])[-\w]*\w/)
|
|
88
|
-
encoder.text_token match, self[1] == '#' ? :constant : :class
|
|
89
|
-
tag = true
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
if tag && match = scan(/(\()([^)]+)?(\))?/)
|
|
93
|
-
# TODO: recognize title=@title, class="widget_#{@widget.number}"
|
|
94
|
-
encoder.text_token self[1], :plain
|
|
95
|
-
@html_scanner.tokenize self[2], :tokens => encoder, :state => :attribute if self[2]
|
|
96
|
-
encoder.text_token self[3], :plain if self[3]
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
if tag && match = scan(/\{/)
|
|
100
|
-
encoder.text_token match, :plain
|
|
101
|
-
|
|
102
|
-
code = ''
|
|
103
|
-
level = 1
|
|
104
|
-
while true
|
|
105
|
-
code << scan(/([^\{\},\n]|, *\n?)*/)
|
|
106
|
-
case match = getch
|
|
107
|
-
when '{'
|
|
108
|
-
level += 1
|
|
109
|
-
code << match
|
|
110
|
-
when '}'
|
|
111
|
-
level -= 1
|
|
112
|
-
if level > 0
|
|
113
|
-
code << match
|
|
114
|
-
else
|
|
115
|
-
break
|
|
116
|
-
end
|
|
117
|
-
when "\n", ",", nil
|
|
118
|
-
break
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
@ruby_scanner.tokenize code, :tokens => encoder unless code.empty?
|
|
122
|
-
|
|
123
|
-
encoder.text_token match, :plain if match
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
if tag && match = scan(/(\[)([^\]\n]+)?(\])?/)
|
|
127
|
-
encoder.text_token self[1], :plain
|
|
128
|
-
@ruby_scanner.tokenize self[2], :tokens => encoder if self[2]
|
|
129
|
-
encoder.text_token self[3], :plain if self[3]
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
if tag && match = scan(/\//)
|
|
133
|
-
encoder.text_token match, :tag
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
if scan(/(>?<?[-=]|[&!]=|(& |!)|~)( *)([^,\n\|]+(?:(, *|\|(?=.|\n.*\|$))\n?[^,\n\|]*)*)?/)
|
|
137
|
-
encoder.text_token self[1] + self[3], :plain
|
|
138
|
-
if self[4]
|
|
139
|
-
if self[2]
|
|
140
|
-
@embedded_ruby_scanner.tokenize self[4], :tokens => encoder
|
|
141
|
-
else
|
|
142
|
-
@ruby_scanner.tokenize self[4], :tokens => encoder
|
|
143
|
-
end
|
|
144
|
-
end
|
|
145
|
-
elsif match = scan(/((?:<|><?)(?![!?\/\w]))?(.+)?/)
|
|
146
|
-
encoder.text_token self[1], :plain if self[1]
|
|
147
|
-
# TODO: recognize #{...} snippets
|
|
148
|
-
@html_scanner.tokenize self[2], :tokens => encoder if self[2]
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
elsif match = scan(/.+/)
|
|
152
|
-
@html_scanner.tokenize match, :tokens => encoder
|
|
153
|
-
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
if match = scan(/\n/)
|
|
157
|
-
encoder.text_token match, :space
|
|
158
|
-
end
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
encoder
|
|
162
|
-
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
end
|
|
168
|
-
end
|