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.
Files changed (258) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +61 -66
  3. data/lib/llm/shell/command.rb +40 -40
  4. data/lib/llm/shell/commands/clear_screen.rb +4 -18
  5. data/lib/llm/shell/commands/debug_mode.rb +12 -0
  6. data/lib/llm/shell/commands/dir_import.rb +4 -20
  7. data/lib/llm/shell/commands/disable_tool.rb +33 -0
  8. data/lib/llm/shell/commands/enable_tool.rb +33 -0
  9. data/lib/llm/shell/commands/file_import.rb +4 -20
  10. data/lib/llm/shell/commands/help.rb +23 -36
  11. data/lib/llm/shell/commands/show_chat.rb +4 -19
  12. data/lib/llm/shell/commands/show_version.rb +4 -20
  13. data/lib/llm/shell/commands/system_prompt.rb +4 -18
  14. data/lib/llm/shell/completion.rb +5 -5
  15. data/lib/llm/shell/config.rb +4 -5
  16. data/lib/llm/shell/formatter.rb +1 -2
  17. data/lib/llm/shell/internal/coderay/lib/coderay/duo.rb +81 -0
  18. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/_map.rb +17 -0
  19. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/comment_filter.rb +25 -0
  20. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/count.rb +39 -0
  21. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/debug.rb +49 -0
  22. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/debug_lint.rb +63 -0
  23. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/div.rb +23 -0
  24. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/encoder.rb +190 -0
  25. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/filter.rb +58 -0
  26. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/html/css.rb +65 -0
  27. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/html/numbering.rb +108 -0
  28. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/html/output.rb +164 -0
  29. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/html.rb +333 -0
  30. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/json.rb +83 -0
  31. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/lines_of_code.rb +45 -0
  32. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/lint.rb +59 -0
  33. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/null.rb +18 -0
  34. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/page.rb +24 -0
  35. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/span.rb +23 -0
  36. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/statistic.rb +95 -0
  37. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/terminal.rb +195 -0
  38. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/text.rb +46 -0
  39. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/token_kind_filter.rb +111 -0
  40. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/xml.rb +72 -0
  41. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/yaml.rb +50 -0
  42. data/lib/llm/shell/internal/coderay/lib/coderay/encoders.rb +18 -0
  43. data/lib/llm/shell/internal/coderay/lib/coderay/for_redcloth.rb +95 -0
  44. data/lib/llm/shell/internal/coderay/lib/coderay/helpers/file_type.rb +151 -0
  45. data/lib/llm/shell/internal/coderay/lib/coderay/helpers/plugin.rb +55 -0
  46. data/lib/llm/shell/internal/coderay/lib/coderay/helpers/plugin_host.rb +221 -0
  47. data/lib/llm/shell/internal/coderay/lib/coderay/helpers/word_list.rb +72 -0
  48. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/_map.rb +24 -0
  49. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/c.rb +189 -0
  50. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/clojure.rb +217 -0
  51. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/cpp.rb +217 -0
  52. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/css.rb +196 -0
  53. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/debug.rb +75 -0
  54. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/delphi.rb +144 -0
  55. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/diff.rb +221 -0
  56. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/erb.rb +81 -0
  57. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/go.rb +208 -0
  58. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/groovy.rb +268 -0
  59. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/haml.rb +168 -0
  60. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/html.rb +275 -0
  61. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/java/builtin_types.rb +421 -0
  62. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/java.rb +174 -0
  63. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/java_script.rb +236 -0
  64. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/json.rb +98 -0
  65. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/lua.rb +280 -0
  66. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/php.rb +527 -0
  67. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/python.rb +287 -0
  68. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/raydebug.rb +75 -0
  69. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/ruby/patterns.rb +178 -0
  70. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/ruby/string_state.rb +79 -0
  71. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/ruby.rb +477 -0
  72. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/sass.rb +232 -0
  73. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/scanner.rb +337 -0
  74. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/sql.rb +169 -0
  75. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/taskpaper.rb +36 -0
  76. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/text.rb +26 -0
  77. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/xml.rb +17 -0
  78. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/yaml.rb +140 -0
  79. data/lib/llm/shell/internal/coderay/lib/coderay/scanners.rb +27 -0
  80. data/lib/llm/shell/internal/coderay/lib/coderay/styles/_map.rb +7 -0
  81. data/lib/llm/shell/internal/coderay/lib/coderay/styles/alpha.rb +153 -0
  82. data/lib/llm/shell/internal/coderay/lib/coderay/styles/style.rb +18 -0
  83. data/lib/llm/shell/internal/coderay/lib/coderay/styles.rb +15 -0
  84. data/lib/llm/shell/internal/coderay/lib/coderay/token_kinds.rb +85 -0
  85. data/lib/llm/shell/internal/coderay/lib/coderay/tokens.rb +164 -0
  86. data/lib/llm/shell/internal/coderay/lib/coderay/tokens_proxy.rb +55 -0
  87. data/lib/llm/shell/internal/coderay/lib/coderay/version.rb +3 -0
  88. data/lib/llm/shell/internal/coderay/lib/coderay.rb +284 -0
  89. data/lib/llm/shell/internal/io-line/lib/io/line/multiple.rb +19 -0
  90. data/lib/{io → llm/shell/internal/io-line/lib/io}/line.rb +2 -0
  91. data/lib/llm/shell/internal/llm.rb/lib/llm/bot/builder.rb +31 -0
  92. data/lib/llm/shell/internal/llm.rb/lib/llm/bot/conversable.rb +37 -0
  93. data/lib/llm/shell/internal/llm.rb/lib/llm/bot/prompt/completion.rb +49 -0
  94. data/lib/llm/shell/internal/llm.rb/lib/llm/bot/prompt/respond.rb +49 -0
  95. data/lib/llm/shell/internal/llm.rb/lib/llm/bot.rb +150 -0
  96. data/lib/llm/shell/internal/llm.rb/lib/llm/buffer.rb +162 -0
  97. data/lib/llm/shell/internal/llm.rb/lib/llm/client.rb +36 -0
  98. data/lib/llm/shell/internal/llm.rb/lib/llm/error.rb +49 -0
  99. data/lib/llm/shell/internal/llm.rb/lib/llm/eventhandler.rb +44 -0
  100. data/lib/llm/shell/internal/llm.rb/lib/llm/eventstream/event.rb +69 -0
  101. data/lib/llm/shell/internal/llm.rb/lib/llm/eventstream/parser.rb +88 -0
  102. data/lib/llm/shell/internal/llm.rb/lib/llm/eventstream.rb +8 -0
  103. data/lib/llm/shell/internal/llm.rb/lib/llm/file.rb +91 -0
  104. data/lib/llm/shell/internal/llm.rb/lib/llm/function.rb +177 -0
  105. data/lib/llm/shell/internal/llm.rb/lib/llm/message.rb +178 -0
  106. data/lib/llm/shell/internal/llm.rb/lib/llm/mime.rb +140 -0
  107. data/lib/llm/shell/internal/llm.rb/lib/llm/multipart.rb +101 -0
  108. data/lib/llm/shell/internal/llm.rb/lib/llm/object/builder.rb +38 -0
  109. data/lib/llm/shell/internal/llm.rb/lib/llm/object/kernel.rb +53 -0
  110. data/lib/llm/shell/internal/llm.rb/lib/llm/object.rb +89 -0
  111. data/lib/llm/shell/internal/llm.rb/lib/llm/provider.rb +352 -0
  112. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/error_handler.rb +36 -0
  113. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/files.rb +155 -0
  114. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/format/completion_format.rb +88 -0
  115. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/format.rb +29 -0
  116. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/models.rb +54 -0
  117. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/response/completion.rb +39 -0
  118. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/response/enumerable.rb +11 -0
  119. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/response/file.rb +23 -0
  120. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/response/web_search.rb +21 -0
  121. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/stream_parser.rb +66 -0
  122. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic.rb +138 -0
  123. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/deepseek/format/completion_format.rb +68 -0
  124. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/deepseek/format.rb +27 -0
  125. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/deepseek.rb +75 -0
  126. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/audio.rb +73 -0
  127. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/error_handler.rb +47 -0
  128. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/files.rb +146 -0
  129. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/format/completion_format.rb +69 -0
  130. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/format.rb +39 -0
  131. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/images.rb +133 -0
  132. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/models.rb +60 -0
  133. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/completion.rb +35 -0
  134. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/embedding.rb +8 -0
  135. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/file.rb +11 -0
  136. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/files.rb +15 -0
  137. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/image.rb +31 -0
  138. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/models.rb +15 -0
  139. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/web_search.rb +22 -0
  140. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/stream_parser.rb +86 -0
  141. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini.rb +173 -0
  142. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/llamacpp.rb +74 -0
  143. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/error_handler.rb +36 -0
  144. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/format/completion_format.rb +77 -0
  145. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/format.rb +29 -0
  146. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/models.rb +56 -0
  147. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/response/completion.rb +28 -0
  148. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/response/embedding.rb +9 -0
  149. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/stream_parser.rb +44 -0
  150. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama.rb +116 -0
  151. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/audio.rb +91 -0
  152. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/error_handler.rb +46 -0
  153. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/files.rb +134 -0
  154. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/format/completion_format.rb +90 -0
  155. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/format/moderation_format.rb +35 -0
  156. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/format/respond_format.rb +72 -0
  157. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/format.rb +54 -0
  158. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/images.rb +109 -0
  159. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/models.rb +55 -0
  160. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/moderations.rb +65 -0
  161. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/audio.rb +7 -0
  162. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/completion.rb +40 -0
  163. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/embedding.rb +9 -0
  164. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/enumerable.rb +23 -0
  165. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/file.rb +7 -0
  166. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/image.rb +16 -0
  167. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/moderations.rb +34 -0
  168. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/responds.rb +48 -0
  169. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/web_search.rb +21 -0
  170. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/responses/stream_parser.rb +76 -0
  171. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/responses.rb +99 -0
  172. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/stream_parser.rb +86 -0
  173. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/vector_stores.rb +228 -0
  174. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai.rb +206 -0
  175. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/xai/images.rb +58 -0
  176. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/xai.rb +72 -0
  177. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/zai.rb +74 -0
  178. data/lib/llm/shell/internal/llm.rb/lib/llm/response.rb +67 -0
  179. data/lib/llm/shell/internal/llm.rb/lib/llm/schema/array.rb +26 -0
  180. data/lib/llm/shell/internal/llm.rb/lib/llm/schema/boolean.rb +13 -0
  181. data/lib/llm/shell/internal/llm.rb/lib/llm/schema/integer.rb +43 -0
  182. data/lib/llm/shell/internal/llm.rb/lib/llm/schema/leaf.rb +78 -0
  183. data/lib/llm/shell/internal/llm.rb/lib/llm/schema/null.rb +13 -0
  184. data/lib/llm/shell/internal/llm.rb/lib/llm/schema/number.rb +43 -0
  185. data/lib/llm/shell/internal/llm.rb/lib/llm/schema/object.rb +41 -0
  186. data/lib/llm/shell/internal/llm.rb/lib/llm/schema/string.rb +34 -0
  187. data/lib/llm/shell/internal/llm.rb/lib/llm/schema/version.rb +8 -0
  188. data/lib/llm/shell/internal/llm.rb/lib/llm/schema.rb +81 -0
  189. data/lib/llm/shell/internal/llm.rb/lib/llm/server_tool.rb +32 -0
  190. data/lib/llm/shell/internal/llm.rb/lib/llm/tool/param.rb +75 -0
  191. data/lib/llm/shell/internal/llm.rb/lib/llm/tool.rb +78 -0
  192. data/lib/llm/shell/internal/llm.rb/lib/llm/utils.rb +19 -0
  193. data/lib/llm/shell/internal/llm.rb/lib/llm/version.rb +5 -0
  194. data/lib/llm/shell/internal/llm.rb/lib/llm.rb +121 -0
  195. data/lib/llm/shell/internal/optparse/lib/optionparser.rb +2 -0
  196. data/lib/llm/shell/internal/optparse/lib/optparse/ac.rb +70 -0
  197. data/lib/llm/shell/internal/optparse/lib/optparse/date.rb +18 -0
  198. data/lib/llm/shell/internal/optparse/lib/optparse/kwargs.rb +27 -0
  199. data/lib/llm/shell/internal/optparse/lib/optparse/shellwords.rb +7 -0
  200. data/lib/llm/shell/internal/optparse/lib/optparse/time.rb +11 -0
  201. data/lib/llm/shell/internal/optparse/lib/optparse/uri.rb +7 -0
  202. data/lib/llm/shell/internal/optparse/lib/optparse/version.rb +80 -0
  203. data/lib/llm/shell/internal/optparse/lib/optparse.rb +2469 -0
  204. data/lib/llm/shell/internal/paint/lib/paint/constants.rb +104 -0
  205. data/lib/llm/shell/internal/paint/lib/paint/pa.rb +13 -0
  206. data/lib/llm/shell/internal/paint/lib/paint/rgb_colors.rb +14 -0
  207. data/lib/llm/shell/internal/paint/lib/paint/shortcuts.rb +100 -0
  208. data/lib/llm/shell/internal/paint/lib/paint/shortcuts_version.rb +5 -0
  209. data/lib/llm/shell/internal/paint/lib/paint/util.rb +16 -0
  210. data/lib/llm/shell/internal/paint/lib/paint/version.rb +5 -0
  211. data/lib/llm/shell/internal/paint/lib/paint.rb +261 -0
  212. data/lib/llm/shell/internal/reline/lib/reline/config.rb +378 -0
  213. data/lib/llm/shell/internal/reline/lib/reline/face.rb +199 -0
  214. data/lib/llm/shell/internal/reline/lib/reline/history.rb +76 -0
  215. data/lib/llm/shell/internal/reline/lib/reline/io/ansi.rb +322 -0
  216. data/lib/llm/shell/internal/reline/lib/reline/io/dumb.rb +120 -0
  217. data/lib/llm/shell/internal/reline/lib/reline/io/windows.rb +530 -0
  218. data/lib/llm/shell/internal/reline/lib/reline/io.rb +55 -0
  219. data/lib/llm/shell/internal/reline/lib/reline/key_actor/base.rb +37 -0
  220. data/lib/llm/shell/internal/reline/lib/reline/key_actor/composite.rb +17 -0
  221. data/lib/llm/shell/internal/reline/lib/reline/key_actor/emacs.rb +517 -0
  222. data/lib/llm/shell/internal/reline/lib/reline/key_actor/vi_command.rb +518 -0
  223. data/lib/llm/shell/internal/reline/lib/reline/key_actor/vi_insert.rb +517 -0
  224. data/lib/llm/shell/internal/reline/lib/reline/key_actor.rb +8 -0
  225. data/lib/llm/shell/internal/reline/lib/reline/key_stroke.rb +119 -0
  226. data/lib/llm/shell/internal/reline/lib/reline/kill_ring.rb +125 -0
  227. data/lib/llm/shell/internal/reline/lib/reline/line_editor.rb +2356 -0
  228. data/lib/llm/shell/internal/reline/lib/reline/unicode/east_asian_width.rb +1292 -0
  229. data/lib/llm/shell/internal/reline/lib/reline/unicode.rb +421 -0
  230. data/lib/llm/shell/internal/reline/lib/reline/version.rb +3 -0
  231. data/lib/llm/shell/internal/reline/lib/reline.rb +527 -0
  232. data/lib/llm/shell/internal/tomlrb/lib/tomlrb/generated_parser.rb +712 -0
  233. data/lib/llm/shell/internal/tomlrb/lib/tomlrb/handler.rb +268 -0
  234. data/lib/llm/shell/internal/tomlrb/lib/tomlrb/local_date.rb +35 -0
  235. data/lib/llm/shell/internal/tomlrb/lib/tomlrb/local_date_time.rb +42 -0
  236. data/lib/llm/shell/internal/tomlrb/lib/tomlrb/local_time.rb +40 -0
  237. data/lib/llm/shell/internal/tomlrb/lib/tomlrb/parser.rb +21 -0
  238. data/lib/llm/shell/internal/tomlrb/lib/tomlrb/scanner.rb +92 -0
  239. data/lib/llm/shell/internal/tomlrb/lib/tomlrb/string_utils.rb +40 -0
  240. data/lib/llm/shell/internal/tomlrb/lib/tomlrb/version.rb +5 -0
  241. data/lib/llm/shell/internal/tomlrb/lib/tomlrb.rb +49 -0
  242. data/lib/llm/shell/options.rb +1 -1
  243. data/lib/llm/shell/renderer.rb +2 -3
  244. data/lib/llm/shell/repl.rb +21 -16
  245. data/lib/llm/shell/tool.rb +42 -0
  246. data/lib/llm/shell/tools/read_file.rb +15 -0
  247. data/lib/llm/shell/tools/system.rb +17 -0
  248. data/lib/llm/shell/tools/write_file.rb +16 -0
  249. data/lib/llm/shell/version.rb +1 -1
  250. data/lib/llm/shell.rb +83 -39
  251. data/libexec/llm-shell/shell +4 -6
  252. data/llm-shell.gemspec +0 -4
  253. metadata +233 -63
  254. data/lib/llm/function.rb +0 -17
  255. data/lib/llm/shell/command/extension.rb +0 -42
  256. data/lib/llm/shell/commands/utils.rb +0 -21
  257. data/lib/llm/shell/functions/read_file.rb +0 -22
  258. data/lib/llm/shell/functions/write_file.rb +0 -22
@@ -0,0 +1,140 @@
1
+ module CodeRay
2
+ module Scanners
3
+
4
+ # Scanner for YAML.
5
+ #
6
+ # Based on the YAML scanner from Syntax by Jamis Buck.
7
+ class YAML < Scanner
8
+
9
+ register_for :yaml
10
+ file_extension 'yml'
11
+
12
+ KINDS_NOT_LOC = :all
13
+
14
+ protected
15
+
16
+ def scan_tokens encoder, options
17
+
18
+ state = :initial
19
+ key_indent = string_indent = 0
20
+
21
+ until eos?
22
+
23
+ key_indent = nil if bol?
24
+
25
+ if match = scan(/ +[\t ]*/)
26
+ encoder.text_token match, :space
27
+
28
+ elsif match = scan(/\n+/)
29
+ encoder.text_token match, :space
30
+ state = :initial if match.index(?\n)
31
+
32
+ elsif match = scan(/#.*/)
33
+ encoder.text_token match, :comment
34
+
35
+ elsif bol? and case
36
+ when match = scan(/---|\.\.\./)
37
+ encoder.begin_group :head
38
+ encoder.text_token match, :head
39
+ encoder.end_group :head
40
+ next
41
+ when match = scan(/%.*/)
42
+ encoder.text_token match, :doctype
43
+ next
44
+ end
45
+
46
+ elsif state == :value and case
47
+ when !check(/(?:"[^"]*")(?=: |:$)/) && match = scan(/"/)
48
+ encoder.begin_group :string
49
+ encoder.text_token match, :delimiter
50
+ encoder.text_token match, :content if (match = scan(/ [^"\\]* (?: \\. [^"\\]* )* /mx)) && !match.empty?
51
+ encoder.text_token match, :delimiter if match = scan(/"/)
52
+ encoder.end_group :string
53
+ next
54
+ when match = scan(/[|>][-+]?/)
55
+ encoder.begin_group :string
56
+ encoder.text_token match, :delimiter
57
+ string_indent = key_indent || column(pos - match.size) - 1
58
+ encoder.text_token matched, :content if scan(/(?:\n+ {#{string_indent + 1}}.*)+/)
59
+ encoder.end_group :string
60
+ next
61
+ when match = scan(/(?![!"*&]).+?(?=$|\s+#)/)
62
+ encoder.begin_group :string
63
+ encoder.text_token match, :content
64
+ string_indent = key_indent || column(pos - match.size) - 1
65
+ encoder.text_token matched, :content if scan(/(?:\n+ {#{string_indent + 1}}.*)+/)
66
+ encoder.end_group :string
67
+ next
68
+ end
69
+
70
+ elsif case
71
+ when match = scan(/[-:](?= |$)/)
72
+ state = :value if state == :colon && (match == ':' || match == '-')
73
+ state = :value if state == :initial && match == '-'
74
+ encoder.text_token match, :operator
75
+ next
76
+ when match = scan(/[,{}\[\]]/)
77
+ encoder.text_token match, :operator
78
+ next
79
+ when state == :initial && match = scan(/[-\w.()\/ ]*\S(?= *:(?: |$))/)
80
+ encoder.text_token match, :key
81
+ key_indent = column(pos - match.size) - 1
82
+ state = :colon
83
+ next
84
+ when match = scan(/(?:"[^"\n]*"|'[^'\n]*')(?= *:(?: |$))/)
85
+ encoder.begin_group :key
86
+ encoder.text_token match[0,1], :delimiter
87
+ encoder.text_token match[1..-2], :content if match.size > 2
88
+ encoder.text_token match[-1,1], :delimiter
89
+ encoder.end_group :key
90
+ key_indent = column(pos - match.size) - 1
91
+ state = :colon
92
+ next
93
+ when match = scan(/(![\w\/]+)(:([\w:]+))?/)
94
+ encoder.text_token self[1], :type
95
+ if self[2]
96
+ encoder.text_token ':', :operator
97
+ encoder.text_token self[3], :class
98
+ end
99
+ next
100
+ when match = scan(/&\S+/)
101
+ encoder.text_token match, :variable
102
+ next
103
+ when match = scan(/\*\w+/)
104
+ encoder.text_token match, :global_variable
105
+ next
106
+ when match = scan(/<</)
107
+ encoder.text_token match, :class_variable
108
+ next
109
+ when match = scan(/\d\d:\d\d:\d\d/)
110
+ encoder.text_token match, :octal
111
+ next
112
+ when match = scan(/\d\d\d\d-\d\d-\d\d\s\d\d:\d\d:\d\d(\.\d+)? [-+]\d\d:\d\d/)
113
+ encoder.text_token match, :octal
114
+ next
115
+ when match = scan(/:\w+/)
116
+ encoder.text_token match, :symbol
117
+ next
118
+ when match = scan(/[^:\s]+(:(?! |$)[^:\s]*)* .*/)
119
+ encoder.text_token match, :error
120
+ next
121
+ when match = scan(/[^:\s]+(:(?! |$)[^:\s]*)*/)
122
+ encoder.text_token match, :error
123
+ next
124
+ end
125
+
126
+ else
127
+ raise if eos?
128
+ encoder.text_token getch, :error
129
+
130
+ end
131
+
132
+ end
133
+
134
+ encoder
135
+ end
136
+
137
+ end
138
+
139
+ end
140
+ end
@@ -0,0 +1,27 @@
1
+ require 'strscan'
2
+
3
+ module CodeRay
4
+
5
+ autoload :WordList, coderay_path('helpers', 'word_list')
6
+
7
+ # = Scanners
8
+ #
9
+ # This module holds the Scanner class and its subclasses.
10
+ # For example, the Ruby scanner is named CodeRay::Scanners::Ruby
11
+ # can be found in coderay/scanners/ruby.
12
+ #
13
+ # Scanner also provides methods and constants for the register
14
+ # mechanism and the [] method that returns the Scanner class
15
+ # belonging to the given lang.
16
+ #
17
+ # See PluginHost.
18
+ module Scanners
19
+
20
+ extend PluginHost
21
+ plugin_path File.dirname(__FILE__), 'scanners'
22
+
23
+ autoload :Scanner, CodeRay.coderay_path('scanners', 'scanner')
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,7 @@
1
+ module CodeRay
2
+ module Styles
3
+
4
+ default :alpha
5
+
6
+ end
7
+ end
@@ -0,0 +1,153 @@
1
+ module CodeRay
2
+ module Styles
3
+
4
+ # A colorful theme using CSS 3 colors (with alpha channel).
5
+ class Alpha < Style
6
+
7
+ register_for :alpha
8
+
9
+ code_background = 'hsl(0,0%,95%)'
10
+ numbers_background = 'hsl(180,65%,90%)'
11
+ border_color = 'silver'
12
+ normal_color = 'black'
13
+
14
+ CSS_MAIN_STYLES = <<-MAIN # :nodoc:
15
+ .CodeRay {
16
+ background-color: #{code_background};
17
+ border: 1px solid #{border_color};
18
+ color: #{normal_color};
19
+ }
20
+ .CodeRay pre {
21
+ margin: 0px;
22
+ }
23
+
24
+ span.CodeRay { white-space: pre; border: 0px; padding: 2px; }
25
+
26
+ table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px; }
27
+ table.CodeRay td { padding: 2px 4px; vertical-align: top; }
28
+
29
+ .CodeRay .line-numbers {
30
+ background-color: #{numbers_background};
31
+ color: gray;
32
+ text-align: right;
33
+ -webkit-user-select: none;
34
+ -moz-user-select: none;
35
+ user-select: none;
36
+ }
37
+ .CodeRay .line-numbers a {
38
+ background-color: #{numbers_background} !important;
39
+ color: gray !important;
40
+ text-decoration: none !important;
41
+ }
42
+ .CodeRay .line-numbers pre {
43
+ word-break: normal;
44
+ }
45
+ .CodeRay .line-numbers a:target { color: blue !important; }
46
+ .CodeRay .line-numbers .highlighted { color: red !important; }
47
+ .CodeRay .line-numbers .highlighted a { color: red !important; }
48
+ .CodeRay span.line-numbers { padding: 0px 4px; }
49
+ .CodeRay .line { display: block; float: left; width: 100%; }
50
+ .CodeRay .code { width: 100%; }
51
+ MAIN
52
+
53
+ TOKEN_COLORS = <<-'TOKENS'
54
+ .debug { color: white !important; background: blue !important; }
55
+
56
+ .annotation { color:#007 }
57
+ .attribute-name { color:#b48 }
58
+ .attribute-value { color:#700 }
59
+ .binary { color:#549 }
60
+ .binary .char { color:#325 }
61
+ .binary .delimiter { color:#325 }
62
+ .char { color:#D20 }
63
+ .char .content { color:#D20 }
64
+ .char .delimiter { color:#710 }
65
+ .class { color:#B06; font-weight:bold }
66
+ .class-variable { color:#369 }
67
+ .color { color:#0A0 }
68
+ .comment { color:#777 }
69
+ .comment .char { color:#444 }
70
+ .comment .delimiter { color:#444 }
71
+ .constant { color:#036; font-weight:bold }
72
+ .decorator { color:#B0B }
73
+ .definition { color:#099; font-weight:bold }
74
+ .delimiter { color:black }
75
+ .directive { color:#088; font-weight:bold }
76
+ .docstring { color:#D42; }
77
+ .doctype { color:#34b }
78
+ .done { text-decoration: line-through; color: gray }
79
+ .entity { color:#800; font-weight:bold }
80
+ .error { color:#F00; background-color:#FAA }
81
+ .escape { color:#666 }
82
+ .exception { color:#C00; font-weight:bold }
83
+ .float { color:#60E }
84
+ .function { color:#06B; font-weight:bold }
85
+ .function .delimiter { color:#059 }
86
+ .function .content { color:#037 }
87
+ .global-variable { color:#d70 }
88
+ .hex { color:#02b }
89
+ .id { color:#33D; font-weight:bold }
90
+ .include { color:#B44; font-weight:bold }
91
+ .inline { background-color: hsla(0,0%,0%,0.07); color: black }
92
+ .inline-delimiter { font-weight: bold; color: #666 }
93
+ .instance-variable { color:#33B }
94
+ .integer { color:#00D }
95
+ .imaginary { color:#f00 }
96
+ .important { color:#D00 }
97
+ .key { color: #606 }
98
+ .key .char { color: #60f }
99
+ .key .delimiter { color: #404 }
100
+ .keyword { color:#080; font-weight:bold }
101
+ .label { color:#970; font-weight:bold }
102
+ .local-variable { color:#950 }
103
+ .map .content { color:#808 }
104
+ .map .delimiter { color:#40A}
105
+ .map { background-color:hsla(200,100%,50%,0.06); }
106
+ .namespace { color:#707; font-weight:bold }
107
+ .octal { color:#40E }
108
+ .operator { }
109
+ .predefined { color:#369; font-weight:bold }
110
+ .predefined-constant { color:#069 }
111
+ .predefined-type { color:#0a8; font-weight:bold }
112
+ .preprocessor { color:#579 }
113
+ .pseudo-class { color:#00C; font-weight:bold }
114
+ .regexp { background-color:hsla(300,100%,50%,0.06); }
115
+ .regexp .content { color:#808 }
116
+ .regexp .delimiter { color:#404 }
117
+ .regexp .modifier { color:#C2C }
118
+ .reserved { color:#080; font-weight:bold }
119
+ .shell { background-color:hsla(120,100%,50%,0.06); }
120
+ .shell .content { color:#2B2 }
121
+ .shell .delimiter { color:#161 }
122
+ .string { background-color:hsla(0,100%,50%,0.05); }
123
+ .string .char { color: #b0b }
124
+ .string .content { color: #D20 }
125
+ .string .delimiter { color: #710 }
126
+ .string .modifier { color: #E40 }
127
+ .symbol { color:#A60 }
128
+ .symbol .content { color:#A60 }
129
+ .symbol .delimiter { color:#740 }
130
+ .tag { color:#070; font-weight:bold }
131
+ .type { color:#339; font-weight:bold }
132
+ .value { color: #088 }
133
+ .variable { color:#037 }
134
+
135
+ .insert { background: hsla(120,100%,50%,0.12) }
136
+ .delete { background: hsla(0,100%,50%,0.12) }
137
+ .change { color: #bbf; background: #007 }
138
+ .head { color: #f8f; background: #505 }
139
+ .head .filename { color: white; }
140
+
141
+ .delete .eyecatcher { background-color: hsla(0,100%,50%,0.2); border: 1px solid hsla(0,100%,45%,0.5); margin: -1px; border-bottom: none; border-top-left-radius: 5px; border-top-right-radius: 5px; }
142
+ .insert .eyecatcher { background-color: hsla(120,100%,50%,0.2); border: 1px solid hsla(120,100%,25%,0.5); margin: -1px; border-top: none; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; }
143
+
144
+ .insert .insert { color: #0c0; background:transparent; font-weight:bold }
145
+ .delete .delete { color: #c00; background:transparent; font-weight:bold }
146
+ .change .change { color: #88f }
147
+ .head .head { color: #f4f }
148
+ TOKENS
149
+
150
+ end
151
+
152
+ end
153
+ end
@@ -0,0 +1,18 @@
1
+ module CodeRay
2
+
3
+ module Styles
4
+
5
+ # Base class for styles.
6
+ #
7
+ # Styles are used by Encoders::HTML to colorize tokens.
8
+ class Style
9
+ extend Plugin
10
+ plugin_host Styles
11
+
12
+ DEFAULT_OPTIONS = { } # :nodoc:
13
+
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,15 @@
1
+ module CodeRay
2
+
3
+ # This module holds the Style class and its subclasses.
4
+ #
5
+ # See Plugin.
6
+ module Styles
7
+
8
+ extend PluginHost
9
+ plugin_path File.dirname(__FILE__), 'styles'
10
+
11
+ autoload :Style, CodeRay.coderay_path('styles', 'style')
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,85 @@
1
+ module CodeRay
2
+
3
+ # A Hash of all known token kinds and their associated CSS classes.
4
+ TokenKinds = Hash.new(false)
5
+
6
+ # speedup
7
+ TokenKinds.compare_by_identity if TokenKinds.respond_to? :compare_by_identity
8
+
9
+ TokenKinds.update( # :nodoc:
10
+ :debug => 'debug', # highlight for debugging (white on blue background)
11
+
12
+ :annotation => 'annotation', # Groovy, Java
13
+ :attribute_name => 'attribute-name', # HTML, CSS
14
+ :attribute_value => 'attribute-value', # HTML
15
+ :binary => 'binary', # Python, Ruby
16
+ :char => 'char', # most scanners, also inside of strings
17
+ :class => 'class', # lots of scanners, for different purposes also in CSS
18
+ :class_variable => 'class-variable', # Ruby, YAML
19
+ :color => 'color', # CSS
20
+ :comment => 'comment', # most scanners
21
+ :constant => 'constant', # PHP, Ruby
22
+ :content => 'content', # inside of strings, most scanners
23
+ :decorator => 'decorator', # Python
24
+ :definition => 'definition', # CSS
25
+ :delimiter => 'delimiter', # inside strings, comments and other types
26
+ :directive => 'directive', # lots of scanners
27
+ :doctype => 'doctype', # Goorvy, HTML, Ruby, YAML
28
+ :docstring => 'docstring', # Python
29
+ :done => 'done', # Taskpaper
30
+ :entity => 'entity', # HTML
31
+ :error => 'error', # invalid token, most scanners
32
+ :escape => 'escape', # Ruby (string inline variables like #$foo, #@bar)
33
+ :exception => 'exception', # Java, PHP, Python
34
+ :filename => 'filename', # Diff
35
+ :float => 'float', # most scanners
36
+ :function => 'function', # CSS, JavaScript, PHP
37
+ :global_variable => 'global-variable', # Ruby, YAML
38
+ :hex => 'hex', # hexadecimal number; lots of scanners
39
+ :id => 'id', # CSS
40
+ :imaginary => 'imaginary', # Python
41
+ :important => 'important', # CSS, Taskpaper
42
+ :include => 'include', # C, Groovy, Java, Python, Sass
43
+ :inline => 'inline', # nested code, eg. inline string evaluation; lots of scanners
44
+ :inline_delimiter => 'inline-delimiter', # used instead of :inline > :delimiter FIXME: Why use inline_delimiter?
45
+ :instance_variable => 'instance-variable', # Ruby
46
+ :integer => 'integer', # most scanners
47
+ :key => 'key', # lots of scanners, used together with :value
48
+ :keyword => 'keyword', # reserved word that's actually implemented; most scanners
49
+ :label => 'label', # C, PHP
50
+ :local_variable => 'local-variable', # local and magic variables; some scanners
51
+ :map => 'map', # Lua tables
52
+ :modifier => 'modifier', # used inside on strings; lots of scanners
53
+ :namespace => 'namespace', # Clojure, Java, Taskpaper
54
+ :octal => 'octal', # lots of scanners
55
+ :predefined => 'predefined', # predefined function: lots of scanners
56
+ :predefined_constant => 'predefined-constant',# lots of scanners
57
+ :predefined_type => 'predefined-type', # C, Java, PHP
58
+ :preprocessor => 'preprocessor', # C, Delphi, HTML
59
+ :pseudo_class => 'pseudo-class', # CSS
60
+ :regexp => 'regexp', # Groovy, JavaScript, Ruby
61
+ :reserved => 'reserved', # most scanners
62
+ :shell => 'shell', # Ruby
63
+ :string => 'string', # most scanners
64
+ :symbol => 'symbol', # Clojure, Ruby, YAML
65
+ :tag => 'tag', # CSS, HTML
66
+ :type => 'type', # CSS, Java, SQL, YAML
67
+ :value => 'value', # used together with :key; CSS, JSON, YAML
68
+ :variable => 'variable', # Sass, SQL, YAML
69
+
70
+ :change => 'change', # Diff
71
+ :delete => 'delete', # Diff
72
+ :head => 'head', # Diff, YAML
73
+ :insert => 'insert', # Diff
74
+ :eyecatcher => 'eyecatcher', # Diff
75
+
76
+ :ident => false, # almost all scanners
77
+ :operator => false, # almost all scanners
78
+
79
+ :space => false, # almost all scanners
80
+ :plain => false # almost all scanners
81
+ )
82
+
83
+ TokenKinds[:method] = TokenKinds[:function]
84
+ TokenKinds[:unknown] = TokenKinds[:plain]
85
+ end
@@ -0,0 +1,164 @@
1
+ module CodeRay
2
+
3
+ # The Tokens class represents a list of tokens returned from
4
+ # a Scanner. It's actually just an Array with a few helper methods.
5
+ #
6
+ # A token itself is not a special object, just two elements in an Array:
7
+ # * the _token_ _text_ (the original source of the token in a String) or
8
+ # a _token_ _action_ (begin_group, end_group, begin_line, end_line)
9
+ # * the _token_ _kind_ (a Symbol representing the type of the token)
10
+ #
11
+ # It looks like this:
12
+ #
13
+ # ..., '# It looks like this', :comment, ...
14
+ # ..., '3.1415926', :float, ...
15
+ # ..., '$^', :error, ...
16
+ #
17
+ # Some scanners also yield sub-tokens, represented by special
18
+ # token actions, for example :begin_group and :end_group.
19
+ #
20
+ # The Ruby scanner, for example, splits "a string" into:
21
+ #
22
+ # [
23
+ # :begin_group, :string,
24
+ # '"', :delimiter,
25
+ # 'a string', :content,
26
+ # '"', :delimiter,
27
+ # :end_group, :string
28
+ # ]
29
+ #
30
+ # Tokens can be used to save the output of a Scanners in a simple
31
+ # Ruby object that can be send to an Encoder later:
32
+ #
33
+ # tokens = CodeRay.scan('price = 2.59', :ruby).tokens
34
+ # tokens.encode(:html)
35
+ # tokens.html
36
+ # CodeRay.encoder(:html).encode_tokens(tokens)
37
+ #
38
+ # Tokens gives you the power to handle pre-scanned code very easily:
39
+ # You can serialize it to a JSON string and store it in a database, pass it
40
+ # around to encode it more than once, send it to other algorithms...
41
+ class Tokens < Array
42
+ # Remove Array#filter that is a new alias for Array#select on Ruby 2.6,
43
+ # for method_missing called with filter method.
44
+ undef_method :filter if instance_methods.include?(:filter)
45
+
46
+ # The Scanner instance that created the tokens.
47
+ attr_accessor :scanner
48
+
49
+ # Encode the tokens using encoder.
50
+ #
51
+ # encoder can be
52
+ # * a plugin name like :html oder 'statistic'
53
+ # * an Encoder object
54
+ #
55
+ # options are passed to the encoder.
56
+ def encode encoder, options = {}
57
+ encoder = Encoders[encoder].new options if encoder.respond_to? :to_sym
58
+ encoder.encode_tokens self, options
59
+ end
60
+
61
+ # Turn tokens into a string by concatenating them.
62
+ def to_s
63
+ encode CodeRay::Encoders::Encoder.new
64
+ end
65
+
66
+ # Redirects unknown methods to encoder calls.
67
+ #
68
+ # For example, if you call +tokens.html+, the HTML encoder
69
+ # is used to highlight the tokens.
70
+ def method_missing meth, options = {}
71
+ encode meth, options
72
+ rescue PluginHost::PluginNotFound
73
+ super
74
+ end
75
+
76
+ # Split the tokens into parts of the given +sizes+.
77
+ #
78
+ # The result will be an Array of Tokens objects. The parts have
79
+ # the text size specified by the parameter. In addition, each
80
+ # part closes all opened tokens. This is useful to insert tokens
81
+ # betweem them.
82
+ #
83
+ # This method is used by @Scanner#tokenize@ when called with an Array
84
+ # of source strings. The Diff encoder uses it for inline highlighting.
85
+ def split_into_parts *sizes
86
+ return Array.new(sizes.size) { Tokens.new } if size == 2 && first == ''
87
+ parts = []
88
+ opened = []
89
+ content = nil
90
+ part = Tokens.new
91
+ part_size = 0
92
+ size = sizes.first
93
+ i = 0
94
+ for item in self
95
+ case content
96
+ when nil
97
+ content = item
98
+ when String
99
+ if size && part_size + content.size > size # token must be cut
100
+ if part_size < size # some part of the token goes into this part
101
+ content = content.dup # content may no be safe to change
102
+ part << content.slice!(0, size - part_size) << item
103
+ end
104
+ # close all open groups and lines...
105
+ closing = opened.reverse.flatten.map do |content_or_kind|
106
+ case content_or_kind
107
+ when :begin_group
108
+ :end_group
109
+ when :begin_line
110
+ :end_line
111
+ else
112
+ content_or_kind
113
+ end
114
+ end
115
+ part.concat closing
116
+ begin
117
+ parts << part
118
+ part = Tokens.new
119
+ size = sizes[i += 1]
120
+ end until size.nil? || size > 0
121
+ # ...and open them again.
122
+ part.concat opened.flatten
123
+ part_size = 0
124
+ redo unless content.empty?
125
+ else
126
+ part << content << item
127
+ part_size += content.size
128
+ end
129
+ content = nil
130
+ when Symbol
131
+ case content
132
+ when :begin_group, :begin_line
133
+ opened << [content, item]
134
+ when :end_group, :end_line
135
+ opened.pop
136
+ else
137
+ raise ArgumentError, 'Unknown token action: %p, kind = %p' % [content, item]
138
+ end
139
+ part << content << item
140
+ content = nil
141
+ else
142
+ raise ArgumentError, 'Token input junk: %p, kind = %p' % [content, item]
143
+ end
144
+ end
145
+ parts << part
146
+ parts << Tokens.new while parts.size < sizes.size
147
+ parts
148
+ end
149
+
150
+ # Return the actual number of tokens.
151
+ def count
152
+ size / 2
153
+ end
154
+
155
+ alias text_token push
156
+ def begin_group kind; push :begin_group, kind end
157
+ def end_group kind; push :end_group, kind end
158
+ def begin_line kind; push :begin_line, kind end
159
+ def end_line kind; push :end_line, kind end
160
+ alias tokens concat
161
+
162
+ end
163
+
164
+ end
@@ -0,0 +1,55 @@
1
+ module CodeRay
2
+
3
+ # The result of a scan operation is a TokensProxy, but should act like Tokens.
4
+ #
5
+ # This proxy makes it possible to use the classic CodeRay.scan.encode API
6
+ # while still providing the benefits of direct streaming.
7
+ class TokensProxy
8
+
9
+ attr_accessor :input, :lang, :options, :block
10
+
11
+ # Create a new TokensProxy with the arguments of CodeRay.scan.
12
+ def initialize input, lang, options = {}, block = nil
13
+ @input = input
14
+ @lang = lang
15
+ @options = options
16
+ @block = block
17
+ end
18
+
19
+ # Call CodeRay.encode if +encoder+ is a Symbol;
20
+ # otherwise, convert the receiver to tokens and call encoder.encode_tokens.
21
+ def encode encoder, options = {}
22
+ if encoder.respond_to? :to_sym
23
+ CodeRay.encode(input, lang, encoder, options)
24
+ else
25
+ encoder.encode_tokens tokens, options
26
+ end
27
+ end
28
+
29
+ # Tries to call encode;
30
+ # delegates to tokens otherwise.
31
+ def method_missing method, *args, &blk
32
+ encode method.to_sym, *args
33
+ rescue PluginHost::PluginNotFound
34
+ tokens.send(method, *args, &blk)
35
+ end
36
+
37
+ # The (cached) result of the tokenized input; a Tokens instance.
38
+ def tokens
39
+ @tokens ||= scanner.tokenize(input)
40
+ end
41
+
42
+ # A (cached) scanner instance to use for the scan task.
43
+ def scanner
44
+ @scanner ||= CodeRay.scanner(lang, options, &block)
45
+ end
46
+
47
+ # Overwrite Struct#each.
48
+ def each *args, &blk
49
+ tokens.each(*args, &blk)
50
+ self
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,3 @@
1
+ module CodeRay
2
+ VERSION = '1.1.3'
3
+ end