Skip to content

Distribute and run LLMs with a single file.

Make some more quality of life improvements

Justine Tunney6dd451b93272
diff --git a/llamafile/chatbot_main.cpp b/llamafile/chatbot_main.cpp
index 9a985b9f..6ea0aa9f 100644
--- a/llamafile/chatbot_main.cpp
+++ b/llamafile/chatbot_main.cpp
@@ -89,6 +89,12 @@ void *server_thread(void *arg) {
exit(server_cli(sargs->argc, sargs->argv));
}
+const char *tip() {
+ if (g_params.verbosity)
+ return "";
+ return " (use the --verbose flag for further details)";
+}
+
int main(int argc, char **argv) {
// print logo
@@ -122,16 +128,15 @@ int main(int argc, char **argv) {
print_ephemeral("loading model...");
llama_model_params model_params = llama_model_params_from_gpt_params(g_params);
g_model = llama_load_model_from_file(g_params.model.c_str(), model_params);
+ clear_ephemeral();
if (g_model == NULL) {
- clear_ephemeral();
- fprintf(stderr, "%s: failed to load model\n", g_params.model.c_str());
+ fprintf(stderr, "%s: failed to load model%s\n", g_params.model.c_str(), tip());
exit(2);
}
if (g_params.n_ctx <= 0 || g_params.n_ctx > llama_n_ctx_train(g_model))
g_params.n_ctx = llama_n_ctx_train(g_model);
if (g_params.n_ctx < g_params.n_batch)
g_params.n_batch = g_params.n_ctx;
- clear_ephemeral();
bool want_server = !llamafile_has(argv, "--chat");
if (want_server) {
@@ -164,7 +169,7 @@ int main(int argc, char **argv) {
g_ctx = llama_new_context_with_model(g_model, ctx_params);
clear_ephemeral();
if (!g_ctx) {
- fprintf(stderr, "error: failed to initialize context\n");
+ fprintf(stderr, "error: failed to initialize context%s\n", tip());
exit(3);
}
@@ -176,7 +181,7 @@ int main(int argc, char **argv) {
g_clip = clip_model_load(FLAG_mmproj, g_params.verbosity);
clear_ephemeral();
if (!g_clip) {
- fprintf(stderr, "%s: failed to initialize clip image model\n", FLAG_mmproj);
+ fprintf(stderr, "%s: failed to initialize clip image model%s\n", FLAG_mmproj, tip());
exit(4);
}
}
diff --git a/llamafile/highlight.h b/llamafile/highlight.h
index c1fe519e..fa50092b 100644
--- a/llamafile/highlight.h
+++ b/llamafile/highlight.h
@@ -561,6 +561,9 @@ class HighlightRuby : public Highlight {
bool pending_heredoc_ = false;
bool indented_heredoc_ = false;
unsigned char nest_[16];
+ unsigned char levels_[16];
+ unsigned char openers_[16];
+ unsigned char closers_[16];
std::string word_;
std::string heredoc_;
};
diff --git a/llamafile/highlight_ruby.cpp b/llamafile/highlight_ruby.cpp
index 0eaf602d..928c1206 100644
--- a/llamafile/highlight_ruby.cpp
+++ b/llamafile/highlight_ruby.cpp
@@ -22,6 +22,7 @@
enum {
NORMAL,
+ NUMBER,
WORD,
EQUAL,
EQUAL_WORD,
@@ -65,6 +66,7 @@ enum {
};
enum {
+ EXPECT_EXPR,
EXPECT_VALUE,
EXPECT_OPERATOR,
};
@@ -214,23 +216,23 @@ void HighlightRuby::feed(std::string *r, std::string_view input) {
is_definition_ = false;
} else if (c == ':') {
t_ = COLON;
- expect_ = EXPECT_OPERATOR;
is_definition_ = false;
} else if (c == '@') {
t_ = AT;
is_definition_ = false;
+ expect_ = EXPECT_OPERATOR;
} else if (c == '=') {
t_ = EQUAL;
expect_ = EXPECT_VALUE;
is_definition_ = false;
- } else if (c == '?' && expect_ == EXPECT_VALUE) {
+ } else if (c == '?') {
t_ = QUESTION;
is_definition_ = false;
} else if (c == '$') {
t_ = DOLLAR;
expect_ = EXPECT_OPERATOR;
is_definition_ = false;
- } else if (c == '%' && expect_ == EXPECT_VALUE) {
+ } else if (c == '%') {
t_ = PERCENT;
q_ = 0;
expect_ = EXPECT_OPERATOR;
@@ -252,30 +254,37 @@ void HighlightRuby::feed(std::string *r, std::string_view input) {
lf::append_wchar(r, c);
expect_ = EXPECT_OPERATOR;
} else if (c == '#') {
- expect_ = EXPECT_VALUE;
+ expect_ = EXPECT_EXPR;
*r += HI_COMMENT;
lf::append_wchar(r, c);
t_ = COMMENT;
- } else if (c == '<' && expect_ == EXPECT_VALUE) {
+ } else if (c == '<' && (expect_ == EXPECT_EXPR || expect_ == EXPECT_VALUE)) {
lf::append_wchar(r, c);
t_ = LT;
- } else if (c == '/' && expect_ == EXPECT_VALUE) {
+ } else if (c == '/' && (expect_ == EXPECT_EXPR || expect_ == EXPECT_VALUE)) {
t_ = REGEX;
*r += HI_STRING;
lf::append_wchar(r, c);
} else if (c == '{' && nesti_ && nesti_ < sizeof(nest_)) {
expect_ = EXPECT_VALUE;
*r += '{';
+ levels_[nesti_] = level_;
+ closers_[nesti_] = closer_;
+ openers_[nesti_] = opener_;
nest_[nesti_++] = NORMAL;
is_definition_ = false;
} else if (c == '}' && nesti_) {
- if ((t_ = nest_[--nesti_]) != NORMAL)
+ --nesti_;
+ level_ = levels_[nesti_];
+ closer_ = closers_[nesti_];
+ opener_ = openers_[nesti_];
+ if ((t_ = nest_[nesti_]) != NORMAL)
*r += HI_STRING;
*r += '}';
expect_ = EXPECT_OPERATOR;
is_definition_ = false;
} else if (c == '\n') {
- expect_ = EXPECT_VALUE;
+ expect_ = EXPECT_EXPR;
lf::append_wchar(r, c);
if (pending_heredoc_) {
*r += HI_STRING;
@@ -283,18 +292,22 @@ void HighlightRuby::feed(std::string *r, std::string_view input) {
t_ = HEREDOC_BOL;
i_ = 0;
}
- } else if (c == ']' || c == ')') {
- expect_ = EXPECT_OPERATOR;
+ } else if (c == '[' || c == '(') {
+ expect_ = EXPECT_VALUE;
lf::append_wchar(r, c);
is_definition_ = false;
- } else if (ispunct(c)) {
- expect_ = EXPECT_VALUE;
+ } else if (c == ']' || c == ')') {
+ expect_ = EXPECT_OPERATOR;
lf::append_wchar(r, c);
is_definition_ = false;
} else if (isdigit(c) || c == '.') {
expect_ = EXPECT_OPERATOR;
lf::append_wchar(r, c);
is_definition_ = false;
+ } else if (ispunct(c)) {
+ expect_ = EXPECT_VALUE;
+ lf::append_wchar(r, c);
+ is_definition_ = false;
} else if (isspace(c)) {
lf::append_wchar(r, c);
} else {
@@ -336,6 +349,7 @@ void HighlightRuby::feed(std::string *r, std::string_view input) {
}
// fallthrough
+ Word:
case WORD:
if (isident(c)) {
lf::append_wchar(&word_, c);
@@ -347,8 +361,11 @@ void HighlightRuby::feed(std::string *r, std::string_view input) {
expect_ = EXPECT_VALUE;
if (word_ == "def") {
is_definition_ = true;
+ } else if (word_ == "class" || word_ == "module") {
+ expect_ = EXPECT_OPERATOR;
}
- } else if (is_keyword_ruby_builtin(word_.data(), word_.size())) {
+ } else if (expect_ == EXPECT_EXPR &&
+ is_keyword_ruby_builtin(word_.data(), word_.size())) {
*r += HI_BUILTIN;
*r += word_;
*r += HI_RESET;
@@ -398,6 +415,9 @@ void HighlightRuby::feed(std::string *r, std::string_view input) {
*r += '{';
*r += HI_RESET;
expect_ = EXPECT_VALUE;
+ levels_[nesti_] = level_;
+ closers_[nesti_] = closer_;
+ openers_[nesti_] = opener_;
nest_[nesti_++] = REGEX;
t_ = NORMAL;
} else if (c == '$') {
@@ -471,9 +491,15 @@ void HighlightRuby::feed(std::string *r, std::string_view input) {
*r += HI_LISPKW;
*r += ':';
lf::append_wchar(r, c);
+ expect_ = EXPECT_OPERATOR;
t_ = COLON_WORD;
+ } else if (c == ':') {
+ *r += "::";
+ expect_ = EXPECT_VALUE;
+ t_ = NORMAL;
} else {
*r += ':';
+ expect_ = EXPECT_VALUE;
t_ = NORMAL;
goto Normal;
}
@@ -523,9 +549,11 @@ void HighlightRuby::feed(std::string *r, std::string_view input) {
*r += HI_STRING;
*r += '%';
lf::append_wchar(r, c);
+ expect_ = EXPECT_OPERATOR;
t_ = PERCENT_STRING;
} else {
*r += '%';
+ expect_ = EXPECT_VALUE;
t_ = NORMAL;
goto Normal;
}
@@ -538,14 +566,16 @@ void HighlightRuby::feed(std::string *r, std::string_view input) {
closer_ = mirror(c);
*r += HI_STRING;
*r += '%';
- *r += q_;
+ lf::append_wchar(r, q_);
lf::append_wchar(r, c);
+ expect_ = EXPECT_OPERATOR;
t_ = PERCENT_STRING;
} else {
*r += '%';
- *r += q_;
- t_ = NORMAL;
- goto Normal;
+ is_definition_ = false;
+ lf::append_wchar(&word_, q_);
+ t_ = WORD;
+ goto Word;
}
break;
@@ -557,6 +587,9 @@ void HighlightRuby::feed(std::string *r, std::string_view input) {
*r += '{';
*r += HI_RESET;
expect_ = EXPECT_VALUE;
+ levels_[nesti_] = level_;
+ closers_[nesti_] = closer_;
+ openers_[nesti_] = opener_;
nest_[nesti_++] = PERCENT_STRING;
t_ = NORMAL;
} else if (c == '$') {
@@ -605,7 +638,7 @@ void HighlightRuby::feed(std::string *r, std::string_view input) {
if (c == opener_ && opener_ != closer_) {
lf::append_wchar(r, c);
++level_;
- } else if (c == '#') {
+ } else if (c == '#' && closer_ != '#') {
t_ = PERCENT_HASH;
} else if (c == closer_) {
lf::append_wchar(r, c);
@@ -695,6 +728,9 @@ void HighlightRuby::feed(std::string *r, std::string_view input) {
*r += '{';
*r += HI_RESET;
expect_ = EXPECT_VALUE;
+ levels_[nesti_] = level_;
+ closers_[nesti_] = closer_;
+ openers_[nesti_] = opener_;
nest_[nesti_++] = DQUOTE;
t_ = NORMAL;
} else if (c == '$') {
@@ -847,6 +883,7 @@ void HighlightRuby::feed(std::string *r, std::string_view input) {
t_ = QUESTION_BACKSLASH;
} else if (isspace(c)) {
*r += '?';
+ expect_ = EXPECT_VALUE;
t_ = NORMAL;
goto Normal;
} else {
diff --git a/llamafile/server/www/chatbot.js b/llamafile/server/www/chatbot.js
index bbc656d7..da4a7ed8 100644
--- a/llamafile/server/www/chatbot.js
+++ b/llamafile/server/www/chatbot.js
@@ -21,6 +21,7 @@ const sendButton = document.getElementById("send-button");
const stopButton = document.getElementById("stop-button");
let abortController = null;
+let disableAutoScroll = false;
let streamingMessageContent = [];
let uploadedFiles = [];
@@ -48,7 +49,8 @@ function createMessageElement(content, role) {
}
function scrollToBottom() {
- chatInput.scrollIntoView({behavior: "instant"});
+ if (!disableAutoScroll)
+ document.getElementById("bottom").scrollIntoView({behavior: "instant"});
}
function onChatInput() {
@@ -57,6 +59,7 @@ function onChatInput() {
}
function cleanupAfterMessage() {
+ disableAutoScroll = false;
chatMessages.scrollTop = chatMessages.scrollHeight;
chatInput.disabled = false;
sendButton.style.display = "inline-block";
@@ -65,6 +68,11 @@ function cleanupAfterMessage() {
chatInput.focus();
}
+function onWheel(e) {
+ if (e.deltaY < 0)
+ disableAutoScroll = true;
+}
+
async function handleChatStream(response) {
const reader = response.body.getReader();
const decoder = new TextDecoder();
@@ -314,12 +322,13 @@ function chatbot() {
stopButton.addEventListener("click", stopMessage);
chatInput.addEventListener("input", onChatInput);
chatInput.addEventListener("keydown", onKeyDown);
- document.body.addEventListener('dragenter', onDragBegin, false);
- document.body.addEventListener('dragover', onDragBegin, false);
- document.body.addEventListener('dragleave', onDragEnd, false);
- document.body.addEventListener('drop', onDragEnd, false);
- document.body.addEventListener('drop', onDrop, false);
- document.body.addEventListener('paste', onPaste);
+ document.addEventListener('wheel', onWheel);
+ document.addEventListener('dragenter', onDragBegin);
+ document.addEventListener('dragover', onDragBegin);
+ document.addEventListener('dragleave', onDragEnd);
+ document.addEventListener('drop', onDragEnd);
+ document.addEventListener('drop', onDrop);
+ document.addEventListener('paste', onPaste);
chatInput.focus();
}
diff --git a/llamafile/server/www/highlight_ruby.js b/llamafile/server/www/highlight_ruby.js
index 43a7f03c..2d35f8df 100644
--- a/llamafile/server/www/highlight_ruby.js
+++ b/llamafile/server/www/highlight_ruby.js
@@ -175,8 +175,9 @@ class HighlightRuby extends Highlighter {
static PERCENT_HASH_DOLLAR = 40;
static PERCENT_HASH_DOLLAR_WORD = 41;
- static EXPECT_VALUE = 0;
- static EXPECT_OPERATOR = 1;
+ static EXPECT_EXPR = 0;
+ static EXPECT_VALUE = 1;
+ static EXPECT_OPERATOR = 2;
static mirror(c) {
switch (c) {
@@ -293,8 +294,11 @@ class HighlightRuby extends Highlighter {
this.heredoc = '';
this.word = '';
this.nest = [];
+ this.levels = [];
+ this.openers = [];
+ this.closers = [];
this.is_definition = false;
- this.expect = HighlightRuby.EXPECT_VALUE;
+ this.expect = HighlightRuby.EXPECT_EXPR;
}
feed(input) {
@@ -311,23 +315,23 @@ class HighlightRuby extends Highlighter {
this.is_definition = false;
} else if (c == ':') {
this.state = HighlightRuby.COLON;
- this.expect = HighlightRuby.EXPECT_VALUE;
this.is_definition = false;
} else if (c == '@') {
this.state = HighlightRuby.AT;
+ this.expect = HighlightRuby.EXPECT_VALUE;
this.is_definition = false;
} else if (c == '=') {
this.state = HighlightRuby.EQUAL;
this.expect = HighlightRuby.EXPECT_VALUE;
this.is_definition = false;
- } else if (c == '?' && this.expect == HighlightRuby.EXPECT_VALUE) {
+ } else if (c == '?') {
this.state = HighlightRuby.QUESTION;
this.is_definition = false;
} else if (c == '$') {
this.state = HighlightRuby.DOLLAR;
this.expect = HighlightRuby.EXPECT_OPERATOR;
this.is_definition = false;
- } else if (c == '%' && this.expect == HighlightRuby.EXPECT_VALUE) {
+ } else if (c == '%') {
this.state = HighlightRuby.PERCENT;
this.expect = HighlightRuby.EXPECT_OPERATOR;
this.q = 0;
@@ -352,11 +356,13 @@ class HighlightRuby extends Highlighter {
this.push("span", "comment");
this.append(c);
this.state = HighlightRuby.COMMENT;
- this.expect = HighlightRuby.EXPECT_VALUE;
- } else if (c == '<' && this.expect == HighlightRuby.EXPECT_VALUE) {
+ this.expect = HighlightRuby.EXPECT_EXPR;
+ } else if (c == '<' && (this.expect == HighlightRuby.EXPECT_EXPR ||
+ this.expect == HighlightRuby.EXPECT_VALUE)) {
this.append(c);
this.state = HighlightRuby.LT;
- } else if (c == '/' && this.expect == HighlightRuby.EXPECT_VALUE) {
+ } else if (c == '/' && (this.expect == HighlightRuby.EXPECT_EXPR ||
+ this.expect == HighlightRuby.EXPECT_VALUE)) {
this.state = HighlightRuby.REGEX;
this.push("span", "string");
this.append(c);
@@ -364,15 +370,21 @@ class HighlightRuby extends Highlighter {
this.expect = HighlightRuby.EXPECT_VALUE;
this.append('{');
this.nest.push(HighlightRuby.NORMAL);
+ this.levels.push(this.level);
+ this.openers.push(this.opener);
+ this.closers.push(this.closer);
this.is_definition = false;
} else if (c == '}' && this.nest.length) {
+ this.level = this.levels.pop();
+ this.opener = this.openers.pop();
+ this.closer = this.closers.pop();
if ((this.state = this.nest.pop()) != HighlightRuby.NORMAL)
this.push("span", "string");
this.append('}');
this.expect = HighlightRuby.EXPECT_OPERATOR;
this.is_definition = false;
} else if (c == '\n') {
- this.expect = HighlightRuby.EXPECT_VALUE;
+ this.expect = HighlightRuby.EXPECT_EXPR;
this.append(c);
if (this.pending_heredoc) {
this.push("span", "string");
@@ -380,18 +392,22 @@ class HighlightRuby extends Highlighter {
this.state = HighlightRuby.HEREDOC_BOL;
this.i = 0;
}
- } else if (c == ']') {
- this.expect = HighlightRuby.EXPECT_OPERATOR;
- this.append(']');
- this.is_definition = false;
- } else if (ispunct(c)) {
+ } else if (c == '[' || c == '(') {
this.expect = HighlightRuby.EXPECT_VALUE;
this.append(c);
this.is_definition = false;
+ } else if (c == ']' || c == ')') {
+ this.expect = HighlightRuby.EXPECT_OPERATOR;
+ this.append(c);
+ this.is_definition = false;
} else if (isdigit(c) || c == '.') {
this.expect = HighlightRuby.EXPECT_OPERATOR;
this.append(c);
this.is_definition = false;
+ } else if (ispunct(c)) {
+ this.expect = HighlightRuby.EXPECT_VALUE;
+ this.append(c);
+ this.is_definition = false;
} else if (isspace(c)) {
this.append(c);
} else {
@@ -441,10 +457,13 @@ class HighlightRuby extends Highlighter {
this.append(this.word);
this.pop();
this.expect = HighlightRuby.EXPECT_VALUE;
- if (this.word == 'def') {
+ if (this.word == "def") {
this.is_definition = true;
+ } else if (this.word == "class" || this.word == "module") {
+ this.expect = HighlightRuby.EXPECT_OPERATOR;
}
- } else if (RUBY_BUILTINS.has(this.word)) {
+ } else if (this.expect = HighlightRuby.EXPECT_EXPR &&
+ RUBY_BUILTINS.has(this.word)) {
this.push("span", "builtin");
this.append(this.word);
this.pop();
@@ -492,6 +511,9 @@ class HighlightRuby extends Highlighter {
this.pop();
this.expect = HighlightRuby.EXPECT_VALUE;
this.nest.push(HighlightRuby.REGEX);
+ this.levels.push(this.level);
+ this.openers.push(this.opener);
+ this.closers.push(this.closer);
this.state = HighlightRuby.NORMAL;
} else if (c == '$') {
this.state = HighlightRuby.REGEX_HASH_DOLLAR;
@@ -561,9 +583,15 @@ class HighlightRuby extends Highlighter {
this.push("span", "lispkw");
this.append(':');
this.append(c);
+ this.expect = HighlightRuby.EXPECT_OPERATOR;
this.state = HighlightRuby.COLON_WORD;
+ } else if (c == ':') {
+ this.append("::");
+ this.expect = HighlightRuby.EXPECT_VALUE;
+ this.state = HighlightRuby.NORMAL;
} else {
this.append(':');
+ this.expect = HighlightRuby.EXPECT_VALUE;
this.epsilon(HighlightRuby.NORMAL);
}
break;
@@ -609,9 +637,11 @@ class HighlightRuby extends Highlighter {
this.push("span", "string");
this.append('%');
this.append(c);
+ this.expect = HighlightRuby.EXPECT_OPERATOR;
this.state = HighlightRuby.PERCENT_STRING;
} else {
this.append('%');
+ this.expect = HighlightRuby.EXPECT_VALUE;
this.epsilon(HighlightRuby.NORMAL);
}
break;
@@ -625,11 +655,13 @@ class HighlightRuby extends Highlighter {
this.append('%');
this.append(this.q);
this.append(c);
+ this.expect = HighlightRuby.EXPECT_OPERATOR;
this.state = HighlightRuby.PERCENT_STRING;
} else {
+ this.word += c;
this.append('%');
- this.append(this.q);
- this.epsilon(HighlightRuby.NORMAL);
+ this.is_definition = false;
+ this.epsilon(HighlightRuby.WORD);
}
break;
@@ -642,6 +674,9 @@ class HighlightRuby extends Highlighter {
this.pop();
this.expect = HighlightRuby.EXPECT_VALUE;
this.nest.push(HighlightRuby.PERCENT_STRING);
+ this.levels.push(this.level);
+ this.openers.push(this.opener);
+ this.closers.push(this.closer);
this.state = HighlightRuby.NORMAL;
} else if (c == '$') {
this.state = HighlightRuby.PERCENT_HASH_DOLLAR;
@@ -685,7 +720,7 @@ class HighlightRuby extends Highlighter {
if (c == this.opener && this.opener != this.closer) {
this.append(c);
++this.level;
- } else if (c == '#') {
+ } else if (c == '#' && this.closer != '#') {
this.state = HighlightRuby.PERCENT_HASH;
} else if (c == this.closer) {
this.append(c);
@@ -772,6 +807,9 @@ class HighlightRuby extends Highlighter {
this.pop();
this.expect = HighlightRuby.EXPECT_VALUE;
this.nest.push(HighlightRuby.DQUOTE);
+ this.levels.push(this.level);
+ this.openers.push(this.opener);
+ this.closers.push(this.closer);
this.state = HighlightRuby.NORMAL;
} else if (c == '$') {
this.state = HighlightRuby.DQUOTE_HASH_DOLLAR;
@@ -917,6 +955,7 @@ class HighlightRuby extends Highlighter {
this.state = HighlightRuby.QUESTION_BACKSLASH;
} else if (isspace(c)) {
this.append('?');
+ this.expect = HighlightRuby.EXPECT_VALUE;
this.epsilon(HighlightRuby.NORMAL);
} else {
this.push('span', 'escape');
diff --git a/llamafile/server/www/index.html b/llamafile/server/www/index.html
index a34aa094..8866a784 100644
--- a/llamafile/server/www/index.html
+++ b/llamafile/server/www/index.html
@@ -21,6 +21,7 @@
<button class="stop-button" id="stop-button" style="display:none">Stop</button>
</div>
</div>
+<div id="bottom"></div>
<script src="ctype.js"></script>
<script src="clipboard.js"></script>
diff --git a/llamafile/server/www/test/test.md b/llamafile/server/www/test/test.md
index 32ee9ee5..37823964 100644
--- a/llamafile/server/www/test/test.md
+++ b/llamafile/server/www/test/test.md
@@ -169,49 +169,216 @@ demonstrates basic input/output operations and error handling.
## Rubby
```ruby
-# comment
-42
-"String with #{ :interpolation }"
-/regex$/
-$/
-[?😀, ?\ , ?', ?(] ?'a':'b'
-"%d %d %d"%[1,2,3]
-% 5 #
-
-/
-$$#$/
-/omix
-
-puts <<HERE<<<<THERE
-foo 42
-HERE
-bla 43
-THERE
-
-puts "This is #{<<HERE.strip} evil"
-incredibly
-HERE
-
-def `
- `hello` / /regex/
+# This is a single-line comment
+
+bone
+c = p / r
+puts puts
+%q#hi#
+module RDoc::Parser::RubyTools
+
+Bundler.ui.info <<-EOS.gsub(/^ {8}/, "")
+--- ERROR REPORT TEMPLATE -------------------------------------------------------
+# Error Report
+EOS
+
+=begin ho
+This is a
+multi-line comment
+=end yo
+
+bone
+
+# String literals
+single_quoted = 'Hello, Ruby!'
+double_quoted = "Hello, Ruby!"
+
+# String interpolation (only works with double quotes)
+name = "Alice"
+greeting = "Hello, #{name}!"
+
+# Heredoc syntax
+long_text = <<-EOT
+ This is a long piece of text.
+ It can span multiple lines.
+ Indentation is preserved.
+EOT
+
+# Flexible quoting
+ha = %
+ha = %q
+flexible_quote = %q{This is a single-quoted string}
+another_flexible = %Q{This is a double-quoted string with #{name}}
+
+# String methods
+upcase_string = "hello".upcase
+downcase_string = "WORLD".downcase
+capitalize_string = "ruby".capitalize
+
+# String concatenation
+concat_string = "Hello " + "World"
+concat_with_shovel = "Hello " << "Ruby"
+
+# Symbols (immutable strings, often used as hash keys)
+symbol = :my_symbol
+
+def is_prime?(num)
+ return false if num <= 1
+ (2..Math.sqrt(num)).each do |i|
+ return false if num % i == 0
+ end
+ true
end
-"hi #$" there" a
-"hi #$abc there" a
-"hi #{hi} there" a
-/hi #$" there/ a
-/hi #$abc there/ a
-/hi #{hi} there/ a
-_=;"#$q"
-
-# Examples:
-%q(Don't worry) # => "Don't worry"
-%Q(Today is #{Date.today}) # => "Today is 2024-11-08"
-%r{^/path/to/\w+} # => /^\/path\/to\/\w+/
-%s(my_symbol) # => :my_symbol
-%w(foo bar baz) # => ["foo", "bar", "baz"]
-%W(foo #{1+1} baz) # => ["foo", "2", "baz"]
-%x(ls -l) # Executes `ls -l` and returns output
-%i(foo bar baz) # => [:foo, :bar, :baz]
-%I(foo#{1+1} bar baz) # => [:foo2, :bar, :baz]
+count = 0
+num = 2
+num = ?h
+dog = :!hi
+
+while count < 10
+ if is_prime?(num)
+ puts num
+ count += 1
+ end
+ num += 1
+end
+
+puts /hi/
+dog /hi/
+
+exit
+dog = $ h $$ h $@ h $! h $/ h $_ h $= e @ e $\ e $` e $< e $> e $' e
+dog = @hi
+dog = @@hi
+dog = $hi ${hi}
+dog = "h\"i"
+dog = 'h\'i'
+dog = `hi\`hi`
+
+print <<'woffle end'
+Hello, world!
+woffle end
+
+print <<''
+Hello, world!
+
+print <<END;
+Hello, world!
+END
+
+print <<ez
+Hello, world!
+ez
+
+print <<"end"
+Hello, world!
+end
+
+print <<`CODE`
+Hello, world!
+CODE
+
+print <<END1, <<END2;
+First heredoc
+END1
+Second heredoc
+END2
+
+ print <<-EOF
+ hello
+ there
+ EOF
+
+ print <<-'EOF'
+ hello
+ there
+ EOF
+
+print "hi"
+
+require 'hi'
+
+print $# hi
+
+if @yaml_config
+ require 'yaml'
+ cfg = YAML.load_file(HERE + @yaml_config)[:generate_module]
+ @path_src = cfg[:defaults][:path_src] if nil?
+ @path_inc = cfg[:defaults][:path_inc] if @path_inc.nil?
+ @path_tst = cfg[:defaults][:path_tst] if @path_tst.nil?
+ @update_svn = cfg[:defaults][:update_svn] if @update_svn.nil?
+ @extra_inc = cfg[:includes]
+ @boilerplates = cfg[:boilerplates]
+else
+ @boilerplates = {}
+end
+
+ugh %q(ugh (hi) ugh) ugh
+ugh %q!ugh hi ugh! ugh
+ugh %q#ugh hi ugh# ugh
+ugh %q<ugh hi ugh> ugh
+ugh %/augh hi ugh/ ugh
+
+/hi/i
+
+if line =~ /^((?:\s*TEST_\/CASE\s*\(.*?\)\s*)*)\s*void\s+((?:#{@options[:test_prefix]}).*)\s*\(\s*(.*)\s*\)/i
+ arguments = $1
+ name = $2
+ call = $3
+ args = nil
+ if (@options[:use_param_tests] and !arguments.empty?)
+ args = []
+ arguments.scan(/\s*TEST_CASE\s*\((.*)\)\s*$/) {|a| args << a[0]}
+ end
+ tests_and_line_numbers << { :test => name, :args => args, :call => call, :line_number => 0 }
+end
+
+ mk << %{
+SHELL = /bin/sh
+
+# V=0 quiet, V=1 verbose. other values don't work.
+V = 0
+Q1 = $(V:1=)
+Q = $(Q1:0=@)
+ECHO1 = $(V:1=@ #{CONFIG['NULLCMD']})
+ECHO = $(ECHO1:0=@ echo)
+NULLCMD = #{CONFIG['NULLCMD']}
+
+#### Start of system configuration section. ####
+#{"top_srcdir = " + $top_srcdir.sub(%r"\A#{Regexp.quote($topdir)}/", "$(topdir)/") if $extmk}
+srcdir = #{srcdir.gsub(/\$\((srcdir)\)|\$\{(srcdir)\}/) {mkintpath(CONFIG[$1||$2]).unspace}}
+topdir = #{mkintpath(topdir = $extmk ? CONFIG["topdir"] : $topdir).unspace}
+hdrdir = #{(hdrdir = CONFIG["hdrdir"]) == topdir ? "$(topdir)" : mkintpath(hdrdir).unspace}
+arch_hdrdir = #{$arch_hdrdir.quote}
+PATH_SEPARATOR = #{CONFIG['PATH_SEPARATOR']}
+VPATH = #{vpath.join(CONFIG['PATH_SEPARATOR'])}
+}
+
+class SimpleScanner < Scanner # :nodoc:
+ def scan
+ stag_reg = (stags == DEFAULT_STAGS) ? /(.*?)(<%[%=#]?|\z)/m : /(.*?)(#{stags.join('|')}|\z)/m
+ etag_reg = (etags == DEFAULT_ETAGS) ? /(.*?)(%%?>|\z)/m : /(.*?)(#{etags.join('|')}|\z)/m
+ scanner = StringScanner.new(@src)
+ while ! scanner.eos?
+ scanner.scan(@stag ? etag_reg : stag_reg)
+ yield(scanner[1])
+ yield(scanner[2])
+ end
+ end
+end
+
+ ARGV.reject! do |arg|
+ case(arg)
+ when '-cexception'
+ options[:plugins] = [:cexception]; true
+ when /\.*\.ya?ml/
+
+ options = UnityTestRunnerGenerator.grab_config(arg); true
+ when /\.*\.h/
+ options[:includes] <<arg; true
+ when /--(\w+)=\"?(.*)\"?/
+ options[$1.to_sym] = $2; true
+ else false
+ end
+ end
```